1 11 package org.eclipse.jdt.internal.core.search.matching; 12 13 import org.eclipse.jdt.internal.compiler.ast.*; 14 15 public class VariableLocator extends PatternLocator { 16 17 protected VariablePattern pattern; 18 19 public VariableLocator(VariablePattern pattern) { 20 super(pattern); 21 22 this.pattern = pattern; 23 } 24 public int match(Expression node, MatchingNodeSet nodeSet) { if (this.pattern.writeAccess) { 26 if (this.pattern.readAccess) return IMPOSSIBLE_MATCH; 28 if (node instanceof Assignment) { 29 Expression lhs = ((Assignment) node).lhs; 30 if (lhs instanceof Reference) 31 return matchReference((Reference) lhs, nodeSet, true); 32 } 33 } else if (this.pattern.readAccess) { 34 if (node instanceof Assignment && !(node instanceof CompoundAssignment)) { 35 Expression lhs = ((Assignment) node).lhs; 38 nodeSet.removePossibleMatch(lhs); 39 nodeSet.removeTrustedMatch(lhs); 40 } 41 } 42 return IMPOSSIBLE_MATCH; 43 } 44 public int match(Reference node, MatchingNodeSet nodeSet) { return this.pattern.readAccess 46 ? matchReference(node, nodeSet, false) 47 : IMPOSSIBLE_MATCH; 48 } 49 protected int matchReference(Reference node, MatchingNodeSet nodeSet, boolean writeOnlyAccess) { 50 if (node instanceof NameReference) { 51 if (this.pattern.name == null) { 52 return nodeSet.addMatch(node, ((InternalSearchPattern)this.pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH); 53 } else if (node instanceof SingleNameReference) { 54 if (matchesName(this.pattern.name, ((SingleNameReference) node).token)) 55 return nodeSet.addMatch(node, POSSIBLE_MATCH); 56 } else { 57 QualifiedNameReference qNameRef = (QualifiedNameReference) node; 58 char[][] tokens = qNameRef.tokens; 59 if (writeOnlyAccess) { 60 if (matchesName(this.pattern.name, tokens[tokens.length-1])) 62 return nodeSet.addMatch(node, POSSIBLE_MATCH); 63 } else { 64 for (int i = 0, max = tokens.length; i < max; i++) 65 if (matchesName(this.pattern.name, tokens[i])) 66 return nodeSet.addMatch(node, POSSIBLE_MATCH); 67 } 68 } 69 } 70 return IMPOSSIBLE_MATCH; 71 } 72 public String toString() { 73 return "Locator for " + this.pattern.toString(); } 75 } 76 | Popular Tags |