/** * Returns method or constructor call right paren. * @param firstNode * call ast(TokenTypes.METHOD_CALL|TokenTypes.CTOR_CALL|TokenTypes.SUPER_CTOR_CALL) * @return ast node containing right paren for specified method or constructor call. If * method calls are chained returns right paren for last call. */ private static DetailAST getCallLastNode(DetailAST firstNode) { return firstNode.getLastChild(); }
/** * Whether the AST is a definition of an anonymous class. * @param ast the AST to process. * @return true if the AST is a definition of an anonymous class. */ private static boolean isAnonymousClassDef(DetailAST ast) { final DetailAST lastChild = ast.getLastChild(); return lastChild != null && lastChild.getType() == TokenTypes.OBJBLOCK; }
/** * Registers given import. This allows us to track imported classes. * @param imp import definition. */ public void registerImport(DetailAST imp) { final FullIdent ident = FullIdent.createFullIdent( imp.getLastChild().getPreviousSibling()); final String fullName = ident.getText(); final int lastDot = fullName.lastIndexOf(DOT); importedClassPackage.put(fullName.substring(lastDot + 1), fullName); }
/** * If token is LITERAL_IF and there is an {@code else} following. * @param ast token to be checked * @return true if token is LITERAL_IF and there is an {@code else} following, else false */ private static boolean isIfTokenWithAnElseFollowing(DetailAST ast) { return ast.getType() == TokenTypes.LITERAL_IF && ast.getLastChild().getType() == TokenTypes.LITERAL_ELSE; }
/** * Method to find right parenthesis of try with resources. * * @return DetailAst right parenthesis of try with resources */ private DetailAST getTryResRparen() { return getMainAst().getFirstChild().getLastChild(); }
/** * 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; }
/** * Sets current package. * @param packageDef node for package definition */ private void visitPackageDef(DetailAST packageDef) { packageName = FullIdent.createFullIdent(packageDef.getLastChild() .getPreviousSibling()); }
/** * Collects the details of a package. * @param ast node containing the package details */ private void processPackage(DetailAST ast) { final DetailAST nameAST = ast.getLastChild().getPreviousSibling(); packageFullIdent = FullIdent.createFullIdent(nameAST); }
/** * Checks if comment is single line comment. * * @param blockCommentStart the AST tree in which a block comment starts * @return true, if comment is single line comment. */ private static boolean isSingleLineJavadoc(DetailAST blockCommentStart) { final DetailAST blockCommentEnd = blockCommentStart.getLastChild(); return blockCommentStart.getLineNo() == blockCommentEnd.getLineNo(); }
/** * Returns semicolon for variable definition statement. * @param variableDef * ast node of type TokenTypes.VARIABLE_DEF * @return ast node of type TokenTypes.SEMI */ private static DetailAST getVarDefStatementSemicolon(DetailAST variableDef) { DetailAST lastNode = variableDef.getLastChild(); if (lastNode.getType() != TokenTypes.SEMI) { lastNode = variableDef.getNextSibling(); } return lastNode; }
/** * 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(); }
@Override public void visitToken(DetailAST ast) { final DetailAST nameAST = ast.getLastChild().getPreviousSibling(); final FullIdent full = FullIdent.createFullIdent(nameAST); if (!format.matcher(full.getText()).find()) { log(full.getDetailAst(), MSG_KEY, full.getText(), format.pattern()); } }
/** * Returns package text. * @param ast PACKAGE_DEF ast node * @return String that represents full package name */ private static String getPackageText(DetailAST ast) { final DetailAST nameAST = ast.getLastChild().getPreviousSibling(); return FullIdent.createFullIdent(nameAST).getText(); }
/** * Perform processing for an package token. * @param ast the package token */ private void processPackageDef(DetailAST ast) { final DetailAST packageNameAST = ast.getLastChild() .getPreviousSibling(); final FullIdent packageIdent = FullIdent.createFullIdent(packageNameAST); pkgName = packageIdent.getText(); }
/** * Stores package of current class we check. * @param pkg package definition. */ private void visitPackageDef(DetailAST pkg) { final FullIdent ident = FullIdent.createFullIdent(pkg.getLastChild().getPreviousSibling()); fileContext.setPackageName(ident.getText()); }
@Override public void addChild(AST ast) { clearBranchTokenTypes(); clearChildCountCache(this); if (ast != null) { ((DetailAST) ast).setParent(this); ((DetailAST) ast).previousSibling = getLastChild(); } super.addChild(ast); }
@Override public void visitToken(DetailAST ast) { if (ast.getLineNo() != ast.getLastChild().getLineNo()) { log(ast.getLineNo(), MSG_KEY, ast.getText()); } }
@Test public void testCommentChildCountInJavaAndJavadocMode() { final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null); parseTree.setParseMode(ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS); final DetailAST commentContentNode = tree.getLastChild().getLastChild() .getPreviousSibling().getLastChild().getFirstChild().getFirstChild(); final int commentChildCount = parseTree.getChildCount(commentContentNode); Assert.assertEquals("Invalid child count", 0, commentChildCount); }
@Test public void testCommentChildInJavaAndJavadocMode() { final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null); parseTree.setParseMode(ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS); final DetailAST commentContentNode = tree.getLastChild().getLastChild() .getPreviousSibling().getLastChild().getFirstChild().getFirstChild(); final Object commentChild = parseTree.getChild(commentContentNode, 0); Assert.assertNull("Child must be null", commentChild); }
@Test public void testDetailASTLeafSelection() { final DetailAST leaf = tree.getLastChild().getFirstChild(); final CodeSelectorPresentation selector = new CodeSelectorPresentation(leaf, linesToPosition); selector.findSelectionPositions(); Assert.assertEquals("Invalid selection start", 130, selector.getSelectionStart()); Assert.assertEquals("Invalid selection end", 131, selector.getSelectionEnd()); }