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);
}
}
}
}
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;
}
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);
}
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);
}
}
}
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());
}
}
Aggregations