Example usage for org.eclipse.jdt.core IJavaProject exists

List of usage examples for org.eclipse.jdt.core IJavaProject exists

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaProject exists.

Prototype

boolean exists();

Source Link

Document

Returns whether this Java element exists in the model.

Usage

From source file:com.iw.plugins.spindle.core.eclipse.TapestryProject.java

License:Mozilla Public License

public Object getAdapter(Class adapter) {
    if (adapter == ITapestryProject.class)
        return this;

    if (adapter == IProject.class)
        return fProject;

    if (adapter == IJavaProject.class) {
        IJavaProject jproject = JavaCore.create(fProject);
        if (jproject.exists())
            return jproject;
    }// w w  w.  j av  a2 s.  c  o m

    return null;
}

From source file:com.liferay.ide.core.util.FileUtil.java

License:Open Source License

public static boolean exists(IJavaProject project) {
    if ((project != null) && project.exists()) {
        return true;
    }//  ww w  . j av a  2  s. co  m

    return false;
}

From source file:com.liferay.ide.core.util.FileUtil.java

License:Open Source License

public static boolean notExists(IJavaProject project) {
    if ((project == null) || !project.exists()) {
        return true;
    }//from   ww w.ja  va 2  s. c  o m

    return false;
}

From source file:com.liferay.ide.portlet.core.descriptor.PortletDescriptorValidator.java

License:Open Source License

@SuppressWarnings("deprecation")
@Override//  w ww .  j a  v a 2 s  .c  o  m
public ValidationResult validate(IResource resource, int kind, ValidationState state,
        IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE) {
        return null;
    }

    ValidationResult result = new ValidationResult();

    IFile portletXml = (IFile) resource;

    if (portletXml.isAccessible() && ProjectUtil.isPortletProject(resource.getProject())) {
        final IJavaProject javaProject = JavaCore.create(portletXml.getProject());

        if (javaProject.exists()) {
            IScopeContext[] scopes = new IScopeContext[] { new InstanceScope(), new DefaultScope() };

            ProjectScope projectScope = new ProjectScope(portletXml.getProject());

            boolean useProjectSettings = projectScope.getNode(PREFERENCE_NODE_QUALIFIER)
                    .getBoolean(LiferayProjectCore.USE_PROJECT_SETTINGS, false);

            if (useProjectSettings) {
                scopes = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
            }

            try {
                Map<String, Object>[] problems = detectProblems(javaProject, portletXml, scopes);

                for (int i = 0; i < problems.length; i++) {
                    ValidatorMessage message = ValidatorMessage
                            .create(problems[i].get(IMarker.MESSAGE).toString(), resource);
                    message.setType(MARKER_TYPE);
                    message.setAttributes(problems[i]);
                    result.add(message);
                }
            } catch (Exception e) {
                PortletCore.logError(e);
            }
        }
    }

    return result;
}

From source file:com.liferay.ide.portlet.ui.editor.PortletURLHyperlinkDetector.java

License:Open Source License

private IMethod[] findPortletMethods(IDocument document, String nameValue) {
    IMethod[] retval = null;//from   w  w  w. j  av  a 2  s . com

    final IFile file = DOMUtils.getFile(document);

    if (file != null && file.exists()) {
        final IJavaProject project = JavaCore.create(file.getProject());

        if (project != null && project.exists()) {
            try {
                final IType portlet = project.findType("javax.portlet.Portlet");

                if (portlet != null) {
                    final List<IMethod> methods = new ArrayList<IMethod>();
                    final SearchRequestor requestor = new ActionMethodCollector(methods);

                    final IJavaSearchScope scope = SearchEngine.createStrictHierarchyScope(project, portlet,
                            true, false, null);

                    final SearchPattern search = SearchPattern.createPattern(nameValue,
                            IJavaSearchConstants.METHOD, IJavaSearchConstants.DECLARATIONS,
                            SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);

                    new SearchEngine().search(search,
                            new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
                            requestor, new NullProgressMonitor());

                    retval = methods.toArray(new IMethod[0]);
                }
            } catch (JavaModelException e) {
            } catch (CoreException e) {
            }
        }
    }

    return retval;
}

From source file:com.liferay.ide.portlet.ui.util.NodeUtils.java

License:Open Source License

public static MessageKey[] findMessageKeys(IDocument document, String key, boolean loadValues) {
    MessageKey[] retval = null;/*from w  ww  . ja v  a2  s .co  m*/

    final IFile file = DOMUtils.getFile(document);

    if (file != null && file.exists()) {
        final IJavaProject project = JavaCore.create(file.getProject());

        if (project != null && project.exists()) {
            final List<MessageKey> keys = new ArrayList<MessageKey>();

            for (final IFolder src : CoreUtil.getSourceFolders(project)) {
                if (src.exists()) {
                    final IFile[] props = PropertiesUtil.visitPropertiesFiles(src, ".*");

                    for (final IFile prop : props) {
                        try {
                            final KeyInfo info = new PropertiesFileLookup(prop.getContents(), key, loadValues)
                                    .getKeyInfo(key);

                            if (info != null && info.offset >= 0) {
                                keys.add(new MessageKey(prop, key, info.offset, info.length, info.value));
                            }
                        } catch (CoreException e) {
                        }
                    }
                }
            }

            retval = keys.toArray(new MessageKey[0]);
        }
    }

    return retval;
}

