use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class TokenUtilTest method testFindFirstTokenByPredicate.
@Test
public void testFindFirstTokenByPredicate() {
final DetailAstImpl astForTest = new DetailAstImpl();
final DetailAstImpl child = new DetailAstImpl();
final DetailAstImpl firstSibling = new DetailAstImpl();
final DetailAstImpl secondSibling = new DetailAstImpl();
final DetailAstImpl thirdSibling = new DetailAstImpl();
firstSibling.setText("first");
secondSibling.setText("second");
thirdSibling.setText("third");
secondSibling.setNextSibling(thirdSibling);
firstSibling.setNextSibling(secondSibling);
child.setNextSibling(firstSibling);
astForTest.setFirstChild(child);
final Optional<DetailAST> result = TokenUtil.findFirstTokenByPredicate(astForTest, ast -> "second".equals(ast.getText()));
assertWithMessage("Invalid second sibling").that(result.orElse(null)).isEqualTo(secondSibling);
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class AnnotationUtilTest method create.
private static DetailAstImpl create(int tokenType, DetailAstImpl child) {
final DetailAstImpl ast = create(tokenType);
ast.addChild(child);
return ast;
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class AnnotationUtilTest method testContainsAnnotation.
@Test
public void testContainsAnnotation() {
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 contain " + astForTest).that(AnnotationUtil.containsAnnotation(astForTest, "Annotation")).isTrue();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class AnnotationUtilTest method testContainsAnnotationTrue.
@Test
public void testContainsAnnotationTrue() {
final DetailAstImpl ast = new DetailAstImpl();
ast.setType(1);
final DetailAstImpl ast2 = new DetailAstImpl();
ast2.setType(TokenTypes.MODIFIERS);
ast.addChild(ast2);
final DetailAstImpl ast3 = new DetailAstImpl();
ast3.setType(TokenTypes.ANNOTATION);
ast2.addChild(ast3);
assertWithMessage("AnnotationUtil should contain " + ast).that(AnnotationUtil.containsAnnotation(ast)).isTrue();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class AnnotationUtilTest method testContainsAnnotationListWithNoAnnotationNode.
@Test
public void testContainsAnnotationListWithNoAnnotationNode() {
final DetailAstImpl ast = new DetailAstImpl();
final DetailAstImpl modifiersAst = new DetailAstImpl();
modifiersAst.setType(TokenTypes.MODIFIERS);
ast.addChild(modifiersAst);
final List<String> annotations = Collections.singletonList("Override");
final boolean result = AnnotationUtil.containsAnnotation(ast, annotations);
assertWithMessage("An empty ast should lead to a false result").that(result).isFalse();
}
Aggregations