Example usage for org.eclipse.jdt.core IClasspathEntry getEntryKind

List of usage examples for org.eclipse.jdt.core IClasspathEntry getEntryKind

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IClasspathEntry getEntryKind.

Prototype

int getEntryKind();

Source Link

Document

Returns the kind of this classpath entry.

Usage

From source file:org.eclipse.buildship.core.workspace.internal.LibraryFilter.java

License:Open Source License

private static IClasspathEntry[] filterLibraries(IClasspathEntry[] classpath) throws JavaModelException {
    return FluentIterable.from(Arrays.asList(classpath)).filter(new Predicate<IClasspathEntry>() {

        @Override/*from  w  w w .j  a  v  a 2 s.com*/
        public boolean apply(IClasspathEntry entry) {
            return entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY;
        }
    }).toArray(IClasspathEntry.class);
}

From source file:org.eclipse.buildship.core.workspace.internal.WtpClasspathUpdater.java

License:Open Source License

private static boolean isGradleClasspathContainer(IClasspathEntry entry) {
    return entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
            && entry.getPath().equals(GradleClasspathContainer.CONTAINER_PATH);
}

From source file:org.eclipse.che.jdt.internal.core.JavaModelManager.java

License:Open Source License

/**
 * Returns the package fragment root represented by the resource, or
 * the package fragment the given resource is located in, or <code>null</code>
 * if the given resource is not on the classpath of the given project.
 *///from   www .  j a  v a2 s.c  om
public static IJavaElement determineIfOnClasspath(File resource, JavaProject project) {
    IPath resourcePath = new Path(resource.getAbsolutePath());
    boolean isExternal = false; //ExternalFoldersManager.isInternalPathForExternalFolder(resourcePath);
    //        if (isExternal)
    //            resourcePath = resource.getLocation();

    try {
        JavaProjectElementInfo projectInfo = (JavaProjectElementInfo) ((JavaProject) project).manager
                .getInfo(project);
        JavaProjectElementInfo.ProjectCache projectCache = projectInfo == null ? null
                : projectInfo.projectCache;
        HashtableOfArrayToObject allPkgFragmentsCache = projectCache == null ? null
                : projectCache.allPkgFragmentsCache;
        boolean isJavaLike = Util.isJavaLikeFileName(resourcePath.lastSegment());
        IClasspathEntry[] entries = isJavaLike ? project.getRawClasspath() // JAVA file can only live inside SRC folder (on the raw path)
                : ((JavaProject) project).getResolvedClasspath();

        int length = entries.length;
        if (length > 0) {
            String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true);
            String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
            for (int i = 0; i < length; i++) {
                IClasspathEntry entry = entries[i];
                if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT)
                    continue;
                IPath rootPath = entry.getPath();
                if (rootPath.equals(resourcePath)) {
                    if (isJavaLike)
                        return null;
                    return project.getPackageFragmentRoot(resource);
                } else if (rootPath.isPrefixOf(resourcePath)) {
                    // allow creation of package fragment if it contains a .java file that is included
                    if (!Util.isExcluded(resourcePath, ((ClasspathEntry) entry).fullInclusionPatternChars(),
                            ((ClasspathEntry) entry).fullExclusionPatternChars(), true)) {
                        // given we have a resource child of the root, it cannot be a JAR pkg root
                        PackageFragmentRoot root =
                                //                                    isExternal ?
                                //                                    new ExternalPackageFragmentRoot(rootPath, (JavaProject) project) :
                                (PackageFragmentRoot) ((JavaProject) project)
                                        .getFolderPackageFragmentRoot(rootPath);
                        if (root == null)
                            return null;
                        IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount());

                        if (resource.isFile()) {
                            // if the resource is a file, then remove the last segment which
                            // is the file name in the package
                            pkgPath = pkgPath.removeLastSegments(1);
                        }
                        String[] pkgName = pkgPath.segments();

                        // if package name is in the cache, then it has already been validated
                        // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=133141)
                        if (allPkgFragmentsCache != null && allPkgFragmentsCache.containsKey(pkgName))
                            return root.getPackageFragment(pkgName);

                        if (pkgName.length != 0 && JavaConventions
                                .validatePackageName(Util.packageName(pkgPath, sourceLevel, complianceLevel),
                                        sourceLevel, complianceLevel)
                                .getSeverity() == IStatus.ERROR) {
                            return null;
                        }
                        return root.getPackageFragment(pkgName);
                    }
                }
            }
        }
    } catch (JavaModelException npe) {
        return null;
    }
    return null;
}

