use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class JavadocTagInfoTest method testParam.
@Test
public void testParam() {
final DetailAstImpl ast = new DetailAstImpl();
final int[] validTypes = { TokenTypes.CLASS_DEF, TokenTypes.INTERFACE_DEF, TokenTypes.METHOD_DEF, TokenTypes.CTOR_DEF };
for (int type : validTypes) {
ast.setType(type);
assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.PARAM.isValidOn(ast)).isTrue();
}
ast.setType(TokenTypes.LAMBDA);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.PARAM.isValidOn(ast)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class JavadocTagInfoTest method testThrows.
@Test
public void testThrows() {
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.THROWS.isValidOn(ast)).isTrue();
}
ast.setType(TokenTypes.LAMBDA);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.THROWS.isValidOn(ast)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class JavadocTagInfoTest method testReturn.
@Test
public void testReturn() {
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.LITERAL_INT);
astChild.setFirstChild(astChild2);
final int[] validTypes = { TokenTypes.METHOD_DEF };
for (int type : validTypes) {
ast.setType(type);
assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.RETURN.isValidOn(ast)).isTrue();
}
astChild2.setType(TokenTypes.LITERAL_VOID);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.RETURN.isValidOn(ast)).isFalse();
ast.setType(TokenTypes.LAMBDA);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.RETURN.isValidOn(ast)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class JavadocTagInfoTest method testSerial.
@Test
public void testSerial() throws ReflectiveOperationException {
final DetailAstImpl ast = new DetailAstImpl();
final DetailAstImpl astParent = new DetailAstImpl();
astParent.setType(TokenTypes.LITERAL_CATCH);
final Method setParent = ast.getClass().getDeclaredMethod("setParent", DetailAstImpl.class);
setParent.setAccessible(true);
setParent.invoke(ast, astParent);
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.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(JavadocTagInfo.SERIAL.isValidOn(ast)).isFalse();
ast.setType(TokenTypes.PARAMETER_DEF);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.SERIAL.isValidOn(ast)).isFalse();
}
use of com.puppycrawl.tools.checkstyle.DetailAstImpl in project checkstyle by checkstyle.
the class JavadocTagInfoTest method testSerialData.
@Test
public void testSerialData() {
final DetailAstImpl ast = new DetailAstImpl();
ast.setType(TokenTypes.METHOD_DEF);
final DetailAstImpl astChild = new DetailAstImpl();
astChild.setType(TokenTypes.IDENT);
astChild.setText("writeObject");
ast.setFirstChild(astChild);
final String[] validNames = { "writeObject", "readObject", "writeExternal", "readExternal", "writeReplace", "readResolve" };
for (String name : validNames) {
astChild.setText(name);
assertWithMessage("Invalid ast type for current tag: " + ast.getType()).that(JavadocTagInfo.SERIAL_DATA.isValidOn(ast)).isTrue();
}
astChild.setText("1111");
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.SERIAL_DATA.isValidOn(ast)).isFalse();
ast.setType(TokenTypes.LAMBDA);
assertWithMessage("Should return false when ast type is invalid for current tag").that(JavadocTagInfo.SERIAL_DATA.isValidOn(ast)).isFalse();
}
Aggregations