From source file:com.liferay.ide.service.core.descriptor.ServiceBuilderDescriptorValidator.java

License:Open Source License

@SuppressWarnings("deprecation")
@Override//w  ww  .j ava 2s.co  m
public ValidationResult validate(IResource resource, int kind, ValidationState state,
        IProgressMonitor monitor) {
    if (resource.getType() != IResource.FILE) {
        return null;
    }

    ValidationResult result = new ValidationResult();

    IFile serviceXml = (IFile) resource;

    if (serviceXml.isAccessible() && ProjectUtil.isPortletProject(resource.getProject())) {
        final IJavaProject javaProject = JavaCore.create(serviceXml.getProject());

        if (javaProject.exists()) {
            IScopeContext[] scopes = new IScopeContext[] { new InstanceScope(), new DefaultScope() };

            ProjectScope projectScope = new ProjectScope(serviceXml.getProject());

            boolean useProjectSettings = projectScope.getNode(PREFERENCE_NODE_QUALIFIER)
                    .getBoolean(LiferayProjectCore.USE_PROJECT_SETTINGS, false);

            if (useProjectSettings) {
                scopes = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
            }

            try {
                Map<String, Object>[] problems = detectProblems(javaProject, serviceXml, scopes);

                for (int i = 0; i < problems.length; i++) {
                    ValidatorMessage message = ValidatorMessage
                            .create(problems[i].get(IMarker.MESSAGE).toString(), resource);
                    message.setType(MARKER_TYPE);
                    message.setAttributes(problems[i]);
                    result.add(message);
                }
            } catch (Exception e) {
                ServiceCore.logError(e);
            }
        }
    }

    return result;
}

From source file:com.redhat.ceylon.eclipse.code.explorer.PackageExplorerContentProvider.java

License:Open Source License

private boolean isOnClassPath(ICompilationUnit element) {
    IJavaProject project = element.getJavaProject();
    if (project == null || !project.exists())
        return false;
    return project.isOnClasspath(element);
}

From source file:com.redhat.ceylon.eclipse.code.explorer.PackageExplorerPart.java

License:Open Source License

private Object convertElement(Object original) {
    if (original instanceof IJavaElement) {
        if (original instanceof ICompilationUnit) {
            ICompilationUnit cu = (ICompilationUnit) original;
            IJavaProject javaProject = cu.getJavaProject();
            if (javaProject != null && javaProject.exists() && !javaProject.isOnClasspath(cu)) {
                // could be a working copy of a .java file that is not on classpath
                IResource resource = cu.getResource();
                if (resource != null)
                    return resource;
            }//from   ww  w.  j  a  v a  2 s.c  o m

        }
        return original;

    } else if (original instanceof IResource) {
        IJavaElement je = JavaCore.create((IResource) original);
        if (je != null && je.exists()) {
            IJavaProject javaProject = je.getJavaProject();
            if (javaProject != null && javaProject.exists()) {
                if (javaProject.equals(je) || javaProject.isOnClasspath(je)) {
                    return je;
                } else {
                    // a working copy of a .java file that is not on classpath
                    return original;
                }
            }
        }
    } else if (original instanceof IAdaptable) {
        IAdaptable adaptable = (IAdaptable) original;
        IJavaElement je = (IJavaElement) adaptable.getAdapter(IJavaElement.class);
        if (je != null && je.exists())
            return je;

        IResource r = (IResource) adaptable.getAdapter(IResource.class);
        if (r != null) {
            je = JavaCore.create(r);
            if (je != null && je.exists())
                return je;
            else
                return r;
        }
    }
    return original;
}

From source file:com.redhat.ceylon.eclipse.code.wizard.CapabilityConfigurationPage.java

License:Open Source License

/**
 * Initializes the page with the project and default classpath.
 * <p>/*from w  w  w.j  a  v a 2 s. c o m*/
 * The default classpath entries must correspond the given project.
 * </p>
 * <p>
 * The caller of this method is responsible for creating the underlying project. The page will create the output,
 * source and library folders if required.
 * </p>
 * <p>
 * The project does not have to exist at the time of initialization, but must exist when executing the runnable
 * obtained by <code>getRunnable()</code>.
 * </p>
 * @param jproject The Java project.
 * @param defaultOutputLocation The default classpath entries or <code>null</code> to let the page choose the default
 * @param defaultEntries The folder to be taken as the default output path or <code>null</code> to let the page choose the default
 * @param defaultsOverrideExistingClasspath If set to <code>true</code>, an existing '.classpath' file is ignored. If set to <code>false</code>
 * the given default classpath and output location is only used if no '.classpath' exists.
 */
public void init(IJavaProject jproject, IPath defaultJavaOutputLocation, IClasspathEntry[] defaultEntries,
        boolean defaultsOverrideExistingClasspath) {
    if (!defaultsOverrideExistingClasspath && jproject.exists()
            && jproject.getProject().getFile(".classpath").exists()) { //$NON-NLS-1$
        defaultJavaOutputLocation = null;
        defaultEntries = null;
    }
    getBuildPathsBlock().init(jproject, defaultJavaOutputLocation, defaultEntries);
    fJavaProject = jproject;
}