From source file:org.eclipse.che.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * This is a helper method returning the resolved classpath for the project
 * as a list of simple (non-variable, non-container) classpath entries.
 * All classpath variable and classpath container entries in the project's
 * raw classpath will be replaced by the simple classpath entries they
 * resolve to.// w  ww . j av a 2s .  c o  m
 * <p>
 * The resulting resolved classpath is accurate for the given point in time.
 * If the project's raw classpath is later modified, or if classpath
 * variables are changed, the resolved classpath can become out of date.
 * Because of this, hanging on resolved classpath is not recommended.
 * </p>
 * <p>
 * Note that if the resolution creates duplicate entries
 * (i.e. {@link IClasspathEntry entries} which are {@link Object#equals(Object)}),
 * only the first one is added to the resolved classpath.
 * </p>
 *
 * @see IClasspathEntry
 */
public IClasspathEntry[] getResolvedClasspath() throws JavaModelException {
    if (resolvedClasspath == null) {
        ResolvedClasspath result = new ResolvedClasspath();
        LinkedHashSet<IClasspathEntry> resolvedEntries = new LinkedHashSet<>();
        for (IClasspathEntry entry : getRawClasspath()) {
            switch (entry.getEntryKind()) {
            case IClasspathEntry.CPE_LIBRARY:
            case IClasspathEntry.CPE_SOURCE:
                addToResult(entry, entry, result, resolvedEntries);
                break;
            case IClasspathEntry.CPE_CONTAINER:
                IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), this);
                for (IClasspathEntry classpathEntry : container.getClasspathEntries()) {
                    addToResult(entry, classpathEntry, result, resolvedEntries);
                }
                break;
            }
        }
        result.resolvedClasspath = new IClasspathEntry[resolvedEntries.size()];
        resolvedEntries.toArray(result.resolvedClasspath);
        resolvedClasspath = result;
    }

    return resolvedClasspath.resolvedClasspath;
}

From source file:org.eclipse.che.jdt.internal.core.JavaProject.java

License:Open Source License

/**
 * Returns the package fragment roots identified by the given entry. In case it refers to
 * a project, it will follow its classpath so as to find exported roots as well.
 * Only works with resolved entry/* w ww. j ava  2  s. co m*/
 *
 * @param resolvedEntry
 *         IClasspathEntry
 * @param accumulatedRoots
 *         ObjectVector
 * @param rootIDs
 *         HashSet
 * @param referringEntry
 *         the CP entry (project) referring to this entry, or null if initial project
 * @param retrieveExportedRoots
 *         boolean
 * @throws JavaModelException
 */
