/** * Tests if the given lambda node has a single parameter, no defined type, and is surrounded * by parentheses. * @param ast a {@code DetailAST} whose type is * {@code TokenTypes.LAMBDA}. * @return {@code true} if the lambda has a single parameter, no defined type, and is * surrounded by parentheses. */ private static boolean isLambdaSingleParameterSurrounded(DetailAST ast) { final DetailAST firstChild = ast.getFirstChild(); return firstChild.getType() == TokenTypes.LPAREN && firstChild.getNextSibling().getChildCount(TokenTypes.PARAMETER_DEF) == 1 && firstChild.getNextSibling().getFirstChild().findFirstToken(TokenTypes.TYPE) .getChildCount() == 0; }
/** * Get string representation of the node as token name, * node text, line number and column number. * @param node DetailAST * @return node info */ private static String getNodeInfo(DetailAST node) { return TokenUtil.getTokenName(node.getType()) + " -> " + escapeAllControlChars(node.getText()) + " [" + node.getLineNo() + ':' + node.getColumnNo() + ']'; }
/** * Checks if a variable is the loop's one. * @param variableDef variable definition. * @return true if a variable is the loop's one. */ private static boolean isForLoopVariable(DetailAST variableDef) { final int parentType = variableDef.getParent().getType(); return parentType == TokenTypes.FOR_INIT || parentType == TokenTypes.FOR_EACH_CLAUSE; }
@Override public void initialize(AST ast) { final DetailAST detailAst = (DetailAST) ast; setText(detailAst.getText()); setType(detailAst.getType()); lineNo = detailAst.getLineNo(); columnNo = detailAst.getColumnNo(); hiddenAfter = detailAst.getHiddenAfter(); hiddenBefore = detailAst.getHiddenBefore(); }
/** * Retrieves the first modifier that is not an annotation. * @param modifiers The ast to examine. * @return The first modifier or {@code null} if none found. */ private static DetailAST getFirstModifierAst(DetailAST modifiers) { DetailAST modifier = modifiers.getFirstChild(); while (modifier != null && modifier.getType() == TokenTypes.ANNOTATION) { modifier = modifier.getNextSibling(); } return modifier; }
/** * Check if given parameter definition is a multiple type catch. * @param parameterDefAst parameter definition * @return true if it is a multiple type catch, false otherwise */ private static boolean isMultipleTypeCatch(DetailAST parameterDefAst) { final DetailAST typeAst = parameterDefAst.findFirstToken(TokenTypes.TYPE); return typeAst.getFirstChild().getType() == TokenTypes.BOR; }
@Override public void visitToken(DetailAST arrayInit) { final DetailAST rcurly = arrayInit.findFirstToken(TokenTypes.RCURLY); final DetailAST previousSibling = rcurly.getPreviousSibling(); if (arrayInit.getLineNo() != rcurly.getLineNo() && arrayInit.getChildCount() != 1 && rcurly.getLineNo() != previousSibling.getLineNo() && arrayInit.getLineNo() != previousSibling.getLineNo() && previousSibling.getType() != TokenTypes.COMMA) { log(rcurly.getLineNo(), MSG_KEY); } }
@Override public boolean isValidOn(final DetailAST ast) { final int astType = ast.getType(); final DetailAST varType = ast.findFirstToken(TokenTypes.TYPE); return astType == TokenTypes.VARIABLE_DEF && varType.getFirstChild().getType() == TokenTypes.ARRAY_DECLARATOR && "ObjectStreamField".equals(varType.getFirstChild().getText()); }
private void forEachChild(DetailAST root) { for (DetailAST ast = root; ast != null; ast = ast.getNextSibling()) { if (ast.getType() == TokenTypes.SINGLE_LINE_COMMENT) { lineComments.add(ast.getLineNo() + "," + ast.getColumnNo()); } else if (ast.getType() == TokenTypes.BLOCK_COMMENT_BEGIN) { blockComments.add(ast.getLineNo() + "," + ast.getColumnNo()); } forEachChild(ast.getFirstChild()); } } }
/** * Extracts the name of an ast. * @param ast to extract the name * @return the text content of the inner {@code TokenTypes.IDENT} node */ private static String getName(DetailAST ast) { return ast.findFirstToken(TokenTypes.IDENT).getText(); }
@Override public void visitToken(DetailAST ast) { final DetailAST whitespaceFollowedAst = getWhitespaceFollowedNode(ast); if (whitespaceFollowedAst.getNextSibling() == null || whitespaceFollowedAst.getNextSibling().getType() != TokenTypes.ANNOTATIONS) { final int whitespaceColumnNo = getPositionAfter(whitespaceFollowedAst); final int whitespaceLineNo = whitespaceFollowedAst.getLineNo(); if (hasTrailingWhitespace(ast, whitespaceColumnNo, whitespaceLineNo)) { log(ast, MSG_KEY, whitespaceFollowedAst.getText()); } } }
/** * Whether the declaration is located before the checked ast. * @param ast1 the IDENT ast of the declaration. * @param ast2 the IDENT ast to check. * @return true, if the declaration is located before the checked ast. */ private static boolean checkPosition(DetailAST ast1, DetailAST ast2) { boolean result = false; if (ast1.getLineNo() < ast2.getLineNo() || ast1.getLineNo() == ast2.getLineNo() && ast1.getColumnNo() < ast2.getColumnNo()) { result = true; } return result; }
/** * Determines if this 'if' statement is part of an 'else' clause * and on the same line. * * @return true if this 'if' is part of an 'else', false otherwise */ private boolean isIfAfterElse() { // check if there is an 'else' and an 'if' on the same line final DetailAST parent = getMainAst().getParent(); return parent.getType() == TokenTypes.LITERAL_ELSE && parent.getLineNo() == getMainAst().getLineNo(); }
@Override public void visitToken(DetailAST ast) { // Strange logic in this method to guard against checking RPAREN tokens // that are not associated with a TYPECAST token. if (ast.getType() == TokenTypes.TYPECAST) { processLeft(ast); } else if (ast.getParent().getType() == TokenTypes.TYPECAST && ast.getParent().findFirstToken(TokenTypes.RPAREN) == ast) { processRight(ast); } }
@Override public void visitToken(DetailAST ast) { if (!isIgnoreSituation(ast)) { final DetailAST nameAst = ast.findFirstToken(TokenTypes.IDENT); final String typeName = nameAst.getText(); final String abbr = getDisallowedAbbreviation(typeName); if (abbr != null) { log(nameAst.getLineNo(), MSG_KEY, typeName, allowedAbbreviationLength + 1); } } }
/** * Returns the name of the given annotation. * @param annotation annotation node. * @return annotation name. */ private static String getAnnotationName(DetailAST annotation) { DetailAST identNode = annotation.findFirstToken(TokenTypes.IDENT); if (identNode == null) { identNode = annotation.findFirstToken(TokenTypes.DOT).getLastChild(); } return identNode.getText(); }
public void foo13() { CheckUtil.getFirstNode(new DetailAST()) .getFirstChild() .getNextSibling(); // comment }
/** * Returns whether a token represents an SLIST as part of an ELSE * statement. * @param ast the token to check * @return whether the toke does represent an SLIST as part of an ELSE */ private static boolean isElseWithCurlyBraces(DetailAST ast) { return ast.getType() == TokenTypes.SLIST && ast.getChildCount() == 2 && isElse(ast.getParent()); }
/** * Check if VARIABLE_DEF is initialized or not. * @param ast VARIABLE_DEF to be checked * @return true if initialized */ private static boolean isInitialized(DetailAST ast) { return ast.getParent().getLastChild().getType() == TokenTypes.ASSIGN; }