You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Artem Zhirkov <az...@develdynamic.com> on 2015/03/10 20:16:06 UTC

DS and custom annotations

Hello,

I'm trying to annotate some methods in my DS class and then get these 
annotations from the host application. Unfortunately, when I calling 
getAnnotation() from the host it always returns null.

My annotation looks like this:
@Retention(RetentionPolicy.RUNTIME)
public @interface DataProvider {
     String optionType();
     String optionTemplate();
}

and the code which looks for DataProvider is (dont mind groovy syntax):
for (Method method : module.class.methods){
             println("method name: " + method.name)

             println("has DataProvider annotation: " + 
method.getAnnotation(DataProvider.class) )

         }
would always print null for every method in my DS, including annotated ones.

Any ideas what I'm doing wrong?

Thank you


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: DS and custom annotations

Posted by Artem Zhirkov <az...@develdynamic.com>.
Neil, thank you so much!
It was my inattention to bundle's imports once again that caused this 
issue. I added the package with the DataProvider annotation to imports 
and things started to work as expected.

Best regards

On 11.03.2015 05:33, Neil Bartlett wrote:
> Does your DS component bundle import the package that contains the DataProvider annotation type? And does the bundle doing the introspection in Groovy code also import that package, from the same provider?
>
> If these don’t match up then I would expect the getAnnotation() method to return null. Classloading for annotations is a little different than for normal classes — when something goes wrong, the JRE does not raise an exception but instead simply throws away the annotation metadata.
>
> Regards,
> Neil
>
>> On 10 Mar 2015, at 19:16, Artem Zhirkov <az...@develdynamic.com> wrote:
>>
>> Hello,
>>
>> I'm trying to annotate some methods in my DS class and then get these annotations from the host application. Unfortunately, when I calling getAnnotation() from the host it always returns null.
>>
>> My annotation looks like this:
>> @Retention(RetentionPolicy.RUNTIME)
>> public @interface DataProvider {
>>     String optionType();
>>     String optionTemplate();
>> }
>>
>> and the code which looks for DataProvider is (dont mind groovy syntax):
>> for (Method method : module.class.methods){
>>             println("method name: " + method.name)
>>
>>             println("has DataProvider annotation: " + method.getAnnotation(DataProvider.class) )
>>
>>         }
>> would always print null for every method in my DS, including annotated ones.
>>
>> Any ideas what I'm doing wrong?
>>
>> Thank you
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: DS and custom annotations

Posted by Neil Bartlett <nj...@gmail.com>.
Does your DS component bundle import the package that contains the DataProvider annotation type? And does the bundle doing the introspection in Groovy code also import that package, from the same provider?

If these don’t match up then I would expect the getAnnotation() method to return null. Classloading for annotations is a little different than for normal classes — when something goes wrong, the JRE does not raise an exception but instead simply throws away the annotation metadata.

Regards,
Neil

> On 10 Mar 2015, at 19:16, Artem Zhirkov <az...@develdynamic.com> wrote:
> 
> Hello,
> 
> I'm trying to annotate some methods in my DS class and then get these annotations from the host application. Unfortunately, when I calling getAnnotation() from the host it always returns null.
> 
> My annotation looks like this:
> @Retention(RetentionPolicy.RUNTIME)
> public @interface DataProvider {
>    String optionType();
>    String optionTemplate();
> }
> 
> and the code which looks for DataProvider is (dont mind groovy syntax):
> for (Method method : module.class.methods){
>            println("method name: " + method.name)
> 
>            println("has DataProvider annotation: " + method.getAnnotation(DataProvider.class) )
> 
>        }
> would always print null for every method in my DS, including annotated ones.
> 
> Any ideas what I'm doing wrong?
> 
> Thank you
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org