aboutsummaryrefslogtreecommitdiff
path: root/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
diff options
context:
space:
mode:
authorRawi01 <Rawi01@users.noreply.github.com>2021-02-02 09:44:36 +0100
committerRoel Spilker <r.spilker@gmail.com>2021-09-06 11:58:05 +0200
commitfdcbaa033d27b344adfea99d8d7bdd99cceacfb3 (patch)
tree5f385d9d193bd66ac7b5036f0f1b63fce4405cfe /src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
parente050dafc9016519e79184e383eab9ffbd579bebd (diff)
downloadlombok-fdcbaa033d27b344adfea99d8d7bdd99cceacfb3.tar.gz
lombok-fdcbaa033d27b344adfea99d8d7bdd99cceacfb3.tar.bz2
lombok-fdcbaa033d27b344adfea99d8d7bdd99cceacfb3.zip
Replace val with native final var in Java >= 10
Diffstat (limited to 'src/eclipseAgent/lombok/eclipse/agent/PatchVal.java')
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchVal.java12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
index 774e5b40..824ecefc 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
@@ -204,6 +204,8 @@ 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++) {
@@ -281,6 +283,14 @@ public class PatchVal {
return is(local.type, scope, "lombok.val");
}
+ private static boolean hasNativeVarSupport(Scope scope) {
+ long sl = scope.problemReporter().options.sourceLevel >> 16;
+ long cl = scope.problemReporter().options.complianceLevel >> 16;
+ if (sl == 0) sl = cl;
+ if (cl == 0) cl = sl;
+ return Math.min((int)(sl - 44), (int)(cl - 44)) >= 10;
+ }
+
public static boolean handleValForForEach(ForeachStatement forEach, BlockScope scope) {
if (forEach.elementVariable == null) return false;
@@ -288,6 +298,8 @@ public class PatchVal {
boolean var = isVar(forEach.elementVariable, scope);
if (!(val || var)) return false;
+ if (hasNativeVarSupport(scope)) return false;
+
TypeBinding component = getForEachComponentType(forEach.collection, scope);
if (component == null) return false;
TypeReference replacement = makeType(component, forEach.elementVariable.type, false);