aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/lombok/javac/handlers/HandleFieldConstants.java22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/core/lombok/javac/handlers/HandleFieldConstants.java b/src/core/lombok/javac/handlers/HandleFieldConstants.java
index 5fe92ab6..45943a33 100644
--- a/src/core/lombok/javac/handlers/HandleFieldConstants.java
+++ b/src/core/lombok/javac/handlers/HandleFieldConstants.java
@@ -86,7 +86,7 @@ import com.sun.tools.javac.util.List;
break;
case TYPE:
if (!onMethod.isEmpty()) {
- annotationNode.addError("'onMethod' is not supported for @FieldConstants on a type.");
+ annotationNode.addError("'onMethod' is not supported for @FieldNameConstants on a type.");
}
generateFieldDefaultsForType(node, annotationNode, level, false);
break;
@@ -105,18 +105,34 @@ import com.sun.tools.javac.util.List;
return;
}
JCVariableDecl field = (JCVariableDecl) fieldNode.get();
- String constantName = lombok.eclipse.handlers.HandleFieldNameConstants.camelCaseToConstant(field.name.toString());
+ String constantName = camelCaseToConstant(field.name.toString());
if (constantName == null) {
source.addWarning("Not generating constant for this field: It does not fit in your @Accessors prefix list");
return;
}
JavacTreeMaker treeMaker = fieldNode.getTreeMaker();
- JCModifiers modifiers = treeMaker.Modifiers(toJavacModifier(level) & Modifier.STATIC & Modifier.FINAL);
+ JCModifiers modifiers = treeMaker.Modifiers(toJavacModifier(level) | Modifier.STATIC | Modifier.FINAL);
JCExpression returnType = chainDots(fieldNode, "java", "lang", "String");
JCExpression init = treeMaker.Literal(fieldNode.getName());
JCVariableDecl fieldConstant = treeMaker.VarDef(modifiers, fieldNode.toName(constantName), returnType, init);
injectField(fieldNode.up(), fieldConstant);
}
+ public static String camelCaseToConstant(final String fieldName) {
+ if (fieldName == null || fieldName.isEmpty()) return "";
+ char[] chars = fieldName.toCharArray();
+ StringBuilder b = new StringBuilder();
+ b.append(Character.toUpperCase(chars[0]));
+ for (int i = 1, iend = chars.length; i < iend; i++) {
+ char c = chars[i];
+ if (Character.isUpperCase(c)) {
+ b.append('_');
+ } else {
+ c = Character.toUpperCase(c);
+ }
+ b.append(c);
+ }
+ return b.toString();
+ }
} \ No newline at end of file