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

Daniel Cunha danielsoro at gmail.com
Thu Jul 3 20:45:54 EDT 2014


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/forge-dev/attachments/20140703/3b8d611c/attachment.html 


More information about the forge-dev mailing list