From deac7023f712b2d16ec6e730627d1c848450efef Mon Sep 17 00:00:00 2001 From: Herman Polderman Date: Wed, 17 Sep 2014 22:34:25 +0200 Subject: fix javac modifiers in src/core/lombok/javac/handlers/HandleFieldConstants.java --- .../javac/handlers/HandleFieldConstants.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src') 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 -- cgit