|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2012 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 13-19
Link Here
|
| 13 |
import org.eclipse.core.runtime.IProgressMonitor; |
13 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 14 |
import org.eclipse.core.runtime.SubProgressMonitor; |
14 |
import org.eclipse.core.runtime.SubProgressMonitor; |
| 15 |
import org.eclipse.jdt.core.*; |
15 |
import org.eclipse.jdt.core.*; |
| 16 |
import org.eclipse.jdt.core.ICompilationUnit; |
|
|
| 17 |
import org.eclipse.jdt.core.compiler.CharOperation; |
16 |
import org.eclipse.jdt.core.compiler.CharOperation; |
| 18 |
import org.eclipse.jdt.core.search.*; |
17 |
import org.eclipse.jdt.core.search.*; |
| 19 |
import org.eclipse.jdt.internal.compiler.ASTVisitor; |
18 |
import org.eclipse.jdt.internal.compiler.ASTVisitor; |
|
Lines 45-63
Link Here
|
| 45 |
public boolean visit(TypeDeclaration typeDeclaration, BlockScope scope) { |
44 |
public boolean visit(TypeDeclaration typeDeclaration, BlockScope scope) { |
| 46 |
ReferenceBinding binding = typeDeclaration.binding; |
45 |
ReferenceBinding binding = typeDeclaration.binding; |
| 47 |
if (SuperTypeNamesCollector.this.matches(binding)) |
46 |
if (SuperTypeNamesCollector.this.matches(binding)) |
| 48 |
collectSuperTypeNames(binding); |
47 |
collectSuperTypeNames(binding, binding.compoundName); |
| 49 |
return true; |
48 |
return true; |
| 50 |
} |
49 |
} |
| 51 |
public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { |
50 |
public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { |
| 52 |
ReferenceBinding binding = typeDeclaration.binding; |
51 |
ReferenceBinding binding = typeDeclaration.binding; |
| 53 |
if (SuperTypeNamesCollector.this.matches(binding)) |
52 |
if (SuperTypeNamesCollector.this.matches(binding)) |
| 54 |
collectSuperTypeNames(binding); |
53 |
collectSuperTypeNames(binding, binding.compoundName); |
| 55 |
return true; |
54 |
return true; |
| 56 |
} |
55 |
} |
| 57 |
public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { |
56 |
public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope scope) { |
| 58 |
ReferenceBinding binding = memberTypeDeclaration.binding; |
57 |
ReferenceBinding binding = memberTypeDeclaration.binding; |
| 59 |
if (SuperTypeNamesCollector.this.matches(binding)) |
58 |
if (SuperTypeNamesCollector.this.matches(binding)) |
| 60 |
collectSuperTypeNames(binding); |
59 |
collectSuperTypeNames(binding, binding.compoundName); |
| 61 |
return true; |
60 |
return true; |
| 62 |
} |
61 |
} |
| 63 |
public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { |
62 |
public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) { |
|
Lines 82-87
Link Here
|
| 82 |
char[][][] result; |
81 |
char[][][] result; |
| 83 |
int resultIndex; |
82 |
int resultIndex; |
| 84 |
|
83 |
|
|
|
84 |
char[][][] samePackageSuperTypeName; // set only if focus is null |
| 85 |
int samePackageIndex; |
| 86 |
|
| 85 |
public SuperTypeNamesCollector( |
87 |
public SuperTypeNamesCollector( |
| 86 |
SearchPattern pattern, |
88 |
SearchPattern pattern, |
| 87 |
char[] typeSimpleName, |
89 |
char[] typeSimpleName, |
|
Lines 98-103
Link Here
|
| 98 |
this.progressMonitor = progressMonitor; |
100 |
this.progressMonitor = progressMonitor; |
| 99 |
} |
101 |
} |
| 100 |
|
102 |
|
|
|
103 |
private boolean addIfSamePackage(char[][] compoundName, char[][] path) { |
| 104 |
if (compoundName.length != path.length) return false; |
| 105 |
int resultLength = this.samePackageSuperTypeName.length; |
| 106 |
for (int i = 0; i < resultLength; i++) |
| 107 |
if (CharOperation.equals(this.samePackageSuperTypeName[i], compoundName)) return false; // already known |
| 108 |
|
| 109 |
for (int i = 0, length = compoundName.length - 1; i < length; i ++) { |
| 110 |
if (!CharOperation.equals(compoundName[i], path[i])) return false; |
| 111 |
} |
| 112 |
if (resultLength == this.samePackageIndex) |
| 113 |
System.arraycopy(this.samePackageSuperTypeName, 0, this.samePackageSuperTypeName = new char[resultLength*2][][], 0, resultLength); |
| 114 |
this.samePackageSuperTypeName[this.samePackageIndex++] = compoundName; |
| 115 |
return true; |
| 116 |
} |
| 117 |
|
| 101 |
protected void addToResult(char[][] compoundName) { |
118 |
protected void addToResult(char[][] compoundName) { |
| 102 |
int resultLength = this.result.length; |
119 |
int resultLength = this.result.length; |
| 103 |
for (int i = 0; i < resultLength; i++) |
120 |
for (int i = 0; i < resultLength; i++) |
|
Lines 107-112
Link Here
|
| 107 |
System.arraycopy(this.result, 0, this.result = new char[resultLength*2][][], 0, resultLength); |
124 |
System.arraycopy(this.result, 0, this.result = new char[resultLength*2][][], 0, resultLength); |
| 108 |
this.result[this.resultIndex++] = compoundName; |
125 |
this.result[this.resultIndex++] = compoundName; |
| 109 |
} |
126 |
} |
|
|
127 |
|
| 110 |
/* |
128 |
/* |
| 111 |
* Parse the given compiation unit and build its type bindings. |
129 |
* Parse the given compiation unit and build its type bindings. |
| 112 |
*/ |
130 |
*/ |
|
Lines 141-147
Link Here
|
| 141 |
if (this.type.isBinary()) { |
159 |
if (this.type.isBinary()) { |
| 142 |
BinaryTypeBinding binding = this.locator.cacheBinaryType(this.type, null); |
160 |
BinaryTypeBinding binding = this.locator.cacheBinaryType(this.type, null); |
| 143 |
if (binding != null) |
161 |
if (binding != null) |
| 144 |
collectSuperTypeNames(binding); |
162 |
collectSuperTypeNames(binding, null); |
| 145 |
} else { |
163 |
} else { |
| 146 |
ICompilationUnit unit = this.type.getCompilationUnit(); |
164 |
ICompilationUnit unit = this.type.getCompilationUnit(); |
| 147 |
SourceType sourceType = (SourceType) this.type; |
165 |
SourceType sourceType = (SourceType) this.type; |
|
Lines 150-156
Link Here
|
| 150 |
if (parsedUnit != null) { |
168 |
if (parsedUnit != null) { |
| 151 |
TypeDeclaration typeDecl = new ASTNodeFinder(parsedUnit).findType(this.type); |
169 |
TypeDeclaration typeDecl = new ASTNodeFinder(parsedUnit).findType(this.type); |
| 152 |
if (typeDecl != null && typeDecl.binding != null) |
170 |
if (typeDecl != null && typeDecl.binding != null) |
| 153 |
collectSuperTypeNames(typeDecl.binding); |
171 |
collectSuperTypeNames(typeDecl.binding, null); |
| 154 |
} |
172 |
} |
| 155 |
} |
173 |
} |
| 156 |
} catch (AbortCompilation e) { |
174 |
} catch (AbortCompilation e) { |
|
Lines 171-176
Link Here
|
| 171 |
Util.sort(paths); // sort by projects |
189 |
Util.sort(paths); // sort by projects |
| 172 |
JavaProject previousProject = null; |
190 |
JavaProject previousProject = null; |
| 173 |
this.result = new char[1][][]; |
191 |
this.result = new char[1][][]; |
|
|
192 |
this.samePackageSuperTypeName = new char[1][][]; |
| 174 |
this.resultIndex = 0; |
193 |
this.resultIndex = 0; |
| 175 |
for (int i = 0, length = paths.length; i < length; i++) { |
194 |
for (int i = 0, length = paths.length; i < length; i++) { |
| 176 |
try { |
195 |
try { |
|
Lines 191-197
Link Here
|
| 191 |
IClassFile classFile = (IClassFile) openable; |
210 |
IClassFile classFile = (IClassFile) openable; |
| 192 |
BinaryTypeBinding binding = this.locator.cacheBinaryType(classFile.getType(), null); |
211 |
BinaryTypeBinding binding = this.locator.cacheBinaryType(classFile.getType(), null); |
| 193 |
if (matches(binding)) |
212 |
if (matches(binding)) |
| 194 |
collectSuperTypeNames(binding); |
213 |
collectSuperTypeNames(binding, binding.compoundName); |
| 195 |
} |
214 |
} |
| 196 |
} catch (AbortCompilation e) { |
215 |
} catch (AbortCompilation e) { |
| 197 |
// ignore: continue with next element |
216 |
// ignore: continue with next element |
|
Lines 206-216
Link Here
|
| 206 |
/** |
225 |
/** |
| 207 |
* Collects the names of all the supertypes of the given type. |
226 |
* Collects the names of all the supertypes of the given type. |
| 208 |
*/ |
227 |
*/ |
| 209 |
protected void collectSuperTypeNames(ReferenceBinding binding) { |
228 |
protected void collectSuperTypeNames(ReferenceBinding binding, char[][] path) { |
| 210 |
ReferenceBinding superclass = binding.superclass(); |
229 |
ReferenceBinding superclass = binding.superclass(); |
|
|
230 |
if (path != null) { |
| 231 |
boolean samePackage = addIfSamePackage(superclass.compoundName, path); |
| 232 |
if (!samePackage) path = null; |
| 233 |
} |
| 211 |
if (superclass != null) { |
234 |
if (superclass != null) { |
| 212 |
addToResult(superclass.compoundName); |
235 |
addToResult(superclass.compoundName); |
| 213 |
collectSuperTypeNames(superclass); |
236 |
collectSuperTypeNames(superclass, null); |
| 214 |
} |
237 |
} |
| 215 |
|
238 |
|
| 216 |
ReferenceBinding[] interfaces = binding.superInterfaces(); |
239 |
ReferenceBinding[] interfaces = binding.superInterfaces(); |
|
Lines 218-224
Link Here
|
| 218 |
for (int i = 0; i < interfaces.length; i++) { |
241 |
for (int i = 0; i < interfaces.length; i++) { |
| 219 |
ReferenceBinding interfaceBinding = interfaces[i]; |
242 |
ReferenceBinding interfaceBinding = interfaces[i]; |
| 220 |
addToResult(interfaceBinding.compoundName); |
243 |
addToResult(interfaceBinding.compoundName); |
| 221 |
collectSuperTypeNames(interfaceBinding); |
244 |
collectSuperTypeNames(interfaceBinding, null); |
| 222 |
} |
245 |
} |
| 223 |
} |
246 |
} |
| 224 |
} |
247 |
} |
|
Lines 254-259
Link Here
|
| 254 |
this.progressMonitor == null ? null : new SubProgressMonitor(this.progressMonitor, 100)); |
277 |
this.progressMonitor == null ? null : new SubProgressMonitor(this.progressMonitor, 100)); |
| 255 |
return pathCollector.getPaths(); |
278 |
return pathCollector.getPaths(); |
| 256 |
} |
279 |
} |
|
|
280 |
public char[][][] getSamePackageSuperTypeNames() { |
| 281 |
return this.samePackageSuperTypeName; |
| 282 |
} |
| 257 |
protected boolean matches(char[][] compoundName) { |
283 |
protected boolean matches(char[][] compoundName) { |
| 258 |
int length = compoundName.length; |
284 |
int length = compoundName.length; |
| 259 |
if (length == 0) return false; |
285 |
if (length == 0) return false; |