1 11 package org.eclipse.jdt.internal.core.search.matching; 12 13 import org.eclipse.core.resources.IContainer; 14 import org.eclipse.core.resources.IFile; 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IPath; 18 import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; 19 import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; 20 import org.eclipse.jdt.internal.core.builder.ClasspathLocation; 21 import org.eclipse.jdt.internal.core.util.ResourceCompilationUnit; 22 import org.eclipse.jdt.internal.core.util.Util; 23 24 public class ClasspathSourceDirectory extends ClasspathLocation { 25 26 IContainer sourceFolder; 27 SimpleLookupTable directoryCache; 28 SimpleLookupTable missingPackageHolder = new SimpleLookupTable(); 29 char[][] fullExclusionPatternChars; 30 char[][] fulInclusionPatternChars; 31 32 ClasspathSourceDirectory(IContainer sourceFolder, char[][] fullExclusionPatternChars, char[][] fulInclusionPatternChars) { 33 this.sourceFolder = sourceFolder; 34 this.directoryCache = new SimpleLookupTable(5); 35 this.fullExclusionPatternChars = fullExclusionPatternChars; 36 this.fulInclusionPatternChars = fulInclusionPatternChars; 37 } 38 39 public void cleanup() { 40 this.directoryCache = null; 41 } 42 43 SimpleLookupTable directoryTable(String qualifiedPackageName) { 44 SimpleLookupTable dirTable = (SimpleLookupTable) directoryCache.get(qualifiedPackageName); 45 if (dirTable == missingPackageHolder) return null; if (dirTable != null) return dirTable; 47 48 try { 49 IResource container = sourceFolder.findMember(qualifiedPackageName); if (container instanceof IContainer) { 51 IResource[] members = ((IContainer) container).members(); 52 dirTable = new SimpleLookupTable(); 53 for (int i = 0, l = members.length; i < l; i++) { 54 IResource m = members[i]; 55 String name; 56 if (m.getType() == IResource.FILE) { 57 int index = Util.indexOfJavaLikeExtension(name = m.getName()); 58 if (index >= 0) { 59 String fullPath = m.getFullPath().toString(); 60 if (!org.eclipse.jdt.internal.compiler.util.Util.isExcluded(fullPath.toCharArray(), this.fulInclusionPatternChars, this.fullExclusionPatternChars, false)) { 61 dirTable.put(name.substring(0, index), m); 62 } 63 } 64 } 65 } 66 directoryCache.put(qualifiedPackageName, dirTable); 67 return dirTable; 68 } 69 } catch(CoreException ignored) { 70 } 72 directoryCache.put(qualifiedPackageName, missingPackageHolder); 73 return null; 74 } 75 76 public boolean equals(Object o) { 77 if (this == o) return true; 78 if (!(o instanceof ClasspathSourceDirectory)) return false; 79 80 return sourceFolder.equals(((ClasspathSourceDirectory) o).sourceFolder); 81 } 82 83 public NameEnvironmentAnswer findClass(String sourceFileWithoutExtension, String qualifiedPackageName, String qualifiedSourceFileWithoutExtension) { 84 SimpleLookupTable dirTable = directoryTable(qualifiedPackageName); 85 if (dirTable != null && dirTable.elementSize > 0) { 86 IFile file = (IFile) dirTable.get(sourceFileWithoutExtension); 87 if (file != null) { 88 return new NameEnvironmentAnswer(new ResourceCompilationUnit(file, file.getLocationURI()), null ); 89 } 90 } 91 return null; 92 } 93 94 public IPath getProjectRelativePath() { 95 return sourceFolder.getProjectRelativePath(); 96 } 97 98 public boolean isPackage(String qualifiedPackageName) { 99 return directoryTable(qualifiedPackageName) != null; 100 } 101 102 public void reset() { 103 this.directoryCache = new SimpleLookupTable(5); 104 } 105 106 public String toString() { 107 return "Source classpath directory " + sourceFolder.getFullPath().toString(); } 109 110 public String debugPathString() { 111 return this.sourceFolder.getFullPath().toString(); 112 } 113 114 } 115 | Popular Tags |