public void computePackageFragmentRoots(IClasspathEntry resolvedEntry, ObjectVector accumulatedRoots,
        HashSet rootIDs, IClasspathEntry referringEntry, boolean retrieveExportedRoots,
        Map rootToResolvedEntries) throws JavaModelException {

    String rootID = ((ClasspathEntry) resolvedEntry).rootID();
    if (rootIDs.contains(rootID))
        return;

    IPath projectPath = this.getFullPath();
    IPath entryPath = resolvedEntry.getPath();
    //        IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
    IPackageFragmentRoot root = null;

    switch (resolvedEntry.getEntryKind()) {

    // source folder
    case IClasspathEntry.CPE_SOURCE:

        //                if (projectPath.isPrefixOf(entryPath)) {
        Object target1 = JavaModelManager.getTarget(entryPath, true/*check existency*/);
        if (target1 == null)
            return;

        if (target1 instanceof File && ((File) target1).isDirectory()) {
            root = getPackageFragmentRoot((File) target1);
        }
        //                }
        break;

    // internal/external JAR or folder
    case IClasspathEntry.CPE_LIBRARY:
        if (referringEntry != null && !resolvedEntry.isExported())
            return;
        Object target = JavaModelManager.getTarget(entryPath, true/*check existency*/);
        if (target == null)
            return;

        //                if (target instanceof IResource){
        //                    // internal target
        //                } else
        if (target instanceof File) {
            // external target
            if (JavaModelManager.isFile(target)) {
                root = new JarPackageFragmentRoot((File) target, this, manager);
            } else if (((File) target).isDirectory()) {
                root = getPackageFragmentRoot((File) target, entryPath);
                //                        root = new ExternalPackageFragmentRoot(entryPath, this);
            }
        }
        break;

    // recurse into required project
    case IClasspathEntry.CPE_PROJECT:

        if (!retrieveExportedRoots)
            return;
        if (referringEntry != null && !resolvedEntry.isExported())
            return;
        //todo multiproject
        //                IResource member = workspaceRoot.findMember(entryPath);
        //                if (member != null && member.getType() == IResource.PROJECT) {// double check if bound to project (23977)
        //                    IProject requiredProjectRsc = (IProject)member;
        //                    if (JavaProject.hasJavaNature(requiredProjectRsc)) { // special builder binary output
        //                        rootIDs.add(rootID);
        //                        JavaProject requiredProject = (JavaProject)JavaCore.create(requiredProjectRsc);
        //                        requiredProject.computePackageFragmentRoots(
        //                                requiredProject.getResolvedClasspath(),
        //                                accumulatedRoots,
        //                                rootIDs,
        //                                rootToResolvedEntries == null ? resolvedEntry
        //                                                              : ((org.eclipse.jdt.internal.core.ClasspathEntry)resolvedEntry)
        //                                        .combineWith((org.eclipse.jdt.internal.core.ClasspathEntry)referringEntry),
        //                                // only combine if need to build the reverse map
        //                                retrieveExportedRoots,
        //                                rootToResolvedEntries);
        //                    }
        //                    break;
        //                }
    }
    if (root != null) {
        accumulatedRoots.add(root);
        rootIDs.add(rootID);
        if (rootToResolvedEntries != null)
            rootToResolvedEntries.put(root,
                    ((ClasspathEntry) resolvedEntry).combineWith((ClasspathEntry) referringEntry));
    }
}

From source file:org.eclipse.che.jdt.internal.core.search.IndexSelector.java

License:Open Source License

/**
 * Returns whether elements of the given project or jar can see the given focus (an IJavaProject or
 * a JarPackageFragmentRot) either because the focus is part of the project or the jar, or because it is
 * accessible throught the project's classpath
 *///from   ww  w  .  j a  v  a  2s  .  c  om
public static int canSeeFocus(SearchPattern pattern, IPath projectOrJarPath) {
    try {
        IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
        IJavaProject project = getJavaProject(projectOrJarPath, model);
        IJavaElement[] focuses = getFocusedElementsAndTypes(pattern, project, null);
        if (focuses.length == 0)
            return PROJECT_CAN_NOT_SEE_FOCUS;
        if (project != null) {
            return canSeeFocus(focuses, (JavaProject) project, null);
        }

        // projectOrJarPath is a jar
        // it can see the focus only if it is on the classpath of a project that can see the focus
        int result = PROJECT_CAN_NOT_SEE_FOCUS;
        IJavaProject[] allProjects = model.getJavaProjects();
        for (int i = 0, length = allProjects.length; i < length; i++) {
            JavaProject otherProject = (JavaProject) allProjects[i];
            IClasspathEntry entry = otherProject.getClasspathEntryFor(projectOrJarPath);
            if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                int canSeeFocus = canSeeFocus(focuses, otherProject, null);
                if (canSeeFocus == PROJECT_CAN_SEE_FOCUS)
                    return PROJECT_CAN_SEE_FOCUS;
                if (canSeeFocus == PROJECT_SOURCE_CAN_NOT_SEE_FOCUS)
                    result = PROJECT_SOURCE_CAN_NOT_SEE_FOCUS;
            }
        }
        return result;
    } catch (JavaModelException e) {
        return PROJECT_CAN_NOT_SEE_FOCUS;
    }
}

From source file:org.eclipse.che.jdt.internal.core.search.IndexSelector.java

License:Open Source License

