/** * Returns whether the variable is mentioned within the statement or not. */ private static boolean hasReferencesIn(ASTBlockStatement block, String varName) { // allow for closures on the var for (ASTName name : block.findDescendantsOfType(ASTName.class, true)) { if (isReference(varName, name.getImage())) { return true; } } return false; }
ASTName name = st.getFirstDescendantOfType(ASTName.class); if (name != null && st.equals(name.getNthParent(5)) && "fail".equals(name.getImage())) { found.add(name); continue; ASTThrowStatement th = st.getFirstDescendantOfType(ASTThrowStatement.class); if (th != null && st.equals(th.getNthParent(2))) { found.add(th);
/** * Returns whether the block contains a return call or throws an exception. * Exclude blocks that have these things as part of an inner class. */ private boolean hasExit(ASTBlockStatement block) { return block.hasDescendantOfAnyType(ASTThrowStatement.class, ASTReturnStatement.class); }
private boolean statementsBeforeReturn(VariableNameDeclaration variableDeclaration, ASTReturnStatement returnStatement) { if (!getProperty(STATEMENT_ORDER_MATTERS)) { return false; } ASTBlockStatement declarationStatement = variableDeclaration.getAccessNodeParent().getFirstParentOfType(ASTBlockStatement.class); ASTBlockStatement returnBlockStatement = returnStatement.getFirstParentOfType(ASTBlockStatement.class); // double check: we should now be at the same level in the AST - both block statements are children of the same parent if (declarationStatement.jjtGetParent() == returnBlockStatement.jjtGetParent()) { return returnBlockStatement.jjtGetChildIndex() - declarationStatement.jjtGetChildIndex() > 1; } return false; }
final public void BlockStatement() throws ParseException { ASTBlockStatement jjtn000 = new ASTBlockStatement(this, JJTBLOCKSTATEMENT); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { if (isNextTokenAnAssert()) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
if (!astBlockStatements.isEmpty()) { for (ASTBlockStatement blockStatement : astBlockStatements) { if (blockStatement.hasDescendantOfType(ASTLocalVariableDeclaration.class)) { List<ASTLocalVariableDeclaration> lVarList = blockStatement .findDescendantsOfType(ASTLocalVariableDeclaration.class); if (!lVarList.isEmpty()) { for (ASTLocalVariableDeclaration localVar : lVarList) {
final String varName = vid.getImage(); for (ASTBlockStatement b : bs) { if (b.hasDescendantOfType(ASTAssignmentOperator.class)) { final ASTStatementExpression se = b.getFirstDescendantOfType(ASTStatementExpression.class); if (se == null || !(se.jjtGetChild(0) instanceof ASTPrimaryExpression)) { continue;
if (!hasNullInitializer(var) && parentBlock.jjtGetParent() == tryBlock.jjtGetParent()) { List<ASTBlockStatement> blocks = parentBlock.jjtGetParent().findChildrenOfType(ASTBlockStatement.class); int parentBlockIndex = blocks.indexOf(parentBlock); int tryBlockIndex = blocks.indexOf(tryBlock); .getFirstDescendantOfType(ASTLocalVariableDeclaration.class); if (varDecl == null) { criticalStatements = true;
/** * Tells if this BlockStatement is an allocation statement. This is done by * * @return the result of * containsDescendantOfType(ASTAllocationExpression.class) */ public final boolean isAllocation() { return hasDescendantOfType(ASTAllocationExpression.class); } }
if (bs.isAllocation()) { for (Iterator<ASTName> iterator = nameNodes.iterator(); iterator.hasNext();) { ASTName name = iterator.next();
private String getVariableAppended(ASTBlockStatement node) { if (isFirstChild(node, ASTStatement.class)) { ASTStatement statement = (ASTStatement) node.jjtGetChild(0); if (isFirstChild(statement, ASTStatementExpression.class)) { ASTStatementExpression stmtExp = (ASTStatementExpression) statement.jjtGetChild(0); ASTLocalVariableDeclaration lvd = (ASTLocalVariableDeclaration) node.jjtGetChild(0);
private boolean isAddShutdownHook(ASTAllocationExpression node) { ASTBlockStatement blockStatement = node.getFirstParentOfType(ASTBlockStatement.class); if (blockStatement == null) { return false; } Token token = (Token)blockStatement.jjtGetFirstToken(); return Runtime.class.getSimpleName().equals(token.image); }
final public void BlockStatement() throws ParseException { ASTBlockStatement jjtn000 = new ASTBlockStatement(this, JJTBLOCKSTATEMENT); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { if (isNextTokenAnAssert()) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
/** * Check if the given node is the first statement in the block. */ private boolean isFirstStatementInBlock(Node node, ASTStatement loopBody) { // find the statement of the operation and the loop body block statement final ASTBlockStatement statement = node.getFirstParentOfType(ASTBlockStatement.class); final ASTBlock block = loopBody.getFirstDescendantOfType(ASTBlock.class); if (statement == null || block == null) { return false; } // is the first statement in the loop body? return block.equals(statement.jjtGetParent()) && statement.jjtGetChildIndex() == 0; }
if (!astBlockStatements.isEmpty()) { for (ASTBlockStatement blockStatement : astBlockStatements) { if (blockStatement.hasDescendantOfType(ASTLocalVariableDeclaration.class)) { List<ASTLocalVariableDeclaration> lVarList = blockStatement .findDescendantsOfType(ASTLocalVariableDeclaration.class); if (!lVarList.isEmpty()) { for (ASTLocalVariableDeclaration localVar : lVarList) {
final String varName = vid.getImage(); for (ASTBlockStatement b : bs) { if (b.hasDescendantOfType(ASTAssignmentOperator.class)) { final ASTStatementExpression se = b.getFirstDescendantOfType(ASTStatementExpression.class); if (se == null || !(se.jjtGetChild(0) instanceof ASTPrimaryExpression)) { continue;
if (!hasNullInitializer(var) && parentBlock.jjtGetParent() == tryBlock.jjtGetParent()) { List<ASTBlockStatement> blocks = parentBlock.jjtGetParent().findChildrenOfType(ASTBlockStatement.class); int parentBlockIndex = blocks.indexOf(parentBlock); int tryBlockIndex = blocks.indexOf(tryBlock); .getFirstDescendantOfType(ASTLocalVariableDeclaration.class); if (varDecl == null) { criticalStatements = true;
/** * Tells if this BlockStatement is an allocation statement. This is done by * * @return the result of * containsDescendantOfType(ASTAllocationExpression.class) */ public final boolean isAllocation() { return hasDescendantOfType(ASTAllocationExpression.class); } }
if (bs.isAllocation()) { for (Iterator<ASTName> iterator = nameNodes.iterator(); iterator.hasNext();) { ASTName name = iterator.next();
private String getVariableAppended(ASTBlockStatement node) { if (isFirstChild(node, ASTStatement.class)) { ASTStatement statement = (ASTStatement) node.jjtGetChild(0); if (isFirstChild(statement, ASTStatementExpression.class)) { ASTStatementExpression stmtExp = (ASTStatementExpression) statement.jjtGetChild(0); ASTLocalVariableDeclaration lvd = (ASTLocalVariableDeclaration) node.jjtGetChild(0);