use of com.sun.tools.javac.tree.JCTree.JCExpression in project error-prone by google.
the class ExpressionTemplate method match.
/**
* Returns the matches of this template against the specified target AST.
*/
@Override
public Iterable<ExpressionTemplateMatch> match(JCTree target, Context context) {
if (target instanceof JCExpression) {
JCExpression targetExpr = (JCExpression) target;
Optional<Unifier> unifier = unify(targetExpr, new Unifier(context)).first();
if (unifier.isPresent()) {
return ImmutableList.of(new ExpressionTemplateMatch(targetExpr, unifier.get()));
}
}
return ImmutableList.of();
}
use of com.sun.tools.javac.tree.JCTree.JCExpression in project error-prone by google.
the class UFreeIdentTest method binds.
@Test
public void binds() {
JCExpression expr = parseExpression("\"abcdefg\".charAt(x + 1)");
UFreeIdent ident = UFreeIdent.create("foo");
assertNotNull(ident.unify(expr, unifier));
assertEquals(ImmutableMap.of(new UFreeIdent.Key("foo"), expr), unifier.getBindings());
}
use of com.sun.tools.javac.tree.JCTree.JCExpression in project error-prone by google.
the class EqualsNaN method matchBinary.
@Override
public Description matchBinary(BinaryTree tree, VisitorState state) {
String prefix;
switch(tree.getKind()) {
case EQUAL_TO:
prefix = "";
break;
case NOT_EQUAL_TO:
prefix = "!";
break;
default:
return Description.NO_MATCH;
}
JCExpression left = (JCExpression) tree.getLeftOperand();
JCExpression right = (JCExpression) tree.getRightOperand();
String leftMatch = matchNaN(left);
if (leftMatch != null) {
return describeMatch(tree, SuggestedFix.replace(tree, String.format("%s%s.isNaN(%s)", prefix, leftMatch, toString(right, state))));
}
String rightMatch = matchNaN(right);
if (rightMatch != null) {
return describeMatch(tree, SuggestedFix.replace(tree, String.format("%s%s.isNaN(%s)", prefix, rightMatch, toString(left, state))));
}
return Description.NO_MATCH;
}
use of com.sun.tools.javac.tree.JCTree.JCExpression in project error-prone by google.
the class ImportStatementsTest method stubPackage.
/**
* A helper method to create a stubbed package JCExpression.
*
* @param endPos the end position of the package JCExpression
* @return a new package JCExpression stub
*/
private static JCExpression stubPackage(int endPos) {
JCExpression result = mock(JCExpression.class);
when(result.getEndPosition(any(EndPosTable.class))).thenReturn(endPos);
return result;
}
use of com.sun.tools.javac.tree.JCTree.JCExpression in project error-prone by google.
the class Matchers method selectedIsInstance.
/**
* Returns true if the expression is a member access on an instance, rather than a static type.
* Supports member method invocations and field accesses.
*/
public static Matcher<ExpressionTree> selectedIsInstance() {
return new Matcher<ExpressionTree>() {
@Override
public boolean matches(ExpressionTree expr, VisitorState state) {
if (!(expr instanceof JCFieldAccess)) {
// TODO(cushon): throw IllegalArgumentException?
return false;
}
JCExpression selected = ((JCFieldAccess) expr).getExpression();
if (selected instanceof JCNewClass) {
return true;
}
Symbol sym = ASTHelpers.getSymbol(selected);
return sym instanceof VarSymbol;
}
};
}
Aggregations