public int match(LambdaExpression node, MatchingNodeSet nodeSet) { if (this.pattern.superRefKind != SuperTypeReferencePattern.ONLY_SUPER_INTERFACES) return IMPOSSIBLE_MATCH; nodeSet.mustResolve = true; return nodeSet.addMatch(node, POSSIBLE_MATCH); } //public int match(MethodDeclaration node, MatchingNodeSet nodeSet) - SKIP IT
@Override protected TypeReference augmentTypeWithAdditionalDimensions(TypeReference typeRef, int additionalDimensions, Annotation [][] additionalAnnotations, boolean isVarargs) { TypeReference result = super.augmentTypeWithAdditionalDimensions(typeRef, additionalDimensions, additionalAnnotations, isVarargs); if (this.nodeSet.removePossibleMatch(typeRef) != null) this.nodeSet.addPossibleMatch(result); else if (this.nodeSet.removeTrustedMatch(typeRef) != null) this.nodeSet.addTrustedMatch(result, true); return result; } @Override
protected void purgeMethodStatements(TypeDeclaration type, boolean checkEachMethod) { checkEachMethod = checkEachMethod && this.currentPossibleMatch.nodeSet.hasPossibleNodes(type.declarationSourceStart, type.declarationSourceEnd); AbstractMethodDeclaration[] methods = type.methods; if (methods != null) { if (checkEachMethod) { for (int j = 0, length = methods.length; j < length; j++) { AbstractMethodDeclaration method = methods[j]; if (!this.currentPossibleMatch.nodeSet.hasPossibleNodes(method.declarationSourceStart, method.declarationSourceEnd)) { method.statements = null; method.javadoc = null; } } } else { for (int j = 0, length = methods.length; j < length; j++) { methods[j].statements = null; methods[j].javadoc = null; } } } TypeDeclaration[] memberTypes = type.memberTypes; if (memberTypes != null) for (int i = 0, l = memberTypes.length; i < l; i++) purgeMethodStatements(memberTypes[i], checkEachMethod); } /**
case PatternLocator.INACCURATE_MATCH: if (matchLevel != maskedLevel) { addTrustedMatch(node, Integer.valueOf(SearchMatch.A_INACCURATE+(matchLevel & PatternLocator.FLAVORS_MASK))); } else { addTrustedMatch(node, POTENTIAL_MATCH); addPossibleMatch(node); break; case PatternLocator.ERASURE_MATCH: if (matchLevel != maskedLevel) { addTrustedMatch(node, Integer.valueOf(SearchPattern.R_ERASURE_MATCH+(matchLevel & PatternLocator.FLAVORS_MASK))); } else { addTrustedMatch(node, ERASURE_MATCH); addTrustedMatch(node, Integer.valueOf(SearchMatch.A_ACCURATE+(matchLevel & PatternLocator.FLAVORS_MASK))); } else { addTrustedMatch(node, EXACT_MATCH);
@Override public int match(Expression node, MatchingNodeSet nodeSet) { // interested in Assignment if (this.pattern.writeAccess) { if (this.pattern.readAccess) return IMPOSSIBLE_MATCH; // already checked the lhs in match(Reference...) before we reached here if (node instanceof Assignment) { Expression lhs = ((Assignment) node).lhs; if (lhs instanceof Reference) return matchReference((Reference) lhs, nodeSet, true); } } else if (this.pattern.readAccess || this.pattern.fineGrain != 0) { if (node instanceof Assignment && !(node instanceof CompoundAssignment)) { // the lhs of a simple assignment may be added in match(Reference...) before we reach here // for example, the fieldRef to 'this.x' in the statement this.x = x; is not considered a readAccess char[] lastToken = null; Expression lhs = ((Assignment) node).lhs; if (lhs instanceof QualifiedNameReference) { char[][] tokens = ((QualifiedNameReference)lhs).tokens; lastToken = tokens[tokens.length-1]; } if (lastToken == null || matchesName(this.pattern.name, lastToken)) { nodeSet.removePossibleMatch(lhs); nodeSet.removeTrustedMatch(lhs); } } } return IMPOSSIBLE_MATCH; } @Override
protected void reportMatchingSuper(TypeReference superReference, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedClassContainer) throws CoreException { ASTNode[] nodes = null; if (superReference instanceof ParameterizedSingleTypeReference || superReference instanceof ParameterizedQualifiedTypeReference) { long lastTypeArgumentInfo = findLastTypeArgumentInfo(superReference); nodes = nodeSet.matchingNodes(superReference.sourceStart, (int)lastTypeArgumentInfo); } if (nodes != null) { if ((this.matchContainer & PatternLocator.CLASS_CONTAINER) == 0) { for (int i = 0, l = nodes.length; i < l; i++) nodeSet.matchingNodes.removeKey(nodes[i]); } else { if (encloses(enclosingElement)) for (int i = 0, l = nodes.length; i < l; i++) { ASTNode node = nodes[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); this.patternLocator.matchReportReference(node, enclosingElement, null, null, elementBinding, level.intValue(), this); } } } else if (encloses(enclosingElement)) { Integer level = (Integer) nodeSet.matchingNodes.removeKey(superReference); if (level != null && matchedClassContainer) this.patternLocator.matchReportReference(superReference, enclosingElement, null, null, elementBinding, level.intValue(), this); } } protected boolean typeInHierarchy(ReferenceBinding binding) {
: this.unitScope.getImport(importRef.tokens, false, importRef.isStatic()); if (inModule) { nodeSet.addMatch(node, this.patternLocator.resolveLevel(binding)); // report all module-info together } else { this.patternLocator.matchLevelAndReportImportRef(importRef, binding, this); nodeSet.addMatch(node, this.patternLocator.resolveLevel(node)); ASTNode[] nodes = nodeSet.matchingNodes(unit.javadoc.sourceStart, unit.javadoc.sourceEnd); if (nodes != null) { if (!matchedUnitContainer) {
public PossibleMatch(MatchLocator locator, IResource resource, Openable openable, SearchDocument document, boolean mustResolve) { this.resource = resource; this.openable = openable; this.document = document; this.nodeSet = new MatchingNodeSet(mustResolve); char[] qualifiedName = getQualifiedName(); if (qualifiedName != null) this.compoundName = CharOperation.splitOn('.', qualifiedName); } public void cleanUp() {
void addTrustedMatch(ASTNode node, Integer level) { // remove existing node at same position from set // (case of recovery that created the same node several time // see http://bugs.eclipse.org/bugs/show_bug.cgi?id=29366) long key = (((long) node.sourceStart) << 32) + node.sourceEnd; ASTNode existing = (ASTNode) this.matchingNodesKeys.get(key); if (existing != null && existing.getClass().equals(node.getClass())) this.matchingNodes.removeKey(existing); // map node to its accuracy level this.matchingNodes.put(node, level); this.matchingNodesKeys.put(key, node); } protected boolean hasPossibleNodes(int start, int end) {
protected void reportMatchingSuper(TypeReference superReference, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedClassContainer) throws CoreException { ASTNode[] nodes = null; if (superReference instanceof ParameterizedSingleTypeReference || superReference instanceof ParameterizedQualifiedTypeReference) { long lastTypeArgumentInfo = findLastTypeArgumentInfo(superReference); nodes = nodeSet.matchingNodes(superReference.sourceStart, (int)lastTypeArgumentInfo); } if (nodes != null) { if ((this.matchContainer & PatternLocator.CLASS_CONTAINER) == 0) { for (int i = 0, l = nodes.length; i < l; i++) nodeSet.matchingNodes.removeKey(nodes[i]); } else { if (encloses(enclosingElement)) for (int i = 0, l = nodes.length; i < l; i++) { ASTNode node = nodes[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); this.patternLocator.matchReportReference(node, enclosingElement, null, null, elementBinding, level.intValue(), this); } } } else if (encloses(enclosingElement)) { Integer level = (Integer) nodeSet.matchingNodes.removeKey(superReference); if (level != null && matchedClassContainer) this.patternLocator.matchReportReference(superReference, enclosingElement, null, null, elementBinding, level.intValue(), this); } } protected boolean typeInHierarchy(ReferenceBinding binding) {
public int match(Expression node, MatchingNodeSet nodeSet) { // interested in Assignment if (this.pattern.writeAccess) { if (this.pattern.readAccess) return IMPOSSIBLE_MATCH; // already checked the lhs in match(Reference...) before we reached here if (node instanceof Assignment) { Expression lhs = ((Assignment) node).lhs; if (lhs instanceof Reference) return matchReference((Reference) lhs, nodeSet, true); } } else if (this.pattern.readAccess || this.pattern.fineGrain != 0) { if (node instanceof Assignment && !(node instanceof CompoundAssignment)) { // the lhs of a simple assignment may be added in match(Reference...) before we reach here // for example, the fieldRef to 'this.x' in the statement this.x = x; is not considered a readAccess char[] lastToken = null; Expression lhs = ((Assignment) node).lhs; if (lhs instanceof QualifiedNameReference) { char[][] tokens = ((QualifiedNameReference)lhs).tokens; lastToken = tokens[tokens.length-1]; } if (lastToken == null || matchesName(this.pattern.name, lastToken)) { nodeSet.removePossibleMatch(lhs); nodeSet.removeTrustedMatch(lhs); } } } return IMPOSSIBLE_MATCH; } public int match(Reference node, MatchingNodeSet nodeSet) { // interested in NameReference & its subtypes
case PatternLocator.INACCURATE_MATCH: if (matchLevel != maskedLevel) { addTrustedMatch(node, Integer.valueOf(SearchMatch.A_INACCURATE+(matchLevel & PatternLocator.FLAVORS_MASK))); } else { addTrustedMatch(node, POTENTIAL_MATCH); addPossibleMatch(node); break; case PatternLocator.ERASURE_MATCH: if (matchLevel != maskedLevel) { addTrustedMatch(node, Integer.valueOf(SearchPattern.R_ERASURE_MATCH+(matchLevel & PatternLocator.FLAVORS_MASK))); } else { addTrustedMatch(node, ERASURE_MATCH); addTrustedMatch(node, Integer.valueOf(SearchMatch.A_ACCURATE+(matchLevel & PatternLocator.FLAVORS_MASK))); } else { addTrustedMatch(node, EXACT_MATCH);
this.patternLocator.matchLevelAndReportImportRef(importRef, binding, this); } else { nodeSet.addMatch(node, this.patternLocator.resolveLevel(node)); ASTNode[] nodes = nodeSet.matchingNodes(unit.javadoc.sourceStart, unit.javadoc.sourceEnd); if (nodes != null) { if (!matchedUnitContainer) {
public PossibleMatch(MatchLocator locator, IResource resource, Openable openable, SearchDocument document, boolean mustResolve) { this.resource = resource; this.openable = openable; this.document = document; this.nodeSet = new MatchingNodeSet(mustResolve); char[] qualifiedName = getQualifiedName(); if (qualifiedName != null) this.compoundName = CharOperation.splitOn('.', qualifiedName); } public void cleanUp() {
void addTrustedMatch(ASTNode node, Integer level) { // remove existing node at same position from set // (case of recovery that created the same node several time // see http://bugs.eclipse.org/bugs/show_bug.cgi?id=29366) long key = (((long) node.sourceStart) << 32) + node.sourceEnd; ASTNode existing = (ASTNode) this.matchingNodesKeys.get(key); if (existing != null && existing.getClass().equals(node.getClass())) this.matchingNodes.removeKey(existing); // map node to its accuracy level this.matchingNodes.put(node, level); this.matchingNodesKeys.put(key, node); } protected boolean hasPossibleNodes(int start, int end) {
protected TypeReference augmentTypeWithAdditionalDimensions(TypeReference typeRef, int additionalDimensions, Annotation [][] additionalAnnotations, boolean isVarargs) { TypeReference result = super.augmentTypeWithAdditionalDimensions(typeRef, additionalDimensions, additionalAnnotations, isVarargs); if (this.nodeSet.removePossibleMatch(typeRef) != null) this.nodeSet.addPossibleMatch(result); else if (this.nodeSet.removeTrustedMatch(typeRef) != null) this.nodeSet.addTrustedMatch(result, true); return result; } protected TypeReference getTypeReference(int dim) {
@Override public int match(TypeDeclaration node, MatchingNodeSet nodeSet) { if (!this.pattern.findReferences) return IMPOSSIBLE_MATCH; if (this.pattern.fineGrain != 0 && (this.pattern.fineGrain & ~IJavaSearchConstants.METHOD_REFERENCE_EXPRESSION) == 0 ) return IMPOSSIBLE_MATCH; // need to look for a generated default constructor return nodeSet.addMatch(node, this.pattern.mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); } //public int match(TypeReference node, MatchingNodeSet nodeSet) - SKIP IT
protected void reportMatchingSuper(TypeReference superReference, IJavaElement enclosingElement, Binding elementBinding, MatchingNodeSet nodeSet, boolean matchedClassContainer) throws CoreException { ASTNode[] nodes = null; if (superReference instanceof ParameterizedSingleTypeReference || superReference instanceof ParameterizedQualifiedTypeReference) { long lastTypeArgumentInfo = findLastTypeArgumentInfo(superReference); nodes = nodeSet.matchingNodes(superReference.sourceStart, (int)lastTypeArgumentInfo); } if (nodes != null) { if ((this.matchContainer & PatternLocator.CLASS_CONTAINER) == 0) { for (int i = 0, l = nodes.length; i < l; i++) nodeSet.matchingNodes.removeKey(nodes[i]); } else { if (encloses(enclosingElement)) for (int i = 0, l = nodes.length; i < l; i++) { ASTNode node = nodes[i]; Integer level = (Integer) nodeSet.matchingNodes.removeKey(node); this.patternLocator.matchReportReference(node, enclosingElement, null, null, elementBinding, level.intValue(), this); } } } else if (encloses(enclosingElement)) { Integer level = (Integer) nodeSet.matchingNodes.removeKey(superReference); if (level != null && matchedClassContainer) this.patternLocator.matchReportReference(superReference, enclosingElement, null, null, elementBinding, level.intValue(), this); } } protected boolean typeInHierarchy(ReferenceBinding binding) {
public int match(Expression node, MatchingNodeSet nodeSet) { // interested in Assignment if (this.pattern.writeAccess) { if (this.pattern.readAccess) return IMPOSSIBLE_MATCH; // already checked the lhs in match(Reference...) before we reached here if (node instanceof Assignment) { Expression lhs = ((Assignment) node).lhs; if (lhs instanceof Reference) return matchReference((Reference) lhs, nodeSet, true); } } else if (this.pattern.readAccess || this.pattern.fineGrain != 0) { if (node instanceof Assignment && !(node instanceof CompoundAssignment)) { // the lhs of a simple assignment may be added in match(Reference...) before we reach here // for example, the fieldRef to 'this.x' in the statement this.x = x; is not considered a readAccess char[] lastToken = null; Expression lhs = ((Assignment) node).lhs; if (lhs instanceof QualifiedNameReference) { char[][] tokens = ((QualifiedNameReference)lhs).tokens; lastToken = tokens[tokens.length-1]; } if (lastToken == null || matchesName(this.pattern.name, lastToken)) { nodeSet.removePossibleMatch(lhs); nodeSet.removeTrustedMatch(lhs); } } } return IMPOSSIBLE_MATCH; } public int match(Reference node, MatchingNodeSet nodeSet) { // interested in NameReference & its subtypes
case PatternLocator.INACCURATE_MATCH: if (matchLevel != maskedLevel) { addTrustedMatch(node, Integer.valueOf(SearchMatch.A_INACCURATE+(matchLevel & PatternLocator.FLAVORS_MASK))); } else { addTrustedMatch(node, POTENTIAL_MATCH); addPossibleMatch(node); break; case PatternLocator.ERASURE_MATCH: if (matchLevel != maskedLevel) { addTrustedMatch(node, Integer.valueOf(SearchPattern.R_ERASURE_MATCH+(matchLevel & PatternLocator.FLAVORS_MASK))); } else { addTrustedMatch(node, ERASURE_MATCH); addTrustedMatch(node, Integer.valueOf(SearchMatch.A_ACCURATE+(matchLevel & PatternLocator.FLAVORS_MASK))); } else { addTrustedMatch(node, EXACT_MATCH);