private static int canSeeFocus(IJavaElement focus, JavaProject javaProject, char[][][] focusQualifiedNames) {
    try {//from www .ja  v a 2  s  . c  o  m
        if (focus == null)
            return PROJECT_CAN_NOT_SEE_FOCUS;
        if (focus.equals(javaProject))
            return PROJECT_CAN_SEE_FOCUS;

        if (focus instanceof JarPackageFragmentRoot) {
            // focus is part of a jar
            IPath focusPath = focus.getPath();
            IClasspathEntry[] entries = javaProject.getExpandedClasspath();
            for (int i = 0, length = entries.length; i < length; i++) {
                IClasspathEntry entry = entries[i];
                if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(focusPath))
                    return PROJECT_CAN_SEE_FOCUS;
            }
            return PROJECT_CAN_NOT_SEE_FOCUS;
        }
        // look for dependent projects
        IPath focusPath = ((JavaProject) focus).getProject().getFullPath();
        IClasspathEntry[] entries = javaProject.getExpandedClasspath();
        for (int i = 0, length = entries.length; i < length; i++) {
            IClasspathEntry entry = entries[i];
            if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && entry.getPath().equals(focusPath)) {
                if (focusQualifiedNames != null) { // builder state is usable, hence use it to try to reduce project which can see the focus...
                    State projectState = (State) JavaModelManager.getJavaModelManager()
                            .getLastBuiltState(javaProject.getProject(), null);
                    if (projectState != null) {
                        Object[] values = projectState.getReferences().valueTable;
                        int vLength = values.length;
                        for (int j = 0; j < vLength; j++) {
                            if (values[j] == null)
                                continue;
                            ReferenceCollection references = (ReferenceCollection) values[j];
                            if (references.includes(focusQualifiedNames, null, null)) {
                                return PROJECT_CAN_SEE_FOCUS;
                            }
                        }
                        return PROJECT_SOURCE_CAN_NOT_SEE_FOCUS;
                    }
                }
                return PROJECT_CAN_SEE_FOCUS;
            }
        }
        return PROJECT_CAN_NOT_SEE_FOCUS;
    } catch (JavaModelException e) {
        return PROJECT_CAN_NOT_SEE_FOCUS;
    }
}

From source file:org.eclipse.che.jdt.internal.core.search.IndexSelector.java

License:Open Source License

private void initializeIndexLocations() {
    IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars();
    // use a linked set to preserve the order during search: see bug 348507
    LinkedHashSet locations = new LinkedHashSet();
    IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern);
    if (focus == null) {
        for (int i = 0; i < projectsAndJars.length; i++) {
            IPath path = projectsAndJars[i];
            Object target = new File(path.toOSString());//JavaModel.getTarget(path, false/*don't check existence*/);
            if (target instanceof IFolder) // case of an external folder
                path = ((IFolder) target).getFullPath();
            locations.add(indexManager.computeIndexLocation(path));
        }//from   ww w  .j av  a 2  s  . co  m
    } else {
        try {
            // See whether the state builder might be used to reduce the number of index locations

            // find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars
            int length = projectsAndJars.length;
            JavaProject[] projectsCanSeeFocus = new JavaProject[length];
            SimpleSet visitedProjects = new SimpleSet(length);
            int projectIndex = 0;
            SimpleSet externalLibsToCheck = new SimpleSet(length);
            ObjectVector superTypes = new ObjectVector();
            IJavaElement[] focuses = getFocusedElementsAndTypes(this.pattern, focus, superTypes);
            char[][][] focusQualifiedNames = null;
            boolean isAutoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
            if (isAutoBuilding && focus instanceof IJavaProject) {
                focusQualifiedNames = getQualifiedNames(superTypes);
            }
            IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel();
            for (int i = 0; i < length; i++) {
                IPath path = projectsAndJars[i];
                JavaProject project = (JavaProject) getJavaProject(path, model);
                if (project != null) {
                    visitedProjects.add(project);
                    int canSeeFocus = canSeeFocus(focuses, project, focusQualifiedNames);
                    if (canSeeFocus == PROJECT_CAN_SEE_FOCUS) {
                        locations.add(indexManager.computeIndexLocation(path));
                    }
                    if (canSeeFocus != PROJECT_CAN_NOT_SEE_FOCUS) {
                        projectsCanSeeFocus[projectIndex++] = project;
                    }
                } else {
                    externalLibsToCheck.add(path);
                }
            }
            for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) {
                IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath();
                for (int j = entries.length; --j >= 0;) {
                    IClasspathEntry entry = entries[j];
                    if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                        IPath path = entry.getPath();
                        if (externalLibsToCheck.remove(path) != null) {
                            Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                            if (target instanceof IFolder) // case of an external folder
                                path = ((IFolder) target).getFullPath();
                            locations.add(indexManager.computeIndexLocation(path));
                        }
                    }
                }
            }
            // jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited
            if (externalLibsToCheck.elementSize > 0) {
                IJavaProject[] allProjects = model.getJavaProjects();
                for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) {
                    JavaProject project = (JavaProject) allProjects[i];
                    if (!visitedProjects.includes(project)) {
                        IClasspathEntry[] entries = project.getResolvedClasspath();
                        for (int j = entries.length; --j >= 0;) {
                            IClasspathEntry entry = entries[j];
                            if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                                IPath path = entry.getPath();
                                if (externalLibsToCheck.remove(path) != null) {
                                    Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                                    if (target instanceof IFolder) // case of an external folder
                                        path = ((IFolder) target).getFullPath();
                                    locations.add(indexManager.computeIndexLocation(path));
                                }
                            }
                        }
                    }
                }
            }
        } catch (JavaModelException e) {
            // ignored
        }
    }

    locations.remove(null); // Ensure no nulls
    this.indexLocations = (IndexLocation[]) locations.toArray(new IndexLocation[locations.size()]);
}

