aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/delombok/lombok/delombok/Delombok.java13
-rw-r--r--src/delombok/lombok/delombok/PrettyPrinter.java69
-rw-r--r--src/delombok/lombok/delombok/ant/DelombokTask.java4
-rw-r--r--src/eclipseAgent/lombok/eclipse/agent/PatchVal.java14
-rw-r--r--src/utils/lombok/javac/JavacTreeMaker.java6
-rw-r--r--src/utils/lombok/permit/Permit.java27
6 files changed, 112 insertions, 21 deletions
diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java
index 8f4f99e5..76b2715a 100755
--- a/src/delombok/lombok/delombok/Delombok.java
+++ b/src/delombok/lombok/delombok/Delombok.java
@@ -93,6 +93,7 @@ public class Delombok {
private boolean noCopy;
private boolean onlyChanged;
private boolean force = false;
+ private boolean disablePreview;
private String classpath, sourcepath, bootclasspath, modulepath;
private LinkedHashMap<File, File> fileToBase = new LinkedHashMap<File, File>();
private List<File> filesToParse = new ArrayList<File>();
@@ -158,6 +159,10 @@ public class Delombok {
@Description("Output only changed files (implies -n)")
private boolean onlyChanged;
+ @Description("By default lombok enables preview features if available (introduced in JDK 12). With this option, lombok won't do that.")
+ @FullName("disable-preview")
+ private boolean disablePreview;
+
private boolean help;
}
@@ -281,6 +286,7 @@ public class Delombok {
if (args.verbose) delombok.setVerbose(true);
if (args.nocopy || args.onlyChanged) delombok.setNoCopy(true);
+ if (args.disablePreview) delombok.setDisablePreview(true);
if (args.onlyChanged) delombok.setOnlyChanged(true);
if (args.print) {
delombok.setOutputToStandardOut();
@@ -516,6 +522,10 @@ public class Delombok {
this.noCopy = noCopy;
}
+ public void setDisablePreview(boolean disablePreview) {
+ this.disablePreview = disablePreview;
+ }
+
public void setOnlyChanged(boolean onlyChanged) {
this.onlyChanged = onlyChanged;
}
@@ -684,6 +694,9 @@ public class Delombok {
argsList.add("--module-path");
argsList.add(modulepath);
}
+
+ if (!disablePreview && Javac.getJavaCompilerVersion() >= 11) argsList.add("--enable-preview");
+
String[] argv = argsList.toArray(new String[0]);
args.init("javac", argv);
options.put("diags.legacy", "TRUE");
diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java
index 832dbe0a..3477c51c 100644
--- a/src/delombok/lombok/delombok/PrettyPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyPrinter.java
@@ -1046,9 +1046,17 @@ public class PrettyPrinter extends JCTree.Visitor {
@Override public void visitBreak(JCBreak tree) {
aPrint("break");
- if (tree.label != null) {
+
+ JCExpression value = readObject(tree, "value", null); // JDK 12+
+ if (value != null) {
print(" ");
- print(tree.label);
+ print(value);
+ } else {
+ Name label = readObject(tree, "label", null);
+ if (label != null) {
+ print(" ");
+ print(label);
+ }
}
println(";", tree);
}
@@ -1230,16 +1238,41 @@ public class PrettyPrinter extends JCTree.Visitor {
}
@Override public void visitCase(JCCase tree) {
- if (tree.pat == null) {
+ // Starting with JDK12, switches allow multiple expressions per case, and can take the form of an expression (preview feature).
+
+ List<JCExpression> pats = readObject(tree, "pats", null); // JDK 12+
+ if (pats == null) {
+ JCExpression pat = readObject(tree, "pat", null); // JDK -11
+ pats = pat == null ? List.<JCExpression>nil() : List.of(pat);
+ }
+
+ if (pats.isEmpty()) {
aPrint("default");
} else {
aPrint("case ");
- print(tree.pat);
+ print(pats, ", ");
+ }
+
+ Enum<?> caseKind = readObject(tree, "caseKind", null); // JDK 12+
+
+ if (caseKind != null && caseKind.name().equalsIgnoreCase("RULE")) {
+ print(" -> ");
+ if (tree.stats.head instanceof JCBreak) {
+ JCBreak b = (JCBreak) tree.stats.head;
+ print((JCExpression) readObject(b, "value", null));
+ print(";");
+ needsNewLine = true;
+ needsAlign = true;
+ } else {
+ print(tree.stats.head);
+ if (tree.stats.head instanceof JCBlock) needsNewLine = false;
+ }
+ } else {
+ println(": ");
+ indent++;
+ print(tree.stats, "");
+ indent--;
}
- println(": ");
- indent++;
- print(tree.stats, "");
- indent--;
}
@Override public void visitCatch(JCCatch tree) {
@@ -1259,10 +1292,26 @@ public class PrettyPrinter extends JCTree.Visitor {
print(")");
}
println(" {");
- print(tree.cases, "\n");
+ print(tree.cases, "");
aPrintln("}", tree);
}
+ void printSwitchExpression(JCTree tree) {
+ aPrint("switch ");
+ JCExpression selector = readObject(tree, "selector", null);
+ if (selector instanceof JCParens) {
+ print(selector);
+ } else {
+ print("(");
+ print(selector);
+ print(")");
+ }
+ println(" {");
+ List<JCCase> cases = readObject(tree, "cases", null);
+ print(cases, "");
+ aPrint("}");
+ }
+
@Override public void visitTry(JCTry tree) {
aPrint("try ");
List<?> resources = readObject(tree, "resources", List.nil());
@@ -1481,6 +1530,8 @@ public class PrettyPrinter extends JCTree.Visitor {
printAnnotatedType0(tree);
} else if ("JCPackageDecl".equals(simpleName)) {
// Starting with JDK9, this is inside the import list, but we've already printed it. Just ignore it.
+ } else if ("JCSwitchExpression".equals(simpleName)) { // Introduced as preview feature in JDK12
+ printSwitchExpression(tree);
} else {
throw new AssertionError("Unhandled tree type: " + tree.getClass() + ": " + tree);
}
diff --git a/src/delombok/lombok/delombok/ant/DelombokTask.java b/src/delombok/lombok/delombok/ant/DelombokTask.java
index e09b8ed2..cb31ef4d 100644
--- a/src/delombok/lombok/delombok/ant/DelombokTask.java
+++ b/src/delombok/lombok/delombok/ant/DelombokTask.java
@@ -154,10 +154,6 @@ class Tasks {
path.add(set);
}
- public Format createFormat() {
- return new Format();
- }
-
public void addFormat(Format format) {
formatOptions.add(format);
}
diff --git a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
index 12f4ad3d..b32c99cd 100644
--- a/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
+++ b/src/eclipseAgent/lombok/eclipse/agent/PatchVal.java
@@ -263,11 +263,15 @@ public class PatchVal {
resolved = null;
}
if (resolved != null) {
- try {
- replacement = makeType(resolved, local.type, false);
- if (!decomponent) init.resolvedType = replacement.resolveType(scope);
- } catch (Exception e) {
- // Some type thing failed.
+ if (resolved.getClass().getSimpleName().startsWith("IntersectionTypeBinding")) {
+ // We intentionally deconstruct these into simply 'Object', because picking an arbitrary type amongst the intersection feels worse.
+ } else {
+ try {
+ replacement = makeType(resolved, local.type, false);
+ if (!decomponent) init.resolvedType = replacement.resolveType(scope);
+ } catch (Exception e) {
+ // Some type thing failed.
+ }
}
}
}
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;