List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE
int K_SOURCE
To view the source code for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE.
Click Source Link
From source file:org.eclipse.che.jdt.core.JavaCore.java
License:Open Source License
/** * Creates and returns a new classpath entry of kind <code>CPE_SOURCE</code> * for the project's source folder identified by the given absolute * workspace-relative path using the given inclusion and exclusion patterns * to determine which source files are included, and the given output path * to control the output location of generated files. * <p>/*w ww . j a v a2 s . c o m*/ * The source folder is referred to using an absolute path relative to the * workspace root, e.g. <code>/Project/src</code>. A project's source * folders are located with that project. That is, a source classpath * entry specifying the path <code>/P1/src</code> is only usable for * project <code>P1</code>. * </p> * <p> * The inclusion patterns determines the initial set of source files that * are to be included; the exclusion patterns are then used to reduce this * set. When no inclusion patterns are specified, the initial file set * includes all relevent files in the resource tree rooted at the source * entry's path. On the other hand, specifying one or more inclusion * patterns means that all <b>and only</b> files matching at least one of * the specified patterns are to be included. If exclusion patterns are * specified, the initial set of files is then reduced by eliminating files * matched by at least one of the exclusion patterns. Inclusion and * exclusion patterns look like relative file paths with wildcards and are * interpreted relative to the source entry's path. File patterns are * case-sensitive can contain '**', '*' or '?' wildcards (see * {@link IClasspathEntry#getExclusionPatterns()} for the full description * of their syntax and semantics). The resulting set of files are included * in the corresponding package fragment root; all package fragments within * the root will have children of type <code>ICompilationUnit</code>. * </p> * <p> * For example, if the source folder path is * <code>/Project/src</code>, there are no inclusion filters, and the * exclusion pattern is * <code>com/xyz/tests/**</code>, then source files * like <code>/Project/src/com/xyz/Foo.java</code> * and <code>/Project/src/com/xyz/utils/Bar.java</code> would be included, * whereas <code>/Project/src/com/xyz/tests/T1.java</code> * and <code>/Project/src/com/xyz/tests/quick/T2.java</code> would be * excluded. * </p> * <p> * Additionally, a source entry can be associated with a specific output location. * By doing so, the Java builder will ensure that the generated ".class" files will * be issued inside this output location, as opposed to be generated into the * project default output location (when output location is <code>null</code>). * Note that multiple source entries may target the same output location. * The output location is referred to using an absolute path relative to the * workspace root, e.g. <code>"/Project/bin"</code>, it must be located inside * the same project as the source folder. * </p> * <p> * Also note that all sources/binaries inside a project are contributed as * a whole through a project entry * (see <code>JavaCore.newProjectEntry</code>). Particular source entries * cannot be selectively exported. * </p> * <p> * The <code>extraAttributes</code> list contains name/value pairs that must be persisted with * this entry. If no extra attributes are provided, an empty array must be passed in.<br> * Note that this list should not contain any duplicate name. * </p> * * @param path the absolute workspace-relative path of a source folder * @param inclusionPatterns the possibly empty list of inclusion patterns * represented as relative paths * @param exclusionPatterns the possibly empty list of exclusion patterns * represented as relative paths * @param specificOutputLocation the specific output location for this source entry (<code>null</code> if using project default ouput location) * @param extraAttributes the possibly empty list of extra attributes to persist with this entry * @return a new source classpath entry with the given exclusion patterns * @see IClasspathEntry#getInclusionPatterns() * @see IClasspathEntry#getExclusionPatterns() * @see IClasspathEntry#getOutputLocation() * @since 3.1 */ public static IClasspathEntry newSourceEntry(IPath path, IPath[] inclusionPatterns, IPath[] exclusionPatterns, IPath specificOutputLocation, IClasspathAttribute[] extraAttributes) { if (path == null) throw new ClasspathEntry.AssertionFailedException("Source path cannot be null"); //$NON-NLS-1$ if (!path.isAbsolute()) throw new ClasspathEntry.AssertionFailedException("Path for IClasspathEntry must be absolute"); //$NON-NLS-1$ if (exclusionPatterns == null) { exclusionPatterns = ClasspathEntry.EXCLUDE_NONE; } if (inclusionPatterns == null) { inclusionPatterns = ClasspathEntry.INCLUDE_ALL; } if (extraAttributes == null) { extraAttributes = ClasspathEntry.NO_EXTRA_ATTRIBUTES; } return new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_SOURCE, path, inclusionPatterns, exclusionPatterns, null, // source attachment null, // source attachment root specificOutputLocation, // custom output location false, null, false, // no access rules to combine extraAttributes); }
From source file:org.eclipse.che.jdt.internal.core.ClasspathEntry.java
License:Open Source License
/** * Returns a printable representation of this classpath entry. *//*from w w w .j a v a 2 s. c o m*/ public String toString() { StringBuffer buffer = new StringBuffer(); // Object target = JavaModel.getTarget(getPath(), true); // if (target instanceof File) buffer.append(getPath().toOSString()); // else // buffer.append(String.valueOf(getPath())); buffer.append('['); switch (getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: buffer.append("CPE_LIBRARY"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_PROJECT: buffer.append("CPE_PROJECT"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_SOURCE: buffer.append("CPE_SOURCE"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_VARIABLE: buffer.append("CPE_VARIABLE"); //$NON-NLS-1$ break; case IClasspathEntry.CPE_CONTAINER: buffer.append("CPE_CONTAINER"); //$NON-NLS-1$ break; } buffer.append("]["); //$NON-NLS-1$ switch (getContentKind()) { case IPackageFragmentRoot.K_BINARY: buffer.append("K_BINARY"); //$NON-NLS-1$ break; case IPackageFragmentRoot.K_SOURCE: buffer.append("K_SOURCE"); //$NON-NLS-1$ break; case ClasspathEntry.K_OUTPUT: buffer.append("K_OUTPUT"); //$NON-NLS-1$ break; } buffer.append(']'); if (getSourceAttachmentPath() != null) { buffer.append("[sourcePath:"); //$NON-NLS-1$ buffer.append(getSourceAttachmentPath()); buffer.append(']'); } if (getSourceAttachmentRootPath() != null) { buffer.append("[rootPath:"); //$NON-NLS-1$ buffer.append(getSourceAttachmentRootPath()); buffer.append(']'); } buffer.append("[isExported:"); //$NON-NLS-1$ buffer.append(this.isExported); buffer.append(']'); IPath[] patterns = this.inclusionPatterns; int length; if ((length = patterns == null ? 0 : patterns.length) > 0) { buffer.append("[including:"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { buffer.append(patterns[i]); if (i != length - 1) { buffer.append('|'); } } buffer.append(']'); } patterns = this.exclusionPatterns; if ((length = patterns == null ? 0 : patterns.length) > 0) { buffer.append("[excluding:"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { buffer.append(patterns[i]); if (i != length - 1) { buffer.append('|'); } } buffer.append(']'); } if (this.accessRuleSet != null) { buffer.append('['); buffer.append(this.accessRuleSet.toString(false/*on one line*/)); buffer.append(']'); } if (this.entryKind == CPE_PROJECT) { buffer.append("[combine access rules:"); //$NON-NLS-1$ buffer.append(this.combineAccessRules); buffer.append(']'); } if (getOutputLocation() != null) { buffer.append("[output:"); //$NON-NLS-1$ buffer.append(getOutputLocation()); buffer.append(']'); } if ((length = this.extraAttributes == null ? 0 : this.extraAttributes.length) > 0) { buffer.append("[attributes:"); //$NON-NLS-1$ for (int i = 0; i < length; i++) { buffer.append(this.extraAttributes[i]); if (i != length - 1) { buffer.append(','); } } buffer.append(']'); } return buffer.toString(); }
From source file:org.eclipse.che.jdt.internal.core.JavaModelManager.java
License:Open Source License
private Map secondaryTypesSearching(IJavaProject project, boolean waitForIndexes, IProgressMonitor monitor, final PerProjectInfo projectInfo) throws JavaModelException { if (VERBOSE || BasicSearchEngine.VERBOSE) { StringBuffer buffer = new StringBuffer("JavaModelManager.secondaryTypesSearch("); //$NON-NLS-1$ buffer.append(project.getElementName()); buffer.append(','); buffer.append(waitForIndexes);/*from ww w. j ava 2 s . c o m*/ buffer.append(')'); Util.verbose(buffer.toString()); } final Hashtable secondaryTypes = new Hashtable(3); IRestrictedAccessTypeRequestor nameRequestor = new IRestrictedAccessTypeRequestor() { public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) { String key = packageName == null ? "" : new String(packageName); //$NON-NLS-1$ HashMap types = (HashMap) secondaryTypes.get(key); if (types == null) types = new HashMap(3); types.put(new String(simpleTypeName), path); secondaryTypes.put(key, types); } }; // Build scope using prereq projects but only source folders IPackageFragmentRoot[] allRoots = project.getAllPackageFragmentRoots(); int length = allRoots.length, size = 0; IPackageFragmentRoot[] allSourceFolders = new IPackageFragmentRoot[length]; for (int i = 0; i < length; i++) { if (allRoots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { allSourceFolders[size++] = allRoots[i]; } } if (size < length) { System.arraycopy(allSourceFolders, 0, allSourceFolders = new IPackageFragmentRoot[size], 0, size); } // Search all secondary types on scope new BasicSearchEngine(indexManager, (JavaProject) project).searchAllSecondaryTypeNames(allSourceFolders, nameRequestor, waitForIndexes, monitor); // Build types from paths Iterator packages = secondaryTypes.values().iterator(); while (packages.hasNext()) { HashMap types = (HashMap) packages.next(); HashMap tempTypes = new HashMap(types.size()); Iterator names = types.entrySet().iterator(); while (names.hasNext()) { Map.Entry entry = (Map.Entry) names.next(); String typeName = (String) entry.getKey(); String path = (String) entry.getValue(); names.remove(); if (Util.isJavaLikeFileName(path)) { File file = new File(path);// ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path)); ICompilationUnit unit = JavaModelManager.createCompilationUnitFrom(file, null); IType type = unit.getType(typeName); tempTypes.put(typeName, type); } } types.putAll(tempTypes); } // Store result in per project info cache if still null or there's still an indexing cache (may have been set by another thread...) if (projectInfo.secondaryTypes == null || projectInfo.secondaryTypes.get(INDEXED_SECONDARY_TYPES) != null) { projectInfo.secondaryTypes = secondaryTypes; if (VERBOSE || BasicSearchEngine.VERBOSE) { System.out.print(Thread.currentThread() + " -> secondary paths stored in cache: "); //$NON-NLS-1$ System.out.println(); Iterator entries = secondaryTypes.entrySet().iterator(); while (entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); String qualifiedName = (String) entry.getKey(); Util.verbose(" - " + qualifiedName + '-' + entry.getValue()); //$NON-NLS-1$ } } } return projectInfo.secondaryTypes; }
From source file:org.eclipse.che.jdt.internal.core.PackageFragmentRoot.java
License:Open Source License
public char[][] fullExclusionPatternChars() { try {//from ww w . j av a2 s . co m if (getKind() != IPackageFragmentRoot.K_SOURCE) return null; ClasspathEntry entry = (ClasspathEntry) getRawClasspathEntry(); if (entry == null) { return null; } else { return entry.fullExclusionPatternChars(); } } catch (JavaModelException e) { return null; } }
From source file:org.eclipse.che.jdt.internal.core.PackageFragmentRoot.java
License:Open Source License
public char[][] fullInclusionPatternChars() { try {//from www . ja v a 2 s . co m if (getKind() != IPackageFragmentRoot.K_SOURCE) return null; ClasspathEntry entry = (ClasspathEntry) getRawClasspathEntry(); if (entry == null) { return null; } else { return entry.fullInclusionPatternChars(); } } catch (JavaModelException e) { return null; } }
From source file:org.eclipse.che.jdt.internal.core.PackageFragmentRoot.java
License:Open Source License
@Override public int getKind() throws JavaModelException { return IPackageFragmentRoot.K_SOURCE; }
From source file:org.eclipse.che.jdt.internal.core.PackageFragmentRoot.java
License:Open Source License
/** * Returns the root's kind - K_SOURCE or K_BINARY, defaults * to K_SOURCE if it is not on the classpath. * * @throws JavaModelException// ww w . j av a 2 s. co m * if the project and root do * not exist. */ protected int determineKind(File underlyingResource) throws JavaModelException { IClasspathEntry entry = ((JavaProject) getJavaProject()) .getClasspathEntryFor(new Path(underlyingResource.getAbsolutePath())); if (entry != null) { return entry.getContentKind(); } return IPackageFragmentRoot.K_SOURCE; }
From source file:org.eclipse.che.jdt.internal.core.search.JavaSearchScope.java
License:Open Source License
/** * Add an element to the java search scope. * * @param element//from ww w . j av a 2s. c o m * The element we want to add to current java search scope * @throws org.eclipse.jdt.core.JavaModelException * May happen if some Java Model info are not available */ public void add(IJavaElement element) throws JavaModelException { IPath containerPath = null; String containerPathToString = null; PackageFragmentRoot root = null; int includeMask = SOURCES | APPLICATION_LIBRARIES | SYSTEM_LIBRARIES; switch (element.getElementType()) { case IJavaElement.JAVA_MODEL: // a workspace sope should be used break; case IJavaElement.JAVA_PROJECT: add((JavaProject) element, null, includeMask, new HashSet(2), new HashSet(2), null); break; case IJavaElement.PACKAGE_FRAGMENT_ROOT: root = (PackageFragmentRoot) element; IPath rootPath = root.internalPath(); containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : rootPath; containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); File rootResource = root.resource(); String projectPath = root.getJavaProject().getPath().toString(); if (rootResource != null /*&& rootResource.isAccessible()*/) { String relativePath = Util.relativePath(new Path(rootResource.getAbsolutePath()), containerPath.segmentCount()); add(projectPath, relativePath, containerPathToString, false/*not a package*/, null); } else { add(projectPath, "", containerPathToString, false/*not a package*/, null); //$NON-NLS-1$ } break; case IJavaElement.PACKAGE_FRAGMENT: root = (PackageFragmentRoot) element.getParent(); projectPath = root.getJavaProject().getPath().toString(); if (root.isArchive()) { String relativePath = org.eclipse.jdt.internal.core.util.Util .concatWith(((PackageFragment) element).names, '/'); containerPath = root.getPath(); containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); add(projectPath, relativePath, containerPathToString, true/*package*/, null); } else { File resource = ((JavaElement) element).resource(); if (resource != null) { // if (resource.isAccessible()) { containerPath = root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.internalPath(); // } else { // // for working copies, get resource container full path // containerPath = resource.getParent().getFullPath(); // } containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); String relativePath = Util.relativePath(new Path(resource.getAbsolutePath()), containerPath.segmentCount()); add(projectPath, relativePath, containerPathToString, true/*package*/, null); } } break; default: // remember sub-cu (or sub-class file) java elements if (element instanceof IMember) { if (this.elements == null) { this.elements = new ArrayList(); } this.elements.add(element); } root = (PackageFragmentRoot) element.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); projectPath = root.getJavaProject().getPath().toString(); String relativePath; if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { containerPath = root.getParent().getPath(); relativePath = Util.relativePath(getPath(element, false/*full path*/), 1/*remove project segment*/); } else { containerPath = root.internalPath(); relativePath = getPath(element, true/*relative path*/).toString(); } containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); add(projectPath, relativePath, containerPathToString, false/*not a package*/, null); } if (root != null) addEnclosingProjectOrJar( root.getKind() == IPackageFragmentRoot.K_SOURCE ? root.getParent().getPath() : root.getPath()); }
From source file:org.eclipse.che.jdt.internal.core.search.matching.JavaSearchNameEnvironment.java
License:Open Source License
private void computeClasspathLocations(JavaProject javaProject) { IPackageFragmentRoot[] roots = null; try {// www. j a v a 2 s. c o m roots = javaProject.getAllPackageFragmentRoots(); } catch (JavaModelException e) { // project doesn't exist this.locations = new CodenvyClasspathLocation[0]; return; } int length = roots.length; CodenvyClasspathLocation[] cpLocations = new CodenvyClasspathLocation[length]; int index = 0; JavaModelManager manager = javaProject.getJavaModelManager(); for (int i = 0; i < length; i++) { PackageFragmentRoot root = (PackageFragmentRoot) roots[i]; IPath path = root.getPath(); try { if (root.isArchive()) { ZipFile zipFile = manager.getZipFile(path); cpLocations[index++] = new ClasspathJar(zipFile, ((ClasspathEntry) root.getRawClasspathEntry()).getAccessRuleSet()); } else { Object target = JavaModelManager.getTarget(path, true); if (target == null) { // target doesn't exist any longer // just resize cpLocations System.arraycopy(cpLocations, 0, cpLocations = new CodenvyClasspathLocation[cpLocations.length - 1], 0, index); } else if (root.getKind() == IPackageFragmentRoot.K_SOURCE) { cpLocations[index++] = new ClasspathSourceDirectory((File) target, root.fullExclusionPatternChars(), root.fullInclusionPatternChars()); } else { cpLocations[index++] = new ClasspathDirectory((IContainer) target, false, ((ClasspathEntry) root.getRawClasspathEntry()).getAccessRuleSet()); } } } catch (CoreException e1) { // problem opening zip file or getting root kind // consider root corrupt and ignore // just resize cpLocations System.arraycopy(cpLocations, 0, cpLocations = new CodenvyClasspathLocation[cpLocations.length - 1], 0, index); } } this.locations = cpLocations; }
From source file:org.eclipse.che.jdt.util.JavaModelUtil.java
License:Open Source License
private static void addAllCus(HashSet<ICompilationUnit> collector, IJavaElement javaElement) throws JavaModelException { switch (javaElement.getElementType()) { case IJavaElement.JAVA_PROJECT: IJavaProject javaProject = (IJavaProject) javaElement; IPackageFragmentRoot[] packageFragmentRoots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < packageFragmentRoots.length; i++) addAllCus(collector, packageFragmentRoots[i]); return;//from ww w . j a v a2s .com case IJavaElement.PACKAGE_FRAGMENT_ROOT: IPackageFragmentRoot packageFragmentRoot = (IPackageFragmentRoot) javaElement; if (packageFragmentRoot.getKind() != IPackageFragmentRoot.K_SOURCE) return; IJavaElement[] packageFragments = packageFragmentRoot.getChildren(); for (int j = 0; j < packageFragments.length; j++) addAllCus(collector, packageFragments[j]); return; case IJavaElement.PACKAGE_FRAGMENT: IPackageFragment packageFragment = (IPackageFragment) javaElement; collector.addAll(Arrays.asList(packageFragment.getCompilationUnits())); return; case IJavaElement.COMPILATION_UNIT: collector.add((ICompilationUnit) javaElement); return; default: IJavaElement cu = javaElement.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) collector.add((ICompilationUnit) cu); } }