aboutsummaryrefslogtreecommitdiff
path: root/src/delombok/lombok
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2018-10-29 23:13:52 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2018-10-29 23:13:59 +0100
commiteca219ee6433cd964f0549a114a791ca4eb9f0fa (patch)
tree20f6fed449504fbf5dbc52bd15ff3f2458dd90f8 /src/delombok/lombok
parent182cb0cb9e8db6341fb4633c3849b5e90ba6d088 (diff)
downloadlombok-eca219ee6433cd964f0549a114a791ca4eb9f0fa.tar.gz
lombok-eca219ee6433cd964f0549a114a791ca4eb9f0fa.tar.bz2
lombok-eca219ee6433cd964f0549a114a791ca4eb9f0fa.zip
eliminate ‘you are using private API’ warnings by streamlining all reflective access via a class that uses sun.misc.Unsafe to arrange access. From the nqzero permit-reflect library.
Diffstat (limited to 'src/delombok/lombok')
-rw-r--r--src/delombok/lombok/delombok/Delombok.java11
-rw-r--r--src/delombok/lombok/delombok/DelombokApp.java3
-rw-r--r--src/delombok/lombok/delombok/PrettyPrinter.java17
-rw-r--r--src/delombok/lombok/delombok/ant/DelombokTask.java12
4 files changed, 21 insertions, 22 deletions
diff --git a/src/delombok/lombok/delombok/Delombok.java b/src/delombok/lombok/delombok/Delombok.java
index 0b97b4be..69898668 100644
--- a/src/delombok/lombok/delombok/Delombok.java
+++ b/src/delombok/lombok/delombok/Delombok.java
@@ -61,6 +61,7 @@ import lombok.javac.CommentCatcher;
import lombok.javac.Javac;
import lombok.javac.LombokOptions;
import lombok.javac.apt.LombokProcessor;
+import lombok.permit.Permit;
import com.sun.tools.javac.code.Symtab;
import com.sun.tools.javac.comp.Todo;
@@ -638,7 +639,7 @@ public class Delombok {
private static final Field MODULE_FIELD = getModuleField();
private static Field getModuleField() {
try {
- return JCCompilationUnit.class.getField("modle");
+ return Permit.getField(JCCompilationUnit.class, "modle");
} catch (NoSuchFieldException e) {
return null;
} catch (SecurityException e) {
@@ -808,10 +809,10 @@ public class Delombok {
private static Object callAttributeMethodOnJavaCompiler(JavaCompiler compiler, Todo arg) {
if (attributeMethod == null) {
try {
- attributeMethod = JavaCompiler.class.getDeclaredMethod("attribute", java.util.Queue.class);
+ attributeMethod = Permit.getMethod(JavaCompiler.class, "attribute", java.util.Queue.class);
} catch (NoSuchMethodException e) {
try {
- attributeMethod = JavaCompiler.class.getDeclaredMethod("attribute", com.sun.tools.javac.util.ListBuffer.class);
+ attributeMethod = Permit.getMethod(JavaCompiler.class, "attribute", com.sun.tools.javac.util.ListBuffer.class);
} catch (NoSuchMethodException e2) {
throw Lombok.sneakyThrow(e2);
}
@@ -830,10 +831,10 @@ public class Delombok {
private static void callFlowMethodOnJavaCompiler(JavaCompiler compiler, Object arg) {
if (flowMethod == null) {
try {
- flowMethod = JavaCompiler.class.getDeclaredMethod("flow", java.util.Queue.class);
+ flowMethod = Permit.getMethod(JavaCompiler.class, "flow", java.util.Queue.class);
} catch (NoSuchMethodException e) {
try {
- flowMethod = JavaCompiler.class.getDeclaredMethod("flow", com.sun.tools.javac.util.List.class);
+ flowMethod = Permit.getMethod(JavaCompiler.class, "flow", com.sun.tools.javac.util.List.class);
} catch (NoSuchMethodException e2) {
throw Lombok.sneakyThrow(e2);
}
diff --git a/src/delombok/lombok/delombok/DelombokApp.java b/src/delombok/lombok/delombok/DelombokApp.java
index 2ba4c6ed..da1975b4 100644
--- a/src/delombok/lombok/delombok/DelombokApp.java
+++ b/src/delombok/lombok/delombok/DelombokApp.java
@@ -36,6 +36,7 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import lombok.core.LombokApp;
+import lombok.permit.Permit;
import org.mangosdk.spi.ProviderFor;
@@ -52,7 +53,7 @@ public class DelombokApp extends LombokApp {
return 1;
}
try {
- loadDelombok(args).getMethod("main", String[].class).invoke(null, new Object[] {args.toArray(new String[0])});
+ Permit.getMethod(loadDelombok(args), "main", String[].class).invoke(null, new Object[] {args.toArray(new String[0])});
} catch (InvocationTargetException e1) {
Throwable t = e1.getCause();
if (t instanceof Error) throw (Error)t;
diff --git a/src/delombok/lombok/delombok/PrettyPrinter.java b/src/delombok/lombok/delombok/PrettyPrinter.java
index 4261a558..3fb1f1b1 100644
--- a/src/delombok/lombok/delombok/PrettyPrinter.java
+++ b/src/delombok/lombok/delombok/PrettyPrinter.java
@@ -93,6 +93,7 @@ import com.sun.tools.javac.util.Position;
import lombok.javac.CommentInfo;
import lombok.javac.PackageName;
+import lombok.permit.Permit;
import lombok.javac.CommentInfo.EndConnection;
import lombok.javac.CommentInfo.StartConnection;
import lombok.javac.JavacTreeMaker.TreeTag;
@@ -1335,7 +1336,6 @@ public class PrettyPrinter extends JCTree.Visitor {
static {
getExtendsClause = getMethod(JCClassDecl.class, "getExtendsClause", new Class<?>[0]);
- getExtendsClause.setAccessible(true);
if (getJavaCompilerVersion() < 8) {
getEndPosition = getMethod(DiagnosticPosition.class, "getEndPosition", java.util.Map.class);
@@ -1350,11 +1350,11 @@ public class PrettyPrinter extends JCTree.Visitor {
throw sneakyThrow(ex);
}
try {
- storeEndMethodTemp = endPosTable.getMethod("storeEnd", JCTree.class, int.class);
+ storeEndMethodTemp = Permit.getMethod(endPosTable, "storeEnd", JCTree.class, int.class);
} catch (NoSuchMethodException e) {
try {
endPosTable = Class.forName("com.sun.tools.javac.parser.JavacParser$AbstractEndPosTable");
- storeEndMethodTemp = endPosTable.getDeclaredMethod("storeEnd", JCTree.class, int.class);
+ storeEndMethodTemp = Permit.getMethod(endPosTable, "storeEnd", JCTree.class, int.class);
} catch (NoSuchMethodException ex) {
throw sneakyThrow(ex);
} catch (ClassNotFoundException ex) {
@@ -1363,13 +1363,13 @@ public class PrettyPrinter extends JCTree.Visitor {
}
storeEnd = storeEndMethodTemp;
}
- getEndPosition.setAccessible(true);
- storeEnd.setAccessible(true);
+ Permit.setAccessible(getEndPosition);
+ Permit.setAccessible(storeEnd);
}
private static Method getMethod(Class<?> clazz, String name, Class<?>... paramTypes) {
try {
- return clazz.getMethod(name, paramTypes);
+ return Permit.getMethod(clazz, name, paramTypes);
} catch (NoSuchMethodException e) {
throw sneakyThrow(e);
}
@@ -1379,7 +1379,7 @@ public class PrettyPrinter extends JCTree.Visitor {
try {
Class<?>[] c = new Class[paramTypes.length];
for (int i = 0; i < paramTypes.length; i++) c[i] = Class.forName(paramTypes[i]);
- return clazz.getMethod(name, c);
+ return Permit.getMethod(clazz, name, c);
} catch (NoSuchMethodException e) {
throw sneakyThrow(e);
} catch (ClassNotFoundException e) {
@@ -1418,11 +1418,10 @@ public class PrettyPrinter extends JCTree.Visitor {
Field f = c.get(fieldName);
if (f == null) {
try {
- f = tClass.getDeclaredField(fieldName);
+ f = Permit.getField(tClass, fieldName);
} catch (Exception e) {
return defaultValue;
}
- f.setAccessible(true);
c.put(fieldName, f);
}
diff --git a/src/delombok/lombok/delombok/ant/DelombokTask.java b/src/delombok/lombok/delombok/ant/DelombokTask.java
index adaf43dd..3828a5db 100644
--- a/src/delombok/lombok/delombok/ant/DelombokTask.java
+++ b/src/delombok/lombok/delombok/ant/DelombokTask.java
@@ -30,6 +30,7 @@ import java.util.ArrayList;
import java.util.List;
import lombok.Lombok;
+import lombok.permit.Permit;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Location;
@@ -176,8 +177,7 @@ class Tasks {
} catch (ClassNotFoundException e) {
// If we get here, it isn't, and we should use the shadowloader.
Class<?> launcherMain = Class.forName("lombok.launch.Main");
- Method m = launcherMain.getDeclaredMethod("createShadowClassLoader");
- m.setAccessible(true);
+ Method m = Permit.getMethod(launcherMain, "createShadowClassLoader");
shadowLoader = (ClassLoader) m.invoke(null);
}
}
@@ -195,10 +195,9 @@ class Tasks {
try {
Object instance = shadowLoadClass("lombok.delombok.ant.DelombokTaskImpl").newInstance();
for (Field selfField : getClass().getDeclaredFields()) {
+ Permit.setAccessible(selfField);
if (selfField.isSynthetic() || Modifier.isStatic(selfField.getModifiers())) continue;
- Field otherField = instance.getClass().getDeclaredField(selfField.getName());
- otherField.setAccessible(true);
- selfField.setAccessible(true);
+ Field otherField = Permit.getField(instance.getClass(), selfField.getName());
if (selfField.getName().equals("formatOptions")) {
List<String> rep = new ArrayList<String>();
for (Format f : formatOptions) {
@@ -211,8 +210,7 @@ class Tasks {
}
}
- Method m = instance.getClass().getMethod("execute", Location.class);
- m.setAccessible(true);
+ Method m = Permit.getMethod(instance.getClass(), "execute", Location.class);
m.invoke(instance, loc);
} catch (InvocationTargetException e) {
throw Lombok.sneakyThrow(e.getCause());