[forge-dev] [Roaster] Type<?> instanceof

Daniel Cunha danielsoro at gmail.com
Fri Jul 4 05:27:19 EDT 2014


Hmmm,

Ok. Thank you very much George. :)


On Fri, Jul 4, 2014 at 12:06 AM, George Gastaldi <ggastald at redhat.com>
wrote:

> Hi Daniel,
>
> You could try to load the class using: Class.forName and then attempt to
> check if the class isAssignableFrom(Number.class)
>
> This will not work if the class does not belong to the current
> classloader, but I am not sure if you're going to run into this issue
> specifically.
>
> Em 03/07/2014, às 21:46, Daniel Cunha <danielsoro at gmail.com> escreveu:
>
> Hi folks,
>
> I want do that:
>
> type instanceof Number.
>
> That case, my type can be AtomicInteger, AtomicLong, BigDecimal,
> BigInteger, Byte, Double, Float, Integer, Long and Short
>
> Eg:.
>
>  public static Type<?> getIdType(JavaClass<?> entity)
>    {
>       for (Member<?> member : entity.getMembers())
>       {
>          if (member.hasAnnotation(Id.class))
>          {
>             if (member instanceof Method)
>             {
>                return ((Method<?, ?>) member).getReturnType();
>             }
>             if (member instanceof Field)
>             {
>                return ((Field<?>) member).getType();
>             }
>          }
>       }
>       return null;
>    }
>
>     public static boolean isNumberIdType(JavaClass<?> entity)
>    {
>       return getIdType(entity) instanceof Number;
>    }
>
> I see the code and I don’t see a simple form to do it.
> How I do that with Roaster Type<?>?
>
> I thought to do that in Types (roaster util):
>
>    public static boolean isNumber(final String type)
>    {
>       if (isBasicType(type))
>       {
>          if (isPrimitive(type))
>          {
>             return Arrays.asList("int", "long", "float", "double", "short").contains(type);
>          }
>          return Arrays.asList("Boolean", "Byte", "Double", "Float", "Integer", "Long", "Short").contains(
>                   type);
>       }
>       return false;
>    }
>
> But, it isn’t good.
>> --
> Daniel Cunha (soro) <http://www.cejug.net>
> Blog: http://www.danielsoro.com.br
> Twitter: https://twitter.com/dvlc_
> GitHub: https://github.com/danielsoro
> LinkedIn:  http://www.linkedin.com/in/danielvlcunha
>
> _______________________________________________
> forge-dev mailing list
> forge-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/forge-dev
>
>
> _______________________________________________
> forge-dev mailing list
> forge-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/forge-dev
>



-- 
Daniel Cunha (soro) <http://www.cejug.net>
Blog: http://www.danielsoro.com.br
Twitter: https://twitter.com/dvlc_
GitHub: https://github.com/danielsoro
LinkedIn:  http://www.linkedin.com/in/danielvlcunha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/forge-dev/attachments/20140704/e6d19d54/attachment.html 


More information about the forge-dev mailing list