use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class AnnotationUtilTest method testContainsAnnotationListWithEmptyList.
@Test
public void testContainsAnnotationListWithEmptyList() {
final DetailAST ast = new DetailAstImpl();
final List<String> annotations = new ArrayList<>();
final boolean result = AnnotationUtil.containsAnnotation(ast, annotations);
assertWithMessage("An empty list should lead to a false result").that(result).isFalse();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class AnnotationUtilTest method create.
private static DetailAstImpl create(int tokenType, String text) {
final DetailAstImpl ast = create(tokenType);
ast.setText(text);
return ast;
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class CheckUtilTest method testGetFirstNode2.
@Test
public void testGetFirstNode2() {
final DetailAstImpl child = new DetailAstImpl();
child.setLineNo(6);
child.setColumnNo(5);
final DetailAstImpl root = new DetailAstImpl();
root.setLineNo(5);
root.setColumnNo(6);
root.addChild(child);
final DetailAST firstNode = CheckUtil.getFirstNode(root);
assertWithMessage("Unexpected node").that(firstNode).isEqualTo(root);
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class CheckUtilTest method testEquals.
@Test
public void testEquals() {
final DetailAstImpl litStatic = new DetailAstImpl();
litStatic.setType(TokenTypes.LITERAL_STATIC);
final DetailAstImpl modifiers = new DetailAstImpl();
modifiers.setType(TokenTypes.MODIFIERS);
modifiers.addChild(litStatic);
final DetailAstImpl metDef = new DetailAstImpl();
metDef.setType(TokenTypes.METHOD_DEF);
metDef.addChild(modifiers);
assertWithMessage("Invalid result: ast is not equals method").that(CheckUtil.isEqualsMethod(metDef)).isFalse();
metDef.removeChildren();
final DetailAstImpl metName = new DetailAstImpl();
metName.setType(TokenTypes.IDENT);
metName.setText("equals");
metDef.addChild(metName);
final DetailAstImpl modifiers2 = new DetailAstImpl();
modifiers2.setType(TokenTypes.MODIFIERS);
metDef.addChild(modifiers2);
final DetailAstImpl parameter1 = new DetailAstImpl();
final DetailAstImpl parameter2 = new DetailAstImpl();
final DetailAstImpl parameters = new DetailAstImpl();
parameters.setType(TokenTypes.PARAMETERS);
parameters.addChild(parameter2);
parameters.addChild(parameter1);
metDef.addChild(parameters);
assertWithMessage("Invalid result: ast is not equals method").that(CheckUtil.isEqualsMethod(metDef)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class CheckUtilTest method testGetAccessModifierFromModifiersTokenWrongTokenType.
@Test
public void testGetAccessModifierFromModifiersTokenWrongTokenType() {
final DetailAstImpl modifiers = new DetailAstImpl();
modifiers.setType(TokenTypes.METHOD_DEF);
try {
CheckUtil.getAccessModifierFromModifiersToken(modifiers);
assertWithMessage("%s was expected.", IllegalArgumentException.class.getSimpleName()).fail();
} catch (IllegalArgumentException exc) {
final String expectedExceptionMsg = "expected non-null AST-token with type 'MODIFIERS'";
final String actualExceptionMsg = exc.getMessage();
assertWithMessage("Invalid exception message").that(actualExceptionMsg).isEqualTo(expectedExceptionMsg);
}
}
Aggregations