aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent/lombok/eclipse/agent
diff options
context:
space:
mode:
authorRawi01 <Rawi01@users.noreply.github.com>2021-09-27 17:46:20 +0200
committerRawi01 <Rawi01@users.noreply.github.com>2021-09-27 17:46:20 +0200
commitc67acc023425bee9c1d0960e38bea94c2254a99a (patch)
treef7c18a6d174a9cc46ae9b38a3c537c58862a3e7f /src/eclipseAgent/lombok/eclipse/agent
parentba68962cec99cb1411ed7cac259301edc417ebc5 (diff)
downloadlombok-c67acc023425bee9c1d0960e38bea94c2254a99a.tar.gz
lombok-c67acc023425bee9c1d0960e38bea94c2254a99a.tar.bz2
lombok-c67acc023425bee9c1d0960e38bea94c2254a99a.zip
[fixes #2972] Use simple type, move code to patch method
Diffstat (limited to 'src/eclipseAgent/lombok/eclipse/agent')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchVal.java13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
index 824ecefc..3e96e75d 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
@@ -59,8 +59,8 @@ import org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
import java.lang.reflect.Field;
import static lombok.Lombok.sneakyThrow;
-import static lombok.eclipse.Eclipse.poss;
-import static lombok.eclipse.handlers.EclipseHandlerUtil.makeType;
+import static lombok.eclipse.Eclipse.*;
+import static lombok.eclipse.handlers.EclipseHandlerUtil.*;
import static org.eclipse.jdt.core.compiler.CategorizedProblem.CAT_TYPE;
public class PatchVal {
@@ -204,8 +204,6 @@ public class PatchVal {
boolean var = isVar(local, scope);
if (!(val || var)) return false;
- if (hasNativeVarSupport(scope)) return false;
-
if (val) {
StackTraceElement[] st = new Throwable().getStackTrace();
for (int i = 0; i < st.length - 2 && i < 10; i++) {
@@ -239,6 +237,13 @@ public class PatchVal {
TypeReference replacement = null;
+ // Java 10+: Lombok uses the native 'var' support and transforms 'val' to 'final var'.
+ if (hasNativeVarSupport(scope) && val) {
+ replacement = new SingleTypeReference("var".toCharArray(), pos(local.type));
+ local.initialization = init;
+ init = null;
+ }
+
if (init != null) {
if (init.getClass().getName().equals("org.eclipse.jdt.internal.compiler.ast.LambdaExpression")) {
return false;