List of usage examples for org.eclipse.jdt.internal.core.util Util isValidCompilationUnitName
public static boolean isValidCompilationUnitName(String name, String sourceLevel, String complianceLevel)
From source file:com.codenvy.ide.ext.java.server.internal.core.DeltaProcessor.java
License:Open Source License
private int elementType(File res, int kind, int parentType, RootInfo rootInfo) { Path path = new Path(res.getAbsolutePath()); switch (parentType) { case IJavaElement.JAVA_MODEL: // case of a movedTo or movedFrom project (other cases are handled in processResourceDelta(...) return IJavaElement.JAVA_PROJECT; case NON_JAVA_RESOURCE: case IJavaElement.JAVA_PROJECT: if (rootInfo == null) { rootInfo = enclosingRootInfo(path, kind); }//from w w w . j a v a 2 s.c o m if (rootInfo != null && rootInfo.isRootOfProject(path)) { return IJavaElement.PACKAGE_FRAGMENT_ROOT; } // not yet in a package fragment root or root of another project // or package fragment to be included (see below) // $FALL-THROUGH$ case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.PACKAGE_FRAGMENT: if (rootInfo == null) { IPath rootPath = externalPath(res); rootInfo = enclosingRootInfo(rootPath, kind); } if (rootInfo == null) { return NON_JAVA_RESOURCE; } if (Util.isExcluded(path, rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) { return NON_JAVA_RESOURCE; } if (res.isDirectory()) { if (parentType == NON_JAVA_RESOURCE && !Util.isExcluded(new Path(res.getParent()), rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) { // parent is a non-Java resource because it doesn't have a valid package name (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=130982) return NON_JAVA_RESOURCE; } String sourceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (Util.isValidFolderNameForPackage(res.getName(), sourceLevel, complianceLevel)) { return IJavaElement.PACKAGE_FRAGMENT; } return NON_JAVA_RESOURCE; } String fileName = res.getName(); String sourceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel)) { return IJavaElement.COMPILATION_UNIT; } else if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) { return IJavaElement.CLASS_FILE; } else { IPath rootPath = externalPath(res); if ((rootInfo = rootInfo(rootPath, kind)) != null && rootInfo.project.getProject().getFullPath().isPrefixOf( rootPath) /*ensure root is a root of its project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185310) */) { // case of proj=src=bin and resource is a jar file on the classpath return IJavaElement.PACKAGE_FRAGMENT_ROOT; } else { return NON_JAVA_RESOURCE; } } default: return NON_JAVA_RESOURCE; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.JavaProjectElementInfo.java
License:Open Source License
/** * Compute the non-java resources contained in this java project. *///ww w . j av a2 s . c o m private Object[] computeNonJavaResources(JavaProject project) { // determine if src == project and/or if bin == project IPath projectPath = project.getProject().getFullPath(); boolean srcIsProject = false; boolean binIsProject = false; char[][] inclusionPatterns = null; char[][] exclusionPatterns = null; IPath projectOutput = null; boolean isClasspathResolved = true; try { IClasspathEntry entry = project.getClasspathEntryFor(projectPath); if (entry != null) { srcIsProject = true; inclusionPatterns = ((ClasspathEntry) entry).fullInclusionPatternChars(); exclusionPatterns = ((ClasspathEntry) entry).fullExclusionPatternChars(); } projectOutput = project.getOutputLocation(); binIsProject = projectPath.equals(projectOutput); } catch (JavaModelException e) { isClasspathResolved = false; } Object[] resources = new IResource[5]; int resourcesCounter = 0; try { IResource[] members = ((IContainer) project.getResource()).members(); int length = members.length; if (length > 0) { String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); IClasspathEntry[] classpath = project.getResolvedClasspath(); for (int i = 0; i < length; i++) { IResource res = members[i]; switch (res.getType()) { case IResource.FILE: IPath resFullPath = res.getFullPath(); String resName = res.getName(); // ignore a jar file on the classpath if (isClasspathResolved && isClasspathEntryOrOutputLocation(resFullPath, res.getLocation()/* see https://bugs.eclipse .org/bugs/show_bug.cgi?id=244406 */, classpath, projectOutput)) { break; } // ignore .java file if src == project if (srcIsProject && Util.isValidCompilationUnitName(resName, sourceLevel, complianceLevel) && !Util.isExcluded(res, inclusionPatterns, exclusionPatterns)) { break; } // ignore .class file if bin == project if (binIsProject && Util.isValidClassFileName(resName, sourceLevel, complianceLevel)) { break; } // else add non java resource if (resources.length == resourcesCounter) { // resize System.arraycopy(resources, 0, (resources = new IResource[resourcesCounter * 2]), 0, resourcesCounter); } resources[resourcesCounter++] = res; break; case IResource.FOLDER: resFullPath = res.getFullPath(); // ignore non-excluded folders on the classpath or that correspond to an output location if ((srcIsProject && !Util.isExcluded(res, inclusionPatterns, exclusionPatterns) && Util.isValidFolderNameForPackage(res.getName(), sourceLevel, complianceLevel)) || (isClasspathResolved && isClasspathEntryOrOutputLocation(resFullPath, res.getLocation(), classpath, projectOutput))) { break; } // else add non java resource if (resources.length == resourcesCounter) { // resize System.arraycopy(resources, 0, (resources = new IResource[resourcesCounter * 2]), 0, resourcesCounter); } resources[resourcesCounter++] = res; } } } if (resources.length != resourcesCounter) { System.arraycopy(resources, 0, (resources = new IResource[resourcesCounter]), 0, resourcesCounter); } } catch (CoreException e) { resources = NO_NON_JAVA_RESOURCES; resourcesCounter = 0; } return resources; }
From source file:com.codenvy.ide.ext.java.server.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 org.eclipse.jdt.core.JavaModelException The resource associated with this package fragment does not exist */// w ww .j a v a2 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; try { IResource[] members = folder.members(); int length = members.length; if (length > 0) { // if package fragment root refers to folder in another IProject, then // folder.getProject() is different than root.getJavaProject().getProject() // use the other java project's options to verify the name IJavaProject otherJavaProject = JavaCore.create(folder.getProject()); String sourceLevel = otherJavaProject.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = otherJavaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true); JavaProject javaProject = (JavaProject) root.getJavaProject(); IClasspathEntry[] classpath = javaProject.getResolvedClasspath(); 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 if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel) && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) 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.che.jdt.internal.core.DeltaProcessor.java
License:Open Source License
private int elementType(File res, int kind, int parentType, RootInfo rootInfo) { Path path = new Path(res.getAbsolutePath()); switch (parentType) { case IJavaElement.JAVA_MODEL: // case of a movedTo or movedFrom project (other cases are handled in processResourceDelta(...) return IJavaElement.JAVA_PROJECT; case NON_JAVA_RESOURCE: case IJavaElement.JAVA_PROJECT: if (rootInfo == null) { rootInfo = enclosingRootInfo(path, kind); }// w w w . j av a2 s . com if (rootInfo != null && rootInfo.isRootOfProject(path)) { return IJavaElement.PACKAGE_FRAGMENT_ROOT; } // not yet in a package fragment root or root of another project // or package fragment to be included (see below) // $FALL-THROUGH$ case IJavaElement.PACKAGE_FRAGMENT_ROOT: case IJavaElement.PACKAGE_FRAGMENT: if (rootInfo == null) { IPath rootPath = externalPath(res); rootInfo = enclosingRootInfo(rootPath, kind); } if (rootInfo == null) { return NON_JAVA_RESOURCE; } if (Util.isExcluded(path, rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) { return NON_JAVA_RESOURCE; } if (res.isDirectory()) { if (parentType == NON_JAVA_RESOURCE && !Util.isExcluded(new Path(res.getParent()), rootInfo.inclusionPatterns, rootInfo.exclusionPatterns, false)) { // parent is a non-Java resource because it doesn't have a valid package name (see https://bugs.eclipse // .org/bugs/show_bug.cgi?id=130982) return NON_JAVA_RESOURCE; } String sourceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (Util.isValidFolderNameForPackage(res.getName(), sourceLevel, complianceLevel)) { return IJavaElement.PACKAGE_FRAGMENT; } return NON_JAVA_RESOURCE; } String fileName = res.getName(); String sourceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = rootInfo.project == null ? null : rootInfo.project.getOption(JavaCore.COMPILER_COMPLIANCE, true); if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel)) { return IJavaElement.COMPILATION_UNIT; } else if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) { return IJavaElement.CLASS_FILE; } else { IPath rootPath = externalPath(res); if ((rootInfo = rootInfo(rootPath, kind)) != null && rootInfo.project.getProject().getFullPath().isPrefixOf(rootPath) /*ensure root is a root of its project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185310) */) { // case of proj=src=bin and resource is a jar file on the classpath return IJavaElement.PACKAGE_FRAGMENT_ROOT; } else { return NON_JAVA_RESOURCE; } } default: return NON_JAVA_RESOURCE; } }
From source file:org.eclipse.jdt.internal.core.PackageFragment.java
License:Open Source License
/** * @see Openable//from w w w. ja v a 2 s .c om */ protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { // add compilation units/class files from resources HashSet vChildren = new HashSet(); int kind = getKind(); try { PackageFragmentRoot root = getPackageFragmentRoot(); char[][] inclusionPatterns = root.fullInclusionPatternChars(); char[][] exclusionPatterns = root.fullExclusionPatternChars(); IResource[] members = ((IContainer) underlyingResource).members(); int length = members.length; if (length > 0) { IJavaProject project = getJavaProject(); String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); for (int i = 0; i < length; i++) { IResource child = members[i]; if (child.getType() != IResource.FOLDER && !Util.isExcluded(child, inclusionPatterns, exclusionPatterns)) { IJavaElement childElement; if (kind == IPackageFragmentRoot.K_SOURCE && Util.isValidCompilationUnitName(child.getName(), sourceLevel, complianceLevel)) { // GROOVY start /* old { childElement = new CompilationUnit(this, child.getName(), DefaultWorkingCopyOwner.PRIMARY); } new */ childElement = LanguageSupportFactory.newCompilationUnit(this, child.getName(), DefaultWorkingCopyOwner.PRIMARY); // GROOVY end vChildren.add(childElement); } else if (kind == IPackageFragmentRoot.K_BINARY && Util.isValidClassFileName(child.getName(), sourceLevel, complianceLevel)) { childElement = getClassFile(child.getName()); vChildren.add(childElement); } } } } } catch (CoreException e) { throw new JavaModelException(e); } if (kind == IPackageFragmentRoot.K_SOURCE) { // add primary compilation units ICompilationUnit[] primaryCompilationUnits = getCompilationUnits(DefaultWorkingCopyOwner.PRIMARY); for (int i = 0, length = primaryCompilationUnits.length; i < length; i++) { ICompilationUnit primary = primaryCompilationUnits[i]; vChildren.add(primary); } } IJavaElement[] children = new IJavaElement[vChildren.size()]; vChildren.toArray(children); info.setChildren(children); return true; }
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 ww . j a v a 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); } }