Exemplo n.º 1
0
 public PrimitiveType unboxedType(TypeMirror t) {
   if (t.getKind() != TypeKind.DECLARED) throw new IllegalArgumentException(t.toString());
   Type unboxed = types.unboxedType((Type) t);
   if (!unboxed.isPrimitive()) // only true primitives, not void
   throw new IllegalArgumentException(t.toString());
   return unboxed;
 }
Exemplo n.º 2
0
 public ArrayType getArrayType(TypeMirror componentType) {
   switch (componentType.getKind()) {
     case VOID:
     case EXECUTABLE:
     case WILDCARD: // heh!
     case PACKAGE:
       throw new IllegalArgumentException(componentType.toString());
   }
   return new Type.ArrayType((Type) componentType, syms.arrayClass);
 }
Exemplo n.º 3
0
  // where
  private DeclaredType getDeclaredType0(Type outer, ClassSymbol sym, TypeMirror... typeArgs) {
    if (typeArgs.length != sym.type.getTypeArguments().length())
      throw new IllegalArgumentException("Incorrect number of type arguments");

    ListBuffer<Type> targs = new ListBuffer<Type>();
    for (TypeMirror t : typeArgs) {
      if (!(t instanceof ReferenceType || t instanceof WildcardType))
        throw new IllegalArgumentException(t.toString());
      targs.append((Type) t);
    }
    // TODO: Would like a way to check that type args match formals.

    return (DeclaredType) new Type.ClassType(outer, targs.toList(), sym);
  }
Exemplo n.º 4
0
 public Element asElement(TypeMirror t) {
   switch (t.getKind()) {
     case DECLARED:
     case ERROR:
     case TYPEVAR:
       Type type = cast(Type.class, t);
       return type.asElement();
     default:
       return null;
   }
 }
Exemplo n.º 5
0
 /** Throws an IllegalArgumentException if a type's kind is one of a set. */
 private void validateTypeNotIn(TypeMirror t, Set<TypeKind> invalidKinds) {
   if (invalidKinds.contains(t.getKind())) throw new IllegalArgumentException(t.toString());
 }
Exemplo n.º 6
0
 public TypeMirror erasure(TypeMirror t) {
   if (t.getKind() == TypeKind.PACKAGE) throw new IllegalArgumentException(t.toString());
   return types.erasure((Type) t);
 }