final ControlFlowNode handleEmbeddedStatement(final Statement embeddedStatement, final ControlFlowNode source) { if (embeddedStatement == null || embeddedStatement.isNull()) { return source; } final ControlFlowNode bodyStart = createStartNode(embeddedStatement); if (source != null) { connect(source, bodyStart); } return embeddedStatement.acceptVisitor(this, bodyStart); }
public final Statement toStatement() { return Statement.forPattern(this); }
assert CollectionUtilities.contains(targetStatement.getAncestors(), parent); for (final AstNode block : targetStatement.getAncestors()) { if (block == parent) { break;
outputStatus = cleanSpecialValues(node.getNextStatement().acceptVisitor(visitor, inputStatus)); node.getNextStatement() instanceof ForStatement; final Expression condition = node.getNextStatement().getChildByRole(Roles.CONDITION); outputStatus = inputStatus; if (node.getPreviousStatement().getRole() == TryCatchStatement.FINALLY_BLOCK_ROLE && (outputStatus == DefiniteAssignmentStatus.DEFINITELY_ASSIGNED || outputStatus == DefiniteAssignmentStatus.POTENTIALLY_ASSIGNED)) { final TryCatchStatement tryFinally = (TryCatchStatement) node.getPreviousStatement().getParent();
constructor == null || constructor.getParent() == null || parentStatement.getNextStatement() == null) { final BlockStatement initializerBody = new BlockStatement(); for (Statement current = parentStatement.getNextStatement(); current != null; ) { final Statement next = current.getNextStatement(); current.remove(); initializerBody.addChild(current, current.getRole()); current = next;
if (firstStatement != null && !firstStatement.isNull()) { offset = firstStatement.getOffset(); (firstStatement instanceof ExpressionStatement || firstStatement instanceof ReturnStatement)) { final Expression simpleBody = firstStatement.getChildByRole(Roles.EXPRESSION);
if (previous == null || previous.isNull()) { return null; if (next == null || next.isNull()) { return null; next = next.getNextStatement(); if (next == null || next.isNull()) { return null; previous.remove();
final BlockStatement block = (BlockStatement) v.getInsertionPoint().getParent(); while (insertionPoint.getPreviousSibling() instanceof LabelStatement) { insertionPoint = (Statement) insertionPoint.getPreviousSibling();
@Override public DefiniteAssignmentStatus visitLabeledStatement(final LabeledStatement node, final DefiniteAssignmentStatus data) { return node.getStatement().acceptVisitor(this, data); }
@Override public Void visitLabelStatement(final LabelStatement node, final Void data) { super.visitLabelStatement(node, data); final Statement next = node.getNextStatement(); if (next == null) { return null; } if (next instanceof LabelStatement || next instanceof LabeledStatement) { // // We have back-to-back labels; dump the first and redirect its references to the second. // final String nextLabel = next.getChildByRole(Roles.LABEL).getName(); redirectLabels(node.getParent(), node.getLabel(), nextLabel); node.remove(); } else { // // Replace LabelStatement with LabeledStatement. // next.remove(); node.replaceWith( new LabeledStatement( node.getLabel(), AstNode.isLoop(next) ? next : new BlockStatement(next) ) ); } return null; }
: edge.getTo().getNextStatement(); if (gotoStatement.getParent() == targetStatement.getParent()) { continue; for (final AstNode ancestor : targetStatement.getAncestors()) { if (ancestor instanceof TryCatchStatement) { targetParentTryCatch.add((TryCatchStatement) ancestor); for (AstNode node = gotoStatement.getParent(); node != null; node = node.getParent()) { if (node instanceof TryCatchStatement) { final TryCatchStatement leftTryCatch = (TryCatchStatement) node;
final Statement loop = newBlock.getStatements().firstOrNullObject(); loop.remove(); insertedStatement.getAncestors(), new Predicate<AstNode>() { @Override
public final Statement getNextStatement() { AstNode next = getNextSibling(); while (next != null && !(next instanceof Statement)) { next = next.getNextSibling(); } return (Statement) next; }
public LabeledStatement(final String name, final Statement statement) { this( statement.getOffset()); setLabel(name); setStatement(statement); }
private static boolean canMoveLocalTypeIntoSubBlock( final Statement statement, final TypeReference localType, final boolean allowPassIntoLoops) { if (!allowPassIntoLoops && AstNode.isLoop(statement)) { return false; } // // We can move the local class into a sub-block only if the local class is used only in that // sub-block (and not in expressions such as the loop condition). // for (AstNode child = statement.getFirstChild(); child != null; child = child.getNextSibling()) { if (!(child instanceof BlockStatement) && referencesType(child, localType)) { if (hasNestedBlocks(child)) { // // Loops, catch clauses, switch sections, and labeled statements can contain nested blocks. // for (AstNode grandChild = child.getFirstChild(); grandChild != null; grandChild = grandChild.getNextSibling()) { if (!(grandChild instanceof BlockStatement) && referencesType(grandChild, localType)) { return false; } } } else { return false; } } } return true; }
constructor == null || constructor.getParent() == null || parentStatement.getNextStatement() == null) { for (Statement current = parentStatement.getNextStatement(); current instanceof ExpressionStatement; ) { final Statement next = current.getNextStatement(); final Expression expression = ((ExpressionStatement) current).getExpression(); final Match match = FIELD_ASSIGNMENT.match(expression);
for (final AstNode child : statement.getChildren()) { if (child instanceof BlockStatement) { if (declareTypeInBlock((BlockStatement) child, type, allowPassIntoLoops, typesToDeclare)) {
public void run(final AstNode root) { if (!(root instanceof MethodDeclaration)) { throw new IllegalArgumentException("InliningVisitor must be run against a MethodDeclaration."); } final MethodDeclaration clone = (MethodDeclaration) root.clone(); super.run(clone); final BlockStatement body = clone.getBody(); final AstNodeCollection<Statement> statements = body.getStatements(); if (statements.size() == 1) { final Statement firstStatement = statements.firstOrNullObject(); if (firstStatement instanceof ExpressionStatement || firstStatement instanceof ReturnStatement) { _result = firstStatement.getChildByRole(Roles.EXPRESSION); _result.remove(); return; } } _result = body; _result.remove(); }
outputStatus = cleanSpecialValues(node.getNextStatement().acceptVisitor(visitor, inputStatus)); node.getNextStatement() instanceof ForStatement; final Expression condition = node.getNextStatement().getChildByRole(Roles.CONDITION); outputStatus = inputStatus; if (node.getPreviousStatement().getRole() == TryCatchStatement.FINALLY_BLOCK_ROLE && (outputStatus == DefiniteAssignmentStatus.DEFINITELY_ASSIGNED || outputStatus == DefiniteAssignmentStatus.POTENTIALLY_ASSIGNED)) { final TryCatchStatement tryFinally = (TryCatchStatement) node.getPreviousStatement().getParent();