Search in sources :

Example 26 with DetailAstImpl

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

the class AnnotationUtilTest method testContainsAnnotationListWithEmptyList.

@Test
public void testContainsAnnotationListWithEmptyList() {
    final DetailAST ast = new DetailAstImpl();
    final List<String> annotations = new ArrayList<>();
    final boolean result = AnnotationUtil.containsAnnotation(ast, annotations);
    assertWithMessage("An empty list should lead to a false result").that(result).isFalse();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 27 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, String text) {
    final DetailAstImpl ast = create(tokenType);
    ast.setText(text);
    return ast;
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl)

Example 28 with DetailAstImpl

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

the class CheckUtilTest method testGetFirstNode2.

@Test
public void testGetFirstNode2() {
    final DetailAstImpl child = new DetailAstImpl();
    child.setLineNo(6);
    child.setColumnNo(5);
    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)

Example 29 with DetailAstImpl

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

the class CheckUtilTest method testEquals.

@Test
public void testEquals() {
    final DetailAstImpl litStatic = new DetailAstImpl();
    litStatic.setType(TokenTypes.LITERAL_STATIC);
    final DetailAstImpl modifiers = new DetailAstImpl();
    modifiers.setType(TokenTypes.MODIFIERS);
    modifiers.addChild(litStatic);
    final DetailAstImpl metDef = new DetailAstImpl();
    metDef.setType(TokenTypes.METHOD_DEF);
    metDef.addChild(modifiers);
    assertWithMessage("Invalid result: ast is not equals method").that(CheckUtil.isEqualsMethod(metDef)).isFalse();
    metDef.removeChildren();
    final DetailAstImpl metName = new DetailAstImpl();
    metName.setType(TokenTypes.IDENT);
    metName.setText("equals");
    metDef.addChild(metName);
    final DetailAstImpl modifiers2 = new DetailAstImpl();
    modifiers2.setType(TokenTypes.MODIFIERS);
    metDef.addChild(modifiers2);
    final DetailAstImpl parameter1 = new DetailAstImpl();
    final DetailAstImpl parameter2 = new DetailAstImpl();
    final DetailAstImpl parameters = new DetailAstImpl();
    parameters.setType(TokenTypes.PARAMETERS);
    parameters.addChild(parameter2);
    parameters.addChild(parameter1);
    metDef.addChild(parameters);
    assertWithMessage("Invalid result: ast is not equals method").that(CheckUtil.isEqualsMethod(metDef)).isFalse();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Example 30 with DetailAstImpl

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

the class CheckUtilTest method testGetAccessModifierFromModifiersTokenWrongTokenType.

@Test
public void testGetAccessModifierFromModifiersTokenWrongTokenType() {
    final DetailAstImpl modifiers = new DetailAstImpl();
    modifiers.setType(TokenTypes.METHOD_DEF);
    try {
        CheckUtil.getAccessModifierFromModifiersToken(modifiers);
        assertWithMessage("%s was expected.", IllegalArgumentException.class.getSimpleName()).fail();
    } catch (IllegalArgumentException exc) {
        final String expectedExceptionMsg = "expected non-null AST-token with type 'MODIFIERS'";
        final String actualExceptionMsg = exc.getMessage();
        assertWithMessage("Invalid exception message").that(actualExceptionMsg).isEqualTo(expectedExceptionMsg);
    }
}
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