Using ParametersInfo annotation in combination with extended interfaces

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Using ParametersInfo annotation in combination with extended interfaces

Tobias Jeger
Hi Hippos,

My Java class extends a class from the SEO forge plug-in. The class in the plug-in has a ParametersInfo annotation (and corresponding interface).
I want to add more parameters to this interface to support extra parameters of my Java class. I create an interface which extends
the ParametersInfo interface from the forge, and annotate all (getter) functions. I annotate my Java class with the new interface as its ParametersInfo type.

When I run this, I get an IllegalArgumentException from the HstParameterInfoProxyFactoryImpl, complaining that one of the inherited ParametersInfo functions
is "not annotated" (while it is, looking at the code). I wonder if the ParametersInfo mechanism is supposed/known to be able to deal with extending interfaces.

any experiences in that area?

thanks a lot

Tobi


--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Using ParametersInfo annotation in combination with extended interfaces

Mathijs den Burger
Hi Tobias,

Annotations on interface methods are not inherited, as described in the javadoc of @Inherited [1]:

"Note also that this meta-annotation only causes annotations to be inherited from superclasses; annotations on implemented interfaces have no effect."

AFAICS the only way to make the extended ParametersInfo class work is to repeat all methods in the super interface, including their annotations. Extending the interface therefore does not add much value, except that you can use the @Overrride annotation on the inherited methods to make sure you don't make any copy-paste errors in the method names :).

best,
Mathijs






On Wed, Jan 30, 2013 at 4:23 PM, Tobias Jeger <[hidden email]> wrote:
Hi Hippos,

My Java class extends a class from the SEO forge plug-in. The class in the plug-in has a ParametersInfo annotation (and corresponding interface).
I want to add more parameters to this interface to support extra parameters of my Java class. I create an interface which extends
the ParametersInfo interface from the forge, and annotate all (getter) functions. I annotate my Java class with the new interface as its ParametersInfo type.

When I run this, I get an IllegalArgumentException from the HstParameterInfoProxyFactoryImpl, complaining that one of the inherited ParametersInfo functions
is "not annotated" (while it is, looking at the code). I wonder if the ParametersInfo mechanism is supposed/known to be able to deal with extending interfaces.

any experiences in that area?

thanks a lot

Tobi


--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Using ParametersInfo annotation in combination with extended interfaces

Tobias Jeger
Ard just had a stop by my desk and figured out that the plug-in was still using an older version of the HST annotations. Using a locally modified plug-in which depends on a newer version of HST and the annotations makes the thing work as I hoped for, without having to duplicate the plug-in's parameter info interface.

I'll be looking into tagging a new version of the SEO forge plug-in.

cheers and thanks

Tobi


On Wed, Jan 30, 2013 at 5:12 PM, Mathijs den Burger <[hidden email]> wrote:
Hi Tobias,

Annotations on interface methods are not inherited, as described in the javadoc of @Inherited [1]:

"Note also that this meta-annotation only causes annotations to be inherited from superclasses; annotations on implemented interfaces have no effect."

AFAICS the only way to make the extended ParametersInfo class work is to repeat all methods in the super interface, including their annotations. Extending the interface therefore does not add much value, except that you can use the @Overrride annotation on the inherited methods to make sure you don't make any copy-paste errors in the method names :).

best,
Mathijs






On Wed, Jan 30, 2013 at 4:23 PM, Tobias Jeger <[hidden email]> wrote:
Hi Hippos,

My Java class extends a class from the SEO forge plug-in. The class in the plug-in has a ParametersInfo annotation (and corresponding interface).
I want to add more parameters to this interface to support extra parameters of my Java class. I create an interface which extends
the ParametersInfo interface from the forge, and annotate all (getter) functions. I annotate my Java class with the new interface as its ParametersInfo type.

When I run this, I get an IllegalArgumentException from the HstParameterInfoProxyFactoryImpl, complaining that one of the inherited ParametersInfo functions
is "not annotated" (while it is, looking at the code). I wonder if the ParametersInfo mechanism is supposed/known to be able to deal with extending interfaces.

any experiences in that area?

thanks a lot

Tobi


--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Ard
Reply | Threaded
Open this post in threaded view
|

Re: Using ParametersInfo annotation in combination with extended interfaces

Ard
In reply to this post by Mathijs den Burger
On Wed, Jan 30, 2013 at 5:12 PM, Mathijs den Burger
<[hidden email]> wrote:
> Hi Tobias,
>
> Annotations on interface methods are not inherited, as described in the
> javadoc of @Inherited [1]:

Yes but this was not Tobias his problem. The SEO interface he was
extending was using the deprecated Parameter annotation which we do
not scan any more