From source file:org.eclipse.che.jdt.internal.core.search.JavaSearchScope.java

License:Open Source License

/**
 * Add a path to current java search scope or all project fragment roots if null.
 * Use project resolved classpath to retrieve and store access restriction on each classpath entry.
 * Recurse if dependent projects are found.
 *
 * @param javaProject/*from   w  w  w.ja v a  2  s  . c  o  m*/
 *         Project used to get resolved classpath entries
 * @param pathToAdd
 *         Path to add in case of single element or null if user want to add all project package fragment roots
 * @param includeMask
 *         Mask to apply on classpath entries
 * @param projectsToBeAdded
 *         Set to avoid infinite recursion
 * @param visitedProjects
 *         Set to avoid adding twice the same project
 * @param referringEntry
 *         Project raw entry in referring project classpath
 * @throws org.eclipse.jdt.core.JavaModelException
 *         May happen while getting java model info
 */
void add(JavaProject javaProject, IPath pathToAdd, int includeMask, HashSet projectsToBeAdded,
        HashSet visitedProjects, IClasspathEntry referringEntry) throws JavaModelException {
    //        IProject project = javaProject.getProject();
    //        if (!project.isAccessible() || !visitedProjects.add(project)) return;

    IPath projectPath = javaProject.getFullPath();
    String projectPathString = projectPath.toString();
    addEnclosingProjectOrJar(projectPath);

    IClasspathEntry[] entries = javaProject.getResolvedClasspath();
    //        IJavaModel model = javaProject.getJavaModel();
    //        JavaModelManager.PerProjectInfo perProjectInfo = javaProject.getPerProjectInfo();
    for (int i = 0, length = entries.length; i < length; i++) {
        IClasspathEntry entry = entries[i];
        AccessRuleSet access = null;
        ClasspathEntry cpEntry = (ClasspathEntry) entry;
        if (referringEntry != null) {
            // Add only exported entries.
            // Source folder are implicitly exported.
            if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) {
                continue;
            }
            cpEntry = cpEntry.combineWith((ClasspathEntry) referringEntry);
            //            cpEntry = ((ClasspathEntry)referringEntry).combineWith(cpEntry);
        }
        access = cpEntry.getAccessRuleSet();
        switch (entry.getEntryKind()) {
        case IClasspathEntry.CPE_LIBRARY:
            IClasspathEntry rawEntry = null;
            //                    Map rootPathToRawEntries = perProjectInfo.rootPathToRawEntries;
            //                    if (rootPathToRawEntries != null) {
            //                        rawEntry = (IClasspathEntry)rootPathToRawEntries.get(entry.getPath());
            //                    }
            //                    if (rawEntry == null) break;
            rawKind: switch (cpEntry.getEntryKind()) {
            case IClasspathEntry.CPE_LIBRARY:
            case IClasspathEntry.CPE_VARIABLE:
                if ((includeMask & APPLICATION_LIBRARIES) != 0) {
                    IPath path = entry.getPath();
                    if (pathToAdd == null || pathToAdd.equals(path)) {
                        //                                    Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                        //                                    if (target instanceof IFolder) // case of an external folder
                        //                                        path = ((IFolder)target).getFullPath();
                        String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
                        add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
                        addEnclosingProjectOrJar(entry.getPath());
                    }
                }
                break;
            case IClasspathEntry.CPE_CONTAINER:
                IClasspathContainer container = JavaCore.getClasspathContainer(rawEntry.getPath(), javaProject);
                if (container == null)
                    break;
                switch (container.getKind()) {
                case IClasspathContainer.K_APPLICATION:
                    if ((includeMask & APPLICATION_LIBRARIES) == 0)
                        break rawKind;
                    break;
                case IClasspathContainer.K_SYSTEM:
                case IClasspathContainer.K_DEFAULT_SYSTEM:
                    if ((includeMask & SYSTEM_LIBRARIES) == 0)
                        break rawKind;
                    break;
                default:
                    break rawKind;
                }
                IPath path = entry.getPath();
                if (pathToAdd == null || pathToAdd.equals(path)) {
                    Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                    if (target instanceof IFolder) // case of an external folder
                        path = ((IFolder) target).getFullPath();
                    String pathToString = path.getDevice() == null ? path.toString() : path.toOSString();
                    add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$
                    addEnclosingProjectOrJar(entry.getPath());
                }
                break;
            }
            break;
        case IClasspathEntry.CPE_PROJECT:
            //                    if ((includeMask & REFERENCED_PROJECTS) != 0) {
            //                        IPath path = entry.getPath();
            //                        if (pathToAdd == null || pathToAdd.equals(path)) {
            //                            JavaProject referencedProject = (JavaProject)model.getJavaProject(path.lastSegment());
            //                            if (!projectsToBeAdded
            //                                    .contains(referencedProject)) { // do not recurse if depending project was used to create the scope
            //                                add(referencedProject, null, includeMask, projectsToBeAdded, visitedProjects, cpEntry);
            //                            }
            //                        }
            //                    }
            break;
        case IClasspathEntry.CPE_SOURCE:
            if ((includeMask & SOURCES) != 0) {
                IPath path = entry.getPath();
                if (pathToAdd == null || pathToAdd.equals(path)) {
                    add(projectPath.toString(),
                            path.toOSString()
                                    .substring(projectPath.toString().length()
                                            + 1)/*Util.relativePath(path, 1*//*remove project segment*//*)*/,
                            projectPathString, false/*not a
                                                    package*/, access);
                }
            }
            break;
        }
    }
}

