Search in sources :

Example 1 with ReferenceCollection

use of org.eclipse.jdt.internal.core.builder.ReferenceCollection in project che by eclipse.

the class IndexSelector method canSeeFocus.

private static int canSeeFocus(IJavaElement focus, JavaProject javaProject, char[][][] focusQualifiedNames) {
    try {
        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;
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) JarPackageFragmentRoot(org.eclipse.jdt.internal.core.JarPackageFragmentRoot) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) State(org.eclipse.jdt.internal.core.builder.State) ReferenceCollection(org.eclipse.jdt.internal.core.builder.ReferenceCollection)

Aggregations

IPath (org.eclipse.core.runtime.IPath)1 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 JarPackageFragmentRoot (org.eclipse.jdt.internal.core.JarPackageFragmentRoot)1 ReferenceCollection (org.eclipse.jdt.internal.core.builder.ReferenceCollection)1 State (org.eclipse.jdt.internal.core.builder.State)1