List of usage examples for org.eclipse.jdt.internal.core ExternalFoldersManager isInternalPathForExternalFolder
public static boolean isInternalPathForExternalFolder(IPath resourcePath)
From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaSearchScope.java
License:Open Source License
public String toString() { StringBuffer result = new StringBuffer("JavaSearchScope on "); //$NON-NLS-1$ if (this.elements != null) { result.append("["); //$NON-NLS-1$ for (int i = 0, length = this.elements.size(); i < length; i++) { JavaElement element = (JavaElement) this.elements.get(i); result.append("\n\t"); //$NON-NLS-1$ result.append(element.toStringWithAncestors()); }//from ww w. j av a 2s . c o m result.append("\n]"); //$NON-NLS-1$ } else { if (this.pathsCount == 0) { result.append("[empty scope]"); //$NON-NLS-1$ } else { result.append("["); //$NON-NLS-1$ String[] paths = new String[this.relativePaths.length]; int index = 0; for (int i = 0; i < this.relativePaths.length; i++) { String path = this.relativePaths[i]; if (path == null) continue; String containerPath; if (ExternalFoldersManager.isInternalPathForExternalFolder(new Path(this.containerPaths[i]))) { Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[i])); containerPath = ((IFolder) target).getLocation().toOSString(); } else { containerPath = this.containerPaths[i]; } if (path.length() > 0) { paths[index++] = containerPath + '/' + path; } else { paths[index++] = containerPath; } } System.arraycopy(paths, 0, paths = new String[index], 0, index); Util.sort(paths); for (int i = 0; i < index; i++) { result.append("\n\t"); //$NON-NLS-1$ result.append(paths[i]); } result.append("\n]"); //$NON-NLS-1$ } } return result.toString(); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.JavaWorkspaceScope.java
License:Open Source License
/** * @see org.eclipse.jdt.internal.core.search.AbstractJavaSearchScope#packageFragmentRoot(String, int, String) *//* ww w . j ava2 s . c o m*/ public IPackageFragmentRoot packageFragmentRoot(String resourcePathString, int jarSeparatorIndex, String jarPath) { HashMap rootInfos = JavaModelManager.getDeltaState().roots; DeltaProcessor.RootInfo rootInfo = null; if (jarPath != null) { IPath path = new Path(jarPath); rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path); } else { IPath path = new Path(resourcePathString); if (ExternalFoldersManager.isInternalPathForExternalFolder(path)) { IResource resource = JavaModel.getWorkspaceTarget( path.uptoSegment(2/*linked folders for external folders are always of size 2*/)); if (resource != null) rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(resource.getLocation()); } else { rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path); while (rootInfo == null && path.segmentCount() > 0) { path = path.removeLastSegments(1); rootInfo = (DeltaProcessor.RootInfo) rootInfos.get(path); } } } if (rootInfo == null) return null; return rootInfo.getPackageFragmentRoot(null/*no resource hint*/); }
From source file:org.eclipse.che.jdt.internal.core.search.JavaSearchScope.java
License:Open Source License
public String toString() { StringBuffer result = new StringBuffer("JavaSearchScope on "); //$NON-NLS-1$ if (this.elements != null) { result.append("["); //$NON-NLS-1$ for (int i = 0, length = this.elements.size(); i < length; i++) { JavaElement element = (JavaElement) this.elements.get(i); result.append("\n\t"); //$NON-NLS-1$ result.append(element.toStringWithAncestors()); }/*from ww w . j a va 2 s . com*/ result.append("\n]"); //$NON-NLS-1$ } else { if (this.pathsCount == 0) { result.append("[empty scope]"); //$NON-NLS-1$ } else { result.append("["); //$NON-NLS-1$ String[] paths = new String[this.relativePaths.length]; int index = 0; for (int i = 0; i < this.relativePaths.length; i++) { String path = this.relativePaths[i]; if (path == null) continue; String containerPath; if (ExternalFoldersManager.isInternalPathForExternalFolder(new Path(this.containerPaths[i]))) { Object target = JavaModel.getWorkspaceTarget(new Path(this.containerPaths[i])); containerPath = ((IFolder) target).getLocation().toOSString(); } else { containerPath = this.containerPaths[i]; } if (path.length() > 0) { paths[index++] = containerPath + '/' + path; } else { paths[index++] = containerPath; } } System.arraycopy(paths, 0, paths = new String[index], 0, index); org.eclipse.jdt.internal.core.util.Util.sort(paths); for (int i = 0; i < index; i++) { result.append("\n\t"); //$NON-NLS-1$ result.append(paths[i]); } result.append("\n]"); //$NON-NLS-1$ } } return result.toString(); }
From source file:org.eclipse.jdt.internal.core.JavaModelManager.java
License:Open Source License
/** * Returns the package fragment root represented by the resource, or * the package fragment the given resource is located in, or <code>null</code> * if the given resource is not on the classpath of the given project. */// w w w .ja v a 2 s . c o m public static IJavaElement determineIfOnClasspath(IResource resource, IJavaProject project) { IPath resourcePath = resource.getFullPath(); boolean isExternal = ExternalFoldersManager.isInternalPathForExternalFolder(resourcePath); if (isExternal) resourcePath = resource.getLocation(); try { JavaProjectElementInfo projectInfo = (JavaProjectElementInfo) getJavaModelManager().getInfo(project); ProjectCache projectCache = projectInfo == null ? null : projectInfo.projectCache; HashtableOfArrayToObject allPkgFragmentsCache = projectCache == null ? null : projectCache.allPkgFragmentsCache; boolean isJavaLike = org.eclipse.jdt.internal.core.util.Util .isJavaLikeFileName(resourcePath.lastSegment()); IClasspathEntry[] entries = isJavaLike ? project.getRawClasspath() // JAVA file can only live inside SRC folder (on the raw path) : ((JavaProject) project).getResolvedClasspath(); int length = entries.length; if (length > 0) { String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); for (int i = 0; i < length; i++) { IClasspathEntry entry = entries[i]; if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) continue; IPath rootPath = entry.getPath(); if (rootPath.equals(resourcePath)) { if (isJavaLike) return null; return project.getPackageFragmentRoot(resource); } else if (rootPath.isPrefixOf(resourcePath)) { // allow creation of package fragment if it contains a .java file that is included if (!Util.isExcluded(resource, ((ClasspathEntry) entry).fullInclusionPatternChars(), ((ClasspathEntry) entry).fullExclusionPatternChars())) { // given we have a resource child of the root, it cannot be a JAR pkg root PackageFragmentRoot root = isExternal ? new ExternalPackageFragmentRoot(rootPath, (JavaProject) project) : (PackageFragmentRoot) ((JavaProject) project) .getFolderPackageFragmentRoot(rootPath); if (root == null) return null; IPath pkgPath = resourcePath.removeFirstSegments(rootPath.segmentCount()); if (resource.getType() == IResource.FILE) { // if the resource is a file, then remove the last segment which // is the file name in the package pkgPath = pkgPath.removeLastSegments(1); } String[] pkgName = pkgPath.segments(); // if package name is in the cache, then it has already been validated // (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=133141) if (allPkgFragmentsCache != null && allPkgFragmentsCache.containsKey(pkgName)) return root.getPackageFragment(pkgName); if (pkgName.length != 0 && JavaConventions .validatePackageName(Util.packageName(pkgPath, sourceLevel, complianceLevel), sourceLevel, complianceLevel) .getSeverity() == IStatus.ERROR) { return null; } return root.getPackageFragment(pkgName); } } } } } catch (JavaModelException npe) { return null; } return null; }
From source file:org.eclipse.jdt.internal.core.JavaProject.java
License:Open Source License
private IPackageFragmentRoot getPackageFragmentRoot(IResource resource, IPath entryPath) { switch (resource.getType()) { case IResource.FILE: return new JarPackageFragmentRoot(resource, this); case IResource.FOLDER: if (ExternalFoldersManager.isInternalPathForExternalFolder(resource.getFullPath())) return new ExternalPackageFragmentRoot(resource, entryPath, this); return new PackageFragmentRoot(resource, this); case IResource.PROJECT: return new PackageFragmentRoot(resource, this); default:/*from w ww. ja v a2 s. com*/ return null; } }
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 *//*from w ww . ja va2 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); } }