aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRawi01 <Rawi01@users.noreply.github.com>2021-05-14 23:06:20 +0200
committerRawi01 <Rawi01@users.noreply.github.com>2021-05-14 23:06:20 +0200
commitbd00fc4b83dd758c4369c8da97243691c04ac3fa (patch)
tree541c207a7ebc452f674f48975921f0828ded9c9e
parenta8f9b1dd359dbbcd63bffe891c5f00a9a2ac1f60 (diff)
downloadlombok-bd00fc4b83dd758c4369c8da97243691c04ac3fa.tar.gz
lombok-bd00fc4b83dd758c4369c8da97243691c04ac3fa.tar.bz2
lombok-bd00fc4b83dd758c4369c8da97243691c04ac3fa.zip
Copy reference types properly
-rw-r--r--src/utils/lombok/javac/TreeMirrorMaker.java17
-rw-r--r--test/transform/resource/after-delombok/ValAnonymousSubclassSelfReference.java10
-rw-r--r--test/transform/resource/after-ecj/ValAnonymousSubclassSelfReference.java9
-rw-r--r--test/transform/resource/before/ValAnonymousSubclassSelfReference.java13
4 files changed, 44 insertions, 5 deletions
diff --git a/src/utils/lombok/javac/TreeMirrorMaker.java b/src/utils/lombok/javac/TreeMirrorMaker.java
index 4b2ad171..778e670d 100644
--- a/src/utils/lombok/javac/TreeMirrorMaker.java
+++ b/src/utils/lombok/javac/TreeMirrorMaker.java
@@ -32,8 +32,10 @@ import lombok.javac.JavacTreeMaker.TypeTag;
import com.sun.source.tree.LabeledStatementTree;
import com.sun.source.tree.VariableTree;
import com.sun.tools.javac.tree.JCTree;
+import com.sun.tools.javac.tree.JCTree.JCFieldAccess;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.tree.TreeCopier;
+import com.sun.tools.javac.tree.TreeScanner;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.List;
@@ -110,7 +112,20 @@ public class TreeMirrorMaker extends TreeCopier<Void> {
copy.sym = null;
copy.type = null;
} else {
- if (original.vartype != null) copy.vartype.type = original.vartype.type;
+ if (original.vartype != null) {
+ copy.vartype.type = original.vartype.type;
+ original.vartype.accept(new TreeScanner() {
+ @Override public void scan(JCTree tree) {
+ super.scan(tree);
+ originalToCopy.get(tree).type = tree.type;
+ }
+
+ @Override public void visitSelect(JCFieldAccess tree) {
+ super.visitSelect(tree);
+ ((JCFieldAccess) originalToCopy.get(tree)).sym = tree.sym;
+ }
+ });
+ }
}
}
diff --git a/test/transform/resource/after-delombok/ValAnonymousSubclassSelfReference.java b/test/transform/resource/after-delombok/ValAnonymousSubclassSelfReference.java
index 4532ec28..a1176a3c 100644
--- a/test/transform/resource/after-delombok/ValAnonymousSubclassSelfReference.java
+++ b/test/transform/resource/after-delombok/ValAnonymousSubclassSelfReference.java
@@ -1,5 +1,13 @@
+import java.util.Map;
+import java.util.HashMap;
+
public class ValAnonymousSubclassSelfReference {
- public void test() {
+ public <T> void test(T arg) {
+ T d = arg;
+ Integer[] e = new Integer[1];
+ int[] f = new int[0];
+ java.util.Map<java.lang.String, Integer> g = new HashMap<String, Integer>();
+ Integer h = 0;
int i = 0;
final int j = 1;
final int k = 2;
diff --git a/test/transform/resource/after-ecj/ValAnonymousSubclassSelfReference.java b/test/transform/resource/after-ecj/ValAnonymousSubclassSelfReference.java
index 8a3c7fa8..12b0f640 100644
--- a/test/transform/resource/after-ecj/ValAnonymousSubclassSelfReference.java
+++ b/test/transform/resource/after-ecj/ValAnonymousSubclassSelfReference.java
@@ -1,9 +1,16 @@
+import java.util.Map;
+import java.util.HashMap;
import lombok.val;
public class ValAnonymousSubclassSelfReference {
public ValAnonymousSubclassSelfReference() {
super();
}
- public void test() {
+ public <T>void test(T arg) {
+ T d = arg;
+ Integer[] e = new Integer[1];
+ int[] f = new int[0];
+ java.util.Map<java.lang.String, Integer> g = new HashMap<String, Integer>();
+ Integer h = 0;
int i = 0;
final @val int j = 1;
final @val int k = 2;
diff --git a/test/transform/resource/before/ValAnonymousSubclassSelfReference.java b/test/transform/resource/before/ValAnonymousSubclassSelfReference.java
index 6ca05b3c..e7c30c84 100644
--- a/test/transform/resource/before/ValAnonymousSubclassSelfReference.java
+++ b/test/transform/resource/before/ValAnonymousSubclassSelfReference.java
@@ -1,9 +1,18 @@
-// issue 2420: to trigger the problem 2 var/val, one normal variable and a anonymous self reference is required
+// issue 2420: to trigger the problem 2 var/val, at least one normal variable and a anonymous self reference is required
+import java.util.Map;
+import java.util.HashMap;
+
import lombok.val;
public class ValAnonymousSubclassSelfReference {
- public void test() {
+ public <T> void test(T arg) {
+ T d = arg;
+ Integer[] e = new Integer[1];
+ int[] f = new int[0];
+ java.util.Map<java.lang.String, Integer> g = new HashMap<String, Integer>();
+ Integer h = 0;
int i = 0;
+
val j = 1;
val k = 2;