Java Code Examples for org.eclipse.jdt.core.IClasspathEntry#getEntryKind()

The following examples show how to use org.eclipse.jdt.core.IClasspathEntry#getEntryKind() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VariableBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private boolean doesChangeRequireFullBuild(List<String> removed, List<String> changed) {
	try {
		IJavaModel model= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
		IJavaProject[] projects= model.getJavaProjects();
		for (int i= 0; i < projects.length; i++) {
			IClasspathEntry[] entries= projects[i].getRawClasspath();
			for (int k= 0; k < entries.length; k++) {
				IClasspathEntry curr= entries[k];
				if (curr.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
					String var= curr.getPath().segment(0);
					if (removed.contains(var) || changed.contains(var)) {
						return true;
					}
				}
			}
		}
	} catch (JavaModelException e) {
		return true;
	}
	return false;
}
 
Example 2
Source File: Importer.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param javaProject
 * @param jar
 * @return
 * @throws JavaModelException
 */
private boolean isClasspathEntryForJar(IJavaProject javaProject, IResource jar) throws JavaModelException
{
	IClasspathEntry[] classPathEntries = javaProject.getRawClasspath();
	if (classPathEntries != null) {
		for (IClasspathEntry classpathEntry : classPathEntries) {
			// fix jar files
			if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
				if (classpathEntry.getPath().equals(jar.getFullPath())) {
					return true;
				}

			}
		}

	}
	return false;
}
 
Example 3
Source File: JavaDocLocations.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static URL getLibraryJavadocLocation(IClasspathEntry entry) {
	if (entry == null) {
		throw new IllegalArgumentException("Entry must not be null"); //$NON-NLS-1$
	}

	int kind= entry.getEntryKind();
	if (kind != IClasspathEntry.CPE_LIBRARY && kind != IClasspathEntry.CPE_VARIABLE) {
		throw new IllegalArgumentException("Entry must be of kind CPE_LIBRARY or CPE_VARIABLE"); //$NON-NLS-1$
	}

	IClasspathAttribute[] extraAttributes= entry.getExtraAttributes();
	for (int i= 0; i < extraAttributes.length; i++) {
		IClasspathAttribute attrib= extraAttributes[i];
		if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) {
			return parseURL(attrib.getValue());
		}
	}
	return null;
}
 
Example 4
Source File: Importer.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Sometimes the project configuration is corrupt and a Java runtime is not on the classpath
 * @param monitor
 * @param javaProject
 * @throws JavaModelException
 */
private void fixMissingJavaRuntime(IProgressMonitor monitor, IJavaProject javaProject) throws JavaModelException {
	
	if (!javaProject.getProject().getName().equals("config")) {
		IClasspathEntry[] classPathEntries = javaProject.getRawClasspath();
		boolean found = false;
		for (IClasspathEntry classpathEntry : classPathEntries) {
			// fix missing runtime
			if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
				if (classpathEntry.getPath().toString().startsWith("org.eclipse.jdt.launching.JRE_CONTAINER")) {
					found = true;
					break;
				}
			}
		}
		
		if (!found) {
			IClasspathEntry entry = JavaCore.newContainerEntry(new Path("org.eclipse.jdt.launching.JRE_CONTAINER"),
					false);
			Set<IClasspathEntry> entries = new HashSet<IClasspathEntry>(Arrays.asList(classPathEntries));
			entries.add(entry);
			FixProjectsUtils.setClasspath(entries.toArray(new IClasspathEntry[entries.size()]), javaProject,
					monitor);
		}
	}
}
 
Example 5
Source File: SuperDevModeSrcArgumentProcessor.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get the class path entries that are the source.
 *
 * @param javaProject the java project.
 * @param entry classpath entry value.
 * @return the path.
 */
private String getPathIfDir(IJavaProject javaProject, IClasspathEntry entry) {
  IPath p = entry.getPath();

  String projectName = javaProject.getProject().getName();

  String path = null;
  // src directories don't have an output
  // cpe source are src,test directories
  if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE
      && (entry.getOutputLocation() == null || (entry.getOutputLocation() != null && !entry
          .getOutputLocation().lastSegment().toString().equals("test-classes")))) {
    String dir = p.toString();
    // if the base segment has the project name,
    // lets remove that so its relative to project
    if (dir.contains(projectName)) {
      IPath relative = p.removeFirstSegments(1);
      path = relative.toString();
    }
  }

  return path;
}
 
