List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE
int CPE_SOURCE
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_SOURCE.
Click Source Link
From source file:org.eclipse.jdt.internal.core.JavaProject.java
License:Open Source License
public boolean isOnClasspath(IJavaElement element) { IClasspathEntry[] rawClasspath;//from w w w . j ava2s . c o m try { rawClasspath = getRawClasspath(); } catch (JavaModelException e) { return false; // not a Java project } int elementType = element.getElementType(); boolean isPackageFragmentRoot = false; boolean isFolderPath = false; boolean isSource = false; switch (elementType) { case IJavaElement.JAVA_MODEL: return false; case IJavaElement.JAVA_PROJECT: break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: isPackageFragmentRoot = true; break; case IJavaElement.PACKAGE_FRAGMENT: isFolderPath = !((IPackageFragmentRoot) element.getParent()).isArchive(); break; case IJavaElement.COMPILATION_UNIT: isSource = true; break; default: isSource = element.getAncestor(IJavaElement.COMPILATION_UNIT) != null; break; } IPath elementPath = element.getPath(); // first look at unresolved entries int length = rawClasspath.length; for (int i = 0; i < length; i++) { IClasspathEntry entry = rawClasspath[i]; switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_PROJECT: case IClasspathEntry.CPE_SOURCE: if (isOnClasspathEntry(elementPath, isFolderPath, isPackageFragmentRoot, entry)) return true; break; } } // no need to go further for compilation units and elements inside a compilation unit // it can only be in a source folder, thus on the raw classpath if (isSource) return false; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=304081 // All the resolved classpath entries need to be considered, including the referenced classpath entries IClasspathEntry[] resolvedClasspath = null; try { resolvedClasspath = getResolvedClasspath(); } catch (JavaModelException e) { return false; // Perhaps, not a Java project } for (int index = 0; index < resolvedClasspath.length; index++) { if (isOnClasspathEntry(elementPath, isFolderPath, isPackageFragmentRoot, resolvedClasspath[index])) return true; } return false; }
From source file:org.eclipse.jdt.internal.core.PackageFragmentRootInfo.java
License:Open Source License
/** * Starting at this folder, create non-java resources for this package fragment root * and add them to the non-java resources collection. * * @exception JavaModelException The resource associated with this package fragment does not exist *///w w w . j ava 2 s. c o m static Object[] computeFolderNonJavaResources(IPackageFragmentRoot root, IContainer folder, char[][] inclusionPatterns, char[][] exclusionPatterns) throws JavaModelException { IResource[] nonJavaResources = new IResource[5]; int nonJavaResourcesCounter = 0; JavaProject project = (JavaProject) root.getJavaProject(); try { // GROOVY start // here, we only care about non-source package roots in Groovy projects boolean isInterestingPackageRoot = LanguageSupportFactory.isInterestingProject(project.getProject()) && root.getRawClasspathEntry().getEntryKind() != IClasspathEntry.CPE_SOURCE; // GROOVY end IClasspathEntry[] classpath = project.getResolvedClasspath(); IResource[] members = folder.members(); int length = members.length; if (length > 0) { String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); nextResource: for (int i = 0; i < length; i++) { IResource member = members[i]; switch (member.getType()) { case IResource.FILE: String fileName = member.getName(); // ignore .java files that are not excluded // GROOVY start /* old { if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel) && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) } new */ if ((Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel) && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) && // we want to show groovy scripts that are coming from class folders !(isInterestingPackageRoot && LanguageSupportFactory.isInterestingSourceFile(fileName))) // GROOVY end continue nextResource; // ignore .class files if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) continue nextResource; // ignore .zip or .jar file on classpath if (isClasspathEntry(member.getFullPath(), classpath)) continue nextResource; break; case IResource.FOLDER: // ignore valid packages or excluded folders that correspond to a nested pkg fragment root if (Util.isValidFolderNameForPackage(member.getName(), sourceLevel, complianceLevel) && (!Util.isExcluded(member, inclusionPatterns, exclusionPatterns) || isClasspathEntry(member.getFullPath(), classpath))) continue nextResource; break; } if (nonJavaResources.length == nonJavaResourcesCounter) { // resize System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]), 0, nonJavaResourcesCounter); } nonJavaResources[nonJavaResourcesCounter++] = member; } } if (ExternalFoldersManager.isInternalPathForExternalFolder(folder.getFullPath())) { IJarEntryResource[] jarEntryResources = new IJarEntryResource[nonJavaResourcesCounter]; for (int i = 0; i < nonJavaResourcesCounter; i++) { jarEntryResources[i] = new NonJavaResource(root, nonJavaResources[i]); } return jarEntryResources; } else if (nonJavaResources.length != nonJavaResourcesCounter) { System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter]), 0, nonJavaResourcesCounter); } return nonJavaResources; } catch (CoreException e) { throw new JavaModelException(e); } }
From source file:org.eclipse.jem.internal.beaninfo.core.BeaninfoEntry.java
License:Open Source License
static int kindFromString(String kindStr) { if (kindStr == null || kindStr.length() == 0) return BIE_PLUGIN; // Default to plugin. If coming from beaninfoconfig, there should always be kind. But if coming from plugin.xml there shouldn't be one. if (kindStr.equalsIgnoreCase("con")) //$NON-NLS-1$ return IClasspathEntry.CPE_CONTAINER; if (kindStr.equalsIgnoreCase("var")) //$NON-NLS-1$ return IClasspathEntry.CPE_VARIABLE; if (kindStr.equalsIgnoreCase("src")) //$NON-NLS-1$ return IClasspathEntry.CPE_SOURCE; if (kindStr.equalsIgnoreCase("lib")) //$NON-NLS-1$ return IClasspathEntry.CPE_LIBRARY; if (kindStr.equalsIgnoreCase("plugin")) //$NON-NLS-1$ return BIE_PLUGIN; return -1;/*from w w w. j a v a 2 s . c o m*/ }
From source file:org.eclipse.jem.internal.beaninfo.core.BeaninfoEntry.java
License:Open Source License
static String kindToString(int kind) { switch (kind) { case IClasspathEntry.CPE_PROJECT: return "src"; // backward compatibility //$NON-NLS-1$ case IClasspathEntry.CPE_SOURCE: return "src"; //$NON-NLS-1$ case IClasspathEntry.CPE_LIBRARY: return "lib"; //$NON-NLS-1$ case IClasspathEntry.CPE_VARIABLE: return "var"; //$NON-NLS-1$ case IClasspathEntry.CPE_CONTAINER: return "con"; //$NON-NLS-1$ case BIE_PLUGIN: return "plugin"; //$NON-NLS-1$ default://from ww w.j a va 2s.c o m return "unknown"; //$NON-NLS-1$ } }
From source file:org.eclipse.jem.internal.beaninfo.core.BeaninfoEntry.java
License:Open Source License
/** * Return the appropriate kind of entry when we know it is a classpath entry. */// w w w .j ava2 s . c o m public static IClasspathEntry createEntry(int kind, IPath path, IProject project, boolean isExported) { switch (kind) { case IClasspathEntry.CPE_LIBRARY: if (path.isAbsolute()) return JavaCore.newLibraryEntry(path, null, null, isExported); break; case IClasspathEntry.CPE_SOURCE: 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())) { // this project return JavaCore.newSourceEntry(path); } else { // another project return JavaCore.newProjectEntry(path, isExported); } } break; case IClasspathEntry.CPE_VARIABLE: return JavaCore.newVariableEntry(path, null, null, isExported); case IClasspathEntry.CPE_CONTAINER: return JavaCore.newContainerEntry(path, isExported); } return null; }
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 ww w. j a v a 2s .co 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./*from ww w .ja va 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.workbench.utility.JemProjectUtilities.java
License:Open Source License
protected static List getSourcePaths(IProject p) { IJavaProject javaProj = getJavaProject(p); if (javaProj == null) return null; IClasspathEntry[] cp = null;//from w w w . j ava 2s . c om try { cp = javaProj.getRawClasspath(); } catch (JavaModelException ex) { JEMUtilPlugin.getLogger().logError(ex); return null; } List sourcePaths = new ArrayList(); for (int i = 0; i < cp.length; i++) { if (cp[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { sourcePaths.add(cp[i].getPath().removeFirstSegments(1)); } } return sourcePaths; }
From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java
License:Open Source License
/** * Is this project a binary project.//from w ww. j a v a 2 s . com * <p> * Typically a Java project is considered binary if it does not have a source entry in the classpath. * * @param project * Project to test * @return <code>true</code> if project is a binary project. */ public static boolean isBinaryProject(IProject aProject) { IJavaProject javaProj = getJavaProject(aProject); if (javaProj == null) return false; IClasspathEntry[] entries = null; entries = javaProj.readRawClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) return false; } return true; }
From source file:org.eclipse.jem.workbench.utility.JemProjectUtilities.java
License:Open Source License
/** * Return the source path matching the parameter; if the parameter is null, or if the source folder is not on the classpath, return the first * source path on the classpath// w ww .j av a 2 s . co m * * @param p * project * @param defaultSourceName * source folder to find if on classpath, or if <code>null</code> the first folder * @return path searched for or <code>null</code> if not java project or some other problem. * * @since 1.0.0 */ public static IPath getSourcePathOrFirst(IProject p, String defaultSourceName) { IJavaProject javaProj = getJavaProject(p); if (javaProj == null) return null; IClasspathEntry[] cp = null; try { cp = javaProj.getRawClasspath(); } catch (JavaModelException ex) { JEMUtilPlugin.getLogger().logError(ex); return null; } IClasspathEntry firstSource = null; IPath defaultSourcePath = null; if (defaultSourceName != null) defaultSourcePath = ProjectUtilities.createPath(p, defaultSourceName); for (int i = 0; i < cp.length; i++) { if (cp[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { if (firstSource == null) { firstSource = cp[i]; if (defaultSourcePath == null) break; } if (cp[i].getPath().equals(defaultSourcePath)) return defaultSourcePath.removeFirstSegments(1); } } if (firstSource == null) return null; if (firstSource.getPath().segment(0).equals(p.getName())) return firstSource.getPath().removeFirstSegments(1); return null; }