1 package annotator.find; 2 3 import annotations.io.ASTPath; 4 5 import com.sun.source.tree.*; 6 import com.sun.source.util.TreePath; 7 8 /** 9 * Represents the criterion that a program element is not enclosed by any 10 * method (i.e. it's a field, class type parameter, etc.). 11 */ 12 final class NotInMethodCriterion implements Criterion { 13 14 /** 15 * {@inheritDoc} 16 */ 17 @Override getKind()18 public Kind getKind() { 19 return Kind.NOT_IN_METHOD; 20 } 21 22 /** {@inheritDoc} */ 23 @Override isSatisfiedBy(TreePath path, Tree leaf)24 public boolean isSatisfiedBy(TreePath path, Tree leaf) { 25 assert path == null || path.getLeaf() == leaf; 26 return isSatisfiedBy(path); 27 } 28 29 /** {@inheritDoc} */ 30 @Override isSatisfiedBy(TreePath path)31 public boolean isSatisfiedBy(TreePath path) { 32 do { 33 Tree.Kind kind = path.getLeaf().getKind(); 34 if (kind == Tree.Kind.METHOD) { 35 return false; 36 } 37 if (ASTPath.isClassEquiv(kind)) { 38 return true; 39 } 40 path = path.getParentPath(); 41 } while (path != null && path.getLeaf() != null); 42 43 return true; 44 } 45 46 /** 47 * {@inheritDoc} 48 */ 49 @Override toString()50 public String toString() { 51 return "not in method"; 52 } 53 54 } 55