Search in sources :

Example 36 with DetailAstImpl

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

the class ElementNodeTest method testGetAttributeValueWrongAttribute.

@Test
public void testGetAttributeValueWrongAttribute() {
    final DetailAstImpl detailAST = new DetailAstImpl();
    detailAST.setType(TokenTypes.IDENT);
    detailAST.setText("HelloWorld");
    final ElementNode elementNode = new ElementNode(rootNode, rootNode, detailAST, 1, 0);
    assertWithMessage("Must be null").that(elementNode.getAttributeValue(null, "somename")).isNull();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Example 37 with DetailAstImpl

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

the class ElementNodeTest method testGetAttributeValue.

@Test
public void testGetAttributeValue() {
    final DetailAstImpl detailAST = new DetailAstImpl();
    detailAST.setType(TokenTypes.IDENT);
    detailAST.setText("HelloWorld");
    final ElementNode elementNode = new ElementNode(rootNode, rootNode, detailAST, 1, 0);
    assertWithMessage("Invalid text attribute").that(elementNode.getAttributeValue(null, "text")).isEqualTo("HelloWorld");
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Example 38 with DetailAstImpl

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

the class ElementNodeTest method testIterateAxisEmptyChildren.

@Test
public void testIterateAxisEmptyChildren() {
    final DetailAstImpl detailAST = new DetailAstImpl();
    detailAST.setType(TokenTypes.METHOD_DEF);
    final ElementNode elementNode = new ElementNode(rootNode, rootNode, detailAST, 1, 0);
    try (AxisIterator iterator = elementNode.iterateAxis(AxisInfo.CHILD)) {
        assertWithMessage("Invalid iterator").that(iterator instanceof EmptyIterator).isTrue();
    }
    try (AxisIterator iterator = elementNode.iterateAxis(AxisInfo.DESCENDANT)) {
        assertWithMessage("Invalid iterator").that(iterator instanceof EmptyIterator).isTrue();
    }
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) EmptyIterator(net.sf.saxon.tree.iter.EmptyIterator) AxisIterator(net.sf.saxon.tree.iter.AxisIterator) Test(org.junit.jupiter.api.Test)

Example 39 with DetailAstImpl

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

the class ElementNodeTest method testIterateAxisWithNoSiblings.

@Test
public void testIterateAxisWithNoSiblings() {
    final DetailAstImpl detailAST = new DetailAstImpl();
    detailAST.setType(TokenTypes.VARIABLE_DEF);
    final DetailAstImpl parentAST = new DetailAstImpl();
    parentAST.setFirstChild(detailAST);
    parentAST.setType(TokenTypes.METHOD_DEF);
    final AbstractNode parentNode = new ElementNode(rootNode, rootNode, parentAST, 1, 0);
    final AbstractNode elementNode = parentNode.getChildren().get(0);
    try (AxisIterator iterator = elementNode.iterateAxis(AxisInfo.FOLLOWING_SIBLING)) {
        assertWithMessage("Invalid iterator").that(iterator instanceof EmptyIterator).isTrue();
    }
    try (AxisIterator iterator = elementNode.iterateAxis(AxisInfo.PRECEDING_SIBLING)) {
        assertWithMessage("Invalid iterator").that(iterator instanceof EmptyIterator).isTrue();
    }
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) EmptyIterator(net.sf.saxon.tree.iter.EmptyIterator) AxisIterator(net.sf.saxon.tree.iter.AxisIterator) Test(org.junit.jupiter.api.Test)

Example 40 with DetailAstImpl

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

the class JavadocUtilTest method testGetJavadocCommentContent.

@Test
public void testGetJavadocCommentContent() {
    final DetailAstImpl detailAST = new DetailAstImpl();
    final DetailAstImpl javadoc = new DetailAstImpl();
    javadoc.setText("1javadoc");
    detailAST.setFirstChild(javadoc);
    final String commentContent = JavadocUtil.getJavadocCommentContent(detailAST);
    assertWithMessage("Invalid comment content").that(commentContent).isEqualTo("javadoc");
}
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