List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT
int CPE_PROJECT
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_PROJECT.
Click Source Link
From source file:org.eclipse.jem.internal.beaninfo.core.BeaninfoEntry.java
License:Open Source License
private void resolveEntry(IWorkspaceRoot root, List paths, IClasspathEntry entry, IJavaProject javaProject) { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: IProject reqProject = (IProject) root.findMember(entry.getPath().lastSegment()); // Project entries only have one segment. if (reqProject != null && reqProject.isOpen()) paths.add(reqProject);//from w w w . j a va 2 s . c o m break; case IClasspathEntry.CPE_SOURCE: reqProject = (IProject) root.findMember(entry.getPath().segment(0)); // Find project from the first segment. IJavaProject jProject = JavaCore.create(reqProject); if (jProject != null) { try { IPath outputLocation = jProject.getOutputLocation(); IResource resource = root.findMember(outputLocation); if (resource != null) { paths.add(resource.getLocation().toString()); } } catch (JavaModelException e) { } } break; case IClasspathEntry.CPE_LIBRARY: IResource library = root.findMember(entry.getPath()); // can be external or in workspace paths.add((library != null) ? library.getLocation().toString() : entry.getPath().toString()); break; case IClasspathEntry.CPE_CONTAINER: try { IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); if (container != null) { IClasspathEntry[] entries = container.getClasspathEntries(); for (int i = 0; i < entries.length; i++) { resolveEntry(root, paths, entries[i], javaProject); } } } catch (JavaModelException e) { BeaninfoPlugin.getPlugin().getLogger().log(e, Level.WARNING); } } }
From source file:org.eclipse.jem.internal.beaninfo.core.SearchpathEntry.java
License:Open Source License
/** * Read the entry in from the element./* www. j a v a 2 s .c o m*/ */ public static SearchpathEntry readEntry(IReader reader, Object element, IProject project, boolean beaninfoChild) { String packageName = reader.getAttribute(element, sPackage); if (beaninfoChild) return new SearchpathEntry(packageName); // Kind/path aren't valid on beaninfo children. String elementKind = reader.getAttribute(element, BeaninfosDoc.sKind); String pathStr = reader.getAttribute(element, BeaninfosDoc.sPath); int kind = BeaninfoEntry.kindFromString(elementKind); IPath path = null; if (pathStr != null) { // ensure path is absolute path = new Path(pathStr); if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && !path.isAbsolute()) { path = project != null ? project.getFullPath().append(path) : path.makeAbsolute(); // Some folder/jar within this project } } // create the appropriate entry boolean valid = true; switch (kind) { case IClasspathEntry.CPE_LIBRARY: valid = path != null && path.isAbsolute(); break; case IClasspathEntry.CPE_SOURCE: if (path == null) valid = false; else if (path.isAbsolute()) { // must be an entry in this project or specify another project String projSegment = path.segment(0); if (project == null || projSegment == null || !projSegment.equals(project.getName())) { // another project kind = IClasspathEntry.CPE_PROJECT; } } break; case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_CONTAINER: break; default: valid = false; break; } if (valid) return new SearchpathEntry(kind, path, packageName); else return null; }
From source file:org.eclipse.jem.internal.proxy.core.ProxyPlugin.java
License:Open Source License
private void expandProject(IPath projectPath, FoundIDs foundIds, boolean visible, boolean first) throws JavaModelException { IResource res = ResourcesPlugin.getWorkspace().getRoot().findMember(projectPath.lastSegment()); if (res == null) return; // Not exist so don't delve into it. IJavaProject project = (IJavaProject) JavaCore.create(res); if (project == null || !project.exists() || !project.getProject().isOpen()) return; // Not exist as a java project or not open, so don't delve into it. IClasspathEntry[] entries = project.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; Boolean currentFlag = null; // Current setting value. boolean newFlag; // The new setting value. switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: // Force true if already true, or this is the first project, or this project is visible and the entry is exported. These override a previous false. currentFlag = (Boolean) foundIds.projects.get(entry.getPath()); newFlag = (currentFlag != null && currentFlag.booleanValue()) || first || (visible && entry.isExported()); if (currentFlag == null || currentFlag.booleanValue() != newFlag) foundIds.projects.put(entry.getPath(), newFlag ? Boolean.TRUE : Boolean.FALSE); if (currentFlag == null) expandProject(entry.getPath(), foundIds, visible && entry.isExported(), false); break; case IClasspathEntry.CPE_CONTAINER: if (!first && JavaRuntime.JRE_CONTAINER.equals(entry.getPath().segment(0))) //$NON-NLS-1$ break; // The first project determines the JRE, so any subsequent ones can be ignored. Map[] paths = (Map[]) foundIds.containerIds.get(entry.getPath().segment(0)); if (paths == null) { paths = new Map[] { new HashMap(2), new HashMap(2) }; foundIds.containerIds.put(entry.getPath().segment(0), paths); }/*from w w w .j a v a 2 s . co m*/ currentFlag = null; if (paths[0].containsKey(entry.getPath())) currentFlag = Boolean.TRUE; else if (paths[1].containsKey(entry.getPath())) currentFlag = Boolean.FALSE; newFlag = (currentFlag != null && currentFlag.booleanValue()) || first || (visible && entry.isExported()); if (currentFlag == null || currentFlag.booleanValue() != newFlag) { if (newFlag) { // It is visible, remove from hidden, if there, and add to visible. paths[1].remove(entry.getPath()); paths[0].put(entry.getPath(), entry.getPath().toString()); } else { // It is hidden, remove from visible, if there, and add to hidden. paths[0].remove(entry.getPath()); paths[1].put(entry.getPath(), entry.getPath().toString()); } } IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), project); // Force true if already true, or this is the first project, or this project is visible and the entry is exported. These override a previous false. currentFlag = (Boolean) foundIds.containers.get(container); newFlag = (currentFlag != null && currentFlag.booleanValue()) || first || (visible && entry.isExported()); if (currentFlag == null || currentFlag.booleanValue() != newFlag) foundIds.containers.put(container, newFlag ? Boolean.TRUE : Boolean.FALSE); break; case IClasspathEntry.CPE_VARIABLE: // We only care about JRE_LIB. If we have that, then we will treat it as JRE_CONTAINER. Only // care about first project too, because the first project is the one that determines the JRE type. if (first && JavaRuntime.JRELIB_VARIABLE.equals(entry.getPath().segment(0))) { //$NON-NLS-1$ paths = (Map[]) foundIds.containerIds.get(JavaRuntime.JRE_CONTAINER); if (paths == null) { paths = new Map[] { new HashMap(2), new HashMap(2) }; foundIds.containerIds.put(JavaRuntime.JRE_CONTAINER, paths); } currentFlag = null; if (paths[0].containsKey(JRE_CONTAINER_PATH)) currentFlag = Boolean.TRUE; else if (paths[1].containsKey(JRE_CONTAINER_PATH)) currentFlag = Boolean.FALSE; newFlag = (currentFlag != null && currentFlag.booleanValue()) || first || (visible && entry.isExported()); if (currentFlag == null || currentFlag.booleanValue() != newFlag) { if (newFlag) { // It is visible, remove from hidden, if there, and add to visible. paths[1].remove(JRE_CONTAINER_PATH); paths[0].put(JRE_CONTAINER_PATH, JavaRuntime.JRE_CONTAINER); } else { // It is hidden, remove from visible, if there, and add to hidden. paths[0].remove(JRE_CONTAINER_PATH); paths[1].put(JRE_CONTAINER_PATH, JavaRuntime.JRE_CONTAINER); } } } break; default: break; } } findPlugins(foundIds, visible, first, project); }
From source file:org.eclipse.jem.workbench.utility.JavaModelListener.java
License:Open Source License
protected boolean isInClasspath(IJavaProject testProject, IJavaProject targetProject, boolean isFirstLevel, Set visited) {//w ww . ja va 2 s.c o m if (visited.contains(targetProject)) return false; visited.add(targetProject); IClasspathEntry[] entries = null; try { entries = targetProject.getRawClasspath(); } catch (JavaModelException e) { return false; } List projects = null; for (int i = 0; i < entries.length; i++) { IClasspathEntry entry; entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_PROJECT: IJavaProject entryProject = getVisibleJavaProject(entry, isFirstLevel); if (entryProject != null) { if (entryProject.equals(testProject)) { return true; } else { if (projects == null) { projects = new ArrayList(); } projects.add(entryProject); } } break; //A container may contain references to projects. case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = null; try { container = JavaCore.getClasspathContainer(entry.getPath(), targetProject); } catch (JavaModelException e) { JEMPlugin.getPlugin().getLogger().logError(e); } if (container == null || container.getKind() != IClasspathContainer.K_APPLICATION) break; //First see if we already resolved IClasspathEntry[] containerEntries = null; containerEntries = (IClasspathEntry[]) resolvedContainers.get(container); if (containerEntries == null) { containerEntries = container.getClasspathEntries(); resolvedContainers.put(container, containerEntries); } for (int j = 0; j < containerEntries.length; j++) { if (containerEntries[j].getEntryKind() == IClasspathEntry.CPE_PROJECT) { IJavaProject conEntryProject = getVisibleJavaProject(containerEntries[j], isFirstLevel); if (conEntryProject != null) { if (conEntryProject.equals(testProject)) { return true; } else { if (projects == null) { projects = new ArrayList(); } projects.add(conEntryProject); } } } } break; } } return isInClasspath(testProject, projects, false, visited); }
From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java
License:Open Source License
private static void collectClasspathURLs(IJavaProject javaProject, List urls, Set visited, boolean isFirstProject) { if (visited.contains(javaProject)) return;/*from w w w. j a v a 2s.c o m*/ visited.add(javaProject); IPath outPath = getJavaProjectOutputAbsoluteLocation(javaProject.getProject()); outPath = outPath.addTrailingSeparator(); URL out = ProjectUtilities.createFileURL(outPath); urls.add(out); IClasspathEntry[] entries = null; try { entries = javaProject.getResolvedClasspath(true); } catch (JavaModelException e) { return; } IClasspathEntry entry; for (int i = 0; i < entries.length; i++) { entry = entries[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_VARIABLE: collectClasspathEntryURL(entry, urls); break; case IClasspathEntry.CPE_PROJECT: { if (isFirstProject || entry.isExported()) collectClasspathURLs(getJavaProject(entry), urls, visited, false); break; } } } }
From source file:org.eclipse.jst.common.jdt.internal.classpath.ClasspathUtil.java
License:Open Source License
public static Set getResolvedClasspath(final IJavaProject jproj, final Set entriesToIgnore) { final Set resolved = new HashSet(); try {//w w w .j a v a 2 s .c o m final IClasspathEntry[] entries = jproj.getRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entriesToIgnore.contains(entry.getPath())) { continue; } switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_PROJECT: { resolved.add(entry.getPath()); break; } case IClasspathEntry.CPE_VARIABLE: { entry = JavaCore.getResolvedClasspathEntry(entry); if (entry != null) { resolved.add(entry.getPath()); } break; } case IClasspathEntry.CPE_CONTAINER: { final IClasspathContainer container; try { container = JavaCore.getClasspathContainer(entry.getPath(), jproj); } catch (JavaModelException e) { Logger.getLogger().logError(e); continue; } if (container != null) { final IClasspathEntry[] containerEntries = container.getClasspathEntries(); for (int j = 0; j < containerEntries.length; j++) { resolved.add(containerEntries[j].getPath()); } } } } } } catch (JavaModelException e) { Logger.getLogger().logError(e); } return resolved; }
From source file:org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil.java
License:Open Source License
public static IClasspathEntry modifyDependencyPath(IClasspathEntry entry, IPath dependencyPath) { IClasspathEntry newEntry = null;/*from w w w . j a v a 2 s .c o m*/ IClasspathAttribute[] newAttributes = modifyDependencyPath(entry.getExtraAttributes(), dependencyPath); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: newEntry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_LIBRARY: newEntry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_VARIABLE: newEntry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_PROJECT: newEntry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(), entry.combineAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_SOURCE: newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), newAttributes); break; } return newEntry; }
From source file:org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.java
License:Open Source License
public IVirtualReference[] getJavaClasspathReferences(IVirtualReference[] hardReferences) { final boolean isLegacyJ2EE = JavaEEProjectUtilities.isLegacyJ2EEComponent(this); final boolean isWebApp = JavaEEProjectUtilities.isDynamicWebComponent(this); final IProject project = getProject(); final List cpRefs = new ArrayList(); try {//www . j a va 2s. c om if (project == null || !project.isAccessible() || !project.hasNature(JavaCoreLite.NATURE_ID)) { return new IVirtualReference[0]; } final IJavaProjectLite javaProjectLite = JavaCoreLite.create(project); if (javaProjectLite == null) return new IVirtualReference[0]; // retrieve all referenced classpath entries final Map referencedEntries = ClasspathDependencyUtil.getComponentClasspathDependencies(javaProjectLite, isLegacyJ2EE); if (referencedEntries.isEmpty()) return new IVirtualReference[0]; IVirtualReference[] innerHardReferences = hardReferences == null ? getHardReferences() : hardReferences; final IPath[] hardRefPaths = new IPath[innerHardReferences.length]; for (int j = 0; j < innerHardReferences.length; j++) { final IVirtualComponent comp = innerHardReferences[j].getReferencedComponent(); if (comp.isBinary()) { hardRefPaths[j] = (IPath) comp.getAdapter(IPath.class); } } IContainer[] mappedClassFolders = null; final Iterator i = referencedEntries.keySet().iterator(); while (i.hasNext()) { final IClasspathEntry entry = (IClasspathEntry) i.next(); final IClasspathAttribute attrib = (IClasspathAttribute) referencedEntries.get(entry); final boolean isClassFolder = ClasspathDependencyUtil.isClassFolderEntry(entry); final IPath runtimePath = ClasspathDependencyUtil.getRuntimePath(attrib, isWebApp, isClassFolder); boolean add = true; final IPath entryLocation = ClasspathDependencyUtil.getEntryLocation(entry); if (entryLocation == null) { // unable to retrieve location for cp entry, do not // contribute as a virtual ref add = false; } else if (!isClassFolder) { // check hard archive refs for (int j = 0; j < hardRefPaths.length; j++) { if (entryLocation.equals(hardRefPaths[j])) { // entry resolves to same file as existing hard // reference, can skip add = false; break; } } } else { // check class folders mapped in component file as // class folders associated with mapped src folders if (mappedClassFolders == null) { List<IContainer> containers = JavaLiteUtilities.getJavaOutputContainers(this); mappedClassFolders = containers.toArray(new IContainer[containers.size()]); } for (int j = 0; j < mappedClassFolders.length; j++) { if (entryLocation.equals(mappedClassFolders[j].getFullPath())) { // entry resolves to same file as existing class // folder mapping, skip add = false; break; } } } if (add && entryLocation != null) { final IVirtualReference entryReference; String componentPath = null; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { final IProject cpEntryProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(entry.getPath().lastSegment()); IVirtualComponent entryComponent = ComponentCore.createComponent(cpEntryProject); entryReference = ComponentCore.createReference(this, entryComponent, runtimePath); entryReference.setArchiveName( VirtualReferenceUtilities.INSTANCE.getDefaultProjectArchiveName(entryComponent)); } else { componentPath = VirtualArchiveComponent.CLASSPATHARCHIVETYPE + IPath.SEPARATOR + entryLocation.toPortableString(); ClasspathDependencyVirtualComponent entryComponent = new ClasspathDependencyVirtualComponent( project, componentPath, isClassFolder); entryReference = ComponentCore.createReference(this, entryComponent, runtimePath); ((VirtualReference) entryReference).setDerived(true); entryReference.setArchiveName(ClasspathDependencyUtil.getArchiveName(entry)); } cpRefs.add(entryReference); } } } catch (CoreException jme) { J2EEPlugin.logError(jme); } return (IVirtualReference[]) cpRefs.toArray(new IVirtualReference[cpRefs.size()]); }
From source file:org.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator.java
License:Open Source License
/** * Checks if the specified Java classpath entry is a valid WTP virtual component reference. * Does not check the runtime path./*from ww w. java2 s.c o m*/ * @param entry Raw or resolved classpath entry to validate. * @param attrib The WTP classpath component dependency attribute. Null if it has not yet been set. * @param isWebApp True if the target project is associated with a web project. * @param project The parent project. * @param data Data required for validation. Can be computed once for the project and reused. * @return IMessages representing validation results. */ public static IMessage[] validateVirtualComponentEntry(final IClasspathEntry entry, final IClasspathAttribute attrib, final boolean isWebApp, final IProject project, final ClasspathDependencyValidatorData data) { List results = new ArrayList(); if (entry == null) { return (IMessage[]) results.toArray(new IMessage[results.size()]); } final int kind = entry.getEntryKind(); final boolean isFile = !ClasspathDependencyUtil.isClassFolderEntry(entry); if (kind == IClasspathEntry.CPE_PROJECT) { // Project cp entry // Allow faceted projects only, and not plain java projects boolean isFacetedProject = false; IProject referencedProject = ResourcesPlugin.getWorkspace().getRoot() .getProject(entry.getPath().toString()); try { isFacetedProject = FacetedProjectFramework.isFacetedProject(referencedProject); } catch (CoreException ce) { //Ignore. Thrown when project metadata cannot be read. In that case we will treat the project as non faceted } if (!isFacetedProject) { results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$ IMessage.HIGH_SEVERITY, ProjectClasspathEntry, new String[] { entry.getPath().toString() }, project)); return (IMessage[]) results.toArray(new IMessage[results.size()]); } } else if (kind == IClasspathEntry.CPE_SOURCE) { // Source cp entry results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$ IMessage.HIGH_SEVERITY, SourceEntry, new String[] { entry.getPath().toString() }, project)); return (IMessage[]) results.toArray(new IMessage[results.size()]); } else if (kind == IClasspathEntry.CPE_CONTAINER) { // get the set of classpath container IDs that should be filtered List filteredIDs = ClasspathDependencyExtensions.get().getFilteredClasspathContainerIDs(); final IPath path = entry.getPath(); for (int i = 0; i < filteredIDs.size(); i++) { final String id = (String) filteredIDs.get(i); if (path.segment(0).equals(id)) { // filtered classpath container results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$ IMessage.HIGH_SEVERITY, FilteredContainer, new String[] { entry.getPath().toString() }, project)); return (IMessage[]) results.toArray(new IMessage[results.size()]); } } } else if (kind == IClasspathEntry.CPE_LIBRARY) { if (!isFile) { final IContainer[] mappedClassFolders = data.getMappedClassFolders(); final IResource resource = ClasspathDependencyUtil.getEntryResource(entry); if (resource != null) { final IPath fullClassFolderPath = resource.getFullPath(); boolean alreadyMapped = false; for (int j = 0; j < mappedClassFolders.length; j++) { if (fullClassFolderPath.equals(mappedClassFolders[j].getFullPath())) { // entry resolves to same file as existing class folder mapping, skip alreadyMapped = true; break; } } // Class folder reference; ensure this is not already mapped via the component file. if (alreadyMapped) { results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$ IMessage.HIGH_SEVERITY, DuplicateClassFolderEntry, new String[] { entry.getPath().toString() }, project)); } } } } // final IPath runtimePath = ClasspathDependencyUtil.getRuntimePath(attrib, isWebApp, !isFile); // if (!isWebApp) { // // only a ../ or / mapping is currently legal in a non-web context // if (!(runtimePath.equals(IClasspathDependencyConstants.RUNTIME_MAPPING_INTO_CONTAINER_PATH) // || runtimePath.equals(IClasspathDependencyConstants.RUNTIME_MAPPING_INTO_COMPONENT_PATH))) { // results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$ // IMessage.HIGH_SEVERITY, InvalidNonWebRuntimePath, new String[]{entry.getPath().toString(), runtimePath.toString()}, project)); // } // } else { // String pathStr = runtimePath.toString(); // // can only be ../, /WEB-INF/lib or /WEB-INF/classes // if (!runtimePath.equals(IClasspathDependencyConstants.RUNTIME_MAPPING_INTO_CONTAINER_PATH) // && !runtimePath.equals(IClasspathDependencyConstants.WEB_INF_LIB_PATH) // && !runtimePath.equals(IClasspathDependencyConstants.WEB_INF_CLASSES_PATH)) { // results.add(new Message("classpathdependencyvalidator", //$NON-NLS-1$ // IMessage.HIGH_SEVERITY, InvalidWebRuntimePath, new String[]{entry.getPath().toString(), pathStr}, project)); // } // } return (IMessage[]) results.toArray(new IMessage[results.size()]); }
From source file:org.eclipse.jst.j2ee.internal.classpathdep.UpdateClasspathAttributesOperation.java
License:Open Source License
/** * Updates the specified Java project so that only the specified classpath entries have * the WTP component dependency attribute. * @param javaProject Target Java project. * @param entries Classpath entries that should have the component dependency attribute. Map from IClasspathEntry * to the IClasspathAttribute for the WTP classpath component dependency. * @param modifyComponentDep True if modifying the dependency attribute, false if modifying the non-dependency attribute. * @throws CoreException Thrown if an error is encountered. *//*from w ww.j a va 2s . c om*/ private void updateDependencyAttributes(final IJavaProject javaProject, final Map entriesWithAttrib, final boolean modifyComponentDep, final boolean isLegacyJ2EE) throws CoreException { if (javaProject == null || !javaProject.getProject().isAccessible()) { return; } final List updatedClasspath = new ArrayList(); final IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); boolean needToUpdateClasspath = false; IClasspathAttribute attrib = UpdateClasspathAttributeUtil.createDependencyAttribute(); if (!modifyComponentDep) { attrib = UpdateClasspathAttributeUtil.createNonDependencyAttribute(); } for (int i = 0; i < rawClasspath.length; i++) { IClasspathEntry entry = rawClasspath[i]; final int kind = entry.getEntryKind(); boolean hasAttribute = ClasspathDependencyUtil .checkForComponentDependencyAttribute(entry, modifyComponentDep ? DependencyAttributeType.CLASSPATH_COMPONENT_DEPENDENCY : DependencyAttributeType.CLASSPATH_COMPONENT_NONDEPENDENCY, isLegacyJ2EE) != null; boolean shouldHaveAttribute = entriesWithAttrib.containsKey(entry); boolean updateAttributes = false; IClasspathAttribute[] updatedAttributes = null; if (shouldHaveAttribute) { if (!hasAttribute) { // should have the attribute and currently missing it attrib = (IClasspathAttribute) entriesWithAttrib.get(entry); updatedAttributes = updateAttributes(entry.getExtraAttributes(), attrib, true); needToUpdateClasspath = true; updateAttributes = true; } } else if (hasAttribute) { // should not have the attribute and currently has it updatedAttributes = updateAttributes(entry.getExtraAttributes(), attrib, false); needToUpdateClasspath = true; updateAttributes = true; } if (updateAttributes) { switch (kind) { case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_VARIABLE: entry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_PROJECT: // although project entries are not yet supported, allow the attribute here and let the validator flag as an error entry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(), entry.combineAccessRules(), updatedAttributes, entry.isExported()); break; case IClasspathEntry.CPE_SOURCE: // although source entries are not supported, allow the attribute here and let the validator flag as an error entry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), updatedAttributes); break; } } updatedClasspath.add(entry); } if (needToUpdateClasspath) { final IClasspathEntry[] updatedCPArray = (IClasspathEntry[]) updatedClasspath .toArray(new IClasspathEntry[updatedClasspath.size()]); javaProject.setRawClasspath(updatedCPArray, null); } }