Search in sources :

Example 31 with JCExpression

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();
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression)

Example 32 with JCExpression

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());
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) Test(org.junit.Test)

Example 33 with JCExpression

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;
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression)

Example 34 with JCExpression

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;
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) EndPosTable(com.sun.tools.javac.tree.EndPosTable)

Example 35 with JCExpression

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;
        }
    };
}
Also used : JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) InstanceMethodMatcher(com.google.errorprone.matchers.method.MethodMatchers.InstanceMethodMatcher) AnyMethodMatcher(com.google.errorprone.matchers.method.MethodMatchers.AnyMethodMatcher) StaticMethodMatcher(com.google.errorprone.matchers.method.MethodMatchers.StaticMethodMatcher) ConstructorMatcher(com.google.errorprone.matchers.method.MethodMatchers.ConstructorMatcher) VisitorState(com.google.errorprone.VisitorState) JCFieldAccess(com.sun.tools.javac.tree.JCTree.JCFieldAccess) MethodSymbol(com.sun.tools.javac.code.Symbol.MethodSymbol) ClassSymbol(com.sun.tools.javac.code.Symbol.ClassSymbol) Symbol(com.sun.tools.javac.code.Symbol) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol) ExpressionTree(com.sun.source.tree.ExpressionTree) JCNewClass(com.sun.tools.javac.tree.JCTree.JCNewClass) VarSymbol(com.sun.tools.javac.code.Symbol.VarSymbol)

Aggregations

JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)311 JCTree (com.sun.tools.javac.tree.JCTree)95 Type (com.redhat.ceylon.model.typechecker.model.Type)85 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)81 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)67 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)59 ListBuffer (com.sun.tools.javac.util.ListBuffer)54 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)39 Name (com.sun.tools.javac.util.Name)39 SyntheticName (com.redhat.ceylon.compiler.java.codegen.Naming.SyntheticName)37 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)35 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)34 JCBlock (com.sun.tools.javac.tree.JCTree.JCBlock)34 JavacTreeMaker (lombok.javac.JavacTreeMaker)33 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)30 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)29 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)27 Function (com.redhat.ceylon.model.typechecker.model.Function)26 Parameter (com.redhat.ceylon.model.typechecker.model.Parameter)26 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)26