use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class FullIdentTest method prepareFullIdentWithCoordinates.
private static FullIdent prepareFullIdentWithCoordinates(int columnNo, int lineNo) {
final DetailAstImpl parent = new DetailAstImpl();
parent.setType(TokenTypes.TYPE);
parent.setColumnNo(1);
parent.setLineNo(1);
parent.setText("Parent");
final DetailAstImpl ast = new DetailAstImpl();
ast.setType(TokenTypes.DOT);
ast.setColumnNo(1);
ast.setLineNo(2);
ast.setText("Root");
final DetailAstImpl ast2 = new DetailAstImpl();
ast2.setType(TokenTypes.LE);
ast2.setColumnNo(columnNo);
ast2.setLineNo(lineNo);
ast2.setText("MyTestik");
final DetailAstImpl ast1 = new DetailAstImpl();
ast1.setType(TokenTypes.LITERAL_NEW);
ast1.setColumnNo(14);
ast1.setLineNo(15);
ast1.setText("MyTest");
parent.addChild(ast);
ast.addChild(ast1);
ast.addChild(ast2);
return FullIdent.createFullIdent(ast);
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class FullIdentTest method testToString.
@Test
public void testToString() {
final DetailAstImpl ast = new DetailAstImpl();
ast.setType(TokenTypes.LITERAL_NEW);
ast.setColumnNo(14);
ast.setLineNo(15);
ast.setText("MyTest");
final DetailAstImpl parent = new DetailAstImpl();
parent.setType(TokenTypes.OBJBLOCK);
parent.setColumnNo(4);
parent.setLineNo(4);
parent.setText("MyParent");
parent.setFirstChild(ast);
final FullIdent indent = FullIdent.createFullIdent(ast);
assertWithMessage("Invalid full indent").that(indent.toString()).isEqualTo("MyTest[15x14]");
assertWithMessage("Invalid text").that(indent.getText()).isEqualTo("MyTest");
assertWithMessage("Invalid line").that(indent.getLineNo()).isEqualTo(15);
assertWithMessage("Invalid column").that(indent.getColumnNo()).isEqualTo(14);
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class SuppressWarningsHolderTest method testGetAnnotationValuesWrongArg.
@Test
public void testGetAnnotationValuesWrongArg() throws ReflectiveOperationException {
final SuppressWarningsHolder holder = new SuppressWarningsHolder();
final Method getAllAnnotationValues = holder.getClass().getDeclaredMethod("getAnnotationValues", DetailAST.class);
getAllAnnotationValues.setAccessible(true);
final DetailAstImpl methodDef = new DetailAstImpl();
methodDef.setType(TokenTypes.METHOD_DEF);
methodDef.setText("Method Def");
methodDef.setLineNo(0);
methodDef.setColumnNo(0);
try {
getAllAnnotationValues.invoke(holder, methodDef);
assertWithMessage("Exception expected").fail();
} catch (ReflectiveOperationException ex) {
assertWithMessage("Error type is unexpected").that(ex).hasCauseThat().isInstanceOf(IllegalArgumentException.class);
assertWithMessage("Error message is unexpected").that(ex).hasCauseThat().hasMessageThat().isEqualTo("Expression or annotation array initializer AST expected: " + "Method Def[0x0]");
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class ThrowsCountCheckTest method testWrongTokenType.
@Test
public void testWrongTokenType() {
final ThrowsCountCheck obj = new ThrowsCountCheck();
final DetailAstImpl ast = new DetailAstImpl();
ast.initialize(new CommonToken(TokenTypes.CLASS_DEF, "class"));
try {
obj.visitToken(ast);
assertWithMessage("IllegalStateException is expected").fail();
} catch (IllegalStateException ex) {
assertWithMessage("Invalid exception message").that(ex.getMessage()).isEqualTo(ast.toString());
}
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class JavadocTagInfoTest method testSerialField.
@Test
public void testSerialField() {
final DetailAstImpl ast = new DetailAstImpl();
final DetailAstImpl astChild = new DetailAstImpl();
astChild.setType(TokenTypes.TYPE);
ast.setFirstChild(astChild);
final DetailAstImpl astChild2 = new DetailAstImpl();
astChild2.setType(TokenTypes.ARRAY_DECLARATOR);
astChild2.setText("ObjectStreamField");
astChild.setFirstChild(astChild2);
final int[] validTypes = { TokenTypes.VARIABLE_DEF };
for (int type : validTypes) {
ast.setType(type);
assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.SERIAL_FIELD.isValidOn(ast)).isTrue();
}
astChild2.setText("1111");
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.SERIAL_FIELD.isValidOn(ast)).isFalse();
astChild2.setType(TokenTypes.LITERAL_VOID);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.SERIAL_FIELD.isValidOn(ast)).isFalse();
ast.setType(TokenTypes.LAMBDA);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.SERIAL_FIELD.isValidOn(ast)).isFalse();
}
Aggregations