Example 6
Source File: ComplianceConfigurationBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private IExecutionEnvironment getEE() {
	if (fProject == null)
		return null;
	
	try {
		IClasspathEntry[] entries= JavaCore.create(fProject).getRawClasspath();
		for (int i= 0; i < entries.length; i++) {
			IClasspathEntry entry= entries[i];
			if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
				String eeId= JavaRuntime.getExecutionEnvironmentId(entry.getPath());
				if (eeId != null) {
					return JavaRuntime.getExecutionEnvironmentsManager().getEnvironment(eeId);
				}
			}
		}
	} catch (CoreException e) {
		JavaPlugin.log(e);
	}
	return null;
}
 
Example 7
Source File: BuildPathsBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private CPListElement findElement(IClasspathEntry entry) {
	CPListElement prefixMatch= null;
	int entryKind= entry.getEntryKind();
	for (int i= 0, len= fClassPathList.getSize(); i < len; i++) {
		CPListElement curr= fClassPathList.getElement(i);
		if (curr.getEntryKind() == entryKind) {
			IPath entryPath= entry.getPath();
			IPath currPath= curr.getPath();
			if (currPath.equals(entryPath)) {
				return curr;
			}
			// in case there's no full match, look for a similar container (same ID segment):
			if (prefixMatch == null && entryKind == IClasspathEntry.CPE_CONTAINER) {
				int n= entryPath.segmentCount();
				if (n > 0) {
					IPath genericContainerPath= n == 1 ? entryPath : entryPath.removeLastSegments(n - 1);
					if (n > 1 && genericContainerPath.isPrefixOf(currPath)) {
						prefixMatch= curr;
					}
				}
			}
		}
	}
	return prefixMatch;
}
 
Example 8
Source File: ClasspathEntry.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns a Java model status describing the problem related to this classpath entry if any,
 * a status object with code <code>IStatus.OK</code> if the entry is fine (that is, if the
 * given classpath entry denotes a valid element to be referenced onto a classpath).
 *
 * @param project the given java project
 * @param entry the given classpath entry
 * @param checkSourceAttachment a flag to determine if source attachment should be checked
 * @param referredByContainer flag indicating whether the given entry is referred by a classpath container
 * @return a java model status describing the problem related to this classpath entry if any, a status object with code <code>IStatus.OK</code> if the entry is fine
 */
public static IJavaModelStatus validateClasspathEntry(IJavaProject project, IClasspathEntry entry, boolean checkSourceAttachment, boolean referredByContainer){
	if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
		JavaModelManager.getJavaModelManager().removeFromInvalidArchiveCache(entry.getPath());
	}
	IJavaModelStatus status = validateClasspathEntry(project, entry, null, checkSourceAttachment, referredByContainer);
	// https://bugs.eclipse.org/bugs/show_bug.cgi?id=171136 and https://bugs.eclipse.org/bugs/show_bug.cgi?id=300136
	// Ignore class path errors from optional entries.
	int statusCode = status.getCode();
	if ( (statusCode == IJavaModelStatusConstants.INVALID_CLASSPATH || 
			statusCode == IJavaModelStatusConstants.CP_CONTAINER_PATH_UNBOUND ||
			statusCode == IJavaModelStatusConstants.CP_VARIABLE_PATH_UNBOUND ||
			statusCode == IJavaModelStatusConstants.INVALID_PATH) &&
			((ClasspathEntry) entry).isOptional())
		return JavaModelStatus.VERIFIED_OK;
	return status;
}
 
Example 9
Source File: ClasspathChange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private ArrayList determineAffectedPackageFragments(IPath location) throws JavaModelException {
	ArrayList fragments = new ArrayList();

	// see if this will cause any package fragments to be affected
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	IResource resource = null;
	if (location != null) {
		resource = workspace.getRoot().findMember(location);
	}
	if (resource != null && resource.getType() == IResource.FOLDER) {
		IFolder folder = (IFolder) resource;
		// only changes if it actually existed
		IClasspathEntry[] classpath = this.project.getExpandedClasspath();
		for (int i = 0; i < classpath.length; i++) {
			IClasspathEntry entry = classpath[i];
			IPath path = classpath[i].getPath();
			if (entry.getEntryKind() != IClasspathEntry.CPE_PROJECT && path.isPrefixOf(location) && !path.equals(location)) {
				IPackageFragmentRoot[] roots = this.project.computePackageFragmentRoots(classpath[i]);
				PackageFragmentRoot root = (PackageFragmentRoot) roots[0];
				// now the output location becomes a package fragment - along with any subfolders
				ArrayList folders = new ArrayList();
				folders.add(folder);
				collectAllSubfolders(folder, folders);
				Iterator elements = folders.iterator();
				int segments = path.segmentCount();
				while (elements.hasNext()) {
					IFolder f = (IFolder) elements.next();
					IPath relativePath = f.getFullPath().removeFirstSegments(segments);
					String[] pkgName = relativePath.segments();
					IPackageFragment pkg = root.getPackageFragment(pkgName);
					if (!Util.isExcluded(pkg))
						fragments.add(pkg);
				}
			}
		}
	}
	return fragments;
}
 
