Fabien POULARD wrote:
> Hi,
> 
> I was wondering if there was an easy way (I did look but found
> nothing) to get the Annotation class corresponding to a particular
> Type.
> 
> As I did not find any I wrote this hacky method... but I don't like
> it, it looks too hacky to work for long !
> 
> public static Class<? extends Annotation> typeToAnnotation(Type t) {
>   // We need to access the class of the annotation corresponding to the
>   // type to use as item
>   String typename  = t.getName();
>   String annotname = typename.replace("_Type", "");
>   Class<? extends Annotation> itemclass = (Class<? extends
> Annotation>) Class.forName(annotname);
>   return itemclass;
> }
> 
> What do you think ? Do you have any pointer ? I deeped into the
> LowLevelTypeSystem as well as the FSGenerator but found nothing.

I guess this will work, as long as there even is a JCas type
for the type you're looking for.  There may not always be one,
and we have this whole meta-programming kind of API for this
kind of situation.  If you tell us what you need the class for,
we may be able to suggest alternative ways of handling this.

--Thilo

> 
> --
> Fabien Poulard

Reply via email to