1 11 package org.eclipse.jdt.internal.core; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.core.resources.IContainer; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IPath; 17 18 import org.eclipse.jdt.core.*; 19 import org.eclipse.jdt.internal.core.util.Util; 20 21 24 class PackageFragmentRootInfo extends OpenableElementInfo { 25 26 30 protected SourceMapper sourceMapper = null; 31 32 38 protected int fRootKind= IPackageFragmentRoot.K_SOURCE; 39 40 43 protected Object [] fNonJavaResources; 44 47 public PackageFragmentRootInfo() { 48 this.fNonJavaResources = null; 49 } 50 56 static Object [] computeFolderNonJavaResources(JavaProject project, IContainer folder, char[][] inclusionPatterns, char[][] exclusionPatterns) throws JavaModelException { 57 Object [] nonJavaResources = new IResource[5]; 58 int nonJavaResourcesCounter = 0; 59 try { 60 IClasspathEntry[] classpath = project.getResolvedClasspath(); 61 IResource[] members = folder.members(); 62 int length = members.length; 63 if (length > 0) { 64 String sourceLevel = project.getOption(JavaCore.COMPILER_SOURCE, true); 65 String complianceLevel = project.getOption(JavaCore.COMPILER_COMPLIANCE, true); 66 nextResource: for (int i = 0; i < length; i++) { 67 IResource member = members[i]; 68 switch (member.getType()) { 69 case IResource.FILE : 70 String fileName = member.getName(); 71 72 if (Util.isValidCompilationUnitName(fileName, sourceLevel, complianceLevel) && !Util.isExcluded(member, inclusionPatterns, exclusionPatterns)) 74 continue nextResource; 75 if (Util.isValidClassFileName(fileName, sourceLevel, complianceLevel)) 77 continue nextResource; 78 if (org.eclipse.jdt.internal.compiler.util.Util.isArchiveFileName(fileName) && isClasspathEntry(member.getFullPath(), classpath)) 80 continue nextResource; 81 break; 82 83 case IResource.FOLDER : 84 if (Util.isValidFolderNameForPackage(member.getName(), sourceLevel, complianceLevel) 86 && (!Util.isExcluded(member, inclusionPatterns, exclusionPatterns) 87 || isClasspathEntry(member.getFullPath(), classpath))) 88 continue nextResource; 89 break; 90 } 91 if (nonJavaResources.length == nonJavaResourcesCounter) { 92 System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter * 2]), 0, nonJavaResourcesCounter); 94 } 95 nonJavaResources[nonJavaResourcesCounter++] = member; 96 } 97 } 98 if (nonJavaResources.length != nonJavaResourcesCounter) { 99 System.arraycopy(nonJavaResources, 0, (nonJavaResources = new IResource[nonJavaResourcesCounter]), 0, nonJavaResourcesCounter); 100 } 101 return nonJavaResources; 102 } catch (CoreException e) { 103 throw new JavaModelException(e); 104 } 105 } 106 109 private Object [] computeNonJavaResources(IJavaProject project, IResource underlyingResource, PackageFragmentRoot handle) { 110 Object [] nonJavaResources = NO_NON_JAVA_RESOURCES; 111 try { 112 if (underlyingResource.getType() == IResource.FOLDER || underlyingResource.getType() == IResource.PROJECT) { 115 nonJavaResources = 116 computeFolderNonJavaResources( 117 (JavaProject)project, 118 (IContainer) underlyingResource, 119 handle.fullInclusionPatternChars(), 120 handle.fullExclusionPatternChars()); 121 } 122 } catch (JavaModelException e) { 123 } 125 return nonJavaResources; 126 } 127 130 synchronized Object [] getNonJavaResources(IJavaProject project, IResource underlyingResource, PackageFragmentRoot handle) { 131 Object [] nonJavaResources = this.fNonJavaResources; 132 if (nonJavaResources == null) { 133 nonJavaResources = this.computeNonJavaResources(project, underlyingResource, handle); 134 this.fNonJavaResources = nonJavaResources; 135 } 136 return nonJavaResources; 137 } 138 141 public int getRootKind() { 142 return this.fRootKind; 143 } 144 148 protected SourceMapper getSourceMapper() { 149 return this.sourceMapper; 150 } 151 private static boolean isClasspathEntry(IPath path, IClasspathEntry[] resolvedClasspath) { 152 for (int i = 0, length = resolvedClasspath.length; i < length; i++) { 153 IClasspathEntry entry = resolvedClasspath[i]; 154 if (entry.getPath().equals(path)) { 155 return true; 156 } 157 } 158 return false; 159 } 160 163 void setNonJavaResources(Object [] resources) { 164 this.fNonJavaResources = resources; 165 } 166 169 protected void setRootKind(int newRootKind) { 170 this.fRootKind = newRootKind; 171 } 172 175 protected void setSourceMapper(SourceMapper mapper) { 176 this.sourceMapper= mapper; 177 } 178 } 179 | Popular Tags |