GROOVY-12206: Ingest type-use annotations when reading compiled classes - #2743
GROOVY-12206: Ingest type-use annotations when reading compiled classes#2743paulk-asert wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses GROOVY-12206 by ensuring Groovy ingests type-use (JSR 308) annotations—including those stored in bytecode “type annotation” attributes—when building AST metadata from compiled classes (both via reflection/VMPlugin and via ASM decompilation). This enables nullness/type-checking features (e.g., NullChecker) to reliably observe libraries like JSpecify, whose annotations are TYPE_USE-only.
Changes:
- Extend
NullCheckerto recognize nullness annotations present on the declared type (type-use annotations) in addition to declaration annotations. - Implement recursive ingestion of reflective
AnnotatedTypestructures inJava8(and reuse inJava16) so type-use annotations on generics/arrays/wildcards/supertypes/throws/type params are applied toClassNode/GenericsTypewithout mutating shared cached nodes. - Enhance ASM decompiler stubs and parsing so bytecode type annotations are captured with position (TypeReference + TypePath) and attached to the correct AST type locations; add tests for both reflection and decompiler paths plus a JSpecify precompiled fixture and documentation updates.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| subprojects/groovy-typecheckers/src/test/groovy/groovy/typecheckers/support/JSpecifyExample.java | Adds a precompiled Java fixture using JSpecify TYPE_USE nullness annotations for regression coverage. |
| subprojects/groovy-typecheckers/src/test/groovy/groovy/typecheckers/NullCheckerTest.groovy | Adds tests verifying NullChecker observes type-use nullness from compiled Java classes on the classpath. |
| subprojects/groovy-typecheckers/src/spec/doc/typecheckers.adoc | Documents recognition of declaration + type-use nullness annotations, including from compiled classes. |
| subprojects/groovy-typecheckers/src/main/groovy/groovy/typecheckers/NullChecker.groovy | Extends annotation detection to consider ClassNode.typeAnnotations for methods/params/fields. |
| src/test/groovy/org/codehaus/groovy/ast/decompiled/support/WhereAnno.java | Introduces a runtime-retained type-use annotation used to validate ingestion and exact positioning. |
| src/test/groovy/org/codehaus/groovy/ast/decompiled/ReflectionTypeAnnotationsTest.groovy | Adds tests for the reflection/VMPlugin path ingesting AnnotatedType type-use annotations. |
| src/test/groovy/org/codehaus/groovy/ast/decompiled/AsmDecompilerTestData.java | Adds a richer fixture class (MoreTypeAnnotations) exercising generics/arrays/wildcards/throws/type params. |
| src/test/groovy/org/codehaus/groovy/ast/decompiled/AsmDecompilerTest.groovy | Adds ASM decompiler path tests validating correct attachment of type-use annotations and non-mutation of shared nodes. |
| src/main/java/org/codehaus/groovy/vmplugin/v8/Java8.java | Applies reflective type-use annotations recursively to ClassNode trees (generics/arrays/wildcards/supertypes/throws/type params). |
| src/main/java/org/codehaus/groovy/vmplugin/v16/Java16.java | Reuses the new reflective annotation application for record component types. |
| src/main/java/org/codehaus/groovy/ast/decompiled/MemberSignatureParser.java | Applies bytecode type annotations (with position) to fields/method return/params/throws/type params during member reconstruction. |
| src/main/java/org/codehaus/groovy/ast/decompiled/ClassStub.java | Extends stubs to store type annotations with typeRef + typePath and unifies member/record-component handling. |
| src/main/java/org/codehaus/groovy/ast/decompiled/ClassSignatureParser.java | Applies class-level type annotations to superclass/interfaces/type parameters and record component types. |
| src/main/java/org/codehaus/groovy/ast/decompiled/AsmDecompiler.java | Captures bytecode type annotations (class/member/field/record component) into stubs with positional metadata. |
| src/main/java/org/codehaus/groovy/ast/decompiled/Annotations.java | Implements position-aware application of bytecode type annotations via TypeReference + TypePath walking. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2743 +/- ##
==================================================
+ Coverage 69.8687% 69.8855% +0.0169%
- Complexity 35137 35190 +53
==================================================
Files 1554 1554
Lines 130731 130864 +133
Branches 23916 23955 +39
==================================================
+ Hits 91340 91455 +115
- Misses 31145 31154 +9
- Partials 8246 8255 +9
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: 7e103e6 Learn more about TestLens at testlens.app. |
No description provided.