Example 10
Source File: SyntaxProjectsManager.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static IPath[] listAllSourcePaths() throws JavaModelException {
	Set<IPath> classpaths = new HashSet<>();
	IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
	for (IProject project : projects) {
		if (ProjectsManager.DEFAULT_PROJECT_NAME.equals(project.getName())) {
			continue;
		}
		IJavaProject javaProject = JavaCore.create(project);
		if (javaProject != null && javaProject.exists()) {
			IClasspathEntry[] classpath = javaProject.getRawClasspath();
			for (IClasspathEntry entry : classpath) {
				if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
					IPath path = entry.getPath();
					if (path == null) {
						continue;
					}

					IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(path);
					if (folder.exists() && !folder.isDerived()) {
						IPath location = folder.getLocation();
						if (location != null && !ResourceUtils.isContainedIn(location, classpaths)) {
							classpaths.add(location);
						}
					}
				}
			}
		}
	}

	return classpaths.toArray(new IPath[classpaths.size()]);
}
 
Example 11
Source File: JavaElementLabelComposer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private boolean appendVariableLabel(IPackageFragmentRoot root, long flags) {
	try {
		IClasspathEntry rawEntry= root.getRawClasspathEntry();
		if (rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
			IClasspathEntry entry= JavaModelUtil.getClasspathEntry(root);
			if (entry.getReferencingEntry() != null) {
				return false; // not the variable entry itself, but a referenced entry
			}
			IPath path= rawEntry.getPath().makeRelative();

			if (getFlag(flags, JavaElementLabels.REFERENCED_ROOT_POST_QUALIFIED)) {
				int segements= path.segmentCount();
				if (segements > 0) {
					fBuilder.append(path.segment(segements - 1));
					if (segements > 1) {
						fBuilder.append(JavaElementLabels.CONCAT_STRING);
						fBuilder.append(path.removeLastSegments(1).toOSString());
					}
				} else {
					fBuilder.append(path.toString());
				}
			} else {
				fBuilder.append(path.toString());
			}
			fBuilder.append(JavaElementLabels.CONCAT_STRING);
			if (root.isExternal()) {
				fBuilder.append(root.getPath().toOSString());
			} else {
				fBuilder.append(root.getPath().makeRelative().toString());
			}

			return true;
		}
	} catch (JavaModelException e) {
		// problems with class path, ignore (bug 202792)
		return false;
	}
	return false;
}
 
Example 12
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static void removeFromClasspath(IJavaProject from, int entryKind, IPath path) throws CoreException {
	List<IClasspathEntry> classpath = Lists.newArrayList(from.getRawClasspath());
	Iterator<IClasspathEntry> iterator = classpath.iterator();
	while (iterator.hasNext()) {
		IClasspathEntry entry = iterator.next();
		if (entry.getEntryKind() == entryKind) {
			if (entry.getPath().equals(path))
				iterator.remove();
		}
	}
	from.setRawClasspath(classpath.toArray(new IClasspathEntry[classpath.size()]), monitor());
}
 
Example 13
Source File: JdtClasspathUriResolver.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
private URI findResourceInProjectRoot(IJavaProject javaProject, String path, Set<String> visited) throws CoreException {
	boolean includeAll = visited.isEmpty();
	if (visited.add(javaProject.getElementName())) {
		IProject project = javaProject.getProject();
		IResource resourceFromProjectRoot = project.findMember(path);
		if (resourceFromProjectRoot != null && resourceFromProjectRoot.exists()) {
			return createPlatformResourceURI(resourceFromProjectRoot);
		}
		for(IClasspathEntry entry: javaProject.getResolvedClasspath(true)) {
			if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) {
				if (includeAll || entry.isExported()) {
					IResource referencedProject = project.getWorkspace().getRoot().findMember(entry.getPath());
					if (referencedProject != null && referencedProject.getType() == IResource.PROJECT) {
						IJavaProject referencedJavaProject = JavaCore.create((IProject) referencedProject);
						if (referencedJavaProject.exists()) {
							URI result = findResourceInProjectRoot(referencedJavaProject, path, visited);
							if (result != null) {
								return result;
							}
						}
					}
					break;
				}
			}
		}
	}
	return null;
}
 
