Search in sources :

Example 31 with DetailAstImpl

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

the class XpathIteratorUtil method createTree.

/**
 * Creates AST tree for iteration tests and returns root.
 * <p>
 * PACKAGE_DEF -> package [1:0]
 * |--ANNOTATIONS -> ANNOTATIONS [1:8]
 *     `--ANNOTATION_DEF -> ANNOTATIONS [1:8]
 * `--CLASS_DEF -> CLASS_DEF [3:0]
 *     `--OBJBLOCK -> OBJBLOCK [3:19]
 *         |--LCURLY -> { [3:19]
 *         |--METHOD_DEF -> METHOD_DEF [4:4]
 *         |   |--PARAMETERS -> PARAMETERS [4:31]
 *         |   `--SLIST -> { [4:33]
 *         `--RCURLY -> } [8:0]
 * </p>
 *
 * @return {@link DetailAST} object.
 */
private static DetailAST createTree() {
    final DetailAstImpl rootNode = createNode(TokenTypes.PACKAGE_DEF, 1, 0);
    final DetailAstImpl annotationsNode = createNode(rootNode, TokenTypes.ANNOTATIONS, 1, 8);
    createNode(annotationsNode, TokenTypes.ANNOTATION_DEF, 1, 8);
    final DetailAstImpl classDefNode = createNode(rootNode, TokenTypes.CLASS_DEF, 3, 0);
    final DetailAstImpl objblockNode = createNode(classDefNode, TokenTypes.OBJBLOCK, 3, 19);
    createNode(objblockNode, TokenTypes.LCURLY, 3, 19);
    final DetailAstImpl methodDefNode = createNode(objblockNode, TokenTypes.METHOD_DEF, 4, 4);
    createNode(objblockNode, TokenTypes.RCURLY, 8, 0);
    createNode(methodDefNode, TokenTypes.PARAMETERS, 4, 31);
    createNode(methodDefNode, TokenTypes.SLIST, 4, 33);
    return rootNode;
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl)

Example 32 with DetailAstImpl

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

the class XpathIteratorUtil method createNode.

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

Example 33 with DetailAstImpl

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

the class ParseTreeTablePresentationTest method testGetIndexOfChild.

@Test
public void testGetIndexOfChild() {
    DetailAST ithChild = tree.getFirstChild();
    assertWithMessage("Child must not be null").that(ithChild).isNotNull();
    final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null);
    int index = 0;
    while (ithChild != null) {
        final int indexOfChild = parseTree.getIndexOfChild(tree, ithChild);
        assertWithMessage("Invalid child index").that(indexOfChild).isEqualTo(index);
        ithChild = ithChild.getNextSibling();
        index++;
    }
    final int indexOfChild = parseTree.getIndexOfChild(tree, new DetailAstImpl());
    assertWithMessage("Invalid child index").that(indexOfChild).isEqualTo(-1);
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) DetailAST(com.puppycrawl.tools.checkstyle.api.DetailAST) Test(org.junit.jupiter.api.Test)

Example 34 with DetailAstImpl

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

the class XpathUtilTest method createDetailAST.

private static DetailAST createDetailAST(int type) {
    final DetailAstImpl detailAST = new DetailAstImpl();
    detailAST.setType(type);
    return detailAST;
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl)

Example 35 with DetailAstImpl

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

the class ElementNodeTest method testParentChildOrdering.

@Test
public void testParentChildOrdering() {
    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 childNode = new ElementNode(rootNode, parentNode, detailAST, 2, 0);
    assertWithMessage("Incorrect ordering value").that(parentNode.compareOrder(childNode)).isEqualTo(-1);
    assertWithMessage("Incorrect ordering value").that(childNode.compareOrder(parentNode)).isEqualTo(1);
}
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