From 5c101911202aa9c15e99e898a62ba935e9e3846e Mon Sep 17 00:00:00 2001
From: Roel Spilker
Date: Wed, 1 May 2019 00:08:53 +0200
Subject: Update documentation
---
src/core/lombok/ConfigurationKeys.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
(limited to 'src/core/lombok/ConfigurationKeys.java')
diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java
index 2b406dbe..ad39f0af 100644
--- a/src/core/lombok/ConfigurationKeys.java
+++ b/src/core/lombok/ConfigurationKeys.java
@@ -51,7 +51,7 @@ public class ConfigurationKeys {
*
* If {@code true}, lombok generates {@code @javax.annotation.Generated("lombok")} on all fields, methods, and types that are generated, unless {@code lombok.addJavaxGeneratedAnnotation} is set.
*
- * BREAKING CHANGE: Starting with lombok v2.0.0, defaults to {@code false} instead of {@code true}, as this annotation is broken in JDK9.
+ * BREAKING CHANGE: Starting with lombok v1.16.20, defaults to {@code false} instead of {@code true}, as this annotation is broken in JDK9.
*
* @see ConfigurationKeys#ADD_JAVAX_GENERATED_ANNOTATIONS
* @see ConfigurationKeys#ADD_LOMBOK_GENERATED_ANNOTATIONS
@@ -65,7 +65,7 @@ public class ConfigurationKeys {
*
* If {@code true}, lombok generates {@code @javax.annotation.Generated("lombok")} on all fields, methods, and types that are generated.
*
- * BREAKING CHANGE: Starting with lombok v2.0.0, defaults to {@code false} instead of {@code true}, as this annotation is broken in JDK9.
+ * BREAKING CHANGE: Starting with lombok v1.16.20, defaults to {@code false} instead of {@code true}, as this annotation is broken in JDK9.
*/
public static final ConfigurationKey ADD_JAVAX_GENERATED_ANNOTATIONS = new ConfigurationKey("lombok.addJavaxGeneratedAnnotation", "Generate @javax.annotation.Generated on all generated code (default: follow lombok.addGeneratedAnnotation).") {};
@@ -103,7 +103,7 @@ public class ConfigurationKeys {
* NB: GWT projects, and probably android projects, should explicitly set this key to {@code true} for the entire project.
*
*
- * BREAKING CHANGE: Starting with lombok v2.0.0, defaults to {@code false} instead of {@code true}, as {@code @ConstructorProperties} requires extra modules in JDK9.
+ * BREAKING CHANGE: Starting with lombok v1.16.20, defaults to {@code false} instead of {@code true}, as {@code @ConstructorProperties} requires extra modules in JDK9.
*
* @see ConfigurationKeys#ANY_CONSTRUCTOR_ADD_CONSTRUCTOR_PROPERTIES
* @deprecated Since version 2.0, use {@link #ANY_CONSTRUCTOR_ADD_CONSTRUCTOR_PROPERTIES} instead.
--
cgit
From bf0499263b05e11fdd43886df3dc5663c8fee5f4 Mon Sep 17 00:00:00 2001
From: Reinier Zwitserloot
Date: Wed, 1 May 2019 01:33:57 +0200
Subject: [issue #2092] Add an uppercase option to FieldNameConstants
---
doc/changelog.markdown | 1 +
src/core/lombok/ConfigurationKeys.java | 9 ++++++++-
.../eclipse/handlers/HandleFieldNameConstants.java | 12 +++++++----
.../javac/handlers/HandleFieldNameConstants.java | 14 ++++++++-----
.../FieldNameConstantsUppercased.java | 12 +++++++++++
.../after-ecj/FieldNameConstantsUppercased.java | 23 ++++++++++++++++++++++
.../before/FieldNameConstantsUppercased.java | 12 +++++++++++
.../features/experimental/FieldNameConstants.html | 8 +++++++-
8 files changed, 80 insertions(+), 11 deletions(-)
create mode 100644 test/transform/resource/after-delombok/FieldNameConstantsUppercased.java
create mode 100644 test/transform/resource/after-ecj/FieldNameConstantsUppercased.java
create mode 100644 test/transform/resource/before/FieldNameConstantsUppercased.java
(limited to 'src/core/lombok/ConfigurationKeys.java')
diff --git a/doc/changelog.markdown b/doc/changelog.markdown
index 614848cb..89ce9929 100644
--- a/doc/changelog.markdown
+++ b/doc/changelog.markdown
@@ -2,6 +2,7 @@ Lombok Changelog
----------------
### v1.18.7 "Edgy Guinea Pig"
+* FEATURE: You can now configure `@FieldNameConstants` to `CONSTANT_CASE` the generated constants, using a `lombok.config` option. See the [FieldNameConstants documentation](https://projectlombok.org/features/experimental/FieldNameConstants). [Issue #2092](https://github.com/rzwitserloot/lombok/issues/2092).
* FEATURE: You can now suppress generation of the `builder` method when using `@Builder`; usually because you're only interested in the `toBuilder` method. As a convenience we won't emit warnings about missing `@Builder.Default` annotations when you do this. [Issue #2046](https://github.com/rzwitserloot/lombok/issues/2046)
* FEATURE: You can now change the access modifier of generated builder classes. [Issue #2083](https://github.com/rzwitserloot/lombok/issues/2083).
* FEATURE: When using `@NonNull`, or any other annotation that would result in a null-check, you can configure to generate an assert statement instead. [Issue #2078](https://github.com/rzwitserloot/lombok/issues/2078).
diff --git a/src/core/lombok/ConfigurationKeys.java b/src/core/lombok/ConfigurationKeys.java
index ad39f0af..84b594f5 100644
--- a/src/core/lombok/ConfigurationKeys.java
+++ b/src/core/lombok/ConfigurationKeys.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013-2018 The Project Lombok Authors.
+ * Copyright (C) 2013-2019 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -543,6 +543,13 @@ public class ConfigurationKeys {
*/
public static final ConfigurationKey FIELD_NAME_CONSTANTS_INNER_TYPE_NAME = new ConfigurationKey("lombok.fieldNameConstants.innerTypeName", "The default name of the inner type generated by @FieldNameConstants. (default: 'Fields').") {};
+ /**
+ * lombok configuration: {@code lombok.fieldNameConstants.uppercase} = {@code true} | {@code false}.
+ *
+ * If true, names of constants generated by {@code @FieldNameConstants} will be UPPER_CASED_LIKE_A_CONSTANT. (Default: {@code false}).
+ */
+ public static final ConfigurationKey FIELD_NAME_CONSTANTS_UPPERCASE = new ConfigurationKey("lombok.fieldNameConstants.uppercase", "The default name of the constants inside the inner type generated by @FieldNameConstants follow the variable name precisely. If this config key is true, lombok will uppercase them as best it can. (default: false).") {};
+
// ----- Wither -----
/**
diff --git a/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java b/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java
index 1caccd59..574c1f41 100644
--- a/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java
+++ b/src/core/lombok/eclipse/handlers/HandleFieldNameConstants.java
@@ -47,6 +47,7 @@ import lombok.AccessLevel;
import lombok.ConfigurationKeys;
import lombok.core.AST.Kind;
import lombok.core.AnnotationValues;
+import lombok.core.handlers.HandlerUtil;
import lombok.eclipse.Eclipse;
import lombok.eclipse.EclipseAnnotationHandler;
import lombok.eclipse.EclipseNode;
@@ -55,7 +56,7 @@ import lombok.experimental.FieldNameConstants;
@ProviderFor(EclipseAnnotationHandler.class)
public class HandleFieldNameConstants extends EclipseAnnotationHandler {
- public void generateFieldNameConstantsForType(EclipseNode typeNode, EclipseNode errorNode, AccessLevel level, boolean asEnum, String innerTypeName, boolean onlyExplicit) {
+ public void generateFieldNameConstantsForType(EclipseNode typeNode, EclipseNode errorNode, AccessLevel level, boolean asEnum, String innerTypeName, boolean onlyExplicit, boolean uppercase) {
TypeDeclaration typeDecl = null;
if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get();
@@ -76,7 +77,7 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler fields, boolean asEnum, String innerTypeName) {
+ private void createInnerTypeFieldNameConstants(EclipseNode typeNode, EclipseNode errorNode, ASTNode source, AccessLevel level, List fields, boolean asEnum, String innerTypeName, boolean uppercase) {
if (fields.isEmpty()) return;
ASTVisitor generatedByVisitor = new SetGeneratedByVisitor(source);
@@ -169,6 +172,7 @@ public class HandleFieldNameConstants extends EclipseAnnotationHandler {
- public void generateFieldNameConstantsForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean asEnum, String innerTypeName, boolean onlyExplicit) {
+ public void generateFieldNameConstantsForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean asEnum, String innerTypeName, boolean onlyExplicit, boolean uppercase) {
JCClassDecl typeDecl = null;
if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get();
@@ -74,7 +75,7 @@ public class HandleFieldNameConstants extends JavacAnnotationHandler fields, boolean asEnum, String innerTypeName) {
+ private void createInnerTypeFieldNameConstants(JavacNode typeNode, JavacNode errorNode, JCTree pos, AccessLevel level, java.util.List fields, boolean asEnum, String innerTypeName, boolean uppercase) {
if (fields.isEmpty()) return;
JavacTreeMaker maker = typeNode.getTreeMaker();
@@ -161,6 +164,7 @@ public class HandleFieldNameConstants extends JavacAnnotationHandler generated = new ArrayList();
for (JavacNode field : fields) {
Name fName = ((JCVariableDecl) field.get()).name;
+ if (uppercase) fName = typeNode.toName(HandlerUtil.camelCaseToConstant(fName.toString()));
if (fieldExists(fName.toString(), fieldsType) != MemberExistsResult.NOT_EXISTS) continue;
JCModifiers constantValueMods = maker.Modifiers(Flags.PUBLIC | Flags.STATIC | Flags.FINAL | (asEnum ? Flags.ENUM : 0L));
JCExpression returnType;
diff --git a/test/transform/resource/after-delombok/FieldNameConstantsUppercased.java b/test/transform/resource/after-delombok/FieldNameConstantsUppercased.java
new file mode 100644
index 00000000..dd7de86a
--- /dev/null
+++ b/test/transform/resource/after-delombok/FieldNameConstantsUppercased.java
@@ -0,0 +1,12 @@
+public class FieldNameConstantsUppercased {
+ String iAmADvdPlayer;
+ int $skipMe;
+ static double skipMeToo;
+ int andMe;
+ String butPrintMePlease;
+ @java.lang.SuppressWarnings("all")
+ static final class Fields {
+ public static final java.lang.String I_AM_A_DVD_PLAYER = "iAmADvdPlayer";
+ public static final java.lang.String BUT_PRINT_ME_PLEASE = "butPrintMePlease";
+ }
+}
diff --git a/test/transform/resource/after-ecj/FieldNameConstantsUppercased.java b/test/transform/resource/after-ecj/FieldNameConstantsUppercased.java
new file mode 100644
index 00000000..a858b91f
--- /dev/null
+++ b/test/transform/resource/after-ecj/FieldNameConstantsUppercased.java
@@ -0,0 +1,23 @@
+import lombok.experimental.FieldNameConstants;
+import lombok.AccessLevel;
+public @FieldNameConstants(level = AccessLevel.PACKAGE) class FieldNameConstantsUppercased {
+ static final @java.lang.SuppressWarnings("all") class Fields {
+ public static final java.lang.String I_AM_A_DVD_PLAYER = "iAmADvdPlayer";
+ public static final java.lang.String BUT_PRINT_ME_PLEASE = "butPrintMePlease";
+ () {
+ }
+ private @java.lang.SuppressWarnings("all") Fields() {
+ super();
+ }
+ }
+ String iAmADvdPlayer;
+ int $skipMe;
+ static double skipMeToo;
+ @FieldNameConstants.Exclude int andMe;
+ String butPrintMePlease;
+ () {
+ }
+ public FieldNameConstantsUppercased() {
+ super();
+ }
+}
\ No newline at end of file
diff --git a/test/transform/resource/before/FieldNameConstantsUppercased.java b/test/transform/resource/before/FieldNameConstantsUppercased.java
new file mode 100644
index 00000000..674cb7f1
--- /dev/null
+++ b/test/transform/resource/before/FieldNameConstantsUppercased.java
@@ -0,0 +1,12 @@
+//CONF: lombok.fieldNameConstants.uppercase = true
+import lombok.experimental.FieldNameConstants;
+import lombok.AccessLevel;
+
+@FieldNameConstants(level = AccessLevel.PACKAGE)
+public class FieldNameConstantsUppercased {
+ String iAmADvdPlayer;
+ int $skipMe;
+ static double skipMeToo;
+ @FieldNameConstants.Exclude int andMe;
+ String butPrintMePlease;
+}
diff --git a/website/templates/features/experimental/FieldNameConstants.html b/website/templates/features/experimental/FieldNameConstants.html
index 1cbef32a..e88b7670 100644
--- a/website/templates/features/experimental/FieldNameConstants.html
+++ b/website/templates/features/experimental/FieldNameConstants.html
@@ -6,6 +6,8 @@
@FieldNameConstants was introduced as experimental feature in lombok v1.16.22.
@FieldNameConstants was redesigned in lombok v1.18.4.
+
+ The lombok.config option lombok.fieldNameConstants.uppercase = true
was added in lombok v1.18.8.
@f.history>
@@ -20,7 +22,7 @@
<@f.overview>
- The @FieldNameConstants
annotation generates an inner type which contains 1 constant for each field in your class; either string constants (fields marked public static final
, of type java.lang.String
) or if you prefer, an enum type with 1 value for each field - write @FieldNameConstants(asEnum = true)
for the enum variant. @FieldNameConstants
is useful for various marshalling and serialization frameworks. The constant field (whether enum value or string constant) always has the exact same name as the field, capitalization and all.
+ The @FieldNameConstants
annotation generates an inner type which contains 1 constant for each field in your class; either string constants (fields marked public static final
, of type java.lang.String
) or if you prefer, an enum type with 1 value for each field - write @FieldNameConstants(asEnum = true)
for the enum variant. @FieldNameConstants
is useful for various marshalling and serialization frameworks. The constant field (whether enum value or string constant) always has the exact same name as the field, capitalization and all, unless you set the lombok.fieldNameConstants.uppercase = true
option in your lombok.config
file; in that case lombok will try to UPPER_CASE
the name.
The generated inner type is by default called Fields
and is public
. You can modify this via @FieldNameConstants(innerTypeName = "FieldNames", access = AccessLevel.PACKAGE)
for example. The default inner type name can also be modified via configuration key lombok.fieldNameConstants.innerTypeName
. The generated fields are always public
.
@@ -39,6 +41,10 @@
lombok.fieldNameConstants.innerTypeName
= a string (default: 'Fields')
The name of the inner type generated by lombok can be controlled with this configuration key.
+
+ lombok.fieldNameConstants.uppercase
= [true
| false
] (default: false)
+
+ If true
, attempt to uppercase the generated fields.
@f.confKeys>
--
cgit