[trivial] error out on mismatch between FieldNameConstants asEnum flag and actual handwritten type.

This commit is contained in:
Reinier Zwitserloot committed 2018-11-01 16:43:25 +01:00
1 parent 2fd46a50b6
commit 4acda73319
2 files changed
+12 -4

No files matched your search

@@ -132,8 +132,12 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler<FieldName
genClinit = asEnum;
} else {
TypeDeclaration builderTypeDeclaration = (TypeDeclaration) fieldsType.get();
if ((builderTypeDeclaration.modifiers & (ClassFileConstants.AccEnum | ClassFileConstants.AccStatic)) == 0) {
errorNode.addError("Existing " + innerTypeName + " must be declared as an 'enum' or a 'static class'.");
if (asEnum && (builderTypeDeclaration.modifiers & ClassFileConstants.AccEnum) == 0) {
errorNode.addError("Existing " + innerTypeName + " must be declared as an 'enum'.");
return;
}
if (!asEnum && (builderTypeDeclaration.modifiers & ClassFileConstants.AccStatic) == 0) {
errorNode.addError("Existing " + innerTypeName + " must be declared as a 'static class'.");
return;
}
genConstr = constructorExists(fieldsType) == MemberExistsResult.NOT_EXISTS;
@@ -139,8 +139,12 @@ public class HandleFieldNameConstants extends JavacAnnotationHandler<FieldNameCo
} else {
JCClassDecl builderTypeDeclaration = (JCClassDecl) fieldsType.get();
long f = builderTypeDeclaration.getModifiers().flags;
if ((f & (Flags.STATIC | Flags.ENUM)) == 0) {
errorNode.addError("Existing " + innerTypeName + " must be declared as an 'enum' or a 'static class'.");
if (asEnum && (f & Flags.ENUM) == 0) {
errorNode.addError("Existing " + innerTypeName + " must be declared as an 'enum'.");
return;
}
if (!asEnum && (f & Flags.STATIC) == 0) {
errorNode.addError("Existing " + innerTypeName + " must be declared as a 'static class'.");
return;
}
genConstr = constructorExists(fieldsType) == MemberExistsResult.NOT_EXISTS;