private BlockStatement transformBlock(final Block block) { final BlockStatement astBlock = new BlockStatement(); if (block != null) { final List<Node> children = block.getChildren(); for (int i = 0; i < children.size(); i++) { final Node node = children.get(i); final Statement statement = transformNode( node, i < children.size() - 1 ? children.get(i + 1) : null ); astBlock.getStatements().add(statement); if (statement instanceof SynchronizedStatement) { i++; } } } return astBlock; }
public final void add(final Statement statement) { addChild(statement, STATEMENT_ROLE); }
public final BlockStatement toBlockStatement() { return BlockStatement.forPattern(this); }
final Statement secondStatement = getOrDefault(loopBody.getStatements(), 1); final BlockStatement body = new BlockStatement(); final BlockStatement parent = (BlockStatement) loop.getParent(); parent.getStatements().insertBefore(loop, forEach); body.add(loop); loop.remove(); body.add(loop); final AstNodeCollection<Statement> bodyStatements = body.getStatements(); final BlockStatement tempOuter = new BlockStatement(); final BlockStatement temp = new BlockStatement(); parent.insertChildBefore(forEach, tempOuter, BlockStatement.STATEMENT_ROLE); previous.remove(); forEach.remove(); temp.add(previous); temp.add(forEach); tempOuter.add(temp); parent.insertChildBefore(tempOuter, previous, BlockStatement.STATEMENT_ROLE); parent.insertChildBefore(tempOuter, forEach, BlockStatement.STATEMENT_ROLE); tempOuter.remove(); if (body.getStatements().isEmpty()) {
final SwitchSection fallThroughSection = (SwitchSection) fallThroughBlock.getParent(); label.remove(); if (fallThroughBlock.getStatements().isEmpty()) { fallThroughBlock.remove(); if (parentBlock.getStatements().isEmpty()) { parentBlock.remove(); final BlockStatement newBlock = new BlockStatement(); final AstNodeCollection<Statement> blockStatements = newBlock.getStatements(); if (!AstNode.isUnconditionalBranch(lastOrDefault(newBlock.getStatements()))) { newBlock.getStatements().add(new BreakStatement(Expression.MYSTERY_OFFSET)); if (newBlock.getStatements().hasSingleElement() && AstNode.isLoop(newBlock.getStatements().firstOrNullObject())) { final Statement loop = newBlock.getStatements().firstOrNullObject(); if (parent.getParent() instanceof LabelStatement) { AstNode insertionPoint = parent; parent.insertChildBefore(insertBefore, insertedStatement, BlockStatement.STATEMENT_ROLE); parent.insertChildAfter(insertAfter, insertedStatement, BlockStatement.STATEMENT_ROLE); parent.getStatements().add(insertedStatement);
final AstNodeCollection<Statement> statements = node.getBody().getStatements(); final Statement firstStatement = statements.firstOrNullObject(); final BlockStatement initializerBody = new BlockStatement(); initializerBody.add(statement);
final BlockStatement body = (BlockStatement) declaration.getBody().clone(); final AstNodeCollection<ParameterDeclaration> parameters = declaration.getParameters(); final Map<String, IdentifierExpression> renamedVariables = new HashMap<>(); final AstNodeCollection<Expression> closureArguments = methodGroup.getClosureArguments(); final Statement firstStatement = body.getStatements().firstOrNullObject(); body.acceptVisitor( new ContextTrackingVisitor<Void>(context) { @Override body.remove(); if (body.getStatements().size() == 1 && (firstStatement instanceof ExpressionStatement || firstStatement instanceof ReturnStatement)) {
final BlockStatement block = new BlockStatement(); block.addChild(new Comment(" ", CommentType.SingleLine), Roles.COMMENT); block.addChild(new Comment(" This method could not be decompiled.", CommentType.SingleLine), Roles.COMMENT); block.addChild(new Comment(" ", CommentType.SingleLine), Roles.COMMENT); block.addChild(new Comment(" Original Bytecode:", CommentType.SingleLine), Roles.COMMENT); block.addChild(new Comment(" ", CommentType.SingleLine), Roles.COMMENT); block.addChild(new Comment(line.replace("\t", " "), CommentType.SingleLine), Roles.COMMENT); block.addChild(new Comment(" ", CommentType.SingleLine), Roles.COMMENT); block.addChild(new Comment(" Could not show original bytecode, likely due to the same error.", CommentType.SingleLine), Roles.COMMENT); block.addChild(new Comment(" ", CommentType.SingleLine), Roles.COMMENT); block.addChild(new Comment(" The error that occurred was:", CommentType.SingleLine), Roles.COMMENT); block.addChild(new Comment(" ", CommentType.SingleLine), Roles.COMMENT); block.addChild(new Comment(" " + line.replace("\t", " "), CommentType.SingleLine), Roles.COMMENT); block.addChild(new Comment(" ", CommentType.SingleLine), Roles.COMMENT); block.add( new ThrowStatement( new ObjectCreationExpression( block.add(new EmptyStatement());
private Statement canInlineInitializerDeclarations(final ForStatement forLoop) { TypeReference variableType = null; final BlockStatement tempOuter = new BlockStatement(); final BlockStatement temp = new BlockStatement(); final Statement[] initializers = forLoop.getInitializers().toArray(new Statement[forLoop.getInitializers().size()]); final Set<String> variableNames = new HashSet<>(); temp.getStatements().add(initializer); temp.getStatements().add(forLoop); tempOuter.getStatements().add(temp); tempOuter.replaceWith(forLoop);
node.getTryBlock().acceptVisitor(this, ignored); if (!node.getFinallyBlock().isNull()) { writeKeyword(TryCatchStatement.FINALLY_KEYWORD_ROLE); node.getFinallyBlock().acceptVisitor(this, ignored);
final BlockStatement initializerBody = new BlockStatement(); initializerBody.addChild(current, current.getRole()); current = next;
final AstNode parent = node.getParent(); final Iterable<AstNode> children = node.getChildren();
method.getBody().insertChildBefore( method.getBody().getFirstChild(), new LocalTypeDeclarationStatement(Expression.MYSTERY_OFFSET, firstUndeclared), BlockStatement.STATEMENT_ROLE block.insertChildBefore( insertionPoint, new LocalTypeDeclarationStatement(Expression.MYSTERY_OFFSET, v.getDeclaration()),
private SynchronizedStatement transformSynchronized(final com.strobel.decompiler.ast.Expression expression, final TryCatchBlock tryCatch) { final SynchronizedStatement s = new SynchronizedStatement( expression.getOffset()); s.setExpression((Expression) transformExpression(expression.getArguments().get(0), false)); if (tryCatch.getCatchBlocks().isEmpty()) { s.setEmbeddedStatement(transformBlock(tryCatch.getTryBlock())); } else { tryCatch.setFinallyBlock(null); s.setEmbeddedStatement(new BlockStatement(transformNode(tryCatch, null))); } return s; }
public final JavaTokenNode getLeftBraceToken() { return getChildByRole(Roles.LEFT_BRACE); }
public final AstNodeCollection<Statement> getStatements() { return getChildrenByRole(STATEMENT_ROLE); }
@Override public Void visitCatchClause(final CatchClause node, final Void ignored) { startNode(node); writeKeyword(CatchClause.CATCH_KEYWORD_ROLE); if (!node.getExceptionTypes().isEmpty()) { space(policy.SpaceBeforeCatchParentheses); leftParenthesis(); space(policy.SpacesWithinCatchParentheses); writePipeSeparatedList(node.getExceptionTypes()); if (!StringUtilities.isNullOrEmpty(node.getVariableName())) { space(); node.getVariableNameToken().acceptVisitor(this, ignored); } space(policy.SpacesWithinCatchParentheses); rightParenthesis(); } node.getBody().acceptVisitor(this, ignored); endNode(node); return null; }
final BlockStatement outerTemp = new BlockStatement(); final BlockStatement temp = new BlockStatement(); temp.add(initializeResource); temp.add(clearCaughtException); temp.add(node); outerTemp.add(temp); outerTemp.replaceWith(node); clearCaughtException.remove(); parent.insertChildBefore(node, initializeResource, BlockStatement.STATEMENT_ROLE); parent.insertChildBefore(node, clearCaughtException, BlockStatement.STATEMENT_ROLE); tryContent.remove(); resource.remove(); resourceInitializer.remove(); ); final Statement firstStatement = firstOrDefault(tryContent.getStatements()); final Statement lastStatement = lastOrDefault(tryContent.getStatements());
final SwitchSection fallThroughSection = (SwitchSection) fallThroughBlock.getParent(); label.remove(); if (fallThroughBlock.getStatements().isEmpty()) { fallThroughBlock.remove(); if (parentBlock.getStatements().isEmpty()) { parentBlock.remove(); final BlockStatement newBlock = new BlockStatement(); final AstNodeCollection<Statement> blockStatements = newBlock.getStatements(); if (!AstNode.isUnconditionalBranch(lastOrDefault(newBlock.getStatements()))) { newBlock.getStatements().add(new BreakStatement(Expression.MYSTERY_OFFSET)); if (newBlock.getStatements().hasSingleElement() && AstNode.isLoop(newBlock.getStatements().firstOrNullObject())) { final Statement loop = newBlock.getStatements().firstOrNullObject(); if (parent.getParent() instanceof LabelStatement) { AstNode insertionPoint = parent; parent.insertChildBefore(insertBefore, insertedStatement, BlockStatement.STATEMENT_ROLE); parent.insertChildAfter(insertAfter, insertedStatement, BlockStatement.STATEMENT_ROLE); parent.getStatements().add(insertedStatement);
final AstNodeCollection<Statement> statements = node.getBody().getStatements(); final Statement firstStatement = statements.firstOrNullObject(); final BlockStatement initializerBody = new BlockStatement(); initializerBody.add(statement);