Search in sources :

Example 76 with DetailAstImpl

use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.

the class AnnotationUtilTest method testContainsAnnotationListWithNullList.

@Test
public void testContainsAnnotationListWithNullList() {
    final DetailAST ast = new DetailAstImpl();
    final List<String> annotations = null;
    try {
        AnnotationUtil.containsAnnotation(ast, annotations);
        assertWithMessage("IllegalArgumentException is expected").fail();
    } catch (IllegalArgumentException ex) {
        assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo("annotations cannot be null");
    }
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.jupiter.api.Test)

Example 77 with DetailAstImpl

use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.

the class XpathIteratorUtil method createNode.

/**
 * Creates {@link DetailAstImpl} node.
 *
 * @param tokenType token type, see {@link TokenTypes}
 * @param lineNo line number
 * @param columnNo column number
 *
 * @return {@link DetailAstImpl} object.
 */
private static DetailAstImpl createNode(int tokenType, int lineNo, int columnNo) {
    final DetailAstImpl result = new DetailAstImpl();
    result.setType(tokenType);
    result.setLineNo(lineNo);
    result.setColumnNo(columnNo);
    return result;
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl)

Example 78 with DetailAstImpl

use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.

the class AbstractCheckTest method testAstLog.

@Test
public void testAstLog() throws Exception {
    final ViolationAstCheck check = new ViolationAstCheck();
    check.configure(new DefaultConfiguration("check"));
    final File file = new File("fileName");
    final FileText theText = new FileText(file, Collections.singletonList("test123"));
    check.setFileContents(new FileContents(theText));
    check.clearViolations();
    final DetailAstImpl ast = new DetailAstImpl();
    ast.setLineNo(1);
    ast.setColumnNo(4);
    check.visitToken(ast);
    final SortedSet<Violation> internalViolations = check.getViolations();
    assertWithMessage("Internal violation should only have 1").that(internalViolations).hasSize(1);
    final Violation firstViolation = internalViolations.iterator().next();
    assertWithMessage("expected line").that(firstViolation.getLineNo()).isEqualTo(1);
    assertWithMessage("expected column").that(firstViolation.getColumnNo()).isEqualTo(5);
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 79 with DetailAstImpl

use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.

the class JavadocUtilTest method testEmptyJavadocCommentAst.

@Test
public void testEmptyJavadocCommentAst() {
    final DetailAstImpl commentBegin = new DetailAstImpl();
    commentBegin.setType(TokenTypes.BLOCK_COMMENT_BEGIN);
    commentBegin.setText("/*");
    final DetailAstImpl javadocCommentContent = new DetailAstImpl();
    javadocCommentContent.setType(TokenTypes.COMMENT_CONTENT);
    javadocCommentContent.setText("*");
    final DetailAstImpl commentEnd = new DetailAstImpl();
    commentEnd.setType(TokenTypes.BLOCK_COMMENT_END);
    commentEnd.setText("*/");
    commentBegin.setFirstChild(javadocCommentContent);
    javadocCommentContent.setNextSibling(commentEnd);
    final DetailAstImpl commentBeginParent = new DetailAstImpl();
    commentBeginParent.setType(TokenTypes.MODIFIERS);
    commentBeginParent.setFirstChild(commentBegin);
    final DetailAstImpl aJavadocPosition = new DetailAstImpl();
    aJavadocPosition.setType(TokenTypes.METHOD_DEF);
    aJavadocPosition.setFirstChild(commentBeginParent);
    assertWithMessage("Should return true when empty javadoc comment ast is passed").that(JavadocUtil.isJavadocComment(commentBegin)).isTrue();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Example 80 with DetailAstImpl

use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.

the class JavadocUtilTest method testEmptyBlockCommentAst.

@Test
public void testEmptyBlockCommentAst() {
    final DetailAstImpl commentBegin = new DetailAstImpl();
    commentBegin.setType(TokenTypes.BLOCK_COMMENT_BEGIN);
    commentBegin.setText("/*");
    final DetailAstImpl commentContent = new DetailAstImpl();
    commentContent.setType(TokenTypes.COMMENT_CONTENT);
    commentContent.setText("");
    final DetailAstImpl commentEnd = new DetailAstImpl();
    commentEnd.setType(TokenTypes.BLOCK_COMMENT_END);
    commentEnd.setText("*/");
    commentBegin.setFirstChild(commentContent);
    commentContent.setNextSibling(commentEnd);
    assertWithMessage("Should return false when empty block comment is passed").that(JavadocUtil.isJavadocComment(commentBegin)).isFalse();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Aggregations

DetailAstImpl (com.puppycrawl.tools.checkstyle.DetailAstImpl)106 Test (org.junit.jupiter.api.Test)90 CommonToken (org.antlr.v4.runtime.CommonToken)14 DetailAST (com.puppycrawl.tools.checkstyle.api.DetailAST)8 Method (java.lang.reflect.Method)6 Violation (com.puppycrawl.tools.checkstyle.api.Violation)5 AxisIterator (net.sf.saxon.tree.iter.AxisIterator)4 Context (com.puppycrawl.tools.checkstyle.api.Context)3 ArrayList (java.util.ArrayList)2 EmptyIterator (net.sf.saxon.tree.iter.EmptyIterator)2 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)1 AbstractNode (com.puppycrawl.tools.checkstyle.xpath.AbstractNode)1 RootNode (com.puppycrawl.tools.checkstyle.xpath.RootNode)1 DescendantIterator (com.puppycrawl.tools.checkstyle.xpath.iterators.DescendantIterator)1 File (java.io.File)1 AbstractMap (java.util.AbstractMap)1 Map (java.util.Map)1 ArrayIterator (net.sf.saxon.tree.iter.ArrayIterator)1