From source file:org.eclipse.che.jdt.internal.core.search.JavaWorkspaceScope.java

License:Open Source License

public IPath[] enclosingProjectsAndJars() {
    IPath[] result = this.enclosingPaths;
    if (result != null) {
        return result;
    }//from   w w w .  jav a2 s  .  c  o  m
    long start = org.eclipse.jdt.internal.core.search.BasicSearchEngine.VERBOSE ? System.currentTimeMillis()
            : -1;
    try {
        IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects();
        // use a linked set to preserve the order during search: see bug 348507
        Set paths = new LinkedHashSet(projects.length * 2);
        for (int i = 0, length = projects.length; i < length; i++) {
            JavaProject javaProject = (JavaProject) projects[i];

            // Add project full path
            IPath projectPath = javaProject.getProject().getFullPath();
            paths.add(projectPath);
        }

        // add the project source paths first in a separate loop above
        // to ensure source files always get higher precedence during search.
        // see bug 348507

        for (int i = 0, length = projects.length; i < length; i++) {
            JavaProject javaProject = (JavaProject) projects[i];

            // Add project libraries paths
            IClasspathEntry[] entries = javaProject.getResolvedClasspath();
            for (int j = 0, eLength = entries.length; j < eLength; j++) {
                IClasspathEntry entry = entries[j];
                if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
                    IPath path = entry.getPath();
                    Object target = JavaModel.getTarget(path, false/*don't check existence*/);
                    if (target instanceof IFolder) // case of an external folder
                        path = ((IFolder) target).getFullPath();
                    paths.add(entry.getPath());
                }
            }
        }
        result = new IPath[paths.size()];
        paths.toArray(result);
        return this.enclosingPaths = result;
    } catch (JavaModelException e) {
        Util.log(e, "Exception while computing workspace scope's enclosing projects and jars"); //$NON-NLS-1$
        return new IPath[0];
    } finally {
        if (BasicSearchEngine.VERBOSE) {
            long time = System.currentTimeMillis() - start;
            int length = result == null ? 0 : result.length;
            Util.verbose("JavaWorkspaceScope.enclosingProjectsAndJars: " + length + " paths computed in " + time //$NON-NLS-1$//$NON-NLS-2$
                    + "ms."); //$NON-NLS-1$
        }
    }
}