aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/javac
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-10-03 23:52:15 +0200
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-10-03 23:52:15 +0200
commit07e921d2b19a660df28e03ee1ed1d0315d5e3458 (patch)
tree78184fd7fd0816ac59321ff9ca1a88068c5cdd9c /src/core/lombok/javac
parent1b534d17d39f687d42ebab733327a59c3466a949 (diff)
downloadlombok-07e921d2b19a660df28e03ee1ed1d0315d5e3458.tar.gz
lombok-07e921d2b19a660df28e03ee1ed1d0315d5e3458.tar.bz2
lombok-07e921d2b19a660df28e03ee1ed1d0315d5e3458.zip
[javac] Added/improved support for the 'receiver parameter' feature
Diffstat (limited to 'src/core/lombok/javac')
-rw-r--r--src/core/lombok/javac/JavacASTVisitor.java26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/core/lombok/javac/JavacASTVisitor.java b/src/core/lombok/javac/JavacASTVisitor.java
index 9b67dda3..e8fd295c 100644
--- a/src/core/lombok/javac/JavacASTVisitor.java
+++ b/src/core/lombok/javac/JavacASTVisitor.java
@@ -22,6 +22,7 @@
package lombok.javac;
import java.io.PrintStream;
+import java.lang.reflect.Field;
import com.sun.source.util.Trees;
import com.sun.tools.javac.code.Flags;
@@ -32,6 +33,7 @@ import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
+import com.sun.tools.javac.util.List;
/**
* Implement so you can ask any JavacAST.LombokNode to traverse depth-first through all children,
@@ -223,6 +225,26 @@ public interface JavacASTVisitor {
} else type = "METHOD";
print("<%s %s> %s returns: %s", type, method.name, printFlags(method.mods.flags), method.restype);
indent++;
+ JCVariableDecl recv;
+ try {
+ Field f = JCMethodDecl.class.getField("recvparam");
+ recv = (JCVariableDecl) f.get(method);
+ } catch (Exception ignore) {
+ recv = null;
+ }
+
+ if (recv != null) {
+ List<JCAnnotation> annotations = recv.mods.annotations;
+ if (recv.mods != null) annotations = recv.mods.annotations;
+ boolean innerContent = annotations != null && annotations.isEmpty();
+ print("<RECEIVER-PARAM (%s) %s %s%s> %s", recv.vartype == null ? "null" : recv.vartype.getClass().toString(), recv.vartype, recv.name, innerContent ? "" : " /", printFlags(recv.mods.flags));
+ if (innerContent) {
+ indent++;
+ for (JCAnnotation ann : annotations) print("<ANNOTATION: %s />", ann);
+ indent--;
+ print("</RECEIVER-PARAM>");
+ }
+ }
if (printContent) {
if (method.body == null) print("(ABSTRACT)");
else print("%s", method.body);
@@ -237,11 +259,11 @@ public interface JavacASTVisitor {
@Override public void endVisitMethod(JavacNode node, JCMethodDecl method) {
if (printContent) disablePrinting--;
indent--;
- print("</%s %s>", "XMETHOD", method.name);
+ print("</%s %s>", "METHOD", method.name);
}
@Override public void visitMethodArgument(JavacNode node, JCVariableDecl arg, JCMethodDecl method) {
- print("<METHODARG %s %s> %s", arg.vartype, arg.name, printFlags(arg.mods.flags));
+ print("<METHODARG (%s) %s %s> %s", arg.vartype.getClass().toString(), arg.vartype, arg.name, printFlags(arg.mods.flags));
indent++;
}