public static BlockStatement block(VariableScope varScope, List<Statement> stmts) { BlockStatement block = new BlockStatement(); block.setVariableScope(varScope); for (Statement stmt : stmts) block.addStatement(stmt); return block; }
public static BlockStatement block(VariableScope varScope, Statement... stmts) { BlockStatement block = new BlockStatement(); block.setVariableScope(varScope); for (Statement stmt : stmts) block.addStatement(stmt); return block; }
public void visitBlockStatement(BlockStatement block) { pushState(); block.setVariableScope(currentScope); super.visitBlockStatement(block); popState(); }
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); } } }
public void visitBlockStatement(BlockStatement block) { pushState(); block.setVariableScope(currentScope); super.visitBlockStatement(block); popState(); }
public void visitBlockStatement(BlockStatement block) { pushState(); block.setVariableScope(currentScope); super.visitBlockStatement(block); popState(); }
public void visitBlockStatement(BlockStatement block) { pushState(); block.setVariableScope(currentScope); super.visitBlockStatement(block); popState(); }
public void visitBlockStatement(BlockStatement block) { pushState(); block.setVariableScope(currentScope); super.visitBlockStatement(block); popState(); }
@Override public void visitMethodCallExpression(MethodCallExpression call) { super.visitMethodCallExpression(call); if (DOLLAR_VALUE.equals(call.getMethodAsString())) { ClosureExpression substitutionClosureExpression = getClosureArgument(source, call); if (substitutionClosureExpression == null) { return; } Statement code = substitutionClosureExpression.getCode(); if (code instanceof BlockStatement) { ((BlockStatement) code).setVariableScope(null); } listExpression.addExpression(substitutionClosureExpression); } } };
public void transformClosureExpression(ClassNode classNode, ClosureExpression closureExpression) { if (closureExpression.getNodeMetaData(TRANSFORMED_MARKER) != null) return; ClassNode previousClassNode = this.currentClassNode; try { this.currentClassNode = classNode; List<String> propertyNames = AstPropertyResolveUtils.getPropertyNames(classNode); Statement code = closureExpression.getCode(); BlockStatement newCode = new BlockStatement(); boolean addAll = false; if (code instanceof BlockStatement) { BlockStatement bs = (BlockStatement) code; addBlockStatementToNewQuery(bs, newCode, addAll, propertyNames, closureExpression.getVariableScope()); newCode.setVariableScope(bs.getVariableScope()); } if (!newCode.getStatements().isEmpty()) { closureExpression.putNodeMetaData(TRANSFORMED_MARKER, Boolean.TRUE); closureExpression.setCode(newCode); } } finally { this.currentClassNode = previousClassNode; } }
private static Statement wrapStatements(Statement code, String threadingMethod) { // TODO deal with non-block statements if (!(code instanceof BlockStatement)) { return code; } BlockStatement codeBlock = (BlockStatement) code; List<Statement> statements = codeBlock.getStatements(); if (statements.isEmpty()) { return code; } VariableScope variableScope = codeBlock.getVariableScope(); BlockStatement block = new BlockStatement(); VariableScope blockScope = variableScope.copy(); makeVariablesShared(blockScope); block.setVariableScope(blockScope); ClosureExpression closure = new ClosureExpression(Parameter.EMPTY_ARRAY, code); VariableScope closureScope = variableScope.copy(); makeVariablesShared(closureScope); closure.setVariableScope(closureScope); block.addStatement(stmnt(new MethodCallExpression(THIS, threadingMethod, args(closure)))); return block; }
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); } } }
constructorStatements ); constructorStatements.setVariableScope(constructorNode.getVariableScope());