List of usage examples for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY
int CPE_LIBRARY
To view the source code for org.eclipse.jdt.core IClasspathEntry CPE_LIBRARY.
Click Source Link
From source file:com.codenvy.ide.ext.java.server.internal.core.JavaElement.java
License:Open Source License
protected static URL getLibraryJavadocLocation(IClasspathEntry entry) throws JavaModelException { switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: break;/*from w ww . jav a 2 s. c o m*/ default: 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())) { String value = attrib.getValue(); try { return new URL(value); } catch (MalformedURLException e) { throw new JavaModelException( new JavaModelStatus(IJavaModelStatusConstants.CANNOT_RETRIEVE_ATTACHED_JAVADOC, value)); } } } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.JavaElement.java
License:Open Source License
protected URL getJavadocBaseLocation() throws JavaModelException { IPackageFragmentRoot root = (IPackageFragmentRoot) getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); if (root == null) { return null; }/*from www . jav a 2 s .c o m*/ if (root.getKind() == IPackageFragmentRoot.K_BINARY) { IClasspathEntry entry = null; try { entry = root.getResolvedClasspathEntry(); URL url = getLibraryJavadocLocation(entry); if (url != null) { return url; } } catch (JavaModelException jme) { // Proceed with raw classpath } entry = root.getRawClasspathEntry(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: return getLibraryJavadocLocation(entry); default: return null; } } return null; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexAllProject.java
License:Open Source License
/** * Ensure consistency of a project index. Need to walk all nested resources, * and discover resources which have either been changed, added or deleted * since the index was produced.//from w w w . j a va2 s . co m */ public boolean execute(IProgressMonitor progressMonitor) { if (this.isCancelled || progressMonitor != null && progressMonitor.isCanceled()) return true; // if (!this.project.isAccessible()) return true; // nothing to do ReadWriteMonitor monitor = null; try { // Get source folder entries. Libraries are done as a separate job // JavaProject javaProject = (JavaProject)JavaCore.create(this.project); // Do not create marker while getting raw classpath (see bug 41859) IClasspathEntry[] entries = project.getRawClasspath(); int length = entries.length; IClasspathEntry[] sourceEntries = new IClasspathEntry[length]; int sourceEntriesNumber = 0; for (int i = 0; i < length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) sourceEntries[sourceEntriesNumber++] = entry; } if (sourceEntriesNumber == 0) { IPath projectPath = project.getPath(); for (int i = 0; i < length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(projectPath)) { // the project is also a library folder (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=89815) // ensure a job exists to index it as a binary folder this.manager.indexLibrary(projectPath, /*this.project,*/ ((ClasspathEntry) entry).getLibraryIndexLocation()); return true; } } // nothing to index but want to save an empty index file so its not 'rebuilt' when part of a search request Index index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/); if (index != null) this.manager.saveIndex(index); return true; } if (sourceEntriesNumber != length) System.arraycopy(sourceEntries, 0, sourceEntries = new IClasspathEntry[sourceEntriesNumber], 0, sourceEntriesNumber); Index index = this.manager.getIndexForUpdate(this.containerPath, true, /*reuse index file*/ true /*create if none*/); if (index == null) return true; monitor = index.monitor; if (monitor == null) return true; // index got deleted since acquired monitor.enterRead(); // ask permission to read String[] paths = index.queryDocumentNames(""); // all file names //$NON-NLS-1$ int max = paths == null ? 0 : paths.length; final SimpleLookupTable indexedFileNames = new SimpleLookupTable(max == 0 ? 33 : max + 11); final String OK = "OK"; //$NON-NLS-1$ final String DELETED = "DELETED"; //$NON-NLS-1$ if (paths != null) { for (int i = 0; i < max; i++) indexedFileNames.put(paths[i], DELETED); } final long indexLastModified = max == 0 ? 0L : index.getIndexLastModified(); // IWorkspaceRoot root = this.project.getWorkspace().getRoot(); for (int i = 0; i < sourceEntriesNumber; i++) { if (this.isCancelled) return false; IClasspathEntry entry = sourceEntries[i]; // IResource sourceFolder = root.findMember(entry.getPath()); Path sourceFolder = FileSystems.getDefault().getPath(entry.getPath().toOSString()); if (sourceFolder != null) { // collect output locations if source is project (see http://bugs.eclipse.org/bugs/show_bug.cgi?id=32041) final HashSet outputs = new HashSet(); //TODO // if (sourceFolder.getType() == IResource.PROJECT) { // // Do not create marker while getting output location (see bug 41859) // outputs.add(javaProject.getOutputLocation()); // for (int j = 0; j < sourceEntriesNumber; j++) { // IPath output = sourceEntries[j].getOutputLocation(); // if (output != null) { // outputs.add(output); // } // } // } final boolean hasOutputs = !outputs.isEmpty(); final char[][] inclusionPatterns = ((ClasspathEntry) entry).fullInclusionPatternChars(); final char[][] exclusionPatterns = ((ClasspathEntry) entry).fullExclusionPatternChars(); if (max == 0) { Files.walkFileTree(sourceFolder, new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (exclusionPatterns != null && inclusionPatterns == null) { // if there are inclusion patterns then we must walk the children if (Util.isExcluded(new org.eclipse.core.runtime.Path(dir.toFile().getPath()), inclusionPatterns, exclusionPatterns, true)) return FileVisitResult.SKIP_SUBTREE; } if (hasOutputs && outputs.contains(dir.toAbsolutePath())) return FileVisitResult.SKIP_SUBTREE; return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Util.isJavaLikeFileName(file.getFileName().toString())) { // IFile file = (IFile) proxy.requestResource(); org.eclipse.core.runtime.Path resourcePath = new org.eclipse.core.runtime.Path( file.toFile().getPath()); if (exclusionPatterns != null || inclusionPatterns != null) { if (Util.isExcluded(resourcePath, inclusionPatterns, exclusionPatterns, false)) return FileVisitResult.CONTINUE; } indexedFileNames.put(resourcePath.makeRelativeTo(containerPath).toOSString(), file); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); // sourceFolder.accept( // new IResourceProxyVisitor() { // public boolean visit(IResourceProxy proxy) { // if (IndexAllProject.this.isCancelled) return false; // switch(proxy.getType()) { // case IResource.FILE : // // case IResource.FOLDER : // // } // return true; // } // }, // IResource.NONE // ); } else { Files.walkFileTree(sourceFolder, new FileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (exclusionPatterns != null || inclusionPatterns != null) if (Util.isExcluded(new org.eclipse.core.runtime.Path(dir.toFile().getPath()), inclusionPatterns, exclusionPatterns, true)) return FileVisitResult.SKIP_SUBTREE; if (hasOutputs && outputs.contains(dir.toAbsolutePath())) return FileVisitResult.SKIP_SUBTREE; return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (Util.isJavaLikeFileName(file.getFileName().toString())) { // IFile file = (IFile) proxy.requestResource(); URI location = file.toUri(); if (location == null) return FileVisitResult.CONTINUE; if (exclusionPatterns != null || inclusionPatterns != null) if (Util.isExcluded( new org.eclipse.core.runtime.Path(file.toFile().getPath()), inclusionPatterns, exclusionPatterns, false)) return FileVisitResult.CONTINUE; String relativePathString = new org.eclipse.core.runtime.Path( file.toFile().getPath()).makeRelativeTo(containerPath).toOSString(); //Util.relativePath(new org.eclipse.core.runtime.Path(file.toFile().getPath()), 1/*remove project segment*/); indexedFileNames.put(relativePathString, indexedFileNames .get(relativePathString) == null || indexLastModified < 0 /*EFS.getStore(location).fetchInfo().getLastModified()*/ ? (Object) file : (Object) OK); } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { return FileVisitResult.CONTINUE; } }); // sourceFolder.accept( // new IResourceProxyVisitor() { // public boolean visit(IResourceProxy proxy) throws CoreException { // if (IndexAllProject.this.isCancelled) return false; // switch(proxy.getType()) { // case IResource.FILE : // if (Util.isJavaLikeFileName(proxy.getName())) { // IFile file = (IFile) proxy.requestResource(); // URI location = file.getLocationURI(); // if (location == null) return false; // if (exclusionPatterns != null || inclusionPatterns != null) // if (Util.isExcluded(file, inclusionPatterns, exclusionPatterns)) // return false; // String relativePathString = Util // .relativePath(file.getFullPath(), 1/*remove project segment*/); // indexedFileNames.put(relativePathString, // indexedFileNames.get(relativePathString) == null // || indexLastModified < 0 /*EFS.getStore(location).fetchInfo().getLastModified()*/ // ? (Object) file // : (Object) OK); // } // return false; // case IResource.FOLDER : // if (exclusionPatterns != null || inclusionPatterns != null) // if (Util.isExcluded(proxy.requestResource(), inclusionPatterns, exclusionPatterns)) // return false; // if (hasOutputs && outputs.contains(proxy.requestFullPath())) // return false; // } // return true; // } // }, // IResource.NONE // ); } } } SourceElementParser parser = this.manager.getSourceElementParser(project, null/*requestor will be set by indexer*/); Object[] names = indexedFileNames.keyTable; Object[] values = indexedFileNames.valueTable; for (int i = 0, namesLength = names.length; i < namesLength; i++) { String name = (String) names[i]; if (name != null) { if (this.isCancelled) return false; Object value = values[i]; if (value != OK) { if (value == DELETED) this.manager.remove(name, this.containerPath); else this.manager.addSource((Path) value, this.containerPath, parser); } } } // request to save index when all cus have been indexed... also sets state to SAVED_STATE this.manager.request(new SaveIndex(this.containerPath, this.manager)); } catch (CoreException e) { if (JobManager.VERBOSE) { Util.verbose("-> failed to index " + this.project + " because of the following exception:", //$NON-NLS-1$//$NON-NLS-2$ System.err); e.printStackTrace(); } this.manager.removeIndex(this.containerPath); return false; } catch (IOException e) { if (JobManager.VERBOSE) { Util.verbose("-> failed to index " + this.project + " because of the following exception:", //$NON-NLS-1$//$NON-NLS-2$ System.err); e.printStackTrace(); } this.manager.removeIndex(this.containerPath); return false; } finally { if (monitor != null) monitor.exitRead(); // free read lock } return true; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.IndexManager.java
License:Open Source License
/** * Trigger addition of the entire content of a project * Note: the actual operation is performed in background *///from ww w . j a v a2s . c o m public void indexAll(JavaProject project) { // if (JavaCore.getPlugin() == null) return; // Also request indexing of binaries on the classpath // determine the new children try { // JavaModel model = JavaModelManager.getJavaModelManager().getJavaModel(); // JavaProject javaProject = (JavaProject)model.getJavaProject(project); // only consider immediate libraries - each project will do the same // NOTE: force to resolve CP variables before calling indexer - 19303, so that initializers // will be run in the current thread. IClasspathEntry[] entries = project.getResolvedClasspath(); for (int i = 0; i < entries.length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) indexLibrary(entry.getPath(), /* project,*/ ((ClasspathEntry) entry).getLibraryIndexLocation()); } } catch (JavaModelException e) { // cannot retrieve classpath info } // check if the same request is not already in the queue IndexRequest request = new IndexAllProject(project, this); if (!isJobWaiting(request)) request(request); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.IndexSelector.java
License:Open Source License
/** * Returns whether elements of the given project or jar can see the given focus (an IJavaProject or * a JarPackageFragmentRot) either because the focus is part of the project or the jar, or because it is * accessible throught the project's classpath *//*from w ww .j a v a 2 s . c o m*/ public static boolean canSeeFocus(SearchPattern pattern, IPath projectOrJarPath) { try { IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel(); IJavaProject project = getJavaProject(projectOrJarPath, model); IJavaElement[] focuses = getFocusedElementsAndTypes(pattern, project, null); if (focuses.length == 0) return false; if (project != null) { return canSeeFocus(focuses, (JavaProject) project, null); } // projectOrJarPath is a jar // it can see the focus only if it is on the classpath of a project that can see the focus IJavaProject[] allProjects = model.getJavaProjects(); for (int i = 0, length = allProjects.length; i < length; i++) { JavaProject otherProject = (JavaProject) allProjects[i]; IClasspathEntry entry = otherProject.getClasspathEntryFor(projectOrJarPath); if (entry != null && entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { if (canSeeFocus(focuses, otherProject, null)) { return true; } } } return false; } catch (JavaModelException e) { return false; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.IndexSelector.java
License:Open Source License
private static boolean canSeeFocus(IJavaElement focus, JavaProject javaProject, char[][][] focusQualifiedNames) { try {//from w w w.j a v a2s .c om if (focus == null) return false; if (focus.equals(javaProject)) return true; if (focus instanceof JarPackageFragmentRoot) { // focus is part of a jar IPath focusPath = focus.getPath(); IClasspathEntry[] entries = javaProject.getExpandedClasspath(); for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY && entry.getPath().equals(focusPath)) return true; } return false; } // look for dependent projects IPath focusPath = ((JavaProject) focus).getProject().getFullPath(); IClasspathEntry[] entries = javaProject.getExpandedClasspath(); for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT && entry.getPath().equals(focusPath)) { if (focusQualifiedNames != null) { // builder state is usable, hence use it to try to reduce project which can see the focus... State projectState = (State) JavaModelManager.getJavaModelManager() .getLastBuiltState(javaProject.getProject(), null); if (projectState != null) { Object[] values = projectState.getReferences().valueTable; int vLength = values.length; for (int j = 0; j < vLength; j++) { if (values[j] == null) continue; ReferenceCollection references = (ReferenceCollection) values[j]; if (references.includes(focusQualifiedNames, null, null)) { return true; } } return false; } } return true; } } return false; } catch (JavaModelException e) { return false; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.IndexSelector.java
License:Open Source License
private void initializeIndexLocations() { IPath[] projectsAndJars = this.searchScope.enclosingProjectsAndJars(); // use a linked set to preserve the order during search: see bug 348507 LinkedHashSet locations = new LinkedHashSet(); IJavaElement focus = MatchLocator.projectOrJarFocus(this.pattern); if (focus == null) { for (int i = 0; i < projectsAndJars.length; i++) { IPath path = projectsAndJars[i]; Object target = new File(path.toOSString());//JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); locations.add(indexManager.computeIndexLocation(path)); }// w ww .j a v a 2 s . c om } else { try { // See whether the state builder might be used to reduce the number of index locations // find the projects from projectsAndJars that see the focus then walk those projects looking for the jars from projectsAndJars int length = projectsAndJars.length; JavaProject[] projectsCanSeeFocus = new JavaProject[length]; SimpleSet visitedProjects = new SimpleSet(length); int projectIndex = 0; SimpleSet externalLibsToCheck = new SimpleSet(length); ObjectVector superTypes = new ObjectVector(); IJavaElement[] focuses = getFocusedElementsAndTypes(this.pattern, focus, superTypes); char[][][] focusQualifiedNames = null; boolean isAutoBuilding = ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding(); if (isAutoBuilding && focus instanceof IJavaProject) { focusQualifiedNames = getQualifiedNames(superTypes); } IJavaModel model = JavaModelManager.getJavaModelManager().getJavaModel(); for (int i = 0; i < length; i++) { IPath path = projectsAndJars[i]; JavaProject project = (JavaProject) getJavaProject(path, model); if (project != null) { visitedProjects.add(project); if (canSeeFocus(focuses, project, focusQualifiedNames)) { locations.add(indexManager.computeIndexLocation(path)); projectsCanSeeFocus[projectIndex++] = project; } } else { externalLibsToCheck.add(path); } } for (int i = 0; i < projectIndex && externalLibsToCheck.elementSize > 0; i++) { IClasspathEntry[] entries = projectsCanSeeFocus[i].getResolvedClasspath(); for (int j = entries.length; --j >= 0;) { IClasspathEntry entry = entries[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = entry.getPath(); if (externalLibsToCheck.remove(path) != null) { Object target = JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); locations.add(indexManager.computeIndexLocation(path)); } } } } // jar files can be included in the search scope without including one of the projects that references them, so scan all projects that have not been visited if (externalLibsToCheck.elementSize > 0) { IJavaProject[] allProjects = model.getJavaProjects(); for (int i = 0, l = allProjects.length; i < l && externalLibsToCheck.elementSize > 0; i++) { JavaProject project = (JavaProject) allProjects[i]; if (!visitedProjects.includes(project)) { IClasspathEntry[] entries = project.getResolvedClasspath(); for (int j = entries.length; --j >= 0;) { IClasspathEntry entry = entries[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = entry.getPath(); if (externalLibsToCheck.remove(path) != null) { Object target = JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); locations.add(indexManager.computeIndexLocation(path)); } } } } } } } catch (JavaModelException e) { // ignored } } locations.remove(null); // Ensure no nulls this.indexLocations = (IndexLocation[]) locations.toArray(new IndexLocation[locations.size()]); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaSearchScope.java
License:Open Source License
/** * Add a path to current java search scope or all project fragment roots if null. * Use project resolved classpath to retrieve and store access restriction on each classpath entry. * Recurse if dependent projects are found. * * @param javaProject/*from w ww. ja v a 2s . c o m*/ * Project used to get resolved classpath entries * @param pathToAdd * Path to add in case of single element or null if user want to add all project package fragment roots * @param includeMask * Mask to apply on classpath entries * @param projectsToBeAdded * Set to avoid infinite recursion * @param visitedProjects * Set to avoid adding twice the same project * @param referringEntry * Project raw entry in referring project classpath * @throws org.eclipse.jdt.core.JavaModelException * May happen while getting java model info */ void add(JavaProject javaProject, IPath pathToAdd, int includeMask, HashSet projectsToBeAdded, HashSet visitedProjects, IClasspathEntry referringEntry) throws JavaModelException { // IProject project = javaProject.getProject(); // if (!project.isAccessible() || !visitedProjects.add(project)) return; IPath projectPath = javaProject.getFullPath(); String projectPathString = projectPath.toString(); addEnclosingProjectOrJar(projectPath); IClasspathEntry[] entries = javaProject.getResolvedClasspath(); // IJavaModel model = javaProject.getJavaModel(); // JavaModelManager.PerProjectInfo perProjectInfo = javaProject.getPerProjectInfo(); for (int i = 0, length = entries.length; i < length; i++) { IClasspathEntry entry = entries[i]; AccessRuleSet access = null; ClasspathEntry cpEntry = (ClasspathEntry) entry; if (referringEntry != null) { // Add only exported entries. // Source folder are implicitly exported. if (!entry.isExported() && entry.getEntryKind() != IClasspathEntry.CPE_SOURCE) { continue; } cpEntry = cpEntry.combineWith((ClasspathEntry) referringEntry); // cpEntry = ((ClasspathEntry)referringEntry).combineWith(cpEntry); } access = cpEntry.getAccessRuleSet(); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: IClasspathEntry rawEntry = null; // Map rootPathToRawEntries = perProjectInfo.rootPathToRawEntries; // if (rootPathToRawEntries != null) { // rawEntry = (IClasspathEntry)rootPathToRawEntries.get(entry.getPath()); // } // if (rawEntry == null) break; rawKind: switch (cpEntry.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: case IClasspathEntry.CPE_VARIABLE: if ((includeMask & APPLICATION_LIBRARIES) != 0) { IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { // Object target = JavaModel.getTarget(path, false/*don't check existence*/); // if (target instanceof IFolder) // case of an external folder // path = ((IFolder)target).getFullPath(); String pathToString = path.getDevice() == null ? path.toString() : path.toOSString(); add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$ addEnclosingProjectOrJar(entry.getPath()); } } break; case IClasspathEntry.CPE_CONTAINER: IClasspathContainer container = JavaCore.getClasspathContainer(rawEntry.getPath(), javaProject); if (container == null) break; switch (container.getKind()) { case IClasspathContainer.K_APPLICATION: if ((includeMask & APPLICATION_LIBRARIES) == 0) break rawKind; break; case IClasspathContainer.K_SYSTEM: case IClasspathContainer.K_DEFAULT_SYSTEM: if ((includeMask & SYSTEM_LIBRARIES) == 0) break rawKind; break; default: break rawKind; } IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { Object target = JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); String pathToString = path.getDevice() == null ? path.toString() : path.toOSString(); add(projectPath.toString(), "", pathToString, false/*not a package*/, access); //$NON-NLS-1$ addEnclosingProjectOrJar(entry.getPath()); } break; } break; case IClasspathEntry.CPE_PROJECT: // if ((includeMask & REFERENCED_PROJECTS) != 0) { // IPath path = entry.getPath(); // if (pathToAdd == null || pathToAdd.equals(path)) { // JavaProject referencedProject = (JavaProject)model.getJavaProject(path.lastSegment()); // if (!projectsToBeAdded // .contains(referencedProject)) { // do not recurse if depending project was used to create the scope // add(referencedProject, null, includeMask, projectsToBeAdded, visitedProjects, cpEntry); // } // } // } break; case IClasspathEntry.CPE_SOURCE: if ((includeMask & SOURCES) != 0) { IPath path = entry.getPath(); if (pathToAdd == null || pathToAdd.equals(path)) { add(projectPath.toString(), Util.relativePath(path, 1/*remove project segment*/), projectPathString, false/*not a package*/, access); } } break; } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaWorkspaceScope.java
License:Open Source License
public IPath[] enclosingProjectsAndJars() { IPath[] result = this.enclosingPaths; if (result != null) { return result; }//from w w w .j a v a 2 s .c o m long start = BasicSearchEngine.VERBOSE ? System.currentTimeMillis() : -1; try { IJavaProject[] projects = JavaModelManager.getJavaModelManager().getJavaModel().getJavaProjects(); // use a linked set to preserve the order during search: see bug 348507 Set paths = new LinkedHashSet(projects.length * 2); for (int i = 0, length = projects.length; i < length; i++) { JavaProject javaProject = (JavaProject) projects[i]; // Add project full path IPath projectPath = javaProject.getProject().getFullPath(); paths.add(projectPath); } // add the project source paths first in a separate loop above // to ensure source files always get higher precedence during search. // see bug 348507 for (int i = 0, length = projects.length; i < length; i++) { JavaProject javaProject = (JavaProject) projects[i]; // Add project libraries paths IClasspathEntry[] entries = javaProject.getResolvedClasspath(); for (int j = 0, eLength = entries.length; j < eLength; j++) { IClasspathEntry entry = entries[j]; if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { IPath path = entry.getPath(); Object target = JavaModel.getTarget(path, false/*don't check existence*/); if (target instanceof IFolder) // case of an external folder path = ((IFolder) target).getFullPath(); paths.add(entry.getPath()); } } } result = new IPath[paths.size()]; paths.toArray(result); return this.enclosingPaths = result; } catch (JavaModelException e) { Util.log(e, "Exception while computing workspace scope's enclosing projects and jars"); //$NON-NLS-1$ return new IPath[0]; } finally { if (BasicSearchEngine.VERBOSE) { long time = System.currentTimeMillis() - start; int length = result == null ? 0 : result.length; Util.verbose("JavaWorkspaceScope.enclosingProjectsAndJars: " + length + " paths computed in " + time //$NON-NLS-1$//$NON-NLS-2$ + "ms."); //$NON-NLS-1$ } } }
From source file:com.drgarbage.bytecode.jdi.dialogs.ProjectBuildPathDialog.java
License:Apache License
/** * Open a dialog to create a new workspace folder. * @see NewFolderDialog//w w w . ja va 2 s. c om */ private void newFolderButtonPressed() { NewFolderDialog dialog = new NewFolderDialog(getShell(), (IContainer) fJavaProject.getProject()); if (dialog.open() == Window.OK) { Object createdFolder = dialog.getResult()[0]; try { IResource res = (IResource) createdFolder; CPListElement classPathElement = new CPListElement(fJavaProject, IClasspathEntry.CPE_LIBRARY, res.getFullPath(), res); IClasspathEntry[] rawClassPath = fJavaProject.getRawClasspath(); List<IClasspathEntry> classPathList = new ArrayList<IClasspathEntry>(rawClassPath.length); for (IClasspathEntry ice : rawClassPath) { classPathList.add(ice); } /* add the new folder to the class path */ classPathList.add(classPathElement.getClasspathEntry()); fJavaProject.setRawClasspath(classPathList.toArray(new IClasspathEntry[0]), new NullProgressMonitor()); } catch (JavaModelException e) { BytecodeVisualizerPlugin.getDefault().getLog() .log(BytecodeVisualizerPlugin.createErrorStatus(e.getMessage(), e)); } /* refresh the input */ fPathViewer.setInput(fJavaProject.getResource().getWorkspace().getRoot()); fPathViewer.refresh(); } }