Lines 15-21
Link Here
|
15 |
import org.eclipse.core.resources.IResource; |
15 |
import org.eclipse.core.resources.IResource; |
16 |
import org.eclipse.core.runtime.CoreException; |
16 |
import org.eclipse.core.runtime.CoreException; |
17 |
import org.eclipse.core.runtime.IPath; |
17 |
import org.eclipse.core.runtime.IPath; |
18 |
import org.eclipse.core.runtime.Path; |
|
|
19 |
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; |
18 |
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer; |
20 |
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; |
19 |
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; |
21 |
import org.eclipse.jdt.internal.core.builder.ClasspathLocation; |
20 |
import org.eclipse.jdt.internal.core.builder.ClasspathLocation; |
Lines 26-32
Link Here
|
26 |
|
25 |
|
27 |
IContainer sourceFolder; |
26 |
IContainer sourceFolder; |
28 |
SimpleLookupTable directoryCache; |
27 |
SimpleLookupTable directoryCache; |
29 |
String[] missingPackageHolder = new String[1]; |
28 |
SimpleLookupTable missingPackageHolder = new SimpleLookupTable(); |
30 |
char[][] fullExclusionPatternChars; |
29 |
char[][] fullExclusionPatternChars; |
31 |
char[][] fulInclusionPatternChars; |
30 |
char[][] fulInclusionPatternChars; |
32 |
|
31 |
|
Lines 41-67
Link Here
|
41 |
this.directoryCache = null; |
40 |
this.directoryCache = null; |
42 |
} |
41 |
} |
43 |
|
42 |
|
44 |
String[] directoryList(String qualifiedPackageName) { |
43 |
SimpleLookupTable directoryTable(String qualifiedPackageName) { |
45 |
String[] dirList = (String[]) directoryCache.get(qualifiedPackageName); |
44 |
SimpleLookupTable dirTable = (SimpleLookupTable) directoryCache.get(qualifiedPackageName); |
46 |
if (dirList == missingPackageHolder) return null; // package exists in another classpath directory or jar |
45 |
if (dirTable == missingPackageHolder) return null; // package exists in another classpath directory or jar |
47 |
if (dirList != null) return dirList; |
46 |
if (dirTable != null) return dirTable; |
48 |
|
47 |
|
49 |
try { |
48 |
try { |
50 |
IResource container = sourceFolder.findMember(qualifiedPackageName); // this is a case-sensitive check |
49 |
IResource container = sourceFolder.findMember(qualifiedPackageName); // this is a case-sensitive check |
51 |
if (container instanceof IContainer) { |
50 |
if (container instanceof IContainer) { |
52 |
IResource[] members = ((IContainer) container).members(); |
51 |
IResource[] members = ((IContainer) container).members(); |
53 |
dirList = new String[members.length]; |
52 |
dirTable = new SimpleLookupTable(); |
54 |
int index = 0; |
|
|
55 |
for (int i = 0, l = members.length; i < l; i++) { |
53 |
for (int i = 0, l = members.length; i < l; i++) { |
56 |
IResource m = members[i]; |
54 |
IResource m = members[i]; |
57 |
String name; |
55 |
String name; |
58 |
if (m.getType() == IResource.FILE && org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(name = m.getName())) |
56 |
if (m.getType() == IResource.FILE) { |
59 |
dirList[index++] = name; |
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/*not a folder path*/)) { |
61 |
dirTable.put(name.substring(0, index), m); |
62 |
} |
63 |
} |
64 |
} |
60 |
} |
65 |
} |
61 |
if (index < dirList.length) |
66 |
directoryCache.put(qualifiedPackageName, dirTable); |
62 |
System.arraycopy(dirList, 0, dirList = new String[index], 0, index); |
67 |
return dirTable; |
63 |
directoryCache.put(qualifiedPackageName, dirList); |
|
|
64 |
return dirList; |
65 |
} |
68 |
} |
66 |
} catch(CoreException ignored) { |
69 |
} catch(CoreException ignored) { |
67 |
// treat as if missing |
70 |
// treat as if missing |
Lines 70-85
Link Here
|
70 |
return null; |
73 |
return null; |
71 |
} |
74 |
} |
72 |
|
75 |
|
73 |
boolean doesFileExist(String fileName, String qualifiedPackageName) { |
|
|
74 |
String[] dirList = directoryList(qualifiedPackageName); |
75 |
if (dirList == null) return false; // most common case |
76 |
|
77 |
for (int i = dirList.length; --i >= 0;) |
78 |
if (fileName.equals(dirList[i])) |
79 |
return true; |
80 |
return false; |
81 |
} |
82 |
|
83 |
public boolean equals(Object o) { |
76 |
public boolean equals(Object o) { |
84 |
if (this == o) return true; |
77 |
if (this == o) return true; |
85 |
if (!(o instanceof ClasspathSourceDirectory)) return false; |
78 |
if (!(o instanceof ClasspathSourceDirectory)) return false; |
Lines 88-107
Link Here
|
88 |
} |
81 |
} |
89 |
|
82 |
|
90 |
public NameEnvironmentAnswer findClass(String sourceFileWithoutExtension, String qualifiedPackageName, String qualifiedSourceFileWithoutExtension) { |
83 |
public NameEnvironmentAnswer findClass(String sourceFileWithoutExtension, String qualifiedPackageName, String qualifiedSourceFileWithoutExtension) { |
91 |
|
84 |
SimpleLookupTable dirTable = directoryTable(qualifiedPackageName); |
92 |
String sourceFolderPath = this.sourceFolder.getFullPath().toString() + IPath.SEPARATOR; |
85 |
if (dirTable != null && dirTable.elementSize > 0) { |
93 |
char[][] javaLikeExtensions = Util.getJavaLikeExtensions(); |
86 |
IFile file = (IFile) dirTable.get(sourceFileWithoutExtension); |
94 |
for (int i = 0, length = javaLikeExtensions.length; i < length; i++) { |
87 |
if (file != null) { |
95 |
String extension = '.' + new String(javaLikeExtensions[i]); |
88 |
return new NameEnvironmentAnswer(new ResourceCompilationUnit(file), null /* no access restriction */); |
96 |
String sourceFileName = sourceFileWithoutExtension + extension; |
89 |
} |
97 |
if (!doesFileExist(sourceFileName, qualifiedPackageName)) continue; // most common case |
|
|
98 |
|
99 |
String qualifiedSourceFileName = qualifiedSourceFileWithoutExtension + extension; |
100 |
if (org.eclipse.jdt.internal.compiler.util.Util.isExcluded((sourceFolderPath + qualifiedSourceFileName).toCharArray(), this.fulInclusionPatternChars, this.fullExclusionPatternChars, false/*not a folder path*/)) |
101 |
continue; |
102 |
IPath path = new Path(qualifiedSourceFileName); |
103 |
IFile file = this.sourceFolder.getFile(path); |
104 |
return new NameEnvironmentAnswer(new ResourceCompilationUnit(file), null /* no access restriction */); |
105 |
} |
90 |
} |
106 |
return null; |
91 |
return null; |
107 |
} |
92 |
} |
Lines 111-117
Link Here
|
111 |
} |
96 |
} |
112 |
|
97 |
|
113 |
public boolean isPackage(String qualifiedPackageName) { |
98 |
public boolean isPackage(String qualifiedPackageName) { |
114 |
return directoryList(qualifiedPackageName) != null; |
99 |
return directoryTable(qualifiedPackageName) != null; |
115 |
} |
100 |
} |
116 |
|
101 |
|
117 |
public void reset() { |
102 |
public void reset() { |