protected void addDefaultConstructor(ClassNode node) { if (!node.getDeclaredConstructors().isEmpty()) return; BlockStatement empty = new BlockStatement(); empty.setSourcePosition(node); ConstructorNode constructor = new ConstructorNode(ACC_PUBLIC, empty); constructor.setSourcePosition(node); constructor.setHasNoRealSourcePosition(true); node.addConstructor(constructor); }
newBlock.setSourcePosition(block); constructorNode.setCode(newBlock);
newBlock.setSourcePosition(block); return newBlock; newBlock.setSourcePosition(statement); return newBlock;
public void visitMethod(MethodNode node) { Statement statement = node.getCode(); if (!node.isVoidMethod()) { if (statement != null) // it happens with @interface methods { final Statement code = addReturnsIfNeeded(statement, node.getVariableScope()); if (doAdd) node.setCode(code); } } else if (!node.isAbstract() && node.getReturnType().redirect()!=ClassHelper.VOID_TYPE) { if (!(statement instanceof BytecodeSequence)) { BlockStatement newBlock = new BlockStatement(); Statement code = node.getCode(); if (code instanceof BlockStatement) { newBlock.setVariableScope(((BlockStatement) code).getVariableScope()); } if (statement instanceof BlockStatement) { newBlock.addStatements(((BlockStatement)statement).getStatements()); } else { newBlock.addStatement(statement); } final ReturnStatement returnStatement = ReturnStatement.RETURN_NULL_OR_VOID; listener.returnStatementAdded(returnStatement); newBlock.addStatement(returnStatement); newBlock.setSourcePosition(statement); if (doAdd) node.setCode(newBlock); } } }
protected void addDefaultConstructor(ClassNode node) { if (!node.getDeclaredConstructors().isEmpty()) return; BlockStatement empty = new BlockStatement(); empty.setSourcePosition(node); ConstructorNode constructor = new ConstructorNode(ACC_PUBLIC, empty); constructor.setSourcePosition(node); constructor.setHasNoRealSourcePosition(true); node.addConstructor(constructor); }
newBlock.setSourcePosition(block); constructorNode.setCode(newBlock);
newBlock.setSourcePosition(block); constructorNode.setCode(newBlock);
newBlock.setSourcePosition(block); constructorNode.setCode(newBlock);
@Override public void visitBlockStatement(BlockStatement block) { blockStatement = block; blockStatementCopy = new BlockStatement(new ArrayList<Statement>(blockStatement.getStatements()), blockStatement.getVariableScope()); blockStatementCopy.copyNodeMetaData(blockStatement); blockStatementCopy.setSourcePosition(blockStatement); for (Statement statement : blockStatementCopy.getStatements()) { if (statement == returnStatement) { blockStatement.getStatements().remove(statement); blockStatement.addStatements(assertionCallStatement.getStatements()); VariableExpression variableExpression = new VariableExpression("result", returnType); variableExpression.setAccessedVariable(variableExpression); blockStatement.addStatement(new ReturnStatement(variableExpression)); return; // we found the return statement under target, let's cancel tree traversal } } super.visitBlockStatement(blockStatement); } }
newBlock.setSourcePosition(block); constructorNode.setCode(newBlock);
@Override public void visitBlockStatement(BlockStatement block) { blockStatement = block; blockStatementCopy = new BlockStatement(new ArrayList<Statement>(blockStatement.getStatements()), blockStatement.getVariableScope()); blockStatementCopy.copyNodeMetaData(blockStatement); blockStatementCopy.setSourcePosition(blockStatement); for (Statement statement : blockStatementCopy.getStatements()) { if (statement == returnStatement) { blockStatement.getStatements().remove(statement); final VariableExpression $_gc_result = new VariableExpression("$_gc_result", ClassHelper.DYNAMIC_TYPE); $_gc_result.setAccessedVariable($_gc_result); blockStatement.addStatement(new ExpressionStatement( new DeclarationExpression($_gc_result, Token.newSymbol(Types.ASSIGN, -1, -1), returnStatement.getExpression()) )); blockStatement.addStatement(assertionCallStatement); ReturnStatement gcResultReturn = new ReturnStatement($_gc_result); gcResultReturn.setSourcePosition(returnStatement); blockStatement.addStatement(gcResultReturn); return; // we found the return statement under target, let's cancel tree traversal } } super.visitBlockStatement(blockStatement); } }
newBlock.setSourcePosition(statement); node.setCode(newBlock);
newBlock.setSourcePosition(block); return newBlock; newBlock.setSourcePosition(statement); return newBlock;
private void addReturnIfNeeded(MethodNode node) { Statement statement = node.getCode(); if (!node.isVoidMethod()) { if (statement != null) // it happens with @interface methods node.setCode(addReturnsIfNeeded(statement, node.getVariableScope())); } else if (!node.isAbstract()) { if (!(statement instanceof BytecodeSequence)) { BlockStatement newBlock = new BlockStatement(); if (statement instanceof BlockStatement) { newBlock.addStatements(((BlockStatement)statement).getStatements()); } else { newBlock.addStatement(statement); } newBlock.addStatement(ReturnStatement.RETURN_NULL_OR_VOID); newBlock.setSourcePosition(statement); node.setCode(newBlock); } } }
); newClosureBlockStatement.setSourcePosition(closureBlockStatement);
protected void addReturnIfNeeded(MethodNode node) { Statement statement = node.getCode(); if (!node.isVoidMethod()) { if (statement != null) // it happens with @interface methods node.setCode(addReturnsIfNeeded(statement, node.getVariableScope())); } else if (!node.isAbstract()) { if (!(statement instanceof BytecodeSequence)) { BlockStatement newBlock = new BlockStatement(); newBlock.setVariableScope(node.getVariableScope()); if (statement instanceof BlockStatement) { newBlock.addStatements(((BlockStatement)statement).getStatements()); } else { newBlock.addStatement(statement); } newBlock.addStatement(ReturnStatement.RETURN_NULL_OR_VOID); newBlock.setSourcePosition(statement); node.setCode(newBlock); } } }
public static void addReturnIfNeeded(MethodNode node) { Statement statement = node.getCode(); if (!node.isVoidMethod()) { if (statement != null) // it happens with @interface methods node.setCode(addReturnsIfNeeded(statement, node.getVariableScope())); } else if (!node.isAbstract() && node.getReturnType().redirect()!=ClassHelper.VOID_TYPE) { if (!(statement instanceof BytecodeSequence)) { BlockStatement newBlock = new BlockStatement(); Statement code = node.getCode(); if (code instanceof BlockStatement) { newBlock.setVariableScope(((BlockStatement) code).getVariableScope()); } if (statement instanceof BlockStatement) { newBlock.addStatements(((BlockStatement)statement).getStatements()); } else { newBlock.addStatement(statement); } newBlock.addStatement(ReturnStatement.RETURN_NULL_OR_VOID); newBlock.setSourcePosition(statement); node.setCode(newBlock); } } }
); newClosureBlockStatement.setSourcePosition(closureBlockStatement);