aboutsummaryrefslogtreecommitdiff
path: root/src/utils/lombok
diff options
context:
space:
mode:
authorBulgakov Alexander <mfourgeneralsherman@gmail.com>2019-05-03 21:50:15 +0300
committerBulgakov Alexander <mfourgeneralsherman@gmail.com>2019-05-03 21:50:15 +0300
commit715c731fc24bf2915d2eaefefd964615e62c12ed (patch)
treeabca888cf3284c6e4bb911a041e15c50d8ca92f9 /src/utils/lombok
parentf0343886a331f3cb2175545a062f3736610f9179 (diff)
parent2335f251665d43b4c8cebe00b980f07ef33bdb17 (diff)
downloadlombok-715c731fc24bf2915d2eaefefd964615e62c12ed.tar.gz
lombok-715c731fc24bf2915d2eaefefd964615e62c12ed.tar.bz2
lombok-715c731fc24bf2915d2eaefefd964615e62c12ed.zip
Merge remote-tracking branch 'lombok/master' into feature/typeInferenceImprovements
Diffstat (limited to 'src/utils/lombok')
-rw-r--r--src/utils/lombok/javac/JavacTreeMaker.java6
-rw-r--r--src/utils/lombok/permit/Permit.java27
2 files changed, 30 insertions, 3 deletions
diff --git a/src/utils/lombok/javac/JavacTreeMaker.java b/src/utils/lombok/javac/JavacTreeMaker.java
index 83d9c53f..84293f11 100644
--- a/src/utils/lombok/javac/JavacTreeMaker.java
+++ b/src/utils/lombok/javac/JavacTreeMaker.java
@@ -441,7 +441,11 @@ public class JavacTreeMaker {
//javac versions: 6-8
private static final MethodId<JCVariableDecl> VarDef = MethodId("VarDef");
public JCVariableDecl VarDef(JCModifiers mods, Name name, JCExpression vartype, JCExpression init) {
- return invoke(VarDef, mods, name, vartype, init);
+ JCVariableDecl varDef = invoke(VarDef, mods, name, vartype, init);
+ // We use 'position of the type is -1' as indicator in delombok that the original node was written using JDK10's 'var' feature, because javac desugars 'var' to the real type and doesn't leave any markers other than the
+ // node position to indicate that it did so. Unfortunately, that means vardecls we generate look like 'var' to delombok. Adjust the position to avoid this.
+ if (varDef.vartype != null && varDef.vartype.pos == -1) varDef.vartype.pos = 0;
+ return varDef;
}
//javac versions: 8
diff --git a/src/utils/lombok/permit/Permit.java b/src/utils/lombok/permit/Permit.java
index 9f0434b8..b7c5f0d9 100644
--- a/src/utils/lombok/permit/Permit.java
+++ b/src/utils/lombok/permit/Permit.java
@@ -46,8 +46,7 @@ public class Permit {
Throwable ex;
try {
- f = AccessibleObject.class.getDeclaredField("override");
- g = UNSAFE.objectFieldOffset(f);
+ g = getOverrideFieldOffset();
ex = null;
} catch (Throwable t) {
f = null;
@@ -74,6 +73,30 @@ public class Permit {
return accessor;
}
+ private static long getOverrideFieldOffset() throws Throwable {
+ Field f = null;
+ Throwable saved = null;
+ try {
+ f = AccessibleObject.class.getDeclaredField("override");
+ } catch (Throwable t) {
+ saved = t;
+ }
+
+ if (f != null) {
+ return UNSAFE.objectFieldOffset(f);
+ }
+ // The below seems very risky, but for all AccessibleObjects in java today it does work, and starting with JDK12, making the field accessible is no longer possible.
+ try {
+ return UNSAFE.objectFieldOffset(Fake.class.getDeclaredField("override"));
+ } catch (Throwable t) {
+ throw saved;
+ }
+ }
+
+ static class Fake {
+ boolean override;
+ }
+
public static Method getMethod(Class<?> c, String mName, Class<?>... parameterTypes) throws NoSuchMethodException {
Method m = null;
Class<?> oc = c;