[
https://issues.apache.org/jira/browse/GROOVY-10789?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17615344#comment-17615344
]
Eric Milles commented on GROOVY-10789:
--------------------------------------
You actually get quite a bit of control over how this works by setting the
"mode" attribute on {{@AnnotationCollector}} in your {{Collector}}
meta-annotation.
{code:java}
enum AnnotationCollectorMode {
/**
* Annotations from the annotation collection will always be inserted.
After all transforms have been run, it will
* be an error if multiple annotations (excluding those with SOURCE
retention) exist.
*/
DUPLICATE,
/**
* Annotations from the collector will be added and any existing
annotations with the same name will be removed.
*/
PREFER_COLLECTOR,
/**
* Annotations from the collector will be ignored if any existing
annotations with the same name are found.
*/
PREFER_EXPLICIT,
/**
* Annotations from the collector will be added and any existing
annotations with the same name will be removed but any new parameters found
within existing annotations will be merged into the added annotation.
*/
PREFER_COLLECTOR_MERGED,
/**
* Annotations from the collector will be ignored if any existing
annotations with the same name are found but any new parameters on the
collector annotation will be added to existing annotations.
*/
PREFER_EXPLICIT_MERGED
}
{code}
For example, {{@Canonical}} lets you do this:
{code:groovy}
@Canonical(defaults=false) // attribute of TupleConstructor
class C {
def foo
}
{code}
> Collected TupleConstructor causes internal compiler error
> ---------------------------------------------------------
>
> Key: GROOVY-10789
> URL: https://issues.apache.org/jira/browse/GROOVY-10789
> Project: Groovy
> Issue Type: Bug
> Components: Compiler
> Affects Versions: 4.0.5
> Reporter: Christopher Smith
> Priority: Major
>
> I have an in-house annotation collector that applies some of the usual
> transforms (TupleConstructor, ToString, CompileStatic/POJO). There's a
> particular class where I want a no-arg constructor available, and I expected
> that I could "override" the annotation's values like this:
> {code:groovy}
> class TcBug {
> @AnnotationCollector
> @TupleConstructor(defaults = false)
> @interface Collector {}
> @Collector
> @TupleConstructor(defaults = true)
> static class Foo {
> Integer value
> }
> }
> {code}
> However, this results in the following error message. I had thought that the
> above would work; if it isn't "supposed to", then a clearer error message
> (with location) would be helpful.
> {code}
> TcBug.groovy: -1: Unable to compile class com.example.TcBug$Foo due to hash
> collision in constructors @ line -1, column -1.
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)