@Override public Void visitIf(IfTree ifTree, List<ReformatOption> optionsToReformat) { StatementTree thenStatement = ifTree.getThenStatement(); if (thenStatement instanceof BlockTree) { addLeftBraceToList(optionsToReformat, ((BlockTree) thenStatement), PreferencesFormatOptions.BRACES_IN_OTHER_DECLARATION); } StatementTree elseStatement = ifTree.getElseStatement(); if (elseStatement instanceof EmptyStatementTree && thenStatement instanceof CompoundTree) { addRightBraceToList(optionsToReformat, ((CompoundTree) thenStatement), PreferencesFormatOptions.AFTER_OTHER_DECLARATION); } else if (elseStatement instanceof BlockTree) { addLeftBraceToList(optionsToReformat, ((BlockTree) elseStatement), PreferencesFormatOptions.BRACES_IN_OTHER_DECLARATION); } return null; }
@Override public Tree visitEmptyStatement(EmptyStatementTree tree, Void p) { EmptyStatementTree n = make.EmptyStatement(); // model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
@Override public Boolean visitEmptyStatement(EmptyStatementTree node, TreePath p) { if (p == null) { super.visitEmptyStatement(node, p); return false; } return node.getKind() == p.getLeaf().getKind(); }
@Override public Void visitEmptyStatement(EmptyStatementTree tree, List<Node> d) { List<Node> below = new ArrayList<Node>(); addCorrespondingType(below); addCorrespondingComments(below); super.visitEmptyStatement(tree, below); d.add(new TreeNode(info, getCurrentPath(), below)); return null; }
@Override public Void visitEmptyStatement(EmptyStatementTree tree, VisitorState visitorState) { VisitorState state = visitorState.withPath(getCurrentPath()); for (EmptyStatementTreeMatcher matcher : emptyStatementMatchers) { if (!isSuppressed(matcher, state)) { try { reportMatch(matcher.matchEmptyStatement(tree, state), tree, state); } catch (Throwable t) { handleError(matcher, t); } } } return super.visitEmptyStatement(tree, state); }
/** * Match empty statement if: - Parent statement is an if - The then part of the parent if is an * empty statement, and - The else part of the parent if does not exist */ @Override public Description matchEmptyStatement(EmptyStatementTree tree, VisitorState state) { boolean matches = false; Tree parent = state.getPath().getParentPath().getLeaf(); if (parent.getKind() == IF) { IfTree parentAsIf = (IfTree) parent; matches = (parentAsIf.getThenStatement() instanceof EmptyStatementTree) && (parentAsIf.getElseStatement() == null); } if (!matches) { return Description.NO_MATCH; } /* * We suggest different fixes depending on what follows the parent if statement. * If there is no statement following the if, then suggest deleting the whole * if statement. If the next statement is a block, then suggest deleting the * empty then part of the if. If the next statement is not a block, then also * suggest deleting the empty then part of the if. */ boolean nextStmtIsNull = parentNode(nextStatement(Matchers.<StatementTree>isSame(null))).matches(tree, state); assert (state.getPath().getParentPath().getLeaf().getKind() == IF); IfTree ifParent = (IfTree) state.getPath().getParentPath().getLeaf(); if (nextStmtIsNull) { // No following statements. Delete whole if. return describeMatch(parent, SuggestedFix.delete(parent)); } else { // There are more statements. Delete the empty then part of the if. return describeMatch( ifParent.getThenStatement(), SuggestedFix.delete(ifParent.getThenStatement())); } }
/** * Match empty statement if: * - Parent statement is an if * - The then part of the parent if is an empty statement, and * - The else part of the parent if does not exist */ @Override public Description matchEmptyStatement(EmptyStatementTree tree, VisitorState state) { boolean matches = false; Tree parent = state.getPath().getParentPath().getLeaf(); if (parent.getKind() == IF) { IfTree parentAsIf = (IfTree)parent; matches = (parentAsIf.getThenStatement() instanceof EmptyStatementTree) && (parentAsIf.getElseStatement() == null); } if (!matches) { return Description.NO_MATCH; } /* * We suggest different fixes depending on what follows the parent if statement. * If there is no statement following the if, then suggest deleting the whole * if statement. If the next statement is a block, then suggest deleting the * empty then part of the if. If the next statement is not a block, then also * suggest deleting the empty then part of the if. */ boolean nextStmtIsNull = parentNode(nextStatement(Matchers.<StatementTree>isSame(null))) .matches(tree, state); assert(state.getPath().getParentPath().getLeaf().getKind() == IF); IfTree ifParent = (IfTree)state.getPath().getParentPath().getLeaf(); SuggestedFix fix = new SuggestedFix(); if (nextStmtIsNull) { // No following statements. Delete whole if. fix.delete(parent); return describeMatch(parent, fix); } else { // There are more statements. Delete the empty then part of the if. fix.delete(ifParent.getThenStatement()); return describeMatch(ifParent.getThenStatement(), fix); } }
@Override public Void visitEmptyStatement(EmptyStatementTree expected, Tree actual) { if (!checkTypeAndCast(expected, actual).isPresent()) { addTypeMismatch(expected, actual); return null; } return null; }
public Boolean visitEmptyStatement(EmptyStatementTree node, ConstructorData p) { super.visitEmptyStatement(node, p); return null; }
@Override public List<? extends TypeMirror> visitEmptyStatement(EmptyStatementTree node, Object p) { return null; }
@Override public Mirror visitEmptyStatement(EmptyStatementTree arg0, EvaluationContext evaluationContext) { return null; }
@Override public Void visitEmptyStatement(EmptyStatementTree node, Void unused) { sync(node); dropEmptyDeclarations(); return null; }
@Override public R visitEmptyStatement(EmptyStatementTree est, P p) { return null; }
@Override public List<T> visitEmptyStatement(EmptyStatementTree node, T p) { return checkForCriteria(node); }
@Override public EmptyStatementTree createEmptyStatement() { return new EmptyStatementTreeImpl(); }
@Override public Object visitEmptyStatement(EmptyStatementTree t, Trees p) { info("EmptyStatementTree" + CL + t.getKind() + SP + t); return super.visitEmptyStatement(t, p); }
@Override public USkip visitEmptyStatement(EmptyStatementTree tree, Void v) { return USkip.INSTANCE; }
@Override @Nullable public Unifier visitEmptyStatement(EmptyStatementTree node, @Nullable Unifier unifier) { return unifier; }
@Override public Boolean visitEmptyStatement(EmptyStatementTree tree, Void unused) { return true; }
@Override public Choice<Unifier> visitEmptyStatement(EmptyStatementTree node, Unifier unifier) { return Choice.of(unifier); }
@Override public Description matchEmptyStatement(EmptyStatementTree emptyStatementTree, VisitorState state) { return describeMatch(emptyStatementTree, new SuggestedFix().delete(emptyStatementTree)); }
@Override public Description matchEmptyStatement(EmptyStatementTree tree, VisitorState state) { return describeMatch(tree, NO_FIX); }
@Override public Node visitEmptyStatement(EmptyStatementTree tree, Void p) { return null; }
@Override public PurityResult visitEmptyStatement(EmptyStatementTree node, PurityResult p) { return p; }
/** * Creates a tree node for an empty statement. * @return a new EmptyStatementTree object */ EmptyStatementTree createEmptyStatement();
Description matchEmptyStatement(EmptyStatementTree tree, VisitorState state);