Example 14
Source File: RemoveFromBuildpathAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean canHandle(IStructuredSelection elements) {
	if (elements.size() == 0)
		return false;

	try {
		for (Iterator<?> iter= elements.iterator(); iter.hasNext();) {
			Object element= iter.next();

			if (element instanceof IJavaProject) {
				IJavaProject project= (IJavaProject)element;
				if (!ClasspathModifier.isSourceFolder(project))
					return false;

			} else if (element instanceof IPackageFragmentRoot) {
				IClasspathEntry entry= JavaModelUtil.getClasspathEntry((IPackageFragmentRoot) element);
				if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER)
					return false;
				if (entry.getReferencingEntry() != null)
					return false;
			} else if (element instanceof ClassPathContainer) {
				return true;
			} else {
				return false;
			}
		}
		return true;
	} catch (JavaModelException e) {
	}
	return false;
}
 
Example 15
Source File: ProjectsManager.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
private String getWorkspaceInfo() {
	StringBuilder b = new StringBuilder();
	b.append("Projects:\n");
	for (IProject project : getWorkspaceRoot().getProjects()) {
		b.append(project.getName()).append(": ").append(project.getLocation().toOSString()).append('\n');
		if (ProjectUtils.isJavaProject(project)) {
			IJavaProject javaProject = JavaCore.create(project);
			try {
				b.append("  resolved classpath:\n");
				IClasspathEntry[] cpEntries = javaProject.getRawClasspath();
				for (IClasspathEntry cpe : cpEntries) {
					b.append("  ").append(cpe.getPath().toString()).append('\n');
					if (cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
						IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(cpe);
						for (IPackageFragmentRoot root : roots) {
							b.append("    ").append(root.getPath().toString()).append('\n');
						}
					}
				}
			} catch (CoreException e) {
				// ignore
			}
		} else {
			b.append("  non-Java project\n");
		}
	}
	b.append("Java Runtimes:\n");
	IVMInstall defaultVMInstall = JavaRuntime.getDefaultVMInstall();
	b.append("  default: ");
	if (defaultVMInstall != null) {
		b.append(defaultVMInstall.getInstallLocation().toString());
	} else {
		b.append("-");
	}
	IExecutionEnvironmentsManager eem = JavaRuntime.getExecutionEnvironmentsManager();
	for (IExecutionEnvironment ee : eem.getExecutionEnvironments()) {
		IVMInstall[] vms = ee.getCompatibleVMs();
		b.append("  ").append(ee.getDescription()).append(": ");
		if (vms.length > 0) {
			b.append(vms[0].getInstallLocation().toString());
		} else {
			b.append("-");
		}
		b.append("\n");
	}
	return b.toString();
}
 
Example 16
Source File: LibraryClasspathContainer.java    From google-cloud-eclipse with Apache License 2.0 4 votes vote down vote up
/** Return {@code true} if the provided classpath entry is for this container type. */
public static boolean isEntry(IClasspathEntry entry) {
  return entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER
      && entry.getPath().segmentCount() == 2
      && CONTAINER_PATH_PREFIX.equals(entry.getPath().segment(0));
}
 
Example 17
Source File: IDEReportClasspathResolver.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
private List<String> getAllClassPathFromEntries(List<IClasspathEntry> list)
{
	List<String> retValue = new ArrayList();
	IWorkspace space = ResourcesPlugin.getWorkspace( );
	IWorkspaceRoot root = space.getRoot( );
	
	
	for (int i=0; i<list.size( ); i++)
	{
		IClasspathEntry curr = list.get( i );
		boolean inWorkSpace = true;
		
		if ( space == null || space.getRoot( ) == null )
		{
			inWorkSpace = false;
		}

		IPath path = curr.getPath( );
		if (curr.getEntryKind( ) == IClasspathEntry.CPE_VARIABLE)
		{
			path = JavaCore.getClasspathVariable( path.segment( 0 ) );
		}
		else
		{
			path = JavaCore.getResolvedClasspathEntry( curr ).getPath( );
		}
		
		if (curr.getEntryKind( ) == IClasspathEntry.CPE_PROJECT)
		{
			if (root.findMember( path ) instanceof IProject)
			{
				List<String> strs = getProjectClasspath( (IProject)root.findMember( path ),false, true );
				for (int j=0; j<strs.size( ); j++)
				{
					addToList( retValue, strs.get( j ) );
				}
			}
		}
		else
		{
			if ( root.findMember( path ) == null )
			{
				inWorkSpace = false;
			}

			if ( inWorkSpace )
			{
				String absPath = getFullPath( path,
						root.findMember( path ).getProject( ) );

				//retValue.add( absPath );
				addToList( retValue, absPath );
			}
			else
			{
				//retValue.add( path.toFile( ).getAbsolutePath( ));
				addToList( retValue, path.toFile( ).getAbsolutePath( ) );
			}
		}
	
		//strs.add( JavaCore.getResolvedClasspathEntry( entry ).getPath( ).toFile( ).getAbsolutePath( ) );
	}
	return retValue;
}
 
