use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ExecutableStatementCountCheckTest method testLeaveTokenWithWrongTokenType.
@Test
public void testLeaveTokenWithWrongTokenType() {
final ExecutableStatementCountCheck checkObj = new ExecutableStatementCountCheck();
final DetailAstImpl ast = new DetailAstImpl();
ast.initialize(new CommonToken(TokenTypes.ENUM, "ENUM"));
try {
checkObj.leaveToken(ast);
assertWithMessage("exception expected").fail();
} catch (IllegalStateException ex) {
assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo("ENUM[0x-1]");
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class AnnotationUtilTest method testContainsAnnotationListWithEmptyAnnotationNode.
@Test
public void testContainsAnnotationListWithEmptyAnnotationNode() {
final DetailAstImpl ast = new DetailAstImpl();
final DetailAstImpl modifiersAst = create(TokenTypes.MODIFIERS, create(TokenTypes.ANNOTATION, create(TokenTypes.DOT, create(TokenTypes.IDENT, "Override"))));
ast.addChild(modifiersAst);
final List<String> annotations = Collections.singletonList("Override");
final boolean result = AnnotationUtil.containsAnnotation(ast, annotations);
assertWithMessage("The dot-ident variation should also work").that(result).isTrue();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class AnnotationUtilTest method testContainsAnnotationFalse.
@Test
public void testContainsAnnotationFalse() {
final DetailAstImpl ast = new DetailAstImpl();
ast.setType(1);
assertWithMessage("AnnotationUtil should not contain " + ast).that(AnnotationUtil.containsAnnotation(ast)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class AnnotationUtilTest method testContainsAnnotationWithComment.
@Test
public void testContainsAnnotationWithComment() {
final DetailAstImpl astForTest = new DetailAstImpl();
astForTest.setType(TokenTypes.PACKAGE_DEF);
final DetailAstImpl child = new DetailAstImpl();
final DetailAstImpl annotations = new DetailAstImpl();
final DetailAstImpl annotation = new DetailAstImpl();
final DetailAstImpl annotationNameHolder = new DetailAstImpl();
final DetailAstImpl annotationName = new DetailAstImpl();
final DetailAstImpl comment = new DetailAstImpl();
annotations.setType(TokenTypes.ANNOTATIONS);
annotation.setType(TokenTypes.ANNOTATION);
annotationNameHolder.setType(TokenTypes.AT);
comment.setType(TokenTypes.BLOCK_COMMENT_BEGIN);
annotationName.setText("Annotation");
annotationNameHolder.setNextSibling(annotationName);
annotation.setFirstChild(comment);
comment.setNextSibling(annotationNameHolder);
annotations.setFirstChild(annotation);
child.setNextSibling(annotations);
astForTest.setFirstChild(child);
assertWithMessage("Annotation should contain " + astForTest).that(AnnotationUtil.containsAnnotation(astForTest, "Annotation")).isTrue();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class AnnotationUtilTest method testAnnotationEmpty.
@Test
public void testAnnotationEmpty() {
try {
AnnotationUtil.getAnnotation(new DetailAstImpl(), "");
assertWithMessage("IllegalArgumentException is expected").fail();
} catch (IllegalArgumentException ex) {
assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo("the annotation is empty or spaces");
}
}
Aggregations