aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-10-03 23:51:33 +0200
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-10-03 23:51:33 +0200
commit1b534d17d39f687d42ebab733327a59c3466a949 (patch)
treed24e04a9c95b0caa0df855fb5d20b63730fc7707 /src/core/lombok/javac
parenteadd3b8ccea16d46249e6b01c4ac4b295c691abd (diff)
downloadlombok-1b534d17d39f687d42ebab733327a59c3466a949.tar.gz
lombok-1b534d17d39f687d42ebab733327a59c3466a949.tar.bz2
lombok-1b534d17d39f687d42ebab733327a59c3466a949.zip
Untangling patches to classes that only exist in eclipse, not ecj
Specifically, Rawi01's patches to make javadoc behaviour in eclipse better, which cannot be applied to ecj as you get load errors (javadoc not a thing there). As part of this commit, tests can be limited to ecj or eclipse, and I made cut-down versions of a few tests (to run on ecj, as the main one cannot be, due to javadoc issues). The tests now marked as eclipse only don't fail on ecj, but they don't generate the same result. Alternatively, we could go with a separated out after-ecj and after-eclipse dir instead, but that's perhaps going overboard.
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/handlers/JavacHandlerUtil.java54
1 files changed, 39 insertions, 15 deletions
diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
index 2379d0a0..5ff29758 100644
--- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java
+++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java
@@ -144,12 +144,12 @@ public class JavacHandlerUtil {
Options options = Options.instance(context);
return (options.keySet().contains("ide") && !options.keySet().contains("backgroundCompilation"));
}
-
+
public static boolean inNetbeansCompileOnSave(Context context) {
Options options = Options.instance(context);
return (options.keySet().contains("ide") && options.keySet().contains("backgroundCompilation"));
}
-
+
public static JCTree getGeneratedBy(JCTree node) {
return JCTree_generatedNode.get(node);
}
@@ -1026,7 +1026,7 @@ public class JavacHandlerUtil {
public static JavacNode injectField(JavacNode typeNode, JCVariableDecl field) {
return injectField(typeNode, field, false);
}
-
+
public static JavacNode injectField(JavacNode typeNode, JCVariableDecl field, boolean addGenerated) {
return injectField(typeNode, field, addGenerated, false);
}
@@ -1076,6 +1076,17 @@ public class JavacHandlerUtil {
private static Constructor<?> CONSTRUCTOR;
private static Field ANNOTATIONS, UNDERLYING_TYPE;
+ private static void initByLoader(ClassLoader classLoader) {
+ if (TYPE != null) return;
+ Class<?> c;
+ try {
+ c = classLoader.loadClass("com.sun.tools.javac.tree.JCTree$JCAnnotatedType");
+ } catch (Exception e) {
+ return;
+ }
+ init(c);
+ }
+
private static void init(Class<?> in) {
if (TYPE != null) return;
if (!in.getName().equals("com.sun.tools.javac.tree.JCTree$JCAnnotatedType")) return;
@@ -1120,17 +1131,18 @@ public class JavacHandlerUtil {
}
static JCExpression create(List<JCAnnotation> annotations, JCExpression underlyingType) {
+ initByLoader(underlyingType.getClass().getClassLoader());
try {
return (JCExpression) CONSTRUCTOR.newInstance(annotations, underlyingType);
} catch (Exception e) {
- return null;
+ return underlyingType;
}
}
}
-
+
static class JCAnnotationReflect {
private static Field ATTRIBUTE;
-
+
static {
try {
ATTRIBUTE = Permit.getField(JCAnnotation.class, "attribute");
@@ -1199,7 +1211,7 @@ public class JavacHandlerUtil {
Context context = typeNode.getContext();
Symtab symtab = Symtab.instance(context);
JCClassDecl type = (JCClassDecl) typeNode.get();
-
+
if (method.getName().contentEquals("<init>")) {
//Scan for default constructor, and remove it.
int idx = 0;
@@ -1216,11 +1228,11 @@ public class JavacHandlerUtil {
idx++;
}
}
-
+
addSuppressWarningsAll(method.mods, typeNode, method.pos, getGeneratedBy(method), typeNode.getContext());
addGenerated(method.mods, typeNode, method.pos, getGeneratedBy(method), typeNode.getContext());
type.defs = type.defs.append(method);
-
+
List<Symbol.VarSymbol> params = null;
if (method.getParameters() != null && !method.getParameters().isEmpty()) {
ListBuffer<Symbol.VarSymbol> newParams = new ListBuffer<Symbol.VarSymbol>();
@@ -1250,12 +1262,12 @@ public class JavacHandlerUtil {
params = newParams.toList();
if (params.length() != method.getParameters().length()) params = null;
}
-
+
fixMethodMirror(typeNode.getContext(), typeNode.getElement(), method.getModifiers().flags, method.getName(), paramTypes, params, returnType);
-
+
typeNode.add(method, Kind.METHOD);
}
-
+
private static void fixMethodMirror(Context context, Element typeMirror, long access, Name methodName, List<Type> paramTypes, List<Symbol.VarSymbol> params, Type returnType) {
if (typeMirror == null || paramTypes == null || returnType == null) return;
ClassSymbol cs = (ClassSymbol) typeMirror;
@@ -1428,6 +1440,7 @@ public class JavacHandlerUtil {
}
return e;
}
+
/**
* In javac, dotted access of any kind, from {@code java.lang.String} to {@code var.methodName}
* is represented by a fold-left of {@code Select} nodes with the leftmost string represented by
@@ -1831,20 +1844,30 @@ public class JavacHandlerUtil {
public static JCExpression namePlusTypeParamsToTypeReference(JavacTreeMaker maker, JavacNode type, List<JCTypeParameter> params) {
JCClassDecl td = (JCClassDecl) type.get();
boolean instance = (td.mods.flags & Flags.STATIC) == 0;
- return namePlusTypeParamsToTypeReference(maker, type.up(), td.name, instance, params);
+ return namePlusTypeParamsToTypeReference(maker, type.up(), td.name, instance, params, List.<JCAnnotation>nil());
+ }
+
+ public static JCExpression namePlusTypeParamsToTypeReference(JavacTreeMaker maker, JavacNode type, List<JCTypeParameter> params, List<JCAnnotation> annotations) {
+ JCClassDecl td = (JCClassDecl) type.get();
+ boolean instance = (td.mods.flags & Flags.STATIC) == 0;
+ return namePlusTypeParamsToTypeReference(maker, type.up(), td.name, instance, params, annotations);
}
public static JCExpression namePlusTypeParamsToTypeReference(JavacTreeMaker maker, JavacNode parentType, Name typeName, boolean instance, List<JCTypeParameter> params) {
+ return namePlusTypeParamsToTypeReference(maker, parentType, typeName, instance, params, List.<JCAnnotation>nil());
+ }
+
+ public static JCExpression namePlusTypeParamsToTypeReference(JavacTreeMaker maker, JavacNode parentType, Name typeName, boolean instance, List<JCTypeParameter> params, List<JCAnnotation> annotations) {
JCExpression r = null;
-
if (parentType != null && parentType.getKind() == Kind.TYPE) {
JCClassDecl td = (JCClassDecl) parentType.get();
boolean outerInstance = instance && ((td.mods.flags & Flags.STATIC) == 0);
List<JCTypeParameter> outerParams = instance ? td.typarams : List.<JCTypeParameter>nil();
- r = namePlusTypeParamsToTypeReference(maker, parentType.up(), td.name, outerInstance, outerParams);
+ r = namePlusTypeParamsToTypeReference(maker, parentType.up(), td.name, outerInstance, outerParams, List.<JCAnnotation>nil());
}
r = r == null ? maker.Ident(typeName) : maker.Select(r, typeName);
+ if (!annotations.isEmpty()) r = JCAnnotatedTypeReflect.create(annotations, r);
if (!params.isEmpty()) r = maker.TypeApply(r, typeParameterNames(maker, params));
return r;
}
@@ -2078,6 +2101,7 @@ public class JavacHandlerUtil {
public static void copyJavadoc(JavacNode from, JCTree to, CopyJavadoc copyMode) {
copyJavadoc(from, to, copyMode, false);
}
+
/**
* Copies javadoc on one node to the other.
*