aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2021-09-27 19:19:46 +0200
committerGitHub <noreply@github.com>2021-09-27 19:19:46 +0200
commitba2b47b974304517ef47154a3939056eff13fade (patch)
tree9eb1bc03741766c847afeb492efbfce7cc9f59dc /src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
parentba68962cec99cb1411ed7cac259301edc417ebc5 (diff)
parent9ef7656a35706f387569189e118076c7279311c3 (diff)
downloadlombok-ba2b47b974304517ef47154a3939056eff13fade.tar.gz
lombok-ba2b47b974304517ef47154a3939056eff13fade.tar.bz2
lombok-ba2b47b974304517ef47154a3939056eff13fade.zip
Merge pull request #2975 from Rawi01/organize-imports-val
Move 'val' -> 'final var' code to patch method
Diffstat (limited to 'src/eclipseAgent/lombok/eclipse/agent/PatchVal.java')
-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;