Search in sources :

Example 71 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class RefactoringScopeFactory method addRelatedReferenced.

private static void addRelatedReferenced(IJavaProject focus, Set<IJavaProject> projects) throws CoreException {
    IProject[] referencedProjects = focus.getProject().getReferencedProjects();
    for (int i = 0; i < referencedProjects.length; i++) {
        IJavaProject candidate = JavaCore.create(referencedProjects[i]);
        if (candidate == null || projects.contains(candidate) || !candidate.exists())
            // break cycle
            continue;
        IClasspathEntry entry = getReferencingClassPathEntry(focus, candidate);
        if (entry != null) {
            projects.add(candidate);
            if (entry.isExported()) {
                addRelatedReferenced(candidate, projects);
                addRelatedReferencing(candidate, projects);
            }
        }
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IProject(org.eclipse.core.resources.IProject)

Example 72 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class RefactoringScopeFactory method getReferencingClassPathEntry.

/*
	 * Finds, if possible, a classpathEntry in one given project such that this classpath entry references another given project. If more than one entry exists for the referenced project and at least one is exported, then an exported entry will be returned.
	 */
private static IClasspathEntry getReferencingClassPathEntry(IJavaProject referencingProject, IJavaProject referencedProject) throws JavaModelException {
    IClasspathEntry result = null;
    IPath path = referencedProject.getProject().getFullPath();
    IClasspathEntry[] classpath = referencingProject.getResolvedClasspath(true);
    for (int i = 0; i < classpath.length; i++) {
        IClasspathEntry entry = classpath[i];
        if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && path.equals(entry.getPath())) {
            if (entry.isExported())
                return entry;
            // Consider it as a candidate. May be there is another entry that is
            // exported.
            result = entry;
        }
    }
    return result;
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 73 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class ClasspathChange method addEntryChange.

public static ClasspathChange addEntryChange(IJavaProject project, IClasspathEntry entryToAdd) throws JavaModelException {
    IClasspathEntry[] rawClasspath = project.getRawClasspath();
    IClasspathEntry[] newClasspath = new IClasspathEntry[rawClasspath.length + 1];
    System.arraycopy(rawClasspath, 0, newClasspath, 0, rawClasspath.length);
    newClasspath[rawClasspath.length] = entryToAdd;
    IPath outputLocation = project.getOutputLocation();
    return newChange(project, newClasspath, outputLocation);
}
Also used : IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Example 74 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class JavaElementLabelComposer method appendInternalArchiveLabel.

private void appendInternalArchiveLabel(IPackageFragmentRoot root, long flags) {
    IResource resource = root.getResource();
    boolean rootQualified = getFlag(flags, JavaElementLabels.ROOT_QUALIFIED);
    if (rootQualified) {
        fBuffer.append(root.getPath().makeRelative().toString());
    } else {
        fBuffer.append(root.getElementName());
        int offset = fBuffer.length();
        boolean referencedPostQualified = getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED);
        if (referencedPostQualified && isReferenced(root)) {
            fBuffer.append(JavaElementLabels.CONCAT_STRING);
            fBuffer.append(resource.getParent().getFullPath().makeRelative().toString());
        } else if (getFlag(flags, JavaElementLabels.ROOT_POST_QUALIFIED)) {
            fBuffer.append(JavaElementLabels.CONCAT_STRING);
            fBuffer.append(root.getParent().getPath().makeRelative().toString());
        }
        if (referencedPostQualified) {
            try {
                IClasspathEntry referencingEntry = JavaModelUtil.getClasspathEntry(root).getReferencingEntry();
                if (referencingEntry != null) {
                    fBuffer.append(Messages.format(JavaUIMessages.JavaElementLabels_onClassPathOf, new Object[] { Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() }));
                }
            } catch (JavaModelException e) {
            // ignore
            }
        }
        if (getFlag(flags, JavaElementLabels.COLORIZE)) {
            fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
        }
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) IResource(org.eclipse.core.resources.IResource)

Example 75 with IClasspathEntry

use of org.eclipse.jdt.core.IClasspathEntry in project che by eclipse.

the class JavaElementLabelComposer method appendExternalArchiveLabel.

private void appendExternalArchiveLabel(IPackageFragmentRoot root, long flags) {
    IPath path;
    IClasspathEntry classpathEntry = null;
    try {
        classpathEntry = JavaModelUtil.getClasspathEntry(root);
        IPath rawPath = classpathEntry.getPath();
        if (classpathEntry.getEntryKind() != IClasspathEntry.CPE_CONTAINER && !rawPath.isAbsolute())
            path = rawPath;
        else
            path = root.getPath();
    } catch (JavaModelException e) {
        path = root.getPath();
    }
    if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) {
        int segements = path.segmentCount();
        if (segements > 0) {
            fBuffer.append(path.segment(segements - 1));
            int offset = fBuffer.length();
            if (segements > 1 || path.getDevice() != null) {
                fBuffer.append(JavaElementLabels.CONCAT_STRING);
                fBuffer.append(path.removeLastSegments(1).toOSString());
            }
            if (classpathEntry != null) {
                IClasspathEntry referencingEntry = classpathEntry.getReferencingEntry();
                if (referencingEntry != null) {
                    fBuffer.append(Messages.format(JavaUIMessages.JavaElementLabels_onClassPathOf, new Object[] { Name.CLASS_PATH.toString(), referencingEntry.getPath().lastSegment() }));
                }
            }
            if (getFlag(flags, JavaElementLabels.COLORIZE)) {
                fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
            }
        } else {
            fBuffer.append(path.toOSString());
        }
    } else {
        fBuffer.append(path.toOSString());
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry)

Aggregations

IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)123 IPath (org.eclipse.core.runtime.IPath)55 IJavaProject (org.eclipse.jdt.core.IJavaProject)44 ArrayList (java.util.ArrayList)35 Path (org.eclipse.core.runtime.Path)27 JavaModelException (org.eclipse.jdt.core.JavaModelException)23 IProject (org.eclipse.core.resources.IProject)20 IClasspathAttribute (org.eclipse.jdt.core.IClasspathAttribute)16 File (java.io.File)15 IFolder (org.eclipse.core.resources.IFolder)13 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)13 CoreException (org.eclipse.core.runtime.CoreException)12 IJavaElement (org.eclipse.jdt.core.IJavaElement)12 JavaProject (org.eclipse.jdt.internal.core.JavaProject)11 IFile (org.eclipse.core.resources.IFile)10 IResource (org.eclipse.core.resources.IResource)10 HashMap (java.util.HashMap)9 Test (org.testng.annotations.Test)8 IOException (java.io.IOException)7 URL (java.net.URL)7