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 |
} |
632 |
/* |
614 |
/* |
633 |
* Creates hierarchy resolver if needed. |
615 |
* Creates hierarchy resolver if needed. |
634 |
* Returns whether focus is visible. |
616 |
* Returns whether focus is visible. |
Lines 1389-1394
Link Here
|
1389 |
|
1371 |
|
1390 |
public SearchMatch newFieldReferenceMatch( |
1372 |
public SearchMatch newFieldReferenceMatch( |
1391 |
IJavaElement enclosingElement, |
1373 |
IJavaElement enclosingElement, |
|
|
1374 |
IJavaElement localElement, |
1392 |
Binding enclosingBinding, |
1375 |
Binding enclosingBinding, |
1393 |
int accuracy, |
1376 |
int accuracy, |
1394 |
int offset, |
1377 |
int offset, |
Lines 1413-1423
Link Here
|
1413 |
IResource resource = this.currentPossibleMatch.resource; |
1396 |
IResource resource = this.currentPossibleMatch.resource; |
1414 |
if (enclosingBinding != null) |
1397 |
if (enclosingBinding != null) |
1415 |
enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding); |
1398 |
enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding); |
1416 |
return new FieldReferenceMatch(enclosingElement, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource); |
1399 |
return new FieldReferenceMatch(enclosingElement, localElement, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource); |
1417 |
} |
1400 |
} |
1418 |
|
1401 |
|
1419 |
public SearchMatch newLocalVariableReferenceMatch( |
1402 |
public SearchMatch newLocalVariableReferenceMatch( |
1420 |
IJavaElement enclosingElement, |
1403 |
IJavaElement enclosingElement, |
|
|
1404 |
IJavaElement localElement, |
1421 |
int accuracy, |
1405 |
int accuracy, |
1422 |
int offset, |
1406 |
int offset, |
1423 |
int length, |
1407 |
int length, |
Lines 1439-1449
Link Here
|
1439 |
boolean insideDocComment = (bits & ASTNode.InsideJavadoc) != 0; |
1423 |
boolean insideDocComment = (bits & ASTNode.InsideJavadoc) != 0; |
1440 |
SearchParticipant participant = getParticipant(); |
1424 |
SearchParticipant participant = getParticipant(); |
1441 |
IResource resource = this.currentPossibleMatch.resource; |
1425 |
IResource resource = this.currentPossibleMatch.resource; |
1442 |
return new LocalVariableReferenceMatch(enclosingElement, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource); |
1426 |
return new LocalVariableReferenceMatch(enclosingElement, localElement, accuracy, offset, length, isReadAccess, isWriteAccess, insideDocComment, participant, resource); |
1443 |
} |
1427 |
} |
1444 |
|
1428 |
|
1445 |
public SearchMatch newMethodReferenceMatch( |
1429 |
public SearchMatch newMethodReferenceMatch( |
1446 |
IJavaElement enclosingElement, |
1430 |
IJavaElement enclosingElement, |
|
|
1431 |
IJavaElement localElement, |
1447 |
Binding enclosingBinding, |
1432 |
Binding enclosingBinding, |
1448 |
int accuracy, |
1433 |
int accuracy, |
1449 |
int offset, |
1434 |
int offset, |
Lines 1457-1467
Link Here
|
1457 |
if (enclosingBinding != null) |
1442 |
if (enclosingBinding != null) |
1458 |
enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding); |
1443 |
enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding); |
1459 |
boolean isOverridden = (accuracy & PatternLocator.SUPER_INVOCATION_FLAVOR) != 0; |
1444 |
boolean isOverridden = (accuracy & PatternLocator.SUPER_INVOCATION_FLAVOR) != 0; |
1460 |
return new MethodReferenceMatch(enclosingElement, accuracy, offset, length, isConstructor, isSynthetic, isOverridden, insideDocComment, participant, resource); |
1445 |
return new MethodReferenceMatch(enclosingElement, localElement, accuracy, offset, length, isConstructor, isSynthetic, isOverridden, insideDocComment, participant, resource); |
1461 |
} |
1446 |
} |
1462 |
|
1447 |
|
1463 |
public SearchMatch newPackageReferenceMatch( |
1448 |
public SearchMatch newPackageReferenceMatch( |
1464 |
IJavaElement enclosingElement, |
1449 |
IJavaElement enclosingElement, |
|
|
1450 |
IJavaElement localElement, |
1465 |
int accuracy, |
1451 |
int accuracy, |
1466 |
int offset, |
1452 |
int offset, |
1467 |
int length, |
1453 |
int length, |
Lines 1469-1479
Link Here
|
1469 |
SearchParticipant participant = getParticipant(); |
1455 |
SearchParticipant participant = getParticipant(); |
1470 |
IResource resource = this.currentPossibleMatch.resource; |
1456 |
IResource resource = this.currentPossibleMatch.resource; |
1471 |
boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0; |
1457 |
boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0; |
1472 |
return new PackageReferenceMatch(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource); |
1458 |
return new PackageReferenceMatch(enclosingElement, localElement, accuracy, offset, length, insideDocComment, participant, resource); |
1473 |
} |
1459 |
} |
1474 |
|
1460 |
|
1475 |
public SearchMatch newTypeParameterReferenceMatch( |
1461 |
public SearchMatch newTypeParameterReferenceMatch( |
1476 |
IJavaElement enclosingElement, |
1462 |
IJavaElement enclosingElement, |
|
|
1463 |
IJavaElement localElement, |
1477 |
int accuracy, |
1464 |
int accuracy, |
1478 |
int offset, |
1465 |
int offset, |
1479 |
int length, |
1466 |
int length, |
Lines 1482-1492
Link Here
|
1482 |
boolean insideDocComment = (bits & ASTNode.InsideJavadoc) != 0; |
1469 |
boolean insideDocComment = (bits & ASTNode.InsideJavadoc) != 0; |
1483 |
SearchParticipant participant = getParticipant(); |
1470 |
SearchParticipant participant = getParticipant(); |
1484 |
IResource resource = this.currentPossibleMatch.resource; |
1471 |
IResource resource = this.currentPossibleMatch.resource; |
1485 |
return new TypeParameterReferenceMatch(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource); |
1472 |
return new TypeParameterReferenceMatch(enclosingElement, localElement, accuracy, offset, length, insideDocComment, participant, resource); |
1486 |
} |
1473 |
} |
1487 |
|
1474 |
|
1488 |
public TypeReferenceMatch newTypeReferenceMatch( |
1475 |
public TypeReferenceMatch newTypeReferenceMatch( |
1489 |
IJavaElement enclosingElement, |
1476 |
IJavaElement enclosingElement, |
|
|
1477 |
IJavaElement localElement, |
1478 |
IJavaElement[] otherElements, |
1490 |
Binding enclosingBinding, |
1479 |
Binding enclosingBinding, |
1491 |
int accuracy, |
1480 |
int accuracy, |
1492 |
int offset, |
1481 |
int offset, |
Lines 1497-1503
Link Here
|
1497 |
boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0; |
1486 |
boolean insideDocComment = (reference.bits & ASTNode.InsideJavadoc) != 0; |
1498 |
if (enclosingBinding != null) |
1487 |
if (enclosingBinding != null) |
1499 |
enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding); |
1488 |
enclosingElement = ((JavaElement) enclosingElement).resolved(enclosingBinding); |
1500 |
return new TypeReferenceMatch(enclosingElement, accuracy, offset, length, insideDocComment, participant, resource); |
1489 |
return new TypeReferenceMatch(enclosingElement, localElement, otherElements, accuracy, offset, length, insideDocComment, participant, resource); |
1501 |
} |
1490 |
} |
1502 |
|
1491 |
|
1503 |
public TypeReferenceMatch newTypeReferenceMatch( |
1492 |
public TypeReferenceMatch newTypeReferenceMatch( |
Lines 1505-1511
Link Here
|
1505 |
Binding enclosingBinding, |
1494 |
Binding enclosingBinding, |
1506 |
int accuracy, |
1495 |
int accuracy, |
1507 |
ASTNode reference) { |
1496 |
ASTNode reference) { |
1508 |
return newTypeReferenceMatch(enclosingElement, enclosingBinding, accuracy, reference.sourceStart, reference.sourceEnd-reference.sourceStart+1, reference); |
1497 |
return newTypeReferenceMatch(enclosingElement, null, null, enclosingBinding, accuracy, reference.sourceStart, reference.sourceEnd-reference.sourceStart+1, reference); |
1509 |
} |
1498 |
} |
1510 |
|
1499 |
|
1511 |
/** |
1500 |
/** |
Lines 2073-2086
Link Here
|
2073 |
|
2062 |
|
2074 |
// handle nodes for the local type first |
2063 |
// handle nodes for the local type first |
2075 |
if ((method.bits & ASTNode.HasLocalType) != 0) { |
2064 |
if ((method.bits & ASTNode.HasLocalType) != 0) { |
2076 |
if (enclosingElement == null) |
2065 |
if (enclosingElement == null) { |
2077 |
enclosingElement = createHandle(method, parent); |
2066 |
enclosingElement = createHandle(method, parent); |
2078 |
LocalDeclarationVisitor localDeclarationVisitor = new LocalDeclarationVisitor(enclosingElement, method.binding, nodeSet); |
2067 |
} |
|
|
2068 |
// Traverse method declaration to report matches both in local types declaration |
2069 |
// and in local variables declaration |
2070 |
ASTNode[] nodes = typeInHierarchy ? nodeSet.matchingNodes(method.declarationSourceStart, method.declarationSourceEnd) : null; |
2071 |
boolean report = (this.matchContainer & PatternLocator.METHOD_CONTAINER) != 0 && encloses(enclosingElement); |
2072 |
MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, report ? nodes : null, nodeSet, this); |
2079 |
try { |
2073 |
try { |
2080 |
method.traverse(localDeclarationVisitor, (ClassScope) null); |
2074 |
method.traverse(declarationVisitor, (ClassScope) null); |
2081 |
} catch (WrappedCoreException e) { |
2075 |
} catch (WrappedCoreException e) { |
2082 |
throw e.coreException; |
2076 |
throw e.coreException; |
2083 |
} |
2077 |
} |
|
|
2078 |
// Report all nodes and remove them |
2079 |
if (nodes != null) { |
2080 |
int length = nodes.length; |
2081 |
for (int i = 0; i < length; i++) { |
2082 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(nodes[i]); |
2083 |
if (report && level != null) { |
2084 |
this.patternLocator.matchReportReference(nodes[i], enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), method.binding, level.intValue(), this); |
2085 |
} |
2086 |
} |
2087 |
} |
2084 |
} |
2088 |
} |
2085 |
|
2089 |
|
2086 |
// report the type parameters |
2090 |
// report the type parameters |
Lines 2105-2117
Link Here
|
2105 |
ASTNode[] nodes = nodeSet.matchingNodes(method.declarationSourceStart, method.declarationSourceEnd); |
2109 |
ASTNode[] nodes = nodeSet.matchingNodes(method.declarationSourceStart, method.declarationSourceEnd); |
2106 |
if (nodes != null) { |
2110 |
if (nodes != null) { |
2107 |
if ((this.matchContainer & PatternLocator.METHOD_CONTAINER) != 0) { |
2111 |
if ((this.matchContainer & PatternLocator.METHOD_CONTAINER) != 0) { |
2108 |
if (enclosingElement == null) |
2112 |
if (enclosingElement == null) { |
2109 |
enclosingElement = createHandle(method, parent); |
2113 |
enclosingElement = createHandle(method, parent); |
|
|
2114 |
} |
2110 |
if (encloses(enclosingElement)) { |
2115 |
if (encloses(enclosingElement)) { |
2111 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2116 |
if (((InternalSearchPattern)this.pattern).mustResolve) { |
2112 |
ASTNode node = nodes[i]; |
2117 |
// Visit only if the pattern must resolve |
2113 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2118 |
MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, nodes, nodeSet, this); |
2114 |
this.patternLocator.matchReportReference(node, enclosingElement, method.binding, method.scope, level.intValue(), this); |
2119 |
method.traverse(declarationVisitor, (ClassScope) null); |
|
|
2120 |
int length = nodes.length; |
2121 |
for (int i = 0; i < length; i++) { |
2122 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(nodes[i]); |
2123 |
this.patternLocator.matchReportReference(nodes[i], enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), method.binding, level.intValue(), this); |
2124 |
} |
2125 |
} else { |
2126 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2127 |
ASTNode node = nodes[i]; |
2128 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2129 |
this.patternLocator.matchReportReference(node, enclosingElement, null, null, method.binding, level.intValue(), this); |
2130 |
} |
2115 |
} |
2131 |
} |
2116 |
return; |
2132 |
return; |
2117 |
} |
2133 |
} |
Lines 2129-2140
Link Here
|
2129 |
protected void reportMatching(Annotation[] annotations, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedContainer, boolean enclosesElement) throws CoreException { |
2145 |
protected void reportMatching(Annotation[] annotations, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedContainer, boolean enclosesElement) throws CoreException { |
2130 |
for (int i=0, al=annotations.length; i<al; i++) { |
2146 |
for (int i=0, al=annotations.length; i<al; i++) { |
2131 |
Annotation annotationType = annotations[i]; |
2147 |
Annotation annotationType = annotations[i]; |
|
|
2148 |
IJavaElement localElement = null; |
2132 |
|
2149 |
|
2133 |
// Look for annotation type ref |
2150 |
// Look for annotation type ref |
2134 |
TypeReference typeRef = annotationType.type; |
2151 |
TypeReference typeRef = annotationType.type; |
2135 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeRef); |
2152 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(typeRef); |
2136 |
if (level != null && matchedContainer) { |
2153 |
if (level != null && matchedContainer) { |
2137 |
this.patternLocator.matchReportReference(typeRef, enclosingElement, elementBinding, level.intValue(), this); |
2154 |
localElement = createHandle(annotationType, (IAnnotatable) enclosingElement); |
|
|
2155 |
this.patternLocator.matchReportReference(typeRef, enclosingElement, localElement, null, elementBinding, level.intValue(), this); |
2138 |
} |
2156 |
} |
2139 |
|
2157 |
|
2140 |
// Look for attribute ref |
2158 |
// Look for attribute ref |
Lines 2144-2150
Link Here
|
2144 |
level = (Integer) nodeSet.matchingNodes.removeKey(pair); |
2162 |
level = (Integer) nodeSet.matchingNodes.removeKey(pair); |
2145 |
if (level != null && enclosesElement) { |
2163 |
if (level != null && enclosesElement) { |
2146 |
ASTNode reference = (annotationType instanceof SingleMemberAnnotation) ? (ASTNode) annotationType: pair; |
2164 |
ASTNode reference = (annotationType instanceof SingleMemberAnnotation) ? (ASTNode) annotationType: pair; |
2147 |
this.patternLocator.matchReportReference(reference, enclosingElement, pair.binding, level.intValue(), this); |
2165 |
if (localElement == null) { |
|
|
2166 |
localElement = createHandle(annotationType, (IAnnotatable) enclosingElement); |
2167 |
} |
2168 |
this.patternLocator.matchReportReference(reference, enclosingElement, localElement, null, pair.binding, level.intValue(), this); |
2148 |
} |
2169 |
} |
2149 |
} |
2170 |
} |
2150 |
|
2171 |
|
Lines 2160-2166
Link Here
|
2160 |
ASTNode node = nodes[j]; |
2181 |
ASTNode node = nodes[j]; |
2161 |
level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2182 |
level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2162 |
if (enclosesElement) { |
2183 |
if (enclosesElement) { |
2163 |
this.patternLocator.matchReportReference(node, enclosingElement, elementBinding, level.intValue(), this); |
2184 |
if (localElement == null) { |
|
|
2185 |
localElement = createHandle(annotationType, (IAnnotatable) enclosingElement); |
2186 |
} |
2187 |
this.patternLocator.matchReportReference(node, enclosingElement, localElement, null, elementBinding, level.intValue(), this); |
2164 |
} |
2188 |
} |
2165 |
} |
2189 |
} |
2166 |
} |
2190 |
} |
Lines 2235-2241
Link Here
|
2235 |
ASTNode node = nodes[i]; |
2259 |
ASTNode node = nodes[i]; |
2236 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2260 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2237 |
if (encloses(element)) { |
2261 |
if (encloses(element)) { |
2238 |
this.patternLocator.matchReportReference(node, element, null/*no binding*/, level.intValue(), this); |
2262 |
this.patternLocator.matchReportReference(node, element, null, null, null/*no binding*/, level.intValue(), this); |
2239 |
} |
2263 |
} |
2240 |
} |
2264 |
} |
2241 |
} |
2265 |
} |
Lines 2300-2313
Link Here
|
2300 |
|
2324 |
|
2301 |
// handle the nodes for the local type first |
2325 |
// handle the nodes for the local type first |
2302 |
if ((field.bits & ASTNode.HasLocalType) != 0) { |
2326 |
if ((field.bits & ASTNode.HasLocalType) != 0) { |
2303 |
if (enclosingElement == null) |
2327 |
if (enclosingElement == null) { |
2304 |
enclosingElement = createHandle(field, type, parent); |
2328 |
enclosingElement = createHandle(field, type, parent); |
2305 |
LocalDeclarationVisitor localDeclarationVisitor = new LocalDeclarationVisitor(enclosingElement, field.binding, nodeSet); |
2329 |
} |
|
|
2330 |
// Traverse field declaration(s) to report matches both in local types declaration |
2331 |
// and in local variables declaration |
2332 |
int fieldEnd = field.endPart2Position == 0 ? field.declarationSourceEnd : field.endPart2Position; |
2333 |
ASTNode[] nodes = typeInHierarchy ? nodeSet.matchingNodes(field.sourceStart, fieldEnd) : null; |
2334 |
boolean report = (this.matchContainer & PatternLocator.FIELD_CONTAINER) != 0 && encloses(enclosingElement); |
2335 |
MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, report ? nodes : null, nodeSet, this); |
2306 |
try { |
2336 |
try { |
2307 |
field.traverse(localDeclarationVisitor, null); |
2337 |
field.traverse(declarationVisitor, (MethodScope) null); |
2308 |
} catch (WrappedCoreException e) { |
2338 |
} catch (WrappedCoreException e) { |
2309 |
throw e.coreException; |
2339 |
throw e.coreException; |
2310 |
} |
2340 |
} |
|
|
2341 |
// Report all nodes and remove them |
2342 |
if (nodes != null) { |
2343 |
int length = nodes.length; |
2344 |
for (int i = 0; i < length; i++) { |
2345 |
ASTNode node = nodes[i]; |
2346 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2347 |
if (report && level != null) { |
2348 |
if (node instanceof TypeDeclaration) { |
2349 |
// use field declaration to report match (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=88174) |
2350 |
AllocationExpression allocation = ((TypeDeclaration)node).allocation; |
2351 |
if (allocation != null && allocation.enumConstant != null) { |
2352 |
node = field; |
2353 |
} |
2354 |
} |
2355 |
this.patternLocator.matchReportReference(node, enclosingElement, declarationVisitor.getLocalElement(i), declarationVisitor.getOtherElements(i), field.binding, level.intValue(), this); |
2356 |
} |
2357 |
} |
2358 |
} |
2311 |
} |
2359 |
} |
2312 |
|
2360 |
|
2313 |
// report annotations |
2361 |
// report annotations |
Lines 2357-2370
Link Here
|
2357 |
ASTNode[] nodes = nodeSet.matchingNodes(field.sourceStart, fieldEnd); |
2405 |
ASTNode[] nodes = nodeSet.matchingNodes(field.sourceStart, fieldEnd); |
2358 |
if (nodes != null) { |
2406 |
if (nodes != null) { |
2359 |
if ((this.matchContainer & PatternLocator.FIELD_CONTAINER) == 0) { |
2407 |
if ((this.matchContainer & PatternLocator.FIELD_CONTAINER) == 0) { |
2360 |
for (int i = 0, l = nodes.length; i < l; i++) |
2408 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2361 |
nodeSet.matchingNodes.removeKey(nodes[i]); |
2409 |
nodeSet.matchingNodes.removeKey(nodes[i]); |
|
|
2410 |
} |
2362 |
} else { |
2411 |
} else { |
2363 |
if (enclosingElement == null) { |
2412 |
if (enclosingElement == null) { |
2364 |
enclosingElement = createHandle(field, type, parent); |
2413 |
enclosingElement = createHandle(field, type, parent); |
2365 |
} |
2414 |
} |
2366 |
if (encloses(enclosingElement)) { |
2415 |
if (encloses(enclosingElement)) { |
2367 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2416 |
MemberDeclarationVisitor declarationVisitor = new MemberDeclarationVisitor(enclosingElement, nodes, nodeSet, this); |
|
|
2417 |
field.traverse(declarationVisitor, (MethodScope) null); |
2418 |
int length = nodes.length; |
2419 |
for (int i = 0; i < length; i++) { |
2368 |
ASTNode node = nodes[i]; |
2420 |
ASTNode node = nodes[i]; |
2369 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2421 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2370 |
if (node instanceof TypeDeclaration) { |
2422 |
if (node instanceof TypeDeclaration) { |
Lines 2374-2386
Link Here
|
2374 |
node = field; |
2426 |
node = field; |
2375 |
} |
2427 |
} |
2376 |
} |
2428 |
} |
2377 |
// Set block scope for initializer in case there would have other local and other elements to report |
2429 |
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 |
} |
2430 |
} |
2385 |
return; |
2431 |
return; |
2386 |
} |
2432 |
} |
Lines 2441-2447
Link Here
|
2441 |
ASTNode node = nodes[i]; |
2487 |
ASTNode node = nodes[i]; |
2442 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2488 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2443 |
if (enclosesElement) { |
2489 |
if (enclosesElement) { |
2444 |
this.patternLocator.matchReportReference(node, enclosingElement, type.binding, level.intValue(), this); |
2490 |
this.patternLocator.matchReportReference(node, enclosingElement, null, null, type.binding, level.intValue(), this); |
2445 |
} |
2491 |
} |
2446 |
} |
2492 |
} |
2447 |
} |
2493 |
} |
Lines 2454-2460
Link Here
|
2454 |
if (superType != null) { |
2500 |
if (superType != null) { |
2455 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(superType); |
2501 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(superType); |
2456 |
if (level != null && matchedClassContainer) |
2502 |
if (level != null && matchedClassContainer) |
2457 |
this.patternLocator.matchReportReference(superType, enclosingElement, type.binding, level.intValue(), this); |
2503 |
this.patternLocator.matchReportReference(superType, enclosingElement, null, null, type.binding, level.intValue(), this); |
2458 |
} |
2504 |
} |
2459 |
} else { |
2505 |
} else { |
2460 |
TypeReference superClass = type.superclass; |
2506 |
TypeReference superClass = type.superclass; |
Lines 2639-2651
Link Here
|
2639 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2685 |
for (int i = 0, l = nodes.length; i < l; i++) { |
2640 |
ASTNode node = nodes[i]; |
2686 |
ASTNode node = nodes[i]; |
2641 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2687 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); |
2642 |
this.patternLocator.matchReportReference(node, enclosingElement, elementBinding, level.intValue(), this); |
2688 |
this.patternLocator.matchReportReference(node, enclosingElement, null, null, elementBinding, level.intValue(), this); |
2643 |
} |
2689 |
} |
2644 |
} |
2690 |
} |
2645 |
} else if (encloses(enclosingElement)) { |
2691 |
} else if (encloses(enclosingElement)) { |
2646 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(superReference); |
2692 |
Integer level = (Integer) nodeSet.matchingNodes.removeKey(superReference); |
2647 |
if (level != null && matchedClassContainer) |
2693 |
if (level != null && matchedClassContainer) |
2648 |
this.patternLocator.matchReportReference(superReference, enclosingElement, elementBinding, level.intValue(), this); |
2694 |
this.patternLocator.matchReportReference(superReference, enclosingElement, null, null, elementBinding, level.intValue(), this); |
2649 |
} |
2695 |
} |
2650 |
} |
2696 |
} |
2651 |
protected boolean typeInHierarchy(ReferenceBinding binding) { |
2697 |
protected boolean typeInHierarchy(ReferenceBinding binding) { |