Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mutated metadata being cleared before it was written in Groovy cl…
…asses (#6749) * Fix mutated metadata being cleared before it was written in Groovy classes * Add test for mutated metadata being used in bean definitions * Read defaults from compile time information for mutable metadata * Reuse existing test instead * Fix test
- Loading branch information
1 parent
cba5528
commit 7ae026d
Showing
9 changed files
with
79 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
inject-groovy/src/test/groovy/io/micronaut/inject/visitor/AnnotationMetadataSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.micronaut.inject.visitor | ||
|
||
import io.micronaut.ast.transform.test.AbstractBeanDefinitionSpec | ||
|
||
class AnnotationMetadataSpec extends AbstractBeanDefinitionSpec { | ||
|
||
void "test mutated metadata from a visitor is available on beans"() { | ||
when: | ||
def definition = buildBeanDefinition('test.TestListener', ''' | ||
package test | ||
import io.micronaut.context.annotation.* | ||
import jakarta.inject.Singleton | ||
import io.micronaut.inject.visitor.SomeAnn | ||
@Singleton | ||
class TestListener { | ||
@SomeAnn | ||
@Executable | ||
void receive(String v) { | ||
} | ||
} | ||
''') | ||
|
||
then: | ||
noExceptionThrown() //asserts default values are available | ||
definition.findMethod("receive", String).get().hasAnnotation('my.custom.Annotation') | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
inject-groovy/src/test/groovy/io/micronaut/inject/visitor/MutatingVisitor.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.micronaut.inject.visitor | ||
|
||
import io.micronaut.inject.ast.MethodElement | ||
|
||
class MutatingVisitor implements TypeElementVisitor<Object, SomeAnn> { | ||
|
||
void visitMethod(MethodElement element, VisitorContext context) { | ||
element.annotate("my.custom.Annotation") | ||
element.annotationMetadata.findAnnotation(SomeAnn).get().getRequiredValue("someValue", String) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
inject-groovy/src/test/groovy/io/micronaut/inject/visitor/SomeAnn.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package io.micronaut.inject.visitor | ||
|
||
@interface SomeAnn { | ||
|
||
String someValue() default "OK" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters