aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac/handlers/HandleFieldNameConstants.java
diff options
context:
space:
mode:
authorAdam Juraszek <Adam.Juraszek@ataccama.com>2019-05-09 08:29:52 +0200
committerAdam Juraszek <Adam.Juraszek@ataccama.com>2019-05-14 18:47:07 +0200
commit4ea4b8d27bb13ad71e3cce2312dce6d488959fd7 (patch)
treee567901b74a3db9f21858530e26c2338e06af7df /src/core/lombok/javac/handlers/HandleFieldNameConstants.java
parentc479920db17e36392fa69e386156c982fe60cc27 (diff)
downloadlombok-4ea4b8d27bb13ad71e3cce2312dce6d488959fd7.tar.gz
lombok-4ea4b8d27bb13ad71e3cce2312dce6d488959fd7.tar.bz2
lombok-4ea4b8d27bb13ad71e3cce2312dce6d488959fd7.zip
IdentifierName instead of String
Diffstat (limited to 'src/core/lombok/javac/handlers/HandleFieldNameConstants.java')
-rw-r--r--src/core/lombok/javac/handlers/HandleFieldNameConstants.java23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/core/lombok/javac/handlers/HandleFieldNameConstants.java b/src/core/lombok/javac/handlers/HandleFieldNameConstants.java
index 628e83dc..ec4015c7 100644
--- a/src/core/lombok/javac/handlers/HandleFieldNameConstants.java
+++ b/src/core/lombok/javac/handlers/HandleFieldNameConstants.java
@@ -30,6 +30,7 @@ import lombok.AccessLevel;
import lombok.ConfigurationKeys;
import lombok.core.AST.Kind;
import lombok.core.AnnotationValues;
+import lombok.core.configuration.IdentifierName;
import lombok.core.handlers.HandlerUtil;
import lombok.experimental.FieldNameConstants;
import lombok.javac.JavacAnnotationHandler;
@@ -54,7 +55,9 @@ import com.sun.tools.javac.util.Name;
@ProviderFor(JavacAnnotationHandler.class)
public class HandleFieldNameConstants extends JavacAnnotationHandler<FieldNameConstants> {
- public void generateFieldNameConstantsForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean asEnum, String innerTypeName, boolean onlyExplicit, boolean uppercase) {
+ private static final IdentifierName FIELDS = IdentifierName.valueOf("Fields");
+
+ public void generateFieldNameConstantsForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean asEnum, IdentifierName innerTypeName, boolean onlyExplicit, boolean uppercase) {
JCClassDecl typeDecl = null;
if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get();
@@ -115,24 +118,30 @@ public class HandleFieldNameConstants extends JavacAnnotationHandler<FieldNameCo
return;
}
- String innerTypeName = annotationInstance.innerTypeName();
- if (innerTypeName.isEmpty()) innerTypeName = annotationNode.getAst().readConfiguration(ConfigurationKeys.FIELD_NAME_CONSTANTS_INNER_TYPE_NAME);
- if (innerTypeName == null || innerTypeName.isEmpty()) innerTypeName = "Fields";
+ IdentifierName innerTypeName;
+ try {
+ innerTypeName = IdentifierName.valueOf(annotationInstance.innerTypeName());
+ } catch(IllegalArgumentException e) {
+ annotationNode.addError("InnerTypeName " + annotationInstance.innerTypeName() + " is not a valid Java identifier.");
+ return;
+ }
+ if (innerTypeName == null) innerTypeName = annotationNode.getAst().readConfiguration(ConfigurationKeys.FIELD_NAME_CONSTANTS_INNER_TYPE_NAME);
+ if (innerTypeName == null) innerTypeName = FIELDS;
Boolean uppercase = annotationNode.getAst().readConfiguration(ConfigurationKeys.FIELD_NAME_CONSTANTS_UPPERCASE);
if (uppercase == null) uppercase = false;
generateFieldNameConstantsForType(node, annotationNode, level, asEnum, innerTypeName, annotationInstance.onlyExplicitlyIncluded(), uppercase);
}
- private void createInnerTypeFieldNameConstants(JavacNode typeNode, JavacNode errorNode, JCTree pos, AccessLevel level, java.util.List<JavacNode> fields, boolean asEnum, String innerTypeName, boolean uppercase) {
+ private void createInnerTypeFieldNameConstants(JavacNode typeNode, JavacNode errorNode, JCTree pos, AccessLevel level, java.util.List<JavacNode> fields, boolean asEnum, IdentifierName innerTypeName, boolean uppercase) {
if (fields.isEmpty()) return;
JavacTreeMaker maker = typeNode.getTreeMaker();
JCModifiers mods = maker.Modifiers(toJavacModifier(level) | (asEnum ? Flags.ENUM : Flags.STATIC | Flags.FINAL));
- Name fieldsName = typeNode.toName(innerTypeName);
+ Name fieldsName = typeNode.toName(innerTypeName.getName());
- JavacNode fieldsType = findInnerClass(typeNode, innerTypeName);
+ JavacNode fieldsType = findInnerClass(typeNode, innerTypeName.getName());
boolean genConstr = false;
if (fieldsType == null) {
JCClassDecl innerType = maker.ClassDef(mods, fieldsName, List.<JCTypeParameter>nil(), null, List.<JCExpression>nil(), List.<JCTree>nil());