use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class ParseTreeTablePresentationTest method testJavadocCommentChildCount.
@Test
public void testJavadocCommentChildCount() {
final DetailAST commentContentNode = tree.getFirstChild().getNextSibling().getFirstChild();
final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null);
final int commentChildCount = parseTree.getChildCount(commentContentNode);
Assert.assertEquals(0, commentChildCount);
parseTree.setParseMode(ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS);
final int javadocCommentChildCount = parseTree.getChildCount(commentContentNode);
Assert.assertEquals(1, javadocCommentChildCount);
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class ParseTreeTablePresentationTest method testCommentChildCountInJavaAndJavadocMode.
@Test
public void testCommentChildCountInJavaAndJavadocMode() {
final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null);
parseTree.setParseMode(ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS);
final DetailAST commentContentNode = tree.getLastChild().getLastChild().getPreviousSibling().getLastChild().getFirstChild().getFirstChild();
final int commentChildCount = parseTree.getChildCount(commentContentNode);
Assert.assertEquals(0, commentChildCount);
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class ParseTreeTablePresentationTest method testGetValueAtDetailNode.
@Test
public void testGetValueAtDetailNode() {
final DetailAST commentContentNode = tree.getFirstChild().getNextSibling().getFirstChild();
Assert.assertNotNull("Comment node cannot be null", commentContentNode);
final int nodeType = commentContentNode.getType();
Assert.assertTrue("Comment node should be a comment type", TokenUtils.isCommentType(nodeType));
Assert.assertEquals("This should be a javadoc comment", "/*", commentContentNode.getParent().getText());
final ParseTreeTablePresentation parseTree = new ParseTreeTablePresentation(null);
parseTree.setParseMode(ParseMode.JAVA_WITH_JAVADOC_AND_COMMENTS);
final Object child = parseTree.getChild(commentContentNode, 0);
Assert.assertFalse(parseTree.isLeaf(child));
Assert.assertTrue(parseTree.isLeaf(tree.getFirstChild()));
final Object treeModel = parseTree.getValueAt(child, 0);
final String type = (String) parseTree.getValueAt(child, 1);
final int line = (int) parseTree.getValueAt(child, 2);
final int column = (int) parseTree.getValueAt(child, 3);
final String text = (String) parseTree.getValueAt(child, 4);
final String expectedText = String.join("", System.lineSeparator(), "* class javadoc", System.lineSeparator(), "<EOF>");
Assert.assertNull(treeModel);
Assert.assertEquals("JAVADOC", type);
Assert.assertEquals(1, line);
Assert.assertEquals(3, column);
Assert.assertEquals(expectedText, text);
try {
parseTree.getValueAt(child, parseTree.getColumnCount());
Assert.fail("IllegalStateException expected");
} catch (IllegalStateException ex) {
Assert.assertEquals("Unknown column", ex.getMessage());
}
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class UncommentedMainCheckTest method testIllegalStateException.
@Test
public void testIllegalStateException() {
final UncommentedMainCheck check = new UncommentedMainCheck();
final DetailAST ast = new DetailAST();
ast.initialize(new CommonHiddenStreamToken(TokenTypes.CTOR_DEF, "ctor"));
try {
check.visitToken(ast);
Assert.fail("IllegalStateException is expected");
} catch (IllegalStateException ex) {
assertEquals(ast.toString(), ex.getMessage());
}
}
use of com.puppycrawl.tools.checkstyle.api.DetailAST in project checkstyle by checkstyle.
the class DeclarationOrderCheckTest method testImproperToken.
@Test
public void testImproperToken() {
final DetailAST parent = new DetailAST();
parent.setType(TokenTypes.STATIC_INIT);
final DetailAST array = new DetailAST();
array.setType(TokenTypes.ARRAY_INIT);
parent.setFirstChild(array);
final DeclarationOrderCheck check = new DeclarationOrderCheck();
check.visitToken(array);
}
Aggregations