Search in sources :

Example 86 with DetailAstImpl

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

the class AnnotationUtilTest method testContainsAnnotationListWithNoMatchingAnnotation.

@Test
public void testContainsAnnotationListWithNoMatchingAnnotation() {
    final DetailAstImpl ast = new DetailAstImpl();
    final DetailAstImpl modifiersAst = create(TokenTypes.MODIFIERS, create(TokenTypes.ANNOTATION, create(TokenTypes.DOT, create(TokenTypes.IDENT, "Override"))));
    ast.addChild(modifiersAst);
    final List<String> annotations = Collections.singletonList("Deprecated");
    final boolean result = AnnotationUtil.containsAnnotation(ast, annotations);
    assertWithMessage("No matching annotation found").that(result).isFalse();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Example 87 with DetailAstImpl

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

the class AnnotationUtilTest method testContainsAnnotationFalse2.

@Test
public void testContainsAnnotationFalse2() {
    final DetailAstImpl ast = new DetailAstImpl();
    ast.setType(1);
    final DetailAstImpl ast2 = new DetailAstImpl();
    ast2.setType(TokenTypes.MODIFIERS);
    ast.addChild(ast2);
    assertWithMessage("AnnotationUtil should not contain " + ast).that(AnnotationUtil.containsAnnotation(ast)).isFalse();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Example 88 with DetailAstImpl

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

the class AnnotationUtilTest method create.

private static DetailAstImpl create(int tokenType) {
    final DetailAstImpl ast = new DetailAstImpl();
    ast.setType(tokenType);
    return ast;
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl)

Example 89 with DetailAstImpl

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

the class AnnotationUtilTest method testAnnotationNull2.

@Test
public void testAnnotationNull2() {
    try {
        AnnotationUtil.getAnnotation(new DetailAstImpl(), null);
        assertWithMessage("IllegalArgumentException is expected").fail();
    } catch (IllegalArgumentException ex) {
        assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo("the annotation is null");
    }
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Example 90 with DetailAstImpl

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

the class CheckUtilTest method testGetFirstNode1.

@Test
public void testGetFirstNode1() {
    final DetailAstImpl child = new DetailAstImpl();
    child.setLineNo(5);
    child.setColumnNo(6);
    final DetailAstImpl root = new DetailAstImpl();
    root.setLineNo(5);
    root.setColumnNo(6);
    root.addChild(child);
    final DetailAST firstNode = CheckUtil.getFirstNode(root);
    assertWithMessage("Unexpected node").that(firstNode).isEqualTo(root);
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) 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