RFR: 8225377: type annotations are not visible to javac plugins across compilation boundaries [v4]
Liam Miller-Cushon
cushon at openjdk.org
Wed Nov 1 19:28:16 UTC 2023
On Mon, 30 Oct 2023 23:46:40 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> looks good to me
Thanks for the review!
I did some more validation of the change on Google's codebase, and everything looks good on that side.
I made one more small update for receiver parameters and added an additional test case. Receiver parameters are not currently filled in for classes loaded from the classpath. (That is potentially an issue even without type annotations being present, I filed [JDK-8319196](https://bugs.openjdk.org/browse/JDK-8319196).)
I updated the logic here to fill in the receiver parameter type if `METHOD_RECEIVER` annotations are present:
diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java
index f86a95e501c..d15d5ca2526 100644
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/ClassReader.java
@@ -2333,8 +2333,9 @@ public Void visitMethodSymbol(Symbol.MethodSymbol s, Void unused) {
}
mt.thrown = thrown.toList();
mt.restype = addTypeAnnotations(mt.restype, TargetType.METHOD_RETURN);
- if (mt.recvtype != null) {
- mt.recvtype = addTypeAnnotations(mt.recvtype, TargetType.METHOD_RECEIVER);
+ if (attributes.stream().anyMatch(a -> a.position.type == TargetType.METHOD_RECEIVER)) {
+ Assert.checkNull(mt.recvtype);
+ mt.recvtype = addTypeAnnotations(s.owner.type, TargetType.METHOD_RECEIVER);
}
return null;
}
diff --git a/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java b/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java
index af63575052c..18b41b4a80c 100644
--- a/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java
+++ b/test/langtools/tools/javac/processing/model/type/BasicAnnoTests.java
@@ -573,4 +573,10 @@ class Inner90<@TA(90) T> {
@Test(posn=4, annoType = TB.class, expect = "100")
class Inner100<T extends Inner100<@TB(100) T>> {
}
+
+ // receiver parameters
+ class Inner110 {
+ @Test(posn=2, annoType = TA.class, expect = "110")
+ void f(@TA(110) Inner110 this) {}
+ }
}
-------------
PR Comment: https://git.openjdk.org/jdk/pull/16407#issuecomment-1789525288
More information about the compiler-dev
mailing list