@SuppressWarnings("unchecked") private static List<Statement> getStatements(BlockStatement blockStat) { return blockStat == null ? Collections.<Statement> emptyList() : blockStat.getStatements(); }
private List<Statement> getStatements(Statement stmt) { if (stmt instanceof BlockStatement) { return ((BlockStatement) stmt).getStatements(); } List<Statement> result = new ArrayList<Statement>(); result.add(stmt); return result; }
public Statement getFirstStatement() { if (code == null) return null; Statement first = code; while (first instanceof BlockStatement) { List<Statement> list = ((BlockStatement) first).getStatements(); if (list.isEmpty()) { first = null; } else { first = list.get(0); } } return first; }
public boolean isEmpty() { return classes.isEmpty() && statementBlock.getStatements().isEmpty(); }
@SuppressWarnings("unchecked") @Override public void visitBlockStatement(BlockStatement stat) { replaceAll(stat.getStatements()); }
@Override @SuppressWarnings("unchecked") public void visitBlockStatement(BlockStatement stat) { replaceAll(stat.getStatements()); }
@SuppressWarnings("unchecked") public static List<Statement> getStatements(ClosureExpression closure) { BlockStatement blockStat = (BlockStatement)closure.getCode(); return blockStat == null ? Collections.<Statement> emptyList() : // it's not possible to add any statements to such a ClosureExpression, so immutable list is OK blockStat.getStatements(); }
public void visitBlockStatement(BlockStatement block) { for (Statement statement : block.getStatements()) { statement.visit(this); } }
/** * @return true if the block's last statement is a return */ private boolean returningBlock(Statement block) { if (block instanceof ReturnStatement) { return true; } if (!(block instanceof BlockStatement)) { return false; } BlockStatement bs = (BlockStatement) block; if (bs.getStatements().size() == 0) { return false; } Statement last = DefaultGroovyMethods.last(bs.getStatements()); if (last instanceof ReturnStatement) { return true; } return false; }
private static ConstructorCallExpression getFirstIfSpecialConstructorCall(BlockStatement code) { if (code == null) return null; final List<Statement> statementList = code.getStatements(); if (statementList.isEmpty()) return null; final Statement statement = statementList.get(0); if (!(statement instanceof ExpressionStatement)) return null; Expression expression = ((ExpressionStatement) statement).getExpression(); if (!(expression instanceof ConstructorCallExpression)) return null; ConstructorCallExpression cce = (ConstructorCallExpression) expression; if (cce.isSpecialCall()) return cce; return null; } }
private static ConstructorCallExpression getConstructorCallExpression(ConstructorNode constructorNode) { Statement code = constructorNode.getCode(); if (!(code instanceof BlockStatement)) return null; BlockStatement block = (BlockStatement) code; List stats = block.getStatements(); if (stats == null || stats.isEmpty()) return null; Statement stat = (Statement) stats.get(0); if (!(stat instanceof ExpressionStatement)) return null; Expression expr = ((ExpressionStatement) stat).getExpression(); if (!(expr instanceof ConstructorCallExpression)) return null; return (ConstructorCallExpression) expr; }
public void visitBlockStatement(final BlockStatement block) { assertStatementAuthorized(block); for (Statement statement : block.getStatements()) { statement.visit(this); } }
protected void staticInit(AST staticInit) { BlockStatement code = (BlockStatement) statementList(staticInit); classNode.addStaticInitializerStatements(code.getStatements(), false); }
private Statement getImplicitThis$0StmtIfInnerClass(List<Statement> otherStatements) { if (!(classNode instanceof InnerClassNode)) return null; for (Statement stmt : otherStatements) { if (stmt instanceof BlockStatement) { List<Statement> stmts = ((BlockStatement) stmt).getStatements(); for (Statement bstmt : stmts) { if (bstmt instanceof ExpressionStatement) { if (extractImplicitThis$0StmtIfInnerClassFromExpression(stmts, bstmt)) return bstmt; } } } else if (stmt instanceof ExpressionStatement) { if (extractImplicitThis$0StmtIfInnerClassFromExpression(otherStatements, stmt)) return stmt; } } return null; }
private static Expression getConstructorCall(Statement code) { if (code==null) return null; if (code instanceof BlockStatement) { BlockStatement bs = (BlockStatement) code; if (bs.isEmpty()) return null; return getConstructorCall(bs.getStatements().get(0)); } if (!(code instanceof ExpressionStatement)) return null; ExpressionStatement es = (ExpressionStatement) code; Expression exp = es.getExpression(); if (!(exp instanceof ConstructorCallExpression)) return null; ConstructorCallExpression cce = (ConstructorCallExpression) exp; if (!cce.isSpecialCall()) return null; return cce; }
public void visit(ASTNode[] nodes, SourceUnit source) { if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) { throw new RuntimeException("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes)); } AnnotationNode annotationNode = (AnnotationNode) nodes[0]; ASTNode node = nodes[1]; if (!(node instanceof MethodNode)) { addError("@NotYetImplemented must only be applied on test methods!",node); return; } MethodNode methodNode = (MethodNode) node; ArrayList<Statement> statements = new ArrayList<Statement>(); Statement statement = methodNode.getCode(); if (statement instanceof BlockStatement) { statements.addAll(((BlockStatement) statement).getStatements()); } if (statements.size() == 0) return; BlockStatement rewrittenMethodCode = new BlockStatement(); rewrittenMethodCode.addStatement(tryCatchAssertionFailedError(annotationNode, methodNode, statements)); rewrittenMethodCode.addStatement(throwAssertionFailedError(annotationNode)); methodNode.setCode(rewrittenMethodCode); }
private void extractModelTypesFromStatement(final Statement code, final Map<String, ClassNode> model) { if (code instanceof BlockStatement) { BlockStatement block = (BlockStatement) code; for (Statement statement : block.getStatements()) { extractModelTypesFromStatement(statement, model); } } else if (code instanceof ExpressionStatement) { Expression expression = ((ExpressionStatement) code).getExpression(); if (expression instanceof DeclarationExpression) { VariableExpression var = ((DeclarationExpression) expression).getVariableExpression(); model.put(var.getName(), var.getOriginType()); } } }
/** * Returns a list of statements of the given method. Modifications to the returned list * will affect the method's statements. * * @param method a method (node) * @return a list of statements of the given method */ @SuppressWarnings("unchecked") public static List<Statement> getStatements(MethodNode method) { Statement code = method.getCode(); if (!(code instanceof BlockStatement)) { // null or single statement BlockStatement block = new BlockStatement(); if (code != null) block.addStatement(code); method.setCode(block); } return ((BlockStatement)method.getCode()).getStatements(); }
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) { for (Object statement : source.getAST().getStatementBlock().getStatements()) ((ExpressionStatement) statement).visit(new CustomCodeVisitorSupport()); } }
public void writeBlockStatement(BlockStatement block) { CompileStack compileStack = controller.getCompileStack(); //GROOVY-4505 use no line number information for the block writeStatementLabel(block); int mark = controller.getOperandStack().getStackLength(); compileStack.pushVariableScope(block.getVariableScope()); for (Statement statement : block.getStatements()) { statement.visit(controller.getAcg()); } compileStack.pop(); // GROOVY-7647 if (block.getLastLineNumber() > 0) { MethodVisitor mv = controller.getMethodVisitor(); Label blockEnd = new Label(); mv.visitLabel(blockEnd); mv.visitLineNumber(block.getLastLineNumber(), blockEnd); } controller.getOperandStack().popDownTo(mark); }