>
> "Note also that this meta-annotation only causes annotations to be inherited
> from superclasses; annotations on implemented interfaces have no effect."
>
> AFAICS the only way to make the extended ParametersInfo class work is to
> repeat all methods in the super interface, including their annotations.

No this is not true. As a matter of fact, the archetype uses interface
inheritance on parameter info! And I just added inheritance on the
backing resource bundles for it in trunk.

> Extending the interface therefore does not add much value, except that you
> can use the @Overrride annotation on the inherited methods to make sure you
> don't make any copy-paste errors in the method names :).

The problem is slightly different. Indeed, annotations are not
inherited. But this is only a problem in case of interface when you
*override* a method from a superinterface and then do not repeat the
same annotations. Since the parameter info works with interfaces only,
this is in general not an issue as you do not redefine the method.

In case of a class implementing an interface with annotations, indeed,
you would loose the interface annotations because class.getMethods do
not give you the interface method instances any more. I needed this in
the past already quite some times, and reuse the same piece of
recursive super class scanning. Pretty trivial after a couple of
times. For example see HST DocumentObjectBinder#doGetAnnotatedMethod
which returns you the annotation (super) method of some class method

Regards Ard

>
> best,
> Mathijs
>
> [1]
> http://docs.oracle.com/javase/6/docs/api/java/lang/annotation/Inherited.html
>
>
>
>
>
> On Wed, Jan 30, 2013 at 4:23 PM, Tobias Jeger <[hidden email]> wrote:
>>
>> Hi Hippos,
>>
>> My Java class extends a class from the SEO forge plug-in. The class in the
>> plug-in has a ParametersInfo annotation (and corresponding interface).
>> I want to add more parameters to this interface to support extra
>> parameters of my Java class. I create an interface which extends
>> the ParametersInfo interface from the forge, and annotate all (getter)
>> functions. I annotate my Java class with the new interface as its
>> ParametersInfo type.
>>
>> When I run this, I get an IllegalArgumentException from the
>> HstParameterInfoProxyFactoryImpl, complaining that one of the inherited
>> ParametersInfo functions
>> is "not annotated" (while it is, looking at the code). I wonder if the
>> ParametersInfo mechanism is supposed/known to be able to deal with extending
>> interfaces.
>>
>> any experiences in that area?
>>
>> thanks a lot
>>
>> Tobi
>>
>>
>> --
>> Amsterdam - Oosteinde 11, 1017 WT Amsterdam
>> Boston - 1 Broadway, Cambridge, MA 02142
>>
>> US +1 877 414 4776 (toll free)
>> Europe +31(0)20 522 4466
>> www.onehippo.com
>>
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/forums.html
>
>
>
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 1 Broadway, Cambridge, MA 02142

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com
_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html
Reply | Threaded
Open this post in threaded view
|

Re: Using ParametersInfo annotation in combination with extended interfaces

Mathijs den Burger
On Wed, Jan 30, 2013 at 5:27 PM, Ard Schrijvers <[hidden email]> wrote:
On Wed, Jan 30, 2013 at 5:12 PM, Mathijs den Burger
<[hidden email]> wrote:
> Hi Tobias,
>
> Annotations on interface methods are not inherited, as described in the
> javadoc of @Inherited [1]:

Yes but this was not Tobias his problem. The SEO interface he was
extending was using the deprecated Parameter annotation which we do
not scan any more

Aha!
 
> "Note also that this meta-annotation only causes annotations to be inherited
> from superclasses; annotations on implemented interfaces have no effect."
>
> AFAICS the only way to make the extended ParametersInfo class work is to
> repeat all methods in the super interface, including their annotations.

No this is not true. As a matter of fact, the archetype uses interface
inheritance on parameter info! And I just added inheritance on the
backing resource bundles for it in trunk.

> Extending the interface therefore does not add much value, except that you
> can use the @Overrride annotation on the inherited methods to make sure you
> don't make any copy-paste errors in the method names :).

The problem is slightly different. Indeed, annotations are not
inherited. But this is only a problem in case of interface when you
*override* a method from a superinterface and then do not repeat the
same annotations. Since the parameter info works with interfaces only,
this is in general not an issue as you do not redefine the method.

In case of a class implementing an interface with annotations, indeed,
you would loose the interface annotations because class.getMethods do
not give you the interface method instances any more. I needed this in
the past already quite some times, and reuse the same piece of
recursive super class scanning. Pretty trivial after a couple of
times. For example see HST DocumentObjectBinder#doGetAnnotatedMethod
which returns you the annotation (super) method of some class method

I see, nice reflection trickery! 

Good to know that this is possible, and now also with inherited resource bundles. 

Mathijs


_______________________________________________
Hippo-cms7-user mailing list and forums
http://www.onehippo.org/cms7/support/forums.html