Lines 13-18
Link Here
|
13 |
import org.eclipse.core.runtime.Path; |
13 |
import org.eclipse.core.runtime.Path; |
14 |
import org.eclipse.jdt.core.IClassFile; |
14 |
import org.eclipse.jdt.core.IClassFile; |
15 |
import org.eclipse.jdt.core.ICompilationUnit; |
15 |
import org.eclipse.jdt.core.ICompilationUnit; |
|
|
16 |
import org.eclipse.jdt.core.IJavaElement; |
16 |
import org.eclipse.jdt.core.IPackageFragment; |
17 |
import org.eclipse.jdt.core.IPackageFragment; |
17 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
18 |
import org.eclipse.jdt.core.IPackageFragmentRoot; |
18 |
import org.eclipse.jdt.core.IType; |
19 |
import org.eclipse.jdt.core.IType; |
Lines 22-28
Link Here
|
22 |
import org.eclipse.jdt.core.search.TypeNameMatchRequestor; |
23 |
import org.eclipse.jdt.core.search.TypeNameMatchRequestor; |
23 |
import org.eclipse.jdt.core.search.TypeNameRequestor; |
24 |
import org.eclipse.jdt.core.search.TypeNameRequestor; |
24 |
import org.eclipse.jdt.internal.compiler.env.AccessRestriction; |
25 |
import org.eclipse.jdt.internal.compiler.env.AccessRestriction; |
|
|
26 |
import org.eclipse.jdt.internal.core.Openable; |
25 |
import org.eclipse.jdt.internal.core.PackageFragmentRoot; |
27 |
import org.eclipse.jdt.internal.core.PackageFragmentRoot; |
|
|
28 |
import org.eclipse.jdt.internal.core.util.HandleFactory; |
26 |
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject; |
29 |
import org.eclipse.jdt.internal.core.util.HashtableOfArrayToObject; |
27 |
|
30 |
|
28 |
/** |
31 |
/** |
Lines 51-56
Link Here
|
51 |
public class TypeNameMatchRequestorWrapper implements IRestrictedAccessTypeRequestor { |
54 |
public class TypeNameMatchRequestorWrapper implements IRestrictedAccessTypeRequestor { |
52 |
TypeNameMatchRequestor requestor; |
55 |
TypeNameMatchRequestor requestor; |
53 |
private IJavaSearchScope scope; // scope is needed to retrieve project path for external resource |
56 |
private IJavaSearchScope scope; // scope is needed to retrieve project path for external resource |
|
|
57 |
private HandleFactory handleFactory; // in case of IJavaSearchScope defined by clients, use an HandleFactory instead |
54 |
|
58 |
|
55 |
/** |
59 |
/** |
56 |
* Cache package fragment root information to optimize speed performance. |
60 |
* Cache package fragment root information to optimize speed performance. |
Lines 66-71
Link Here
|
66 |
public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) { |
70 |
public TypeNameMatchRequestorWrapper(TypeNameMatchRequestor requestor, IJavaSearchScope scope) { |
67 |
this.requestor = requestor; |
71 |
this.requestor = requestor; |
68 |
this.scope = scope; |
72 |
this.scope = scope; |
|
|
73 |
if (!(scope instanceof JavaSearchScope)) { |
74 |
this.handleFactory = new HandleFactory(); |
75 |
} |
69 |
} |
76 |
} |
70 |
|
77 |
|
71 |
/* (non-Javadoc) |
78 |
/* (non-Javadoc) |
Lines 73-82
Link Here
|
73 |
*/ |
80 |
*/ |
74 |
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) { |
81 |
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) { |
75 |
try { |
82 |
try { |
76 |
int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR); |
83 |
IType type = null; |
77 |
IType type = separatorIndex == -1 |
84 |
if (this.handleFactory != null) { |
78 |
? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames) |
85 |
Openable openable = this.handleFactory.createOpenable(path, this.scope); |
79 |
: createTypeFromJar(path, separatorIndex); |
86 |
if (openable == null) return; |
|
|
87 |
switch (openable.getElementType()) { |
88 |
case IJavaElement.COMPILATION_UNIT: |
89 |
ICompilationUnit cu = (ICompilationUnit) openable; |
90 |
if (enclosingTypeNames != null && enclosingTypeNames.length > 0) { |
91 |
type = cu.getType(new String(enclosingTypeNames[0])); |
92 |
for (int j=1, l=enclosingTypeNames.length; j<l; j++) { |
93 |
type = type.getType(new String(enclosingTypeNames[j])); |
94 |
} |
95 |
} else { |
96 |
type = cu.getType(new String(simpleTypeName)); |
97 |
} |
98 |
break; |
99 |
case IJavaElement.CLASS_FILE: |
100 |
type = ((IClassFile)openable).getType(); |
101 |
break; |
102 |
} |
103 |
} else { |
104 |
int separatorIndex= path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR); |
105 |
type = separatorIndex == -1 |
106 |
? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames) |
107 |
: createTypeFromJar(path, separatorIndex); |
108 |
} |
80 |
if (type != null) { |
109 |
if (type != null) { |
81 |
this.requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, modifiers)); |
110 |
this.requestor.acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, modifiers)); |
82 |
} |
111 |
} |
Lines 91-97
Link Here
|
91 |
|| this.lastPkgFragmentRootPath.length() > resourcePath.length() |
120 |
|| this.lastPkgFragmentRootPath.length() > resourcePath.length() |
92 |
|| !resourcePath.startsWith(this.lastPkgFragmentRootPath)) { |
121 |
|| !resourcePath.startsWith(this.lastPkgFragmentRootPath)) { |
93 |
String jarPath= resourcePath.substring(0, separatorIndex); |
122 |
String jarPath= resourcePath.substring(0, separatorIndex); |
94 |
IPackageFragmentRoot root= ((JavaSearchScope)scope).packageFragmentRoot(resourcePath); |
123 |
IPackageFragmentRoot root= ((JavaSearchScope)this.scope).packageFragmentRoot(resourcePath); |
95 |
if (root == null) return null; |
124 |
if (root == null) return null; |
96 |
this.lastPkgFragmentRootPath= jarPath; |
125 |
this.lastPkgFragmentRootPath= jarPath; |
97 |
this.lastPkgFragmentRoot= root; |
126 |
this.lastPkgFragmentRoot= root; |
Lines 123-129
Link Here
|
123 |
|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath) |
152 |
|| !(resourcePath.startsWith(this.lastPkgFragmentRootPath) |
124 |
&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0 |
153 |
&& (rootPathLength = this.lastPkgFragmentRootPath.length()) > 0 |
125 |
&& resourcePath.charAt(rootPathLength) == '/')) { |
154 |
&& resourcePath.charAt(rootPathLength) == '/')) { |
126 |
IPackageFragmentRoot root= ((JavaSearchScope)scope).packageFragmentRoot(resourcePath); |
155 |
IPackageFragmentRoot root = ((JavaSearchScope)this.scope).packageFragmentRoot(resourcePath); |
127 |
if (root == null) return null; |
156 |
if (root == null) return null; |
128 |
this.lastPkgFragmentRoot = root; |
157 |
this.lastPkgFragmentRoot = root; |
129 |
this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString(); |
158 |
this.lastPkgFragmentRootPath = this.lastPkgFragmentRoot.getPath().toString(); |