Example 18
Source File: SourceAttachmentPropertyPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Control createPageContent(Composite composite) {
	try {
		fContainerPath= null;
		fEntry= null;
		fRoot= getJARPackageFragmentRoot();
		if (fRoot == null || fRoot.getKind() != IPackageFragmentRoot.K_BINARY) {
			return createMessageContent(composite, PreferencesMessages.SourceAttachmentPropertyPage_noarchive_message, null);
		}

		IPath containerPath= null;
		IJavaProject jproject= fRoot.getJavaProject();
		IClasspathEntry entry= JavaModelUtil.getClasspathEntry(fRoot);
		boolean canEditEncoding= true;
		if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
			containerPath= entry.getPath();
			ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0));
			IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, jproject);
			if (initializer == null || container == null) {
				return createMessageContent(composite, Messages.format(PreferencesMessages.SourceAttachmentPropertyPage_invalid_container, BasicElementLabels.getPathLabel(containerPath, false)), fRoot);
			}
			String containerName= container.getDescription();

			IStatus status= initializer.getSourceAttachmentStatus(containerPath, jproject);
			if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED) {
				return createMessageContent(composite, Messages.format(PreferencesMessages.SourceAttachmentPropertyPage_not_supported, containerName), null);
			}
			if (status.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY) {
				return createMessageContent(composite, Messages.format(PreferencesMessages.SourceAttachmentPropertyPage_read_only, containerName), fRoot);
			}
			IStatus attributeStatus= initializer.getAttributeStatus(containerPath, jproject, IClasspathAttribute.SOURCE_ATTACHMENT_ENCODING);
			canEditEncoding= !(attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED || attributeStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_READ_ONLY);

			entry= JavaModelUtil.findEntryInContainer(container, fRoot.getPath());
		}
		fContainerPath= containerPath;
		fEntry= entry;

		fSourceAttachmentBlock= new SourceAttachmentBlock(this, entry, canEditEncoding);
		return fSourceAttachmentBlock.createControl(composite);
	} catch (CoreException e) {
		JavaPlugin.log(e);
		return createMessageContent(composite, PreferencesMessages.SourceAttachmentPropertyPage_noarchive_message, null);
	}
}
 
Example 19
Source File: ClasspathModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Try to find the corresponding and modified <code>CPListElement</code> for the root
 * in the list of elements and return it.
 * If no one can be found, the roots <code>ClasspathEntry</code> is converted to a
 * <code>CPListElement</code> and returned.
 *
 * @param elements a list of <code>CPListElements</code>
 * @param root the root to find the <code>ClasspathEntry</code> for represented by
 * a <code>CPListElement</code>
 * @return the <code>CPListElement</code> found in the list (matching by using the path) or
 * the roots own <code>IClasspathEntry</code> converted to a <code>CPListElement</code>.
 * @throws JavaModelException
 */
public static CPListElement getClasspathEntry(List<CPListElement> elements, IPackageFragmentRoot root) throws JavaModelException {
	IClasspathEntry entry= root.getRawClasspathEntry();
	for (int i= 0; i < elements.size(); i++) {
		CPListElement element= elements.get(i);
		if (element.getPath().equals(root.getPath()) && element.getEntryKind() == entry.getEntryKind())
			return elements.get(i);
	}
	CPListElement newElement= CPListElement.createFromExisting(entry, root.getJavaProject());
	elements.add(newElement);
	return newElement;
}
 
Example 20
Source File: ClasspathModifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Test if the provided kind is of type
 * <code>IClasspathEntry.CPE_SOURCE</code>
 *
 * @param entry the classpath entry to be compared with the provided type
 * @param kind the kind to be checked
 * @return <code>true</code> if kind equals
 * <code>IClasspathEntry.CPE_SOURCE</code>,
 * <code>false</code> otherwise
 */
private static boolean equalEntryKind(IClasspathEntry entry, int kind) {
	return entry.getEntryKind() == kind;
}