use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class JavadocTagInfoTest method testAuthor.
@Test
public void testAuthor() {
final DetailAstImpl ast = new DetailAstImpl();
final int[] validTypes = { TokenTypes.PACKAGE_DEF, TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF, TokenTypes.ENUM_DEF, TokenTypes.ANNOTATION_DEF };
for (int type : validTypes) {
ast.setType(type);
assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.AUTHOR.isValidOn(ast)).isTrue();
}
ast.setType(TokenTypes.LAMBDA);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.AUTHOR.isValidOn(ast)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class JavadocTagInfoTest method testOthers.
@Test
public void testOthers() throws ReflectiveOperationException {
final JavadocTagInfo[] tags = { JavadocTagInfo.CODE, JavadocTagInfo.DOC_ROOT, JavadocTagInfo.LINK, JavadocTagInfo.LINKPLAIN, JavadocTagInfo.LITERAL, JavadocTagInfo.SEE, JavadocTagInfo.SINCE, JavadocTagInfo.VALUE };
for (JavadocTagInfo tagInfo : tags) {
final DetailAstImpl astParent = new DetailAstImpl();
astParent.setType(TokenTypes.LITERAL_CATCH);
final DetailAstImpl ast = new DetailAstImpl();
final Method setParent = ast.getClass().getDeclaredMethod("setParent", DetailAstImpl.class);
setParent.setAccessible(true);
setParent.invoke(ast, astParent);
final int[] validTypes = { TokenTypes.PACKAGE_DEF, TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF, TokenTypes.ENUM_DEF, TokenTypes.ANNOTATION_DEF, TokenTypes.METHOD_DEF, TokenTypes.CTOR_DEF, TokenTypes.VARIABLE_DEF };
for (int type : validTypes) {
ast.setType(type);
assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(tagInfo.isValidOn(ast)).isTrue();
}
astParent.setType(TokenTypes.SLIST);
ast.setType(TokenTypes.VARIABLE_DEF);
assertWithMessage("Should return false when ast type is invalid for current tag").that(tagInfo.isValidOn(ast)).isFalse();
ast.setType(TokenTypes.PARAMETER_DEF);
assertWithMessage("Should return false when ast type is invalid for current tag").that(tagInfo.isValidOn(ast)).isFalse();
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class JavadocTagInfoTest method testException.
@Test
public void testException() {
final DetailAstImpl ast = new DetailAstImpl();
final int[] validTypes = { TokenTypes.METHOD_DEF, TokenTypes.CTOR_DEF };
for (int type : validTypes) {
ast.setType(type);
assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.EXCEPTION.isValidOn(ast)).isTrue();
}
ast.setType(TokenTypes.LAMBDA);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.EXCEPTION.isValidOn(ast)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ExecutableStatementCountCheckTest method testVisitTokenWithWrongTokenType.
@Test
public void testVisitTokenWithWrongTokenType() {
final ExecutableStatementCountCheck checkObj = new ExecutableStatementCountCheck();
final DetailAstImpl ast = new DetailAstImpl();
ast.initialize(new CommonToken(TokenTypes.ENUM, "ENUM"));
try {
checkObj.visitToken(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 testContainsAnnotationWithStringFalse.
@Test
public void testContainsAnnotationWithStringFalse() {
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();
annotations.setType(TokenTypes.ANNOTATIONS);
annotation.setType(TokenTypes.ANNOTATION);
annotationNameHolder.setType(TokenTypes.AT);
annotationName.setText("Annotation");
annotationNameHolder.setNextSibling(annotationName);
annotation.setFirstChild(annotationNameHolder);
annotations.setFirstChild(annotation);
child.setNextSibling(annotations);
astForTest.setFirstChild(child);
assertWithMessage("Annotation should not contain " + astForTest).that(AnnotationUtil.containsAnnotation(astForTest, "AnnotationBad")).isFalse();
}
Aggregations