From e4ec9e664806612a5998bfdfa921837a43d58569 Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Mon, 22 Jun 2020 12:52:48 +0700 Subject: Fix missing parameter names, annotations in following annotation processors --- src/stubs/com/sun/tools/javac/code/Symbol.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/stubs/com/sun/tools/javac/code/Symbol.java') diff --git a/src/stubs/com/sun/tools/javac/code/Symbol.java b/src/stubs/com/sun/tools/javac/code/Symbol.java index 4aef63ad..7324cb8e 100644 --- a/src/stubs/com/sun/tools/javac/code/Symbol.java +++ b/src/stubs/com/sun/tools/javac/code/Symbol.java @@ -18,6 +18,7 @@ import javax.lang.model.element.TypeParameterElement; import javax.lang.model.element.VariableElement; import javax.lang.model.type.TypeMirror; +import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.Name; public abstract class Symbol implements Element { @@ -41,6 +42,7 @@ public abstract class Symbol implements Element { public static abstract class TypeSymbol extends Symbol {} public static class MethodSymbol extends Symbol implements ExecutableElement { + public List params = null; public MethodSymbol(long flags, Name name, Type type, Symbol owner) {} @Override public ElementKind getKind() { return null; } @Override public Set getModifiers() { return null; } -- cgit From eb78f5c7665833c8e7dedce75fbe102774e370ae Mon Sep 17 00:00:00 2001 From: Denis Stepanov Date: Wed, 19 Aug 2020 20:34:45 +0700 Subject: Fix missing parameter names, annotations in following annotation processors 2 --- .../lombok/javac/handlers/JavacHandlerUtil.java | 58 +++++++++++++++++++--- src/stubs/com/sun/tools/javac/code/Symbol.java | 8 ++- src/stubs/com/sun/tools/javac/code/Symtab.java | 2 + 3 files changed, 59 insertions(+), 9 deletions(-) (limited to 'src/stubs/com/sun/tools/javac/code/Symbol.java') diff --git a/src/core/lombok/javac/handlers/JavacHandlerUtil.java b/src/core/lombok/javac/handlers/JavacHandlerUtil.java index e0af0e52..a8189562 100644 --- a/src/core/lombok/javac/handlers/JavacHandlerUtil.java +++ b/src/core/lombok/javac/handlers/JavacHandlerUtil.java @@ -40,6 +40,7 @@ import java.util.regex.Pattern; import javax.lang.model.element.Element; +import com.sun.tools.javac.code.Attribute; import com.sun.tools.javac.code.BoundKind; import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.code.Scope; @@ -1127,7 +1128,25 @@ public class JavacHandlerUtil { } } } - + + static class JCAnnotationReflect { + private static Field ATTRIBUTE; + + static { + try { + ATTRIBUTE = Permit.getField(JCAnnotation.class, "attribute"); + } catch (Exception ignore) {} + } + + static Attribute.Compound getAttribute(JCAnnotation jcAnnotation) { + try { + return (Attribute.Compound) ATTRIBUTE.get(jcAnnotation); + } catch (Exception e) { + return null; + } + } + } + // jdk9 support, types have changed, names stay the same static class ClassSymbolMembersField { private static final Field membersField; @@ -1178,8 +1197,10 @@ public class JavacHandlerUtil { * Also takes care of updating the JavacAST. */ public static void injectMethod(JavacNode typeNode, JCMethodDecl method, List paramTypes, Type returnType) { + Context context = typeNode.getContext(); + Symtab symtab = Symtab.instance(context); JCClassDecl type = (JCClassDecl) typeNode.get(); - + if (method.getName().contentEquals("")) { //Scan for default constructor, and remove it. int idx = 0; @@ -1196,7 +1217,7 @@ 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); @@ -1204,18 +1225,41 @@ public class JavacHandlerUtil { List params = null; if (method.getParameters() != null && !method.getParameters().isEmpty()) { ListBuffer newParams = new ListBuffer(); - for (JCTree.JCVariableDecl param : method.getParameters()) { - if (param.sym != null) newParams.append(param.sym); + for (int i = 0; i < method.getParameters().size(); i++) { + JCTree.JCVariableDecl param = method.getParameters().get(i); + if (param.sym == null) { + Type paramType = param.getType().type; + if (paramTypes != null) { + paramType = paramTypes.get(i); + } + VarSymbol varSymbol = new VarSymbol(param.mods.flags, param.name, paramType, symtab.noSymbol); + List annotations = param.getModifiers().getAnnotations(); + if (annotations != null && !annotations.isEmpty()) { + ListBuffer newAnnotations = new ListBuffer(); + for (JCAnnotation jcAnnotation : annotations) { + Attribute.Compound attribute = JCAnnotationReflect.getAttribute(jcAnnotation); + if (attribute != null) { + newAnnotations.append(attribute); + } + } + if (annotations.length() == newAnnotations.length()) { + varSymbol.appendAttributes(newAnnotations.toList()); + } + } + newParams.append(varSymbol); + } else { + newParams.append(param.sym); + } } 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 paramTypes, List params, Type returnType) { if (typeMirror == null || paramTypes == null || returnType == null) return; ClassSymbol cs = (ClassSymbol) typeMirror; diff --git a/src/stubs/com/sun/tools/javac/code/Symbol.java b/src/stubs/com/sun/tools/javac/code/Symbol.java index 7324cb8e..15b04148 100644 --- a/src/stubs/com/sun/tools/javac/code/Symbol.java +++ b/src/stubs/com/sun/tools/javac/code/Symbol.java @@ -24,7 +24,7 @@ import com.sun.tools.javac.util.Name; public abstract class Symbol implements Element { public Type type; public Name name; - + public long flags() { return 0; } public boolean isStatic() { return false; } public boolean isConstructor() { return false; } @@ -38,7 +38,9 @@ public abstract class Symbol implements Element { @Override public Name getSimpleName() { return null; } @Override public java.util.List getEnclosedElements() { return null; } @Override public Element getEnclosingElement() { return null; } - + public void appendAttributes(List l) { + } + public static abstract class TypeSymbol extends Symbol {} public static class MethodSymbol extends Symbol implements ExecutableElement { @@ -60,6 +62,8 @@ public abstract class Symbol implements Element { public static class VarSymbol extends Symbol implements VariableElement { public Type type; + public VarSymbol(long flags, Name name, Type type, Symbol owner) { + } @Override public ElementKind getKind() { return null; } @Override public Set getModifiers() { return null; } @Override public R accept(ElementVisitor v, P p) { return null; } diff --git a/src/stubs/com/sun/tools/javac/code/Symtab.java b/src/stubs/com/sun/tools/javac/code/Symtab.java index 2b524e4c..8d823531 100644 --- a/src/stubs/com/sun/tools/javac/code/Symtab.java +++ b/src/stubs/com/sun/tools/javac/code/Symtab.java @@ -5,6 +5,7 @@ package com.sun.tools.javac.code; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.ModuleSymbol; +import com.sun.tools.javac.code.Symbol.TypeSymbol; import com.sun.tools.javac.util.Context; public class Symtab { @@ -14,6 +15,7 @@ public class Symtab { public Type objectType; public static Symtab instance(Context context) {return null;} public Type unknownType; + public TypeSymbol noSymbol; // JDK 9 public ModuleSymbol unnamedModule; -- cgit