[forge-dev] Fully qualified classes within annotations?

Richard Kennard richard at kennardconsulting.com
Sun Jan 15 21:28:35 EST 2012


Lincoln,

Okay that may work for me. I tried it and Class seems okay. However Annotations are still tricky. I can do...

          if (Annotation.class.isAssignableFrom(returnType))
          {
             String resolvedType = StringUtils.substringAfter(literalValue, "@");
             resolvedType = ((JavaSource<?>) this.annotationSource.getOrigin()).resolveType(resolvedType);

...and 'resolvedType' is a fully qualified String. But how can I turn that String into a 'proper' AnnotationImpl Object? I need this so I can call 
.getLiteralValue(...attribute...) on it.

Richard.

On 14/01/2012 4:41 AM, Lincoln Baxter, III wrote:
> Hey Richard,
>
> There is a method in JavaSource called resolveType(); This method will return the fully qualified type of the given Class name; however, there is a big 
> issue here at the moment. We cannot resolve wildcards, or classes from the same package that are in the 'package' visibility scope.
>
> https://issues.jboss.org/browse/FORGE-424
>
> In these two cases, resolveType() will actually return the class name unchanged, which is your signal to take desperate measures, because I don't think 
> that we will be fixing this in time for .Final. In the case of Column.class, I would start by assuming that the class is what you expect, and in the case 
> of other unknown types, at this point - unfortunately - it's going to be up to you to figure out what that type is, and if reasonable assumptions can be 
> made.
>
> Sorry about this, I know it's a big gap, but it's going to take a lot of work to fix this as you might be able to see in the issue. But definitely call 
> resolveType() as a first step, then you'll have to "worry" about handling potential issues where the type information is not available.
>
> We also can't tell if a Class literal is a class, interface, enum, etc...
>
> ~Lincoln
>
> On Thu, Jan 12, 2012 at 11:46 PM, Richard Kennard <richard at kennardconsulting.com <mailto:richard at kennardconsulting.com>> wrote:
>
>     Lincoln,
>
>     As you may recall, the new 'static Metawidget' scaffolding tries to reuse Inspectors between the runtime/static worlds. To do this, it needs to reify the
>     annotations from org.jboss.forge.parser.java.Annotations into 'proper' java.lang.annotation.Annotations.
>
>     This is mostly working, but I am struggling with reifying two things:
>
>     1. If the annotation's value is a Class
>     2. If the annotation's value is another annotation
>
>     The problem is the same in both cases - I am lacking the qualified name of the class/annotation. If they user enters:
>
>         @MyAnnotation( Column.class )
>
>     Then I need to know that it's actually a javax.persistence.Column.class. This is a bit beyond me! I have left a couple of TODOs in ForgePropertyStyle and
>     in ForgePropertyStyleTest. Could you take a look?
>
>     Regards,
>
>     Richard.
>     _______________________________________________
>     forge-dev mailing list
>     forge-dev at lists.jboss.org <mailto:forge-dev at lists.jboss.org>
>     https://lists.jboss.org/mailman/listinfo/forge-dev
>
>
>
>
> -- 
> Lincoln Baxter, III
> http://ocpsoft.com
> http://scrumshark.com
> "Keep it Simple"
>
>
> _______________________________________________
> forge-dev mailing list
> forge-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/forge-dev



More information about the forge-dev mailing list