@Override public boolean matches(AssertTree tree, VisitorState state) { return conditionMatcher.matches(tree.getCondition(), state); } };
@Override public boolean matches(StatementTree statementTree, VisitorState state) { if (!(statementTree instanceof AssertTree)) { return false; } return expressionMatcher.matches(((AssertTree) statementTree).getCondition(), state); } }
@Override public UAssert visitAssert(AssertTree tree, Void v) { return UAssert.create( template(tree.getCondition()), (tree.getDetail() == null) ? null : template(tree.getDetail())); }
@Override public Choice<Unifier> visitAssert(AssertTree node, Unifier unifier) { return getCondition() .unify(node.getCondition(), unifier) .thenChoose(unifications(getDetail(), node.getDetail())); }
/** Handles the case "expr1 == expr2" */ private static void suggestFixForSameReference( SuggestedFix.Builder fix, AssertTree foundAssert, VisitorState state, boolean isEqual) { BinaryTree equalityTree = (BinaryTree) TreeInfo.skipParens((JCTree) foundAssert.getCondition()); ExpressionTree expr1 = equalityTree.getLeftOperand(); ExpressionTree expr2 = equalityTree.getRightOperand(); if (expr1.getKind() == NULL_LITERAL) { // case: "assert null [op] expr" addFix(fix, (JCExpression) expr2, foundAssert, state, isEqual ? IS_NULL : IS_NOT_NULL); } else if (expr2.getKind() == NULL_LITERAL) { // case: "assert expr [op] null" addFix(fix, (JCExpression) expr1, foundAssert, state, isEqual ? IS_NULL : IS_NOT_NULL); } else { // case: "assert expr1 [op] expr2" addFix( fix, (JCExpression) expr1, foundAssert, state, String.format(isEqual ? IS_SAME_AS : IS_NOT_SAME_AS, expr2)); } }
private static void replaceAssert( SuggestedFix.Builder fix, AssertTree foundAssert, VisitorState state) { ExpressionTree expr = foundAssert.getCondition(); expr = (ExpressionTree) TreeInfo.skipParens((JCTree) expr); // case: "assert !expr" if (expr.getKind().equals(LOGICAL_COMPLEMENT)) { addFix(fix, ((JCUnary) expr).getExpression(), foundAssert, state, IS_FALSE); return; } // case: "assert expr1.equals(expr2)" if (instanceMethod().onClass(Any.INSTANCE).named("equals").matches(expr, state)) { JCMethodInvocation equalsCall = ((JCMethodInvocation) expr); JCExpression expr1 = ((JCFieldAccess) ((JCMethodInvocation) expr).meth).selected; JCExpression expr2 = equalsCall.getArguments().get(0); addFix( fix, expr1, foundAssert, state, String.format(IS_EQUAL_TO, normalizedSourceForExpression(expr2, state))); return; } // case: "assert expr1 == expr2" or "assert expr1 != expr2" if (expr.getKind().equals(Kind.EQUAL_TO) || expr.getKind().equals(Kind.NOT_EQUAL_TO)) { suggestFixForSameReference(fix, foundAssert, state, expr.getKind().equals(Kind.EQUAL_TO)); return; } // case: "assert expr", which didn't match any of the previous cases. addFix(fix, (JCExpression) expr, foundAssert, state, IS_TRUE); }
@Override public boolean matches(StatementTree statementTree, VisitorState state) { if (!(statementTree instanceof AssertTree)) { return false; } return expressionMatcher.matches(((AssertTree) statementTree).getCondition(), state); } }
@Override public boolean matches(AssertTree tree, VisitorState state) { return conditionMatcher.matches(tree.getCondition(), state); } };
@Override public Void visitAssert(AssertTree expected, Tree actual) { Optional<AssertTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getCondition(), other.get().getCondition()); scan(expected.getDetail(), other.get().getDetail()); return null; }
@Override public Void visitAssert(AssertTree expected, Tree actual) { Optional<AssertTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getCondition(), other.get().getCondition()); scan(expected.getDetail(), other.get().getDetail()); return null; }
@Override public Void visitAssert(AssertTree expected, Tree actual) { Optional<AssertTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } scan(expected.getCondition(), other.get().getCondition()); scan(expected.getDetail(), other.get().getDetail()); return null; }
public R visitAssert(AssertTree node, P p) { R r = scan(node.getCondition(), p); r = scanAndReduce(node.getDetail(), p, r); return r; }
public R visitAssert(AssertTree node, P p) { R r = scan(node.getCondition(), p); r = scanAndReduce(node.getDetail(), p, r); return r; }
public R visitAssert(AssertTree node, P p) { R r = scan(node.getCondition(), p); r = scanAndReduce(node.getDetail(), p, r); return r; }
public Boolean visitAssert(AssertTree node, TreePath p) { if (p == null) { super.visitAssert(node, p); return false; } AssertTree at = (AssertTree) p.getLeaf(); if (!scan(node.getCondition(), at.getCondition(), p)) { return false; } return scan(node.getDetail(), at.getDetail(), p); }
public List<Tree> visitAssert(AssertTree node, ExpressionScanner.ExpressionsInfo p) { List<Tree> result = scan(node.getCondition(), p); result = reduce(result, scan(node.getDetail(), p)); return result; }
@Override public List<Tree> visitAssert(AssertTree node, ExpressionScanner.ExpressionsInfo p) { if (acceptsTree(node)) { List<Tree> result = scan(node.getCondition(), p); result = reduce(result, scan(node.getDetail(), p)); return result; } else { return null; } }
@Override public UAssert visitAssert(AssertTree tree, Void v) { return UAssert.create( template(tree.getCondition()), (tree.getDetail() == null) ? null : template(tree.getDetail())); }
@Override public Choice<Unifier> visitAssert(AssertTree node, Unifier unifier) { return getCondition() .unify(node.getCondition(), unifier) .thenChoose(unifications(getDetail(), node.getDetail())); }
@Override public Tree visitAssert(AssertTree tree, Void p) { AssertTree n = make.Assert(tree.getCondition(), tree.getDetail()); model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }