Java Code Examples for org.eclipse.jdt.core.IClasspathEntry#CPE_CONTAINER
The following examples show how to use
org.eclipse.jdt.core.IClasspathEntry#CPE_CONTAINER .
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: JavaModelUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Returns the classpath entry of the given package fragment root. This is the raw entry, except * if the root is a referenced library, in which case it's the resolved entry. * * @param root a package fragment root * @return the corresponding classpath entry * @throws JavaModelException if accessing the entry failed * @since 3.6 */ public static IClasspathEntry getClasspathEntry(IPackageFragmentRoot root) throws JavaModelException { IClasspathEntry rawEntry= root.getRawClasspathEntry(); int rawEntryKind= rawEntry.getEntryKind(); switch (rawEntryKind) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: case IClasspathEntry.CPE_CONTAINER: // should not happen, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=305037 if (root.isArchive() && root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry resolvedEntry= root.getResolvedClasspathEntry(); if (resolvedEntry.getReferencingEntry() != null) return resolvedEntry; else return rawEntry; } } return rawEntry; }
Example 2
Source File: AccessRulesDialog.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private String getDescriptionString() { String desc; String name= BasicElementLabels.getResourceName(fCurrElement.getPath().lastSegment()); switch (fCurrElement.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: try { name= JavaElementLabels.getContainerEntryLabel(fCurrElement.getPath(), fCurrElement.getJavaProject()); } catch (JavaModelException e) { } desc= NewWizardMessages.AccessRulesDialog_container_description; break; case IClasspathEntry.CPE_PROJECT: desc= NewWizardMessages.AccessRulesDialog_project_description; break; default: desc= NewWizardMessages.AccessRulesDialog_description; } return Messages.format(desc, name); }
Example 3
Source File: ReorgCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static boolean canModifyAccessRules(IBinding binding) { IJavaElement element= binding.getJavaElement(); if (element == null) return false; IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element); if (root == null) return false; try { IClasspathEntry classpathEntry= root.getRawClasspathEntry(); if (classpathEntry == null) return false; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) return true; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { ClasspathContainerInitializer classpathContainerInitializer= JavaCore.getClasspathContainerInitializer(classpathEntry.getPath().segment(0)); IStatus status= classpathContainerInitializer.getAccessRulesStatus(classpathEntry.getPath(), root.getJavaProject()); return status.isOK(); } } catch (JavaModelException e) { return false; } return false; }
Example 4
Source File: JavaSearchScopeFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public boolean isInsideJRE(IJavaElement element) { IPackageFragmentRoot root= (IPackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root != null) { try { IClasspathEntry entry= root.getRawClasspathEntry(); if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IClasspathContainer container= JavaCore.getClasspathContainer(entry.getPath(), root.getJavaProject()); return container != null && container.getKind() == IClasspathContainer.K_DEFAULT_SYSTEM; } return false; } catch (JavaModelException e) { JavaPlugin.log(e); } } return true; // include JRE in doubt }
Example 5
Source File: BuildPathsBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 6
Source File: AbstractGWTRuntimeTest.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
protected boolean assertGWTRuntimeEntry(IPath runtimePath, IClasspathEntry[] entries) { boolean hasGWTRuntime = false; for (IClasspathEntry entry : entries) { IPath entryPath = entry.getPath(); if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (GWTRuntimeContainer.isPathForGWTRuntimeContainer(entryPath)) { // Make sure we have only one GWT runtime if (hasGWTRuntime) { return false; } // We found at a GWT runtime hasGWTRuntime = true; // Make sure it's the one we're looking for if (!entryPath.equals(runtimePath)) { return false; } } } // Make sure we don't have any gwt-user.jar dependencies if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { String jarName = entryPath.lastSegment(); if (jarName.equals(GwtSdk.GWT_USER_JAR)) { return false; } } } return hasGWTRuntime; }
Example 7
Source File: JavaDocLocations.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static IClasspathEntry getConvertedEntry(IClasspathEntry entry, IJavaProject project, Map<IPath, String> oldLocationMap) { IPath path= null; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: case IClasspathEntry.CPE_PROJECT: return null; case IClasspathEntry.CPE_CONTAINER: convertContainer(entry, project, oldLocationMap); return null; case IClasspathEntry.CPE_LIBRARY: path= entry.getPath(); break; case IClasspathEntry.CPE_VARIABLE: path= JavaCore.getResolvedVariablePath(entry.getPath()); break; default: return null; } if (path == null) { return null; } IClasspathAttribute[] extraAttributes= entry.getExtraAttributes(); for (int i= 0; i < extraAttributes.length; i++) { if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(extraAttributes[i].getName())) { return null; } } String libraryJavadocLocation= oldLocationMap.get(path); if (libraryJavadocLocation != null) { CPListElement element= CPListElement.createFromExisting(entry, project); element.setAttribute(CPListElement.JAVADOC, libraryJavadocLocation); return element.getClasspathEntry(); } return null; }
Example 8
Source File: BuildPathSupport.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Finds a javadoc location for a new archive in the existing classpaths. * @param elem The new classpath entry * @return A javadoc location found in a similar classpath entry or <code>null</code>. */ public static String guessJavadocLocation(CPListElement elem) { if (elem.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { return null; } IJavaProject currProject= elem.getJavaProject(); // can be null try { // try if the jar itself contains the source IJavaModel jmodel= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); IJavaProject[] jprojects= jmodel.getJavaProjects(); for (int i= 0; i < jprojects.length; i++) { IJavaProject curr= jprojects[i]; if (!curr.equals(currProject)) { IClasspathEntry[] entries= curr.getRawClasspath(); for (int k= 0; k < entries.length; k++) { IClasspathEntry entry= entries[k]; if (entry.getEntryKind() == elem.getEntryKind() && entry.getPath().equals(elem.getPath())) { IClasspathAttribute[] attributes= entry.getExtraAttributes(); for (int n= 0; n < attributes.length; n++) { IClasspathAttribute attrib= attributes[n]; if (IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME.equals(attrib.getName())) { return attrib.getValue(); } } } } } } } catch (JavaModelException e) { JavaPlugin.log(e.getStatus()); } return null; }
Example 9
Source File: ClasspathContainerDescriptor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public boolean canEdit(IClasspathEntry entry) { String id = fConfigElement.getAttribute(ATT_ID); if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { String type = entry.getPath().segment(0); return id.equals(type); } return false; }
Example 10
Source File: ClasspathUtilities.java From gwt-eclipse-plugin with Eclipse Public License 1.0 | 5 votes |
/** * Finds all the classpath containers in the specified project that match the * provided container ID. * * @param javaProject the project to query * @param containerId The container ID we are trying to match. * @return an array of matching classpath containers. */ public static IClasspathEntry[] findClasspathContainersWithContainerId( IJavaProject javaProject, final String containerId) throws JavaModelException { Predicate<IClasspathEntry> matchPredicate = new Predicate<IClasspathEntry>() { @Override public boolean apply(IClasspathEntry entry) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { IPath containerPath = entry.getPath(); if (containerPath.segmentCount() > 0 && containerPath.segment(0).equals(containerId)) { return true; } } return false; } }; IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); int matchCount = 0; for (int i = 0; i < classpathEntries.length; i++) { if (matchPredicate.apply(classpathEntries[i])) { matchCount++; } } IClasspathEntry[] matchingClasspathEntries = new IClasspathEntry[matchCount]; int matchingClasspathEntriesIdx = 0; for (int i = 0; i < classpathEntries.length; i++) { if (matchPredicate.apply(classpathEntries[i])) { matchingClasspathEntries[matchingClasspathEntriesIdx] = classpathEntries[i]; matchingClasspathEntriesIdx++; } } return matchingClasspathEntries; }
Example 11
Source File: ClasspathEntry.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Answers an ID which is used to distinguish entries during package * fragment root computations */ public String rootID(){ if (this.rootID == null) { switch(this.entryKind){ case IClasspathEntry.CPE_LIBRARY : this.rootID = "[LIB]"+this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_PROJECT : this.rootID = "[PRJ]"+this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_SOURCE : this.rootID = "[SRC]"+this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_VARIABLE : this.rootID = "[VAR]"+this.path; //$NON-NLS-1$ break; case IClasspathEntry.CPE_CONTAINER : this.rootID = "[CON]"+this.path; //$NON-NLS-1$ break; default : this.rootID = ""; //$NON-NLS-1$ break; } } return this.rootID; }
Example 12
Source File: CPListElement.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static void insert(CPListElement element, List<CPListElement> cpList) { int length= cpList.size(); CPListElement[] elements= cpList.toArray(new CPListElement[length]); int i= 0; while (i < length && elements[i].getEntryKind() != element.getEntryKind()) { i++; } if (i < length) { i++; while (i < length && elements[i].getEntryKind() == element.getEntryKind()) { i++; } cpList.add(i, element); return; } switch (element.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: cpList.add(0, element); break; case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_PROJECT: case IClasspathEntry.CPE_VARIABLE: default: cpList.add(element); break; } }
Example 13
Source File: DialogPackageExplorer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public boolean select(Viewer viewer, Object parentElement, Object element) { try { if (element instanceof IFile) { IFile file= (IFile) element; if (file.getName().equals(".classpath") || file.getName().equals(".project")) //$NON-NLS-1$//$NON-NLS-2$ return false; } else if (element instanceof IPackageFragmentRoot) { IClasspathEntry cpe= ((IPackageFragmentRoot)element).getRawClasspathEntry(); if (cpe == null || cpe.getEntryKind() == IClasspathEntry.CPE_CONTAINER || cpe.getEntryKind() == IClasspathEntry.CPE_LIBRARY || cpe.getEntryKind() == IClasspathEntry.CPE_VARIABLE) return false; } else if (element instanceof PackageFragmentRootContainer) { return false; } else if (element instanceof IPackageFragment) { IPackageFragment fragment= (IPackageFragment)element; if (fragment.isDefaultPackage() && !fragment.hasChildren()) return false; } else if (element instanceof IFolder) { IFolder folder= (IFolder)element; if (folder.getName().startsWith(".")) //$NON-NLS-1$ return false; } } catch (JavaModelException e) { JavaPlugin.log(e); } /*if (element instanceof IPackageFragmentRoot) { IPackageFragmentRoot root= (IPackageFragmentRoot)element; if (root.getElementName().endsWith(".jar") || root.getElementName().endsWith(".zip")) //$NON-NLS-1$ //$NON-NLS-2$ return false; }*/ return /*super.select(viewer, parentElement, element) &&*/ fOutputFolderFilter.select(viewer, parentElement, element); }
Example 14
Source File: JREContainerProvider.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
public static IClasspathEntry getJREContainerEntry(IJavaProject javaProject) throws JavaModelException { IClasspathEntry defaultJREContainerEntry = getDefaultJREContainerEntry(); IClasspathEntry[] rawClasspath = javaProject.getRawClasspath(); for (IClasspathEntry classpathEntry : rawClasspath) { int entryKind = classpathEntry.getEntryKind(); if (entryKind == IClasspathEntry.CPE_CONTAINER && defaultJREContainerEntry.getPath().isPrefixOf(classpathEntry.getPath())) { return classpathEntry; } } return null; }
Example 15
Source File: FacetUtilTest.java From google-cloud-eclipse with Apache License 2.0 | 5 votes |
private static boolean hasWtpClasspathContainers(IProject project) throws JavaModelException { boolean seenWebContainer = false; IJavaProject javaProject = JavaCore.create(project); for (IClasspathEntry entry : javaProject.getRawClasspath()) { if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getPath().equals(new Path("org.eclipse.jst.j2ee.internal.web.container"))) { seenWebContainer = true; } } } return seenWebContainer; }
Example 16
Source File: BuildPathSupport.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Finds a source attachment for a new archive in the existing classpaths. * @param elem The new classpath entry * @return A path to be taken for the source attachment or <code>null</code> */ public static IPath guessSourceAttachment(CPListElement elem) { if (elem.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { return null; } IJavaProject currProject= elem.getJavaProject(); // can be null try { IJavaModel jmodel= JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); IJavaProject[] jprojects= jmodel.getJavaProjects(); for (int i= 0; i < jprojects.length; i++) { IJavaProject curr= jprojects[i]; if (!curr.equals(currProject)) { IClasspathEntry[] entries= curr.getRawClasspath(); for (int k= 0; k < entries.length; k++) { IClasspathEntry entry= entries[k]; if (entry.getEntryKind() == elem.getEntryKind() && entry.getPath().equals(elem.getPath())) { IPath attachPath= entry.getSourceAttachmentPath(); if (attachPath != null && !attachPath.isEmpty()) { return attachPath; } } } } } } catch (JavaModelException e) { JavaPlugin.log(e.getStatus()); } return null; }
Example 17
Source File: BuildPathsBlock.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private int getPageIndex(int entryKind) { switch (entryKind) { case IClasspathEntry.CPE_CONTAINER: case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: return 2; case IClasspathEntry.CPE_PROJECT: return 1; case IClasspathEntry.CPE_SOURCE: return 0; } return 0; }
Example 18
Source File: JavaProjectModulesManager.java From Pydev with Eclipse Public License 1.0 | 4 votes |
/** * This method passes through all the java packages and calls the filter callback passed * on each package found. * * If true is returned on the callback, the children of each package (classes) will also be visited, * otherwise, they'll be skipped. */ private void filterJavaPackages(IFilter filter) { IClasspathEntry[] rawClasspath; try { rawClasspath = this.javaProject.getRawClasspath(); FastStringBuffer buffer = new FastStringBuffer(); for (IClasspathEntry entry : rawClasspath) { int entryKind = entry.getEntryKind(); IClasspathEntry resolvedClasspathEntry = JavaCore.getResolvedClasspathEntry(entry); if (entryKind != IClasspathEntry.CPE_CONTAINER) { //ignore if it's in the system classpath... IPackageFragmentRoot[] roots = javaProject.findPackageFragmentRoots(resolvedClasspathEntry); //get the package roots for (IPackageFragmentRoot root : roots) { IJavaElement[] children = root.getChildren(); //get the actual packages for (IJavaElement child : children) { IPackageFragment childPackage = (IPackageFragment) child; String elementName = childPackage.getElementName(); //and if the java package is 'accepted' if (filter.accept(elementName, root, childPackage)) { buffer.clear(); buffer.append(elementName); int packageNameLen = buffer.length(); if (packageNameLen > 0) { buffer.append('.'); packageNameLen++; } //traverse its classes for (IJavaElement class_ : childPackage.getChildren()) { buffer.append(FullRepIterable.getFirstPart(class_.getElementName())); filter.accept(buffer.toString(), root, class_); buffer.setCount(packageNameLen); //leave only the package part for the next append } } } } } } } catch (Exception e) { throw new RuntimeException(e); } }
Example 19
Source File: CPListLabelProvider.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private ImageDescriptor getCPListElementBaseImage(CPListElement cpentry) { switch (cpentry.getEntryKind()) { case IClasspathEntry.CPE_SOURCE: if (cpentry.getPath().segmentCount() == 1) { return fProjectImage; } else { return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_PACKFRAG_ROOT); } case IClasspathEntry.CPE_LIBRARY: IResource res= cpentry.getResource(); IPath path= (IPath) cpentry.getAttribute(CPListElement.SOURCEATTACHMENT); if (res == null) { if (ArchiveFileFilter.isArchivePath(cpentry.getPath(), true)) { if (path == null || path.isEmpty()) { return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE); } else { return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_EXTERNAL_ARCHIVE_WITH_SOURCE); } } else { if (path == null || path.isEmpty()) { return JavaPluginImages.DESC_OBJS_CLASSFOLDER; } else { return JavaPluginImages.DESC_OBJS_CLASSFOLDER_WSRC; } } } else if (res instanceof IFile) { if (path == null || path.isEmpty()) { return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_JAR); } else { return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_JAR_WITH_SOURCE); } } else { return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_PACKFRAG_ROOT); } case IClasspathEntry.CPE_PROJECT: return fProjectImage; case IClasspathEntry.CPE_VARIABLE: ImageDescriptor variableImage= fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_CLASSPATH_VAR_ENTRY); if (cpentry.isDeprecated()) { return new JavaElementImageDescriptor(variableImage, JavaElementImageDescriptor.DEPRECATED, JavaElementImageProvider.SMALL_SIZE); } return variableImage; case IClasspathEntry.CPE_CONTAINER: return fSharedImages.getImageDescriptor(ISharedImages.IMG_OBJS_LIBRARY); default: return null; } }
Example 20
Source File: IDECPListElement.java From birt with Eclipse Public License 1.0 | 4 votes |
private IClasspathEntry newClasspathEntry( ) { IClasspathAttribute[] extraAttributes = new IClasspathAttribute[0]; switch ( fEntryKind ) { case IClasspathEntry.CPE_SOURCE : return JavaCore.newSourceEntry( fPath, null, null, null, extraAttributes ); case IClasspathEntry.CPE_LIBRARY : { return JavaCore.newLibraryEntry( fPath, null, null, null, extraAttributes, isExported( ) ); } case IClasspathEntry.CPE_PROJECT : { return JavaCore.newProjectEntry( fPath, null, false, extraAttributes, isExported( ) ); } case IClasspathEntry.CPE_CONTAINER : { return JavaCore.newContainerEntry( fPath, null, extraAttributes, isExported( ) ); } case IClasspathEntry.CPE_VARIABLE : { return JavaCore.newVariableEntry( fPath, null, null, null, extraAttributes, isExported( ) ); } default : return null; } }