Example #1
0
 /**
  * Return a conservative estimage on the min/max number of items of a type.
  *
  * @return {@code maxCount << 12 | minCount & 0xFFF}, where a {@code maxCount} of -1 means
  *     unbounded.
  */
 public static int itemCountRange(Type type) {
   if (type instanceof SingletonType) return (1 << 12) | 1;
   if (type instanceof OccurrenceType) {
     OccurrenceType occ = (OccurrenceType) type;
     int min = occ.minOccurs();
     int max = occ.maxOccurs();
     int bnum = itemCountRange(occ.getBase());
     if ((min == 1 && max == 1) || bnum == 0) return bnum;
     if (max > 0xfffff) max = -1;
     if (max == 0) return 0;
     int bmin = bnum & 0xfff;
     int bmax = bnum >> 12;
     if (bnum != 0x1001) {
       if (min > 0xfff) min = 0xfff;
       min = min * bmin;
       if (min > 0xfff) min = 0xfff;
       if (max < 0 || bmax < 0) max = -1;
       else max = max * bmax;
       if (max > 0xfffff) max = -1;
     }
     return (max << 12) | min;
   }
   if (type instanceof PrimType) return type.isVoid() ? 0 : 0x1001;
   if (type instanceof ArrayType) return 0x1001;
   if (type instanceof ObjectType) {
     int cmp = type.compare(Compilation.typeValues);
     if (cmp == -3) return 0x1001;
   }
   return -1 << 12;
 }
Example #2
0
  /**
   * Returns the Type that represents the declared Class type of the given type. For primitive
   * types, the boxed class will be used. Examples:
   *
   * <ul>
   *   <li>If type represents {@code java.lang.Integer}, it will return the type that represents
   *       {@code Class<Integer>}.
   *   <li>If type represents {@code int}, it will return the type that represents {@code
   *       Class<Integer>}.
   * </ul>
   *
   * @param type the type to return the declared class type for
   * @return the type representing {@code Class<type>}.
   */
  public Type classTypeOf(Type type) {
    TypeMirror typeToUse;
    if (type.isVoid()) {
      return null;
    } else if (type.isPrimitive()) {
      typeToUse = typeUtils.boxedClass((PrimitiveType) type.getTypeMirror()).asType();
    } else {
      typeToUse = type.getTypeMirror();
    }

    return getType(
        typeUtils.getDeclaredType(elementUtils.getTypeElement("java.lang.Class"), typeToUse));
  }