@Override public void visitToken(DetailAST ast) { final DetailAST parent = ast.getParent(); if (parent.getType() == TokenTypes.SLIST && (!allowInSwitchCase || parent.getNumberOfChildren() != 1)) { log(ast, MSG_KEY_BLOCK_NESTED); } }
/** * Gets all METHOD_CALL nodes which are below on the current parent * METHOD_DEF or CTOR_DEF node. * * @param parentAST * The current parent METHOD_DEF or CTOR_DEF node. * @return List contains all METHOD_CALL nodes which are below on the * current parent node. */ private List<DetailAST> getMethodCallsList(final DetailAST parentAST) { final List<DetailAST> result = new LinkedList<>(); for (DetailAST curNode : getChildren(parentAST)) { if (curNode.getNumberOfChildren() > 0) { if (curNode.getType() == TokenTypes.METHOD_CALL) { result.add(curNode); } else { result.addAll(getMethodCallsList(curNode)); } } } return result; }
@Override public void visitToken(DetailAST ast) { final DetailAST parent = ast.getParent(); if (parent.getType() == TokenTypes.SLIST && (!allowInSwitchCase || parent.getNumberOfChildren() != 1)) { log(ast, MSG_KEY_BLOCK_NESTED); } }
/** * Gets all the children one level below on the current top node. * @param node - current parent node. * @return an array of childs one level below * on the current parent node aNode. */ private static DetailAST[] getChilds(DetailAST node) { final DetailAST[] result = new DetailAST[node.getChildCount()]; DetailAST currNode = node.getFirstChild(); for (int i = 0; i < node.getNumberOfChildren(); i++) { result[i] = currNode; currNode = currNode.getNextSibling(); } return result; }
/** * Checks is the current expression has * keywords "true" or "false". * @param parentAST - the current TokenTypes.EXPR parent node. * @return true if the current processed expression contains * "true" or "false" keywords and false otherwise. */ public final boolean hasTrueOrFalseLiteral(final DetailAST parentAST) { for (DetailAST currentNode : getChildren(parentAST)) { if (currentNode.getNumberOfChildren() > 0) { hasTrueOrFalseLiteral(currentNode); } final int type = currentNode.getType(); if (type == TokenTypes.LITERAL_TRUE || type == TokenTypes.LITERAL_FALSE) { hasTrueOrFalseLiteral = true; } if (hasTrueOrFalseLiteral) { break; } } return hasTrueOrFalseLiteral; }
/** * Recursive method which searches for the <code>LITERAL_THROW</code> * DetailASTs all levels below on the current <code>aParentAST</code> node * without entering into nested try/catch blocks. * @param parentAST A start node for "throw" keyword <code>DetailASTs * </code> searching. * @return null-safe list of <code>LITERAL_THROW</code> literals */ private List<DetailAST> makeThrowList(DetailAST parentAST) { final List<DetailAST> throwList = new LinkedList<>(); for (DetailAST currentNode : getChildNodes(parentAST)) { if (currentNode.getType() == TokenTypes.LITERAL_THROW) { throwList.add(currentNode); } if (currentNode.getType() != TokenTypes.PARAMETER_DEF && currentNode.getType() != TokenTypes.LITERAL_THROW && currentNode.getType() != TokenTypes.LITERAL_TRY && currentNode.getNumberOfChildren() > 0) { throwList.addAll(makeThrowList(currentNode)); } } return throwList; }
/** * Returns a List of<code>DetailAST</code> that contains the names of * parameters for current "throw" keyword. * @param startNode The start node for exception name searching. * @param paramNamesAST The list, that will be contain names of the * parameters * @return A null-safe list of tokens (<code>DetailAST</code>) contains the * thrown exception name if it was found or null otherwise. */ private List<DetailAST> buildThrowParamNamesList(DetailAST startNode, List<DetailAST> paramNamesAST) { for (DetailAST currentNode : getChildNodes(startNode)) { if (currentNode.getType() == TokenTypes.IDENT) { paramNamesAST.add(currentNode); } if (currentNode.getType() != TokenTypes.PARAMETER_DEF && currentNode.getType() != TokenTypes.LITERAL_TRY && currentNode.getNumberOfChildren() > 0) { buildThrowParamNamesList(currentNode, paramNamesAST); } } return paramNamesAST; }
if (curNode.getNumberOfChildren() > 0) { if (curNode.getType() == TokenTypes.METHOD_DEF) { final String curMethodName = curNode.findFirstToken(
/** * Looking for the keyword "throw" among current (aParentAST) node childs. * @param parentAST - the current parent node. * @return null if the "throw" keyword was not found * or the LITERAL_THROW DetailAST otherwise */ public DetailAST getThrowAST(DetailAST parentAST) { DetailAST result = null; final DetailAST[] asts = getChilds(parentAST); for (DetailAST currentNode : asts) { if (currentNode.getType() != TokenTypes.PARAMETER_DEF && currentNode.getNumberOfChildren() > 0) { result = getThrowAST(currentNode); } if (currentNode.getType() == TokenTypes.LITERAL_THROW) { result = currentNode; } if (result != null) { break; } } return result; }
/** Searches for all supported operands names in current expression. * When checking, treatments to external class variables, method calls, * etc are not considered as expression operands. * @param exprParentAST - the current TokenTypes.EXPR parent node. * @return List of supported operands contained in current expression. */ public final List<String> getSupportedOperandsNames( final DetailAST exprParentAST) { for (DetailAST currentNode : getChildren(exprParentAST)) { if (currentNode.getNumberOfChildren() > 0 && currentNode.getType() != TokenTypes.METHOD_CALL) { getSupportedOperandsNames(currentNode); } if (currentNode.getType() == TokenTypes.IDENT && currentNode.getParent().getType() != TokenTypes.DOT) { supportedOperands.add(currentNode.getText()); } } return supportedOperands; }
&& currentNode.getNumberOfChildren() > 0) { wrapExcNames.addAll(makeExceptionsList(currentCatchAST, currentNode, currentExcName));