[
https://issues.jboss.org/browse/CDI-43?page=com.atlassian.jira.plugin.sys...
]
Jozef Hartinger commented on CDI-43:
------------------------------------
Several consequences are implicit and we should discuss whether these are expected and/or
should be declared explicitly:
h3. Overriding
As per current proposal of
https://issues.jboss.org/browse/CDI-132,
AnnotatedType.getMethods() returns even those methods that are overridden. Therefore in
this situation:
{code:JAVA}
public class SimpleExtension implements Extension {
void observe(@Observes @WithAnnotations(Blah.class) ProcessAnnotatedType<Bar>
event)
}
public class Foo {
@Blah
public void ping() {
}
}
public class Bar extends Foo {
// no annotation here
public void ping() {
}
}
{code}
The observer method would be invoked for ProcessAnnotatedType<Bar> even though Bar
does not effectively use the @Blah annotation.
h3. Modification by extensions
Having a class
{code:JAVA}
@Bar
public class Foo {
}
{code}
there may be multiple observers of ProcessAnnotatedType<Foo>. These observers may
modify the annotated type and therefore modify the annotations that the type provides.
That means that if there are extension observer methods:
{code:JAVA}
void observe1(@Observes ProcessAnnotatedType<Foo> event) {
event.setAnnotatedType(removeBar(event.getAnnotatedType)); // removes @Bar from the
annotated type
}
void observe2(@Observes @WithAnnotations(Bar.class) ProcessAnnotatedType<Foo> event)
{
}
{code}
We can either:
* resolve the observer methods upfront and invoke observe2 even if observe1 has been
invoked before and the AnnotatedType no longer contains Bar which is required by
observe2.
* check the annotations of an AnnotatedType after each modification of the AnnotatedType
and only invoke the other observer method if the AnnotatedType still matches its
requirements
The latter approach seems wrong. Since the order of observer method invocation is not
specified, this could lead to random results. (the result would be dependent on the
unspecified order)
However, from the extension developer perspective it may be confusing if the observe2
method is invoked but the AnnotatedType contains no @Bar even though the observer methods
defined @WithAnnotations(Bar.class), so we should probably document that this may happen.
Allow Extensions to specify the annotations that they are interested
in
-----------------------------------------------------------------------
Key: CDI-43
URL:
https://issues.jboss.org/browse/CDI-43
Project: CDI Specification Issues
Issue Type: Feature Request
Components: Portable Extensions
Affects Versions: 1.0
Reporter: Stuart Douglas
Assignee: Pete Muir
Fix For: 1.1 (Proposed)
Currently portable extensions that wish to look for a specific annotation have to look
through all availible classes in the ProcessAnnotatatedType event, which is quite
inefficient. It would be good if extensions could do something like:
public void processAnnotatedType(@Observes @RequireAnnotations({(a)Unwraps.class})
ProcessAnnotatedType pat)
This could allow the container to take advantage of annotation indexing to improve boot
time performance, as well as reducing uneeded processing in the observer.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:
http://www.atlassian.com/software/jira