aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/lombok/javac/handlers/HandleGetter.java13
-rw-r--r--test/transform/resource/after-delombok/GetterLazyArguments.java101
-rw-r--r--test/transform/resource/after-ecj/GetterLazyArguments.java106
-rw-r--r--test/transform/resource/before/GetterLazyArguments.java21
4 files changed, 241 insertions, 0 deletions
diff --git a/src/core/lombok/javac/handlers/HandleGetter.java b/src/core/lombok/javac/handlers/HandleGetter.java
index 22f43d61..110941d6 100644
--- a/src/core/lombok/javac/handlers/HandleGetter.java
+++ b/src/core/lombok/javac/handlers/HandleGetter.java
@@ -232,9 +232,17 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
List<JCStatement> statements;
JCTree toClearOfMarkers = null;
+ int[] methodArgPos = null;
boolean addSuppressWarningsUnchecked = false;
if (lazy && !inNetbeansEditor(field)) {
toClearOfMarkers = fieldNode.init;
+ if (toClearOfMarkers instanceof JCMethodInvocation) {
+ List<JCExpression> args = ((JCMethodInvocation) toClearOfMarkers).args;
+ methodArgPos = new int[args.length()];
+ for (int i = 0; i < methodArgPos.length; i++) {
+ methodArgPos[i] = args.get(i).pos;
+ }
+ }
statements = createLazyGetterBody(treeMaker, field, source);
addSuppressWarningsUnchecked = LombokOptionsFactory.getDelombokOptions(field.getContext()).getFormatPreferences().generateSuppressWarnings();
} else {
@@ -262,6 +270,11 @@ public class HandleGetter extends JavacAnnotationHandler<Getter> {
methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source, field.getContext());
if (toClearOfMarkers != null) recursiveSetGeneratedBy(toClearOfMarkers, null, null);
+ if (methodArgPos != null) {
+ for (int i = 0; i < methodArgPos.length; i++) {
+ ((JCMethodInvocation) toClearOfMarkers).args.get(i).pos = methodArgPos[i];
+ }
+ }
decl.mods.annotations = decl.mods.annotations.appendList(delegates);
if (addSuppressWarningsUnchecked) {
diff --git a/test/transform/resource/after-delombok/GetterLazyArguments.java b/test/transform/resource/after-delombok/GetterLazyArguments.java
new file mode 100644
index 00000000..a8a422c0
--- /dev/null
+++ b/test/transform/resource/after-delombok/GetterLazyArguments.java
@@ -0,0 +1,101 @@
+class GetterLazyArguments {
+ static String fun() {
+ return null;
+ }
+
+ static String stringInt(String arg1, Integer arg2) {
+ return null;
+ }
+
+ static String stringRunnable(String arg1, Runnable arg2) {
+ return null;
+ }
+
+ private final java.util.concurrent.atomic.AtomicReference<java.lang.Object> field1 = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
+ private final java.util.concurrent.atomic.AtomicReference<java.lang.Object> field2 = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
+ private final java.util.concurrent.atomic.AtomicReference<java.lang.Object> field3 = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
+ private final java.util.concurrent.atomic.AtomicReference<java.lang.Object> field4 = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
+ private final java.util.concurrent.atomic.AtomicReference<java.lang.Object> field5 = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
+
+ @java.lang.SuppressWarnings({"all", "unchecked"})
+ public String getField1() {
+ java.lang.Object value = this.field1.get();
+ if (value == null) {
+ synchronized (this.field1) {
+ value = this.field1.get();
+ if (value == null) {
+ final String actualValue = stringInt(("a"), (1));
+ value = actualValue == null ? this.field1 : actualValue;
+ this.field1.set(value);
+ }
+ }
+ }
+ return (String) (value == this.field1 ? null : value);
+ }
+
+ @java.lang.SuppressWarnings({"all", "unchecked"})
+ public String getField2() {
+ java.lang.Object value = this.field2.get();
+ if (value == null) {
+ synchronized (this.field2) {
+ value = this.field2.get();
+ if (value == null) {
+ final String actualValue = stringInt(true ? "a" : "b", true ? 1 : 0);
+ value = actualValue == null ? this.field2 : actualValue;
+ this.field2.set(value);
+ }
+ }
+ }
+ return (String) (value == this.field2 ? null : value);
+ }
+
+ @java.lang.SuppressWarnings({"all", "unchecked"})
+ public String getField3() {
+ java.lang.Object value = this.field3.get();
+ if (value == null) {
+ synchronized (this.field3) {
+ value = this.field3.get();
+ if (value == null) {
+ final String actualValue = stringInt(("a"), true ? 1 : 0);
+ value = actualValue == null ? this.field3 : actualValue;
+ this.field3.set(value);
+ }
+ }
+ }
+ return (String) (value == this.field3 ? null : value);
+ }
+
+ @java.lang.SuppressWarnings({"all", "unchecked"})
+ public String getField4() {
+ java.lang.Object value = this.field4.get();
+ if (value == null) {
+ synchronized (this.field4) {
+ value = this.field4.get();
+ if (value == null) {
+ final String actualValue = stringRunnable(fun(), () -> {
+ });
+ value = actualValue == null ? this.field4 : actualValue;
+ this.field4.set(value);
+ }
+ }
+ }
+ return (String) (value == this.field4 ? null : value);
+ }
+
+ @java.lang.SuppressWarnings({"all", "unchecked"})
+ public String getField5() {
+ java.lang.Object value = this.field5.get();
+ if (value == null) {
+ synchronized (this.field5) {
+ value = this.field5.get();
+ if (value == null) {
+ final String actualValue = stringRunnable(("a"), () -> {
+ });
+ value = actualValue == null ? this.field5 : actualValue;
+ this.field5.set(value);
+ }
+ }
+ }
+ return (String) (value == this.field5 ? null : value);
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/after-ecj/GetterLazyArguments.java b/test/transform/resource/after-ecj/GetterLazyArguments.java
new file mode 100644
index 00000000..41f1771f
--- /dev/null
+++ b/test/transform/resource/after-ecj/GetterLazyArguments.java
@@ -0,0 +1,106 @@
+class GetterLazyArguments {
+ private final @lombok.Getter(lazy = true) java.util.concurrent.atomic.AtomicReference<java.lang.Object> field1 = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
+ private final @lombok.Getter(lazy = true) java.util.concurrent.atomic.AtomicReference<java.lang.Object> field2 = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
+ private final @lombok.Getter(lazy = true) java.util.concurrent.atomic.AtomicReference<java.lang.Object> field3 = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
+ private final @lombok.Getter(lazy = true) java.util.concurrent.atomic.AtomicReference<java.lang.Object> field4 = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
+ private final @lombok.Getter(lazy = true) java.util.concurrent.atomic.AtomicReference<java.lang.Object> field5 = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
+ GetterLazyArguments() {
+ super();
+ }
+ static String fun() {
+ return null;
+ }
+ static String stringInt(String arg1, Integer arg2) {
+ return null;
+ }
+ static String stringRunnable(String arg1, Runnable arg2) {
+ return null;
+ }
+ public @java.lang.SuppressWarnings({"all", "unchecked"}) String getField1() {
+ java.lang.Object value = this.field1.get();
+ if ((value == null))
+ {
+ synchronized (this.field1)
+ {
+ value = this.field1.get();
+ if ((value == null))
+ {
+ final String actualValue = stringInt("a", 1);
+ value = ((actualValue == null) ? this.field1 : actualValue);
+ this.field1.set(value);
+ }
+ }
+ }
+ return (String) ((value == this.field1) ? null : value);
+ }
+ public @java.lang.SuppressWarnings({"all", "unchecked"}) String getField2() {
+ java.lang.Object value = this.field2.get();
+ if ((value == null))
+ {
+ synchronized (this.field2)
+ {
+ value = this.field2.get();
+ if ((value == null))
+ {
+ final String actualValue = stringInt((true ? "a" : "b"), (true ? 1 : 0));
+ value = ((actualValue == null) ? this.field2 : actualValue);
+ this.field2.set(value);
+ }
+ }
+ }
+ return (String) ((value == this.field2) ? null : value);
+ }
+ public @java.lang.SuppressWarnings({"all", "unchecked"}) String getField3() {
+ java.lang.Object value = this.field3.get();
+ if ((value == null))
+ {
+ synchronized (this.field3)
+ {
+ value = this.field3.get();
+ if ((value == null))
+ {
+ final String actualValue = stringInt("a", (true ? 1 : 0));
+ value = ((actualValue == null) ? this.field3 : actualValue);
+ this.field3.set(value);
+ }
+ }
+ }
+ return (String) ((value == this.field3) ? null : value);
+ }
+ public @java.lang.SuppressWarnings({"all", "unchecked"}) String getField4() {
+ java.lang.Object value = this.field4.get();
+ if ((value == null))
+ {
+ synchronized (this.field4)
+ {
+ value = this.field4.get();
+ if ((value == null))
+ {
+ final String actualValue = stringRunnable(fun(), () -> {
+});
+ value = ((actualValue == null) ? this.field4 : actualValue);
+ this.field4.set(value);
+ }
+ }
+ }
+ return (String) ((value == this.field4) ? null : value);
+ }
+ public @java.lang.SuppressWarnings({"all", "unchecked"}) String getField5() {
+ java.lang.Object value = this.field5.get();
+ if ((value == null))
+ {
+ synchronized (this.field5)
+ {
+ value = this.field5.get();
+ if ((value == null))
+ {
+ final String actualValue = stringRunnable("a", () -> {
+});
+ value = ((actualValue == null) ? this.field5 : actualValue);
+ this.field5.set(value);
+ }
+ }
+ }
+ return (String) ((value == this.field5) ? null : value);
+ }
+} \ No newline at end of file
diff --git a/test/transform/resource/before/GetterLazyArguments.java b/test/transform/resource/before/GetterLazyArguments.java
new file mode 100644
index 00000000..47dfae55
--- /dev/null
+++ b/test/transform/resource/before/GetterLazyArguments.java
@@ -0,0 +1,21 @@
+// version 8:
+class GetterLazyArguments {
+ static String fun() { return null; }
+ static String stringInt(String arg1, Integer arg2) { return null; }
+ static String stringRunnable(String arg1, Runnable arg2) { return null; }
+
+ @lombok.Getter(lazy=true)
+ private final String field1 = stringInt(("a"), (1));
+
+ @lombok.Getter(lazy=true)
+ private final String field2 = stringInt(true ? "a" : "b", true ? 1 : 0);
+
+ @lombok.Getter(lazy=true)
+ private final String field3 = stringInt(("a"), true ? 1 : 0);
+
+ @lombok.Getter(lazy=true)
+ private final String field4 = stringRunnable(fun(), () -> { });
+
+ @lombok.Getter(lazy=true)
+ private final String field5 = stringRunnable(("a"), () -> { });
+}