Search in sources :

Example 91 with DetailAstImpl

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

the class CheckUtilTest method testElseWithCurly.

@Test
public void testElseWithCurly() {
    final DetailAstImpl ast = new DetailAstImpl();
    ast.setType(TokenTypes.ASSIGN);
    ast.setText("ASSIGN");
    assertWithMessage("Invalid elseIf check result 'ASSIGN' is not 'else if'").that(CheckUtil.isElseIf(ast)).isFalse();
    final DetailAstImpl parentAst = new DetailAstImpl();
    parentAst.setType(TokenTypes.LCURLY);
    parentAst.setText("LCURLY");
    final DetailAstImpl ifAst = new DetailAstImpl();
    ifAst.setType(TokenTypes.LITERAL_IF);
    ifAst.setText("IF");
    parentAst.addChild(ifAst);
    assertWithMessage("Invalid elseIf check result: 'IF' is not 'else if'").that(CheckUtil.isElseIf(ifAst)).isFalse();
    final DetailAstImpl parentAst2 = new DetailAstImpl();
    parentAst2.setType(TokenTypes.SLIST);
    parentAst2.setText("SLIST");
    parentAst2.addChild(ifAst);
    assertWithMessage("Invalid elseIf check result: 'SLIST' is not 'else if'").that(CheckUtil.isElseIf(ifAst)).isFalse();
    final DetailAstImpl elseAst = new DetailAstImpl();
    elseAst.setType(TokenTypes.LITERAL_ELSE);
    elseAst.setFirstChild(ifAst);
    assertWithMessage("Invalid elseIf check result").that(CheckUtil.isElseIf(ifAst)).isTrue();
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) Test(org.junit.jupiter.api.Test)

Example 92 with DetailAstImpl

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

the class XpathUtilTest method testCreateChildren.

@Test
public void testCreateChildren() {
    final DetailAstImpl rootAst = new DetailAstImpl();
    final DetailAstImpl elementAst = new DetailAstImpl();
    rootAst.addChild(elementAst);
    final RootNode rootNode = new RootNode(rootAst);
    final List<AbstractNode> children = XpathUtil.createChildren(rootNode, rootNode, elementAst);
    assertWithMessage("Expected one child node").that(children).hasSize(1);
    assertWithMessage("Node depth should be 1").that(children.get(0).getDepth()).isEqualTo(1);
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) RootNode(com.puppycrawl.tools.checkstyle.xpath.RootNode) AbstractNode(com.puppycrawl.tools.checkstyle.xpath.AbstractNode) Test(org.junit.jupiter.api.Test)

Example 93 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, String text) {
    final DetailAstImpl detailAST = new DetailAstImpl();
    detailAST.setType(type);
    detailAST.setText(text);
    return detailAST;
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl)

Example 94 with DetailAstImpl

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

the class ElementNodeTest method testGetAttributeCached.

@Test
public void testGetAttributeCached() {
    final DetailAstImpl detailAST = new DetailAstImpl();
    detailAST.setType(TokenTypes.IDENT);
    detailAST.setText("HelloWorld");
    final ElementNode elementNode = new ElementNode(rootNode, rootNode, detailAST, 1, 0);
    try (AxisIterator first = elementNode.iterateAxis(AxisInfo.ATTRIBUTE);
        AxisIterator second = elementNode.iterateAxis(AxisInfo.ATTRIBUTE)) {
        assertWithMessage("Expected same attribute node").that(second.next()).isSameInstanceAs(first.next());
    }
}
Also used : DetailAstImpl(com.puppycrawl.tools.checkstyle.DetailAstImpl) AxisIterator(net.sf.saxon.tree.iter.AxisIterator) Test(org.junit.jupiter.api.Test)

Example 95 with DetailAstImpl

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

the class ElementNodeTest method testGetAttributeValueNoAttribute.

@Test
public void testGetAttributeValueNoAttribute() {
    final DetailAstImpl detailAST = new DetailAstImpl();
    detailAST.setType(TokenTypes.CLASS_DEF);
    detailAST.setText("HelloWorld");
    final ElementNode elementNode = new ElementNode(rootNode, rootNode, detailAST, 1, 0);
    assertWithMessage("Must be null").that(elementNode.getAttributeValue(null, "text")).isNull();
}
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