Lines 21-26
Link Here
|
21 |
import org.eclipse.core.resources.IResource; |
21 |
import org.eclipse.core.resources.IResource; |
22 |
import org.eclipse.core.runtime.*; |
22 |
import org.eclipse.core.runtime.*; |
23 |
import org.eclipse.jdt.core.Flags; |
23 |
import org.eclipse.jdt.core.Flags; |
|
|
24 |
import org.eclipse.jdt.core.IAnnotatable; |
25 |
import org.eclipse.jdt.core.IAnnotation; |
24 |
import org.eclipse.jdt.core.IClassFile; |
26 |
import org.eclipse.jdt.core.IClassFile; |
25 |
import org.eclipse.jdt.core.IJavaElement; |
27 |
import org.eclipse.jdt.core.IJavaElement; |
26 |
import org.eclipse.jdt.core.IJavaModelStatusConstants; |
28 |
import org.eclipse.jdt.core.IJavaModelStatusConstants; |
Lines 35-41
Link Here
|
35 |
import org.eclipse.jdt.core.Signature; |
37 |
import org.eclipse.jdt.core.Signature; |
36 |
import org.eclipse.jdt.core.compiler.*; |
38 |
import org.eclipse.jdt.core.compiler.*; |
37 |
import org.eclipse.jdt.core.search.*; |
39 |
import org.eclipse.jdt.core.search.*; |
38 |
import org.eclipse.jdt.internal.compiler.ASTVisitor; |
|
|
39 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
40 |
import org.eclipse.jdt.internal.compiler.CompilationResult; |
40 |
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; |
41 |
import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; |
41 |
import org.eclipse.jdt.internal.compiler.ast.*; |
42 |
import org.eclipse.jdt.internal.compiler.ast.*; |
Lines 48-54
Link Here
|
48 |
import org.eclipse.jdt.internal.compiler.lookup.*; |
49 |
import org.eclipse.jdt.internal.compiler.lookup.*; |
49 |
import org.eclipse.jdt.internal.compiler.parser.*; |
50 |
import org.eclipse.jdt.internal.compiler.parser.*; |
50 |
import org.eclipse.jdt.internal.compiler.problem.*; |
51 |
import org.eclipse.jdt.internal.compiler.problem.*; |
51 |
import org.eclipse.jdt.internal.compiler.util.HashtableOfIntValues; |
|
|
52 |
import org.eclipse.jdt.internal.compiler.util.Messages; |
52 |
import org.eclipse.jdt.internal.compiler.util.Messages; |
53 |
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; |
53 |
import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; |
54 |
import org.eclipse.jdt.internal.compiler.util.SimpleSet; |
54 |
import org.eclipse.jdt.internal.compiler.util.SimpleSet; |
Lines 146-191
Link Here
|
146 |
|
146 |
|
147 |
private final boolean searchPackageDeclaration; |
147 |
private final boolean searchPackageDeclaration; |
148 |
|
148 |
|
149 |
/** |
|
|
150 |
* An ast visitor that visits local type declarations. |
151 |
*/ |
152 |
public class LocalDeclarationVisitor extends ASTVisitor { |
153 |
IJavaElement enclosingElement; |
154 |
Binding enclosingElementBinding; |
155 |
MatchingNodeSet nodeSet; |
156 |
HashtableOfIntValues occurrencesCounts = new HashtableOfIntValues(); // key = class name (char[]), value = occurrenceCount (int) |
157 |
public LocalDeclarationVisitor(IJavaElement enclosingElement, Binding enclosingElementBinding, MatchingNodeSet nodeSet) { |
158 |
this.enclosingElement = enclosingElement; |
159 |
this.enclosingElementBinding = enclosingElementBinding; |
160 |
this.nodeSet = nodeSet; |
161 |
} |
162 |
public boolean visit(TypeDeclaration typeDeclaration, BlockScope unused) { |
163 |
try { |
164 |
char[] simpleName; |
165 |
if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) { |
166 |
simpleName = CharOperation.NO_CHAR; |
167 |
} else { |
168 |
simpleName = typeDeclaration.name; |
169 |
} |
170 |
int occurrenceCount = occurrencesCounts.get(simpleName); |
171 |
if (occurrenceCount == HashtableOfIntValues.NO_VALUE) { |
172 |
occurrenceCount = 1; |
173 |
} else { |
174 |
occurrenceCount = occurrenceCount + 1; |
175 |
} |
176 |
occurrencesCounts.put(simpleName, occurrenceCount); |
177 |
if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) { |
178 |
reportMatching(typeDeclaration, this.enclosingElement, -1, nodeSet, occurrenceCount); |
179 |
} else { |
180 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeDeclaration); |
181 |
reportMatching(typeDeclaration, this.enclosingElement, level != null ? level.intValue() : -1, nodeSet, occurrenceCount); |
182 |
} |
183 |
return false; // don't visit members as this was done during reportMatching(...) |
184 |
} catch (CoreException e) { |
185 |
throw new WrappedCoreException(e); |
186 |
} |
187 |
} |
188 |
} |
189 |
public static class WorkingCopyDocument extends JavaSearchDocument { |
149 |
public static class WorkingCopyDocument extends JavaSearchDocument { |
190 |
public org.eclipse.jdt.core.ICompilationUnit workingCopy; |
150 |
public org.eclipse.jdt.core.ICompilationUnit workingCopy; |
191 |
WorkingCopyDocument(org.eclipse.jdt.core.ICompilationUnit workingCopy, SearchParticipant participant) { |
151 |
WorkingCopyDocument(org.eclipse.jdt.core.ICompilationUnit workingCopy, SearchParticipant participant) { |
Lines 600-606
Link Here
|
600 |
return ((IType) parent).getInitializer(occurrenceCount); |
560 |
return ((IType) parent).getInitializer(occurrenceCount); |
601 |
} |
561 |
} |
602 |
/** |
562 |
/** |
603 |
* Create an handle for a local variable declartion (may be a local variable or type parameter). |
563 |
* Create an handle for a local variable declaration (may be a local variable or type parameter). |
604 |
*/ |
564 |
*/ |
605 |
protected IJavaElement createHandle(AbstractVariableDeclaration variableDeclaration, IJavaElement parent) { |
565 |
protected IJavaElement createHandle(AbstractVariableDeclaration variableDeclaration, IJavaElement parent) { |
606 |
switch (variableDeclaration.getKind()) { |
566 |
switch (variableDeclaration.getKind()) { |
Lines 629-634
Link Here
|
629 |
} |
589 |
} |
630 |
return null; |
590 |
return null; |
631 |
} |
591 |
} |
|
|
592 |
/** |
593 |
* Create an handle for a local variable declaration (may be a local variable or type parameter). |
594 |
*/ |
595 |
protected IJavaElement createHandle(Annotation annotation, IAnnotatable parent) { |
596 |
if (parent == null) return null; |
597 |
TypeReference typeRef = annotation.type; |
598 |
char[][] typeName = typeRef.getTypeName(); |
599 |
String name = new String(typeName[typeName.length-1]); |
600 |
try { |
601 |
IAnnotation[] annotations = parent.getAnnotations(); |
602 |
int length = annotations == null ? 0 : annotations.length; |
603 |
for (int i=0; i<length; i++) { |
604 |
if (annotations[i].getElementName().equals(name)) { |
605 |
return annotations[i]; |
606 |
} |
607 |
} |
608 |
} |
609 |
catch (JavaModelException jme) { |
610 |
// skip |
611 |
} |
612 |
return null; |
613 |
} |
614 |
/* |
615 |
* Create handles for a list of fields |
616 |
*/ |
617 |
private IJavaElement[] createHandles(FieldDeclaration[] fields, TypeDeclaration type, IJavaElement parent) { |
618 |
IJavaElement[] otherElements = null; |
619 |
if (fields != null) { |
620 |
int length = fields.length; |
621 |
int size = 0; |
622 |
while (size<length && fields[size] != null) { |
623 |
size++; |
624 |
} |
625 |
otherElements = new IJavaElement[size]; |
626 |
for (int j=0; j<size; j++) { |
627 |
otherElements[j] = createHandle(fields[j], type, parent); |
628 |
} |
629 |
} |
630 |
return otherElements; |
631 |
} |
632 |
/* |
632 |
/* |
633 |
* Creates hierarchy resolver if needed. |
633 |
* Creates hierarchy resolver if needed. |
634 |
* Returns whether focus is visible. |
634 |
* Returns whether focus is visible. |
Lines 1387-1399
Link Here
|
1387 |
} |
1387 |
} |
1388 |
} |
1388 |
} |
1389 |
|
1389 |
|
1390 |
public SearchMatch newFieldReferenceMatch( |
1390 |
public FieldReferenceMatch newFieldReferenceMatch( |
1391 |
IJavaElement enclosingElement, |
1391 |
IJavaElement enclosingElement, |
|
|
1392 |
IJavaElement localElement, |
1392 |
Binding enclosingBinding, |
1393 |
Binding enclosingBinding, |
1393 |
int accuracy, |
1394 |
int accuracy, |
1394 |
int offset, |
1395 |
int offset, |
1395 |
int length, |
1396 |
int length, ASTNode reference) { |
1396 |
ASTNode reference) { |
|
|
1397 |
int bits = reference.bits; |
1397 |
int bits = reference.bits; |
1398 |
boolean isCompoundAssigned = (bits & ASTNode.IsCompoundAssigned) != 0; |
1398 |
boolean isCompoundAssigned = (bits & ASTNode.IsCompoundAssigned) != 0; |
1399 |
boolean isReadAccess = isCompoundAssigned || (bits & ASTNode.IsStrictlyAssigned) == 0; |
1399 |
boolean isReadAccess = isCompoundAssigned || (bits & ASTNode.IsStrictlyAssigned) == 0; |
Lines 1411-1419
Link Here
|
1411 |
boolean insideDocComment = (bits & ASTNode.InsideJavadoc) != 0; |
1411 |
boolean insideDocComment = (bits & ASTNode.InsideJavadoc) != 0; |
1412 |
SearchParticipant participant = getParticipant(); |
1412 |
SearchParticipant participant = getParticipant(); |
1413 |
IResource resource = this.currentPossibleMatch.resource; |
1413 |
IResource resource = this.currentPossibleMatch.resource; |
1414 |
if (enclosingBinding != null) |
1414 |
if (enclosingBinding != null) { |
1415 |
enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding); |
1415 |
enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding); |
1416 |
return new FieldReferenceMatch(enclosingElement, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource); |
1416 |
} |
|
|
1417 |
FieldReferenceMatch match = new FieldReferenceMatch(enclosingElement, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource); |
1418 |
match.localElement(localElement); |
1419 |
return match; |
1417 |
} |
1420 |
} |
1418 |
|
1421 |
|
1419 |
public SearchMatch newLocalVariableReferenceMatch( |
1422 |
public SearchMatch newLocalVariableReferenceMatch( |
Lines 1442-1448
Link Here
|
1442 |
return new LocalVariableReferenceMatch(enclosingElement, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource); |
1445 |
return new LocalVariableReferenceMatch(enclosingElement, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource); |
1443 |
} |
1446 |
} |
1444 |
|
1447 |
|
1445 |
public SearchMatch newMethodReferenceMatch( |
1448 |
public MethodReferenceMatch newMethodReferenceMatch( |
1446 |
IJavaElement enclosingElement, |
1449 |
IJavaElement enclosingElement, |
1447 |
Binding enclosingBinding, |
1450 |
Binding enclosingBinding, |
1448 |
int accuracy, |
1451 |
int accuracy, |
Lines 1460-1466
Link Here
|
1460 |
return new MethodReferenceMatch(enclosingElement, accuracy, offset, length, isConstructor, isSynthetic, isOverridden, insideDocComment, participant, resource); |
1463 |
return new MethodReferenceMatch(enclosingElement, accuracy, offset, length, isConstructor, isSynthetic, isOverridden, insideDocComment, participant, resource); |
1461 |
} |
1464 |
} |
1462 |
|
1465 |
|
1463 |
public SearchMatch newPackageReferenceMatch( |
1466 |
public PackageReferenceMatch newPackageReferenceMatch( |
1464 |
IJavaElement enclosingElement, |
1467 |
IJavaElement enclosingElement, |
1465 |
int accuracy, |
1468 |
int accuracy, |
1466 |
int offset, |
1469 |
int offset, |
Lines 2073-2086
Link Here
|
2073 |
|
2076 |
|
2074 |
// handle nodes for the local type first |
2077 |
// handle nodes for the local type first |
2075 |
if ((method.bits & ASTNode.HasLocalType) != 0) { |
2078 |
if ((method.bits & ASTNode.HasLocalType) != 0) { |
2076 |
if (enclosingElement == null) |
2079 |
if (enclosingElement == null) { |
2077 |
enclosingElement = createHandle(method, parent); |
2080 |
enclosingElement = createHandle(method, parent); |
2078 |
LocalDeclarationVisitor localDeclarationVisitor = new LocalDeclarationVisitor(enclosingElement, method.binding, nodeSet); |
2081 |
} |
|
|
2082 |
// Traverse method declaration to report matches both in local types declaration |
2083 |
// and in local variables declaration |
2084 |
ASTNode[] nodes = typeInHierarchy ? nodeSet.matchingNodes(method.declarationSourceStart, method.declarationSourceEnd) : null; |
2085 |
boolean report = (this.matchContainer & PatternLocator.METHOD_CONTAINER) != 0 && encloses(enclosingElement); |
2086 |
MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, report ? nodes : null, nodeSet, this); |
2079 |
try { |
2087 |
try { |
2080 |
method.traverse(localDeclarationVisitor, (ClassScope) null); |
2088 |
method.traverse(declarationVisitor, (ClassScope) null); |
2081 |
} catch (WrappedCoreException e) { |
2089 |
} catch (WrappedCoreException e) { |
2082 |
throw e.coreException; |
2090 |
throw e.coreException; |
2083 |
} |
2091 |
} |
|
|
2092 |
// Report all nodes and remove them |
2093 |
if (nodes != null) { |
2094 |
int length = nodes.length; |
2095 |
for (int i = 0; i < length; i++) { |
2096 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(nodes[i]); |
2097 |
if (report && level != null) { |
2098 |
this.patternLocator.matchReportReference(nodes[i], enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), method.binding, level.intValue(), this); |
2099 |
} |
2100 |
} |
2101 |
} |
2084 |
} |
2102 |
} |
2085 |
|
2103 |
|
2086 |
// report the type parameters |
2104 |
// report the type parameters |
Lines 2097-2103
Link Here
|
2097 |
if (enclosingElement == null) { |
2115 |
if (enclosingElement == null) { |
2098 |
enclosingElement = createHandle(method, parent); |
2116 |
enclosingElement = createHandle(method, parent); |
2099 |
} |
2117 |
} |
2100 |
reportMatching(method.annotations, enclosingElement, method.binding, nodeSet, true, true); |
2118 |
reportMatching(method.annotations, enclosingElement, null, method.binding, nodeSet, true, true); |
2101 |
} |
2119 |
} |
2102 |
|
2120 |
|
2103 |
// references in this method |
2121 |
// references in this method |
Lines 2105-2117
Link Here
|
2105 |
ASTNode[] nodes = nodeSet.matchingNodes(method.declarationSourceStart, method.declarationSourceEnd); |
2123 |
ASTNode[] nodes = nodeSet.matchingNodes(method.declarationSourceStart, method.declarationSourceEnd); |
2106 |
if (nodes != null) { |
2124 |
if (nodes != null) { |
2107 |
if ((this.matchContainer & PatternLocator.METHOD_CONTAINER) != 0) { |
2125 |
if ((this.matchContainer & PatternLocator.METHOD_CONTAINER) != 0) { |
2108 |
if (enclosingElement == null) |
2126 |
if (enclosingElement == null) { |
2109 |
enclosingElement = createHandle(method, parent); |
2127 |
enclosingElement = createHandle(method, parent); |
|
|
2128 |
} |
2110 |
if (encloses(enclosingElement)) { |
2129 |
if (encloses(enclosingElement)) { |
2111 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2130 |
if (((InternalSearchPattern)this.pattern).mustResolve) { |
2112 |
ASTNode node = nodes[i]; |
2131 |
// Visit only if the pattern must resolve |
2113 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2132 |
MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, nodes, nodeSet, this); |
2114 |
this.patternLocator.matchReportReference(node, enclosingElement, method.binding, method.scope, level.intValue(), this); |
2133 |
method.traverse(declarationVisitor, (ClassScope) null); |
|
|
2134 |
int length = nodes.length; |
2135 |
for (int i = 0; i < length; i++) { |
2136 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(nodes[i]); |
2137 |
this.patternLocator.matchReportReference(nodes[i], enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), method.binding, level.intValue(), this); |
2138 |
} |
2139 |
} else { |
2140 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2141 |
ASTNode node = nodes[i]; |
2142 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2143 |
this.patternLocator.matchReportReference(node, enclosingElement, null, null, method.binding, level.intValue(), this); |
2144 |
} |
2115 |
} |
2145 |
} |
2116 |
return; |
2146 |
return; |
2117 |
} |
2147 |
} |
Lines 2125-2140
Link Here
|
2125 |
} |
2155 |
} |
2126 |
/** |
2156 |
/** |
2127 |
* Report matching in annotations. |
2157 |
* Report matching in annotations. |
|
|
2158 |
* @param otherElements TODO |
2128 |
*/ |
2159 |
*/ |
2129 |
protected void reportMatching(Annotation[] annotations, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedContainer, boolean enclosesElement) throws CoreException { |
2160 |
protected void reportMatching(Annotation[] annotations, IJavaElement enclosingElement, IJavaElement[] otherElements, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedContainer, boolean enclosesElement) throws CoreException { |
2130 |
for (int i=0, al=annotations.length; i<al; i++) { |
2161 |
for (int i=0, al=annotations.length; i<al; i++) { |
2131 |
Annotation annotationType = annotations[i]; |
2162 |
Annotation annotationType = annotations[i]; |
|
|
2163 |
IJavaElement localElement = null; |
2132 |
|
2164 |
|
2133 |
// Look for annotation type ref |
2165 |
// Look for annotation type ref |
2134 |
TypeReference typeRef = annotationType.type; |
2166 |
TypeReference typeRef = annotationType.type; |
2135 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeRef); |
2167 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeRef); |
2136 |
if (level != null && matchedContainer) { |
2168 |
if (level != null && matchedContainer) { |
2137 |
this.patternLocator.matchReportReference(typeRef, enclosingElement, elementBinding, level.intValue(), this); |
2169 |
localElement = createHandle(annotationType, (IAnnotatable) enclosingElement); |
|
|
2170 |
this.patternLocator.matchReportReference(typeRef, enclosingElement, localElement, otherElements, elementBinding, level.intValue(), this); |
2138 |
} |
2171 |
} |
2139 |
|
2172 |
|
2140 |
// Look for attribute ref |
2173 |
// Look for attribute ref |
Lines 2144-2150
Link Here
|
2144 |
level = (Integer) nodeSet.matchingNodes.removeKey(pair); |
2177 |
level = (Integer) nodeSet.matchingNodes.removeKey(pair); |
2145 |
if (level != null && enclosesElement) { |
2178 |
if (level != null && enclosesElement) { |
2146 |
ASTNode reference = (annotationType instanceof SingleMemberAnnotation) ? (ASTNode) annotationType: pair; |
2179 |
ASTNode reference = (annotationType instanceof SingleMemberAnnotation) ? (ASTNode) annotationType: pair; |
2147 |
this.patternLocator.matchReportReference(reference, enclosingElement, pair.binding, level.intValue(), this); |
2180 |
if (localElement == null) { |
|
|
2181 |
localElement = createHandle(annotationType, (IAnnotatable) enclosingElement); |
2182 |
} |
2183 |
this.patternLocator.matchReportReference(reference, enclosingElement, localElement, otherElements, pair.binding, level.intValue(), this); |
2148 |
} |
2184 |
} |
2149 |
} |
2185 |
} |
2150 |
|
2186 |
|
Lines 2160-2166
Link Here
|
2160 |
ASTNode node = nodes[j]; |
2196 |
ASTNode node = nodes[j]; |
2161 |
level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2197 |
level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2162 |
if (enclosesElement) { |
2198 |
if (enclosesElement) { |
2163 |
this.patternLocator.matchReportReference(node, enclosingElement, elementBinding, level.intValue(), this); |
2199 |
if (localElement == null) { |
|
|
2200 |
localElement = createHandle(annotationType, (IAnnotatable) enclosingElement); |
2201 |
} |
2202 |
this.patternLocator.matchReportReference(node, enclosingElement, localElement, otherElements, elementBinding, level.intValue(), this); |
2164 |
} |
2203 |
} |
2165 |
} |
2204 |
} |
2166 |
} |
2205 |
} |
Lines 2235-2241
Link Here
|
2235 |
ASTNode node = nodes[i]; |
2274 |
ASTNode node = nodes[i]; |
2236 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2275 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2237 |
if (encloses(element)) { |
2276 |
if (encloses(element)) { |
2238 |
this.patternLocator.matchReportReference(node, element, null/*no binding*/, level.intValue(), this); |
2277 |
this.patternLocator.matchReportReference(node, element, null, null, null/*no binding*/, level.intValue(), this); |
2239 |
} |
2278 |
} |
2240 |
} |
2279 |
} |
2241 |
} |
2280 |
} |
Lines 2247-2253
Link Here
|
2247 |
if (pkg != null && pkg.annotations != null) { |
2286 |
if (pkg != null && pkg.annotations != null) { |
2248 |
IJavaElement element = createPackageDeclarationHandle(unit); |
2287 |
IJavaElement element = createPackageDeclarationHandle(unit); |
2249 |
if (element != null) { |
2288 |
if (element != null) { |
2250 |
reportMatching(pkg.annotations, element, null, nodeSet, true, encloses(element)); |
2289 |
reportMatching(pkg.annotations, element, null, null, nodeSet, true, encloses(element)); |
2251 |
} |
2290 |
} |
2252 |
} |
2291 |
} |
2253 |
|
2292 |
|
Lines 2300-2321
Link Here
|
2300 |
|
2339 |
|
2301 |
// handle the nodes for the local type first |
2340 |
// handle the nodes for the local type first |
2302 |
if ((field.bits & ASTNode.HasLocalType) != 0) { |
2341 |
if ((field.bits & ASTNode.HasLocalType) != 0) { |
2303 |
if (enclosingElement == null) |
2342 |
if (enclosingElement == null) { |
2304 |
enclosingElement = createHandle(field, type, parent); |
2343 |
enclosingElement = createHandle(field, type, parent); |
2305 |
LocalDeclarationVisitor localDeclarationVisitor = new LocalDeclarationVisitor(enclosingElement, field.binding, nodeSet); |
2344 |
} |
|
|
2345 |
// Traverse field declaration(s) to report matches both in local types declaration |
2346 |
// and in local variables declaration |
2347 |
int fieldEnd = field.endPart2Position == 0 ? field.declarationSourceEnd : field.endPart2Position; |
2348 |
ASTNode[] nodes = typeInHierarchy ? nodeSet.matchingNodes(field.sourceStart, fieldEnd) : null; |
2349 |
boolean report = (this.matchContainer & PatternLocator.FIELD_CONTAINER) != 0 && encloses(enclosingElement); |
2350 |
MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, report ? nodes : null, nodeSet, this); |
2306 |
try { |
2351 |
try { |
2307 |
field.traverse(localDeclarationVisitor, null); |
2352 |
field.traverse(declarationVisitor, (MethodScope) null); |
2308 |
} catch (WrappedCoreException e) { |
2353 |
} catch (WrappedCoreException e) { |
2309 |
throw e.coreException; |
2354 |
throw e.coreException; |
2310 |
} |
2355 |
} |
|
|
2356 |
// Report all nodes and remove them |
2357 |
if (nodes != null) { |
2358 |
int length = nodes.length; |
2359 |
for (int i = 0; i < length; i++) { |
2360 |
ASTNode node = nodes[i]; |
2361 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2362 |
if (report && level != null) { |
2363 |
if (node instanceof TypeDeclaration) { |
2364 |
// use field declaration to report match (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88174) |
2365 |
AllocationExpression allocation = ((TypeDeclaration)node).allocation; |
2366 |
if (allocation != null && allocation.enumConstant != null) { |
2367 |
node = field; |
2368 |
} |
2369 |
} |
2370 |
this.patternLocator.matchReportReference(node, enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), field.binding, level.intValue(), this); |
2371 |
} |
2372 |
} |
2373 |
} |
2311 |
} |
2374 |
} |
2312 |
|
2375 |
|
2313 |
// report annotations |
2376 |
// report annotations |
|
|
2377 |
IJavaElement[] otherElements = null; |
2314 |
if (field.annotations != null) { |
2378 |
if (field.annotations != null) { |
2315 |
if (enclosingElement == null) { |
2379 |
if (enclosingElement == null) { |
2316 |
enclosingElement = createHandle(field, type, parent); |
2380 |
enclosingElement = createHandle(field, type, parent); |
2317 |
} |
2381 |
} |
2318 |
reportMatching(field.annotations, enclosingElement, field.binding, nodeSet, true, true); |
2382 |
if (otherFields != null) { |
|
|
2383 |
otherElements = createHandles(otherFields, type, parent); |
2384 |
} |
2385 |
reportMatching(field.annotations, enclosingElement, otherElements, field.binding, nodeSet, true, true); |
2319 |
} |
2386 |
} |
2320 |
|
2387 |
|
2321 |
if (typeInHierarchy) { |
2388 |
if (typeInHierarchy) { |
Lines 2333-2349
Link Here
|
2333 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2400 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2334 |
ASTNode node = nodes[i]; |
2401 |
ASTNode node = nodes[i]; |
2335 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2402 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2336 |
IJavaElement[] otherElements = null; |
2403 |
if (otherFields != null && otherElements == null) { |
2337 |
if (otherFields != null) { |
2404 |
otherElements = createHandles(otherFields, type, parent); |
2338 |
int length = otherFields.length; |
|
|
2339 |
int size = 0; |
2340 |
while (size<length && otherFields[size] != null) { |
2341 |
size++; |
2342 |
} |
2343 |
otherElements = new IJavaElement[size]; |
2344 |
for (int j=0; j<size; j++) { |
2345 |
otherElements[j] = createHandle(otherFields[j], type, parent); |
2346 |
} |
2347 |
} |
2405 |
} |
2348 |
this.patternLocator.matchReportReference(node, enclosingElement, null, otherElements, field.binding, level.intValue(), this); |
2406 |
this.patternLocator.matchReportReference(node, enclosingElement, null, otherElements, field.binding, level.intValue(), this); |
2349 |
} |
2407 |
} |
Lines 2357-2370
Link Here
|
2357 |
ASTNode[] nodes = nodeSet.matchingNodes(field.sourceStart, fieldEnd); |
2415 |
ASTNode[] nodes = nodeSet.matchingNodes(field.sourceStart, fieldEnd); |
2358 |
if (nodes != null) { |
2416 |
if (nodes != null) { |
2359 |
if ((this.matchContainer & PatternLocator.FIELD_CONTAINER) == 0) { |
2417 |
if ((this.matchContainer & PatternLocator.FIELD_CONTAINER) == 0) { |
2360 |
for (int i = 0, l = nodes.length; i < l; i++) |
2418 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2361 |
nodeSet.matchingNodes.removeKey(nodes[i]); |
2419 |
nodeSet.matchingNodes.removeKey(nodes[i]); |
|
|
2420 |
} |
2362 |
} else { |
2421 |
} else { |
2363 |
if (enclosingElement == null) { |
2422 |
if (enclosingElement == null) { |
2364 |
enclosingElement = createHandle(field, type, parent); |
2423 |
enclosingElement = createHandle(field, type, parent); |
2365 |
} |
2424 |
} |
2366 |
if (encloses(enclosingElement)) { |
2425 |
if (encloses(enclosingElement)) { |
2367 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2426 |
MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, nodes, nodeSet, this); |
|
|
2427 |
field.traverse(declarationVisitor, (MethodScope) null); |
2428 |
int length = nodes.length; |
2429 |
for (int i = 0; i < length; i++) { |
2368 |
ASTNode node = nodes[i]; |
2430 |
ASTNode node = nodes[i]; |
2369 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2431 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2370 |
if (node instanceof TypeDeclaration) { |
2432 |
if (node instanceof TypeDeclaration) { |
Lines 2374-2386
Link Here
|
2374 |
node = field; |
2436 |
node = field; |
2375 |
} |
2437 |
} |
2376 |
} |
2438 |
} |
2377 |
// Set block scope for initializer in case there would have other local and other elements to report |
2439 |
this.patternLocator.matchReportReference(node, enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), field.binding, level.intValue(), this); |
2378 |
BlockScope blockScope = null; |
|
|
2379 |
if (field.getKind() == AbstractVariableDeclaration.INITIALIZER) { |
2380 |
Block block = ((Initializer)field).block; |
2381 |
if (block != null) blockScope = block.scope; |
2382 |
} |
2383 |
this.patternLocator.matchReportReference(node, enclosingElement, field.binding, blockScope, level.intValue(), this); |
2384 |
} |
2440 |
} |
2385 |
return; |
2441 |
return; |
2386 |
} |
2442 |
} |
Lines 2426-2432
Link Here
|
2426 |
|
2482 |
|
2427 |
// report annotations |
2483 |
// report annotations |
2428 |
if (type.annotations != null) { |
2484 |
if (type.annotations != null) { |
2429 |
reportMatching(type.annotations, enclosingElement, type.binding, nodeSet, matchedClassContainer, enclosesElement); |
2485 |
reportMatching(type.annotations, enclosingElement, null, type.binding, nodeSet, matchedClassContainer, enclosesElement); |
2430 |
} |
2486 |
} |
2431 |
|
2487 |
|
2432 |
// report references in javadoc |
2488 |
// report references in javadoc |
Lines 2441-2447
Link Here
|
2441 |
ASTNode node = nodes[i]; |
2497 |
ASTNode node = nodes[i]; |
2442 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2498 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2443 |
if (enclosesElement) { |
2499 |
if (enclosesElement) { |
2444 |
this.patternLocator.matchReportReference(node, enclosingElement, type.binding, level.intValue(), this); |
2500 |
this.patternLocator.matchReportReference(node, enclosingElement, null, null, type.binding, level.intValue(), this); |
2445 |
} |
2501 |
} |
2446 |
} |
2502 |
} |
2447 |
} |
2503 |
} |
Lines 2454-2460
Link Here
|
2454 |
if (superType != null) { |
2510 |
if (superType != null) { |
2455 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(superType); |
2511 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(superType); |
2456 |
if (level != null && matchedClassContainer) |
2512 |
if (level != null && matchedClassContainer) |
2457 |
this.patternLocator.matchReportReference(superType, enclosingElement, type.binding, level.intValue(), this); |
2513 |
this.patternLocator.matchReportReference(superType, enclosingElement, null, null, type.binding, level.intValue(), this); |
2458 |
} |
2514 |
} |
2459 |
} else { |
2515 |
} else { |
2460 |
TypeReference superClass = type.superclass; |
2516 |
TypeReference superClass = type.superclass; |
Lines 2639-2651
Link Here
|
2639 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2695 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2640 |
ASTNode node = nodes[i]; |
2696 |
ASTNode node = nodes[i]; |
2641 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2697 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2642 |
this.patternLocator.matchReportReference(node, enclosingElement, elementBinding, level.intValue(), this); |
2698 |
this.patternLocator.matchReportReference(node, enclosingElement, null, null, elementBinding, level.intValue(), this); |
2643 |
} |
2699 |
} |
2644 |
} |
2700 |
} |
2645 |
} else if (encloses(enclosingElement)) { |
2701 |
} else if (encloses(enclosingElement)) { |
2646 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(superReference); |
2702 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(superReference); |
2647 |
if (level != null && matchedClassContainer) |
2703 |
if (level != null && matchedClassContainer) |
2648 |
this.patternLocator.matchReportReference(superReference, enclosingElement, elementBinding, level.intValue(), this); |
2704 |
this.patternLocator.matchReportReference(superReference, enclosingElement, null, null, elementBinding, level.intValue(), this); |
2649 |
} |
2705 |
} |
2650 |
} |
2706 |
} |
2651 |
protected boolean typeInHierarchy(ReferenceBinding binding) { |
2707 |
protected boolean typeInHierarchy(ReferenceBinding binding) { |