Java Code Examples for java.lang.reflect.GenericDeclaration

The following examples show how to use java.lang.reflect.GenericDeclaration. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: j2objc   Source File: GenericSignatureParser.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Parses the generic signature of a class and creates the data structure
 * representing the signature.
 *
 * @param genericDecl the GenericDeclaration calling this method
 * @param signature the generic signature of the class
 */
public void parseForClass(GenericDeclaration genericDecl, String signature) {
    setInput(genericDecl, signature);
    if (!eof) {
        parseClassSignature();
    } else {
        if(genericDecl instanceof Class) {
            Class c = (Class) genericDecl;
            this.formalTypeParameters = EmptyArray.TYPE_VARIABLE;
            this.superclassType = c.getSuperclass();
            Class<?>[] interfaces = c.getInterfaces();
            if (interfaces.length == 0) {
                this.interfaceTypes = ListOfTypes.EMPTY;
            } else {
                this.interfaceTypes = new ListOfTypes(interfaces);
            }
        } else {
            this.formalTypeParameters = EmptyArray.TYPE_VARIABLE;
            this.superclassType = Object.class;
            this.interfaceTypes = ListOfTypes.EMPTY;
        }
    }
}
 
Example 2
public Class<?> getGenericType(Method method) {
	Type genericReturnType = method.getGenericReturnType();
	if (method.getGenericReturnType() instanceof ParameterizedType) {
		ParameterizedType parameterizedTypeImpl = (ParameterizedType)genericReturnType;
		Type first = parameterizedTypeImpl.getActualTypeArguments()[0];
		if (first instanceof WildcardType) {
			return null;
		} else if (first instanceof ParameterizedType) {
			return null;
		} else if (first instanceof TypeVariable) {
			TypeVariable<?> typeVariableImpl = (TypeVariable<?>)first;
			GenericDeclaration genericDeclaration = typeVariableImpl.getGenericDeclaration();
			if (genericDeclaration instanceof Class) {
				return (Class<?>) genericDeclaration;
			}
		} else {
			return (Class<?>) first;
		}
	}
	Type genericReturnType2 = method.getGenericReturnType();
	if (genericReturnType2 instanceof Class) {
		return (Class<?>)genericReturnType2;
	}
	return null;
}
 
Example 3
Source Project: vertx-codegen   Source File: TypeParamInfo.java    License: Apache License 2.0 6 votes vote down vote up
public static TypeParamInfo create(java.lang.reflect.TypeVariable typeVariable) {
  GenericDeclaration decl = typeVariable.getGenericDeclaration();
  TypeVariable<?>[] typeParams = decl.getTypeParameters();
  for (int index = 0;index < typeParams.length;index++) {
    if (typeParams[index].equals(typeVariable)) {
      if (decl instanceof java.lang.Class) {
        java.lang.Class classDecl = (java.lang.Class) decl;
        return new Class(classDecl.getName(), index, typeVariable.getName());
      } else if (decl instanceof java.lang.reflect.Method) {
        java.lang.reflect.Method methodDecl = (java.lang.reflect.Method) decl;
        return new Method(methodDecl.getDeclaringClass().getName(), methodDecl.getName(), index, typeVariable.getName());
      } else {
        throw new UnsupportedOperationException();
      }
    }
  }
  throw new AssertionError();
}
 
Example 4
Source Project: Java-Coding-Problems   Source File: Main.java    License: MIT License 5 votes vote down vote up
private static void printGenericsOfExceptions(Type genericType) {
    
    if (genericType instanceof TypeVariable) {

        TypeVariable typeVariable = (TypeVariable) genericType;
        GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();

        System.out.println("Generic declaration: " + genericDeclaration);
            System.out.println("Bounds: ");
            for (Type type: typeVariable.getBounds()) {
                System.out.println(type);
            }
    }
}
 
Example 5
Source Project: framework   Source File: $Gson$Types.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by
 * a class.
 */
private static Class<?> declaringClassOf(TypeVariable<?> typeVariable) {
  GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
  return genericDeclaration instanceof Class
      ? (Class<?>) genericDeclaration
      : null;
}
 
Example 6
Source Project: cxf   Source File: InjectionUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static Type getSuperType(Class<?> serviceClass, TypeVariable<?> var) {

        int pos = 0;
        GenericDeclaration genericDeclaration = var.getGenericDeclaration();
        TypeVariable<?>[] vars = genericDeclaration.getTypeParameters();
        for (; pos < vars.length; pos++) {
            if (vars[pos].getName().equals(var.getName())) {
                break;
            }
        }

        ParameterizedType genericSubtype = findGenericDeclaration(genericDeclaration, serviceClass);
        Type result = null;
        if (genericSubtype != null) {
            result = genericSubtype.getActualTypeArguments()[pos];
        }
        if (result instanceof TypeVariable) {
            result = getSuperType(serviceClass, (TypeVariable<?>) result);
        }

        if (result == null || result == Object.class) {
            for (Type bound : var.getBounds()) {
                if (bound != Object.class) {
                    result = bound;
                    break;
                }
            }
        }
        return result;
    }
 
Example 7
Source Project: j2objc   Source File: TypeVariableImpl.java    License: Apache License 2.0 5 votes vote down vote up
static TypeVariable findFormalVar(GenericDeclaration layer, String name) {
    TypeVariable[] formalVars = layer.getTypeParameters();
    for (TypeVariable var : formalVars) {
        if (name.equals(var.getName())) {
            return var;
        }
    }
    // resolve() looks up the next level only, if null is returned
    return null;
}
 
Example 8
Source Project: j2objc   Source File: GenericSignatureParser.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Parses the generic signature of a field and creates the data structure
 * representing the signature.
 *
 * @param genericDecl the GenericDeclaration calling this method
 * @param signature the generic signature of the class
 */
public void parseForField(GenericDeclaration genericDecl,
        String signature) {
    setInput(genericDecl, signature);
    if (!eof) {
        this.fieldType = parseFieldTypeSignature();
    }
}
 
Example 9
Source Project: baratine   Source File: JavaWriter.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Prints the Java representation of the type
 */
@SuppressWarnings("unchecked")
public void printType(Type type)
  throws IOException
{
  if (type instanceof Class<?>) {
    printTypeClass((Class<?>) type);
  } 
  else if (type instanceof ParameterizedType) {
    ParameterizedType parameterizedType = (ParameterizedType) type;
    
    printParameterizedType(parameterizedType);
  }
  else if (type instanceof WildcardType) {
    WildcardType wildcardType = (WildcardType) type;
    
    printWildcardType(wildcardType);
  }
  else if (type instanceof TypeVariable<?>) {
    TypeVariable<? extends GenericDeclaration> typeVariable = (TypeVariable<? extends GenericDeclaration>) type;
    
    printTypeVariable(typeVariable);
  }
  else if (type instanceof GenericArrayType) {
    GenericArrayType genericArrayType = (GenericArrayType) type;

    printType(genericArrayType.getGenericComponentType());
    print("[]");
  }
  else {
    throw new UnsupportedOperationException(type.getClass().getName() + " "
        + String.valueOf(type));
  }
}
 
Example 10
protected void enhanceGenericDeclaration(JvmExecutable result, GenericDeclaration declaration) {
	TypeVariable<?>[] typeParameters = declaration.getTypeParameters();
	if (typeParameters.length != 0) {
		InternalEList<JvmTypeParameter> jvmTypeParameters = (InternalEList<JvmTypeParameter>)result.getTypeParameters();
		for (TypeVariable<?> variable : typeParameters) {
			jvmTypeParameters.addUnique(createTypeParameter(variable, result));
		}
	}
}
 
Example 11
private static void check2(Type t, String what) {
    if (t instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) t;
        check(pt.getActualTypeArguments(), "type argument", what);
    } else if (t instanceof TypeVariable) {
        TypeVariable<?> tv = (TypeVariable<?>) t;
        check(tv.getBounds(), "bound", what);
        GenericDeclaration gd = tv.getGenericDeclaration();
        if (gd instanceof Type)
            check((Type) gd, "declaration containing " + what);
    } else if (t instanceof WildcardType) {
        WildcardType wt = (WildcardType) t;
        check(wt.getLowerBounds(), "lower bound", "wildcard type in " + what);
        check(wt.getUpperBounds(), "upper bound", "wildcard type in " + what);
    } else if (t instanceof Class<?>) {
        Class<?> c = (Class<?>) t;
        check(c.getGenericInterfaces(), "superinterface", c.toString());
        check(c.getGenericSuperclass(), "superclass of " + c);
        check(c.getTypeParameters(), "type parameter", c.toString());
    } else if (t instanceof GenericArrayType) {
        GenericArrayType gat = (GenericArrayType) t;
        Type comp = gat.getGenericComponentType();
        if (comp instanceof Class) {
            fail("Type " + t + " uses GenericArrayType when plain " +
                    "array would do, in " + what);
        } else
            check(comp, "component type of " + what);
    } else {
        fail("TEST BUG: mutant Type " + t + " (a " + t.getClass().getName() + ")");
    }
}
 
Example 12
Source Project: google-http-java-client   Source File: Types.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Resolves the actual type of the given type variable that comes from a field type based on the
 * given context list.
 *
 * <p>In case the type variable can be resolved partially, it will return the partially resolved
 * type variable.
 *
 * @param context context list, ordering from least specific to most specific type context, for
 *     example container class and then its field
 * @param typeVariable type variable
 * @return resolved or partially resolved actual type (type variable, class, parameterized type,
 *     or generic array type, but not wildcard type) or {@code null} if unable to resolve at all
 */
public static Type resolveTypeVariable(List<Type> context, TypeVariable<?> typeVariable) {
  // determine where the type variable was declared
  GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
  if (genericDeclaration instanceof Class<?>) {
    Class<?> rawGenericDeclaration = (Class<?>) genericDeclaration;
    // check if the context extends that declaration
    int contextIndex = context.size();
    ParameterizedType parameterizedType = null;
    while (parameterizedType == null && --contextIndex >= 0) {
      parameterizedType =
          getSuperParameterizedType(context.get(contextIndex), rawGenericDeclaration);
    }
    if (parameterizedType != null) {
      // find the type variable's index in the declaration's type parameters
      TypeVariable<?>[] typeParameters = genericDeclaration.getTypeParameters();
      int index = 0;
      for (; index < typeParameters.length; index++) {
        TypeVariable<?> typeParameter = typeParameters[index];
        if (typeParameter.equals(typeVariable)) {
          break;
        }
      }
      // use that index to get the actual type argument
      Type result = parameterizedType.getActualTypeArguments()[index];
      if (result instanceof TypeVariable<?>) {
        // attempt to resolve type variable
        Type resolve = resolveTypeVariable(context, (TypeVariable<?>) result);
        if (resolve != null) {
          return resolve;
        }
        // partially resolved type variable is okay
      }
      return result;
    }
  }
  return null;
}
 
Example 13
Source Project: baratine   Source File: TypeRefBase.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static TypeRef visitParameterizedType(TypeVisitor visitor,
                                              Type rawType,
                                              Type []typeArguments,
                                              Map<String,? extends Type> parentMap)
{
  if (rawType instanceof GenericDeclaration) {
    GenericDeclaration decl = (GenericDeclaration) rawType;
    
    TypeVariable<?> []vars = decl.getTypeParameters();
    
    Map<String,Type> varMap = new LinkedHashMap<>();
    
    for (int i = 0; i < vars.length; i++) {
      Type typeArg = typeArguments[i];
      
      if (typeArg instanceof TypeVariable) {
        TypeVariable<?> typeVar = (TypeVariable<?>) typeArg;
        
        Type parentType = parentMap.get(typeVar.getName());
        
        if (parentType != null) {
          varMap.put(vars[i].getName(), parentType);
        }
        else {
          varMap.put(vars[i].getName(), typeVar.getBounds()[0]);
        }
      }
      else {
        varMap.put(vars[i].getName(), typeArg);
      }
    }
    
    return visit(visitor, rawType, varMap);
  }
  else {
    System.out.println("UNKNOWN2: " + rawType);
    return null;
  }
}
 
Example 14
private static void check2(Type t, String what) {
    if (t instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) t;
        check(pt.getActualTypeArguments(), "type argument", what);
    } else if (t instanceof TypeVariable) {
        TypeVariable<?> tv = (TypeVariable<?>) t;
        check(tv.getBounds(), "bound", what);
        GenericDeclaration gd = tv.getGenericDeclaration();
        if (gd instanceof Type)
            check((Type) gd, "declaration containing " + what);
    } else if (t instanceof WildcardType) {
        WildcardType wt = (WildcardType) t;
        check(wt.getLowerBounds(), "lower bound", "wildcard type in " + what);
        check(wt.getUpperBounds(), "upper bound", "wildcard type in " + what);
    } else if (t instanceof Class<?>) {
        Class<?> c = (Class<?>) t;
        check(c.getGenericInterfaces(), "superinterface", c.toString());
        check(c.getGenericSuperclass(), "superclass of " + c);
        check(c.getTypeParameters(), "type parameter", c.toString());
    } else if (t instanceof GenericArrayType) {
        GenericArrayType gat = (GenericArrayType) t;
        Type comp = gat.getGenericComponentType();
        if (comp instanceof Class) {
            fail("Type " + t + " uses GenericArrayType when plain " +
                    "array would do, in " + what);
        } else
            check(comp, "component type of " + what);
    } else {
        fail("TEST BUG: mutant Type " + t + " (a " + t.getClass().getName() + ")");
    }
}
 
Example 15
Source Project: GVGAI_GYM   Source File: $Gson$Types.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by
 * a class.
 */
private static Class<?> declaringClassOf(TypeVariable<?> typeVariable) {
  GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
  return genericDeclaration instanceof Class
      ? (Class<?>) genericDeclaration
      : null;
}
 
Example 16
protected boolean isLocal(Type parameterType, GenericDeclaration member) {
	if (parameterType instanceof TypeVariable<?>) {
		return member.equals(((TypeVariable<?>) parameterType).getGenericDeclaration());
	} else if (parameterType instanceof GenericArrayType) {
		return isLocal(((GenericArrayType) parameterType).getGenericComponentType(), member);
	}
	return false;
}
 
Example 17
@Override
public boolean equals(Object o) {
    if (o instanceof TypeVariable &&
            o.getClass() == TypeVariableImpl.class) {
        TypeVariable<?> that = (TypeVariable<?>) o;

        GenericDeclaration thatDecl = that.getGenericDeclaration();
        String thatName = that.getName();

        return Objects.equals(genericDeclaration, thatDecl) &&
            Objects.equals(name, thatName);

    } else
        return false;
}
 
Example 18
Source Project: hottub   Source File: TypeVariableImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Factory method.
 * @param decl - the reflective object that declared the type variable
 * that this method should create
 * @param name - the name of the type variable to be returned
 * @param bs - an array of ASTs representing the bounds for the type
 * variable to be created
 * @param f - a factory that can be used to manufacture reflective
 * objects that represent the bounds of this type variable
 * @return A type variable with name, bounds, declaration and factory
 * specified
 */
public static <T extends GenericDeclaration>
                         TypeVariableImpl<T> make(T decl, String name,
                                                  FieldTypeSignature[] bs,
                                                  GenericsFactory f) {

    if (!((decl instanceof Class) ||
            (decl instanceof Method) ||
            (decl instanceof Constructor))) {
        throw new AssertionError("Unexpected kind of GenericDeclaration" +
                decl.getClass().toString());
    }
    return new TypeVariableImpl<T>(decl, name, bs, f);
}
 
Example 19
private static void check2(Type t, String what) {
    if (t instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) t;
        check(pt.getActualTypeArguments(), "type argument", what);
    } else if (t instanceof TypeVariable) {
        TypeVariable<?> tv = (TypeVariable<?>) t;
        check(tv.getBounds(), "bound", what);
        GenericDeclaration gd = tv.getGenericDeclaration();
        if (gd instanceof Type)
            check((Type) gd, "declaration containing " + what);
    } else if (t instanceof WildcardType) {
        WildcardType wt = (WildcardType) t;
        check(wt.getLowerBounds(), "lower bound", "wildcard type in " + what);
        check(wt.getUpperBounds(), "upper bound", "wildcard type in " + what);
    } else if (t instanceof Class<?>) {
        Class<?> c = (Class<?>) t;
        check(c.getGenericInterfaces(), "superinterface", c.toString());
        check(c.getGenericSuperclass(), "superclass of " + c);
        check(c.getTypeParameters(), "type parameter", c.toString());
    } else if (t instanceof GenericArrayType) {
        GenericArrayType gat = (GenericArrayType) t;
        Type comp = gat.getGenericComponentType();
        if (comp instanceof Class) {
            fail("Type " + t + " uses GenericArrayType when plain " +
                    "array would do, in " + what);
        } else
            check(comp, "component type of " + what);
    } else {
        fail("TEST BUG: mutant Type " + t + " (a " + t.getClass().getName() + ")");
    }
}
 
Example 20
Source Project: jade-plugin-sql   Source File: OperationMapper.java    License: Apache License 2.0 5 votes vote down vote up
protected Class<?> resolveParameterType(Type type) {
	if(type instanceof Class) {
		return (Class<?>) type;
	} else if(type instanceof ParameterizedType
			&& ((ParameterizedType) type).getRawType() instanceof Class
			&& Collection.class.isAssignableFrom((Class<?>) ((ParameterizedType) type).getRawType())) {
		
		// GenericDAO中的集合泛型参数
		return resolveParameterType(((ParameterizedType) type).getActualTypeArguments()[0]);
	} else if(type instanceof TypeVariable) {
		
		// GenericDAO中的非集合泛型参数,或许是主键或许是实体。
		GenericDeclaration genericDeclaration = ((TypeVariable<?>) type).getGenericDeclaration();
		if(genericDeclaration == GenericDAO.class) {
			Type[] bounds = ((TypeVariable<?>) type).getBounds();
			
			if(bounds[0] == Object.class) {
				String name = ((TypeVariable<?>) type).getName();
				if("E".equals(name)) {
					return entityType;
				} else if("ID".equals(name)) {
					return primaryKeyType;
				} else {
					throw new MappingException("Unknown type variable \"" + type + "\".");
				}
			} else {
				return resolveParameterType(bounds[0]);
			}
		} else {
			throw new MappingException("Unsupported generic declaration \"" + genericDeclaration + "\".");
		}
	}
	throw new MappingException("Unknown type \"" + type + "\".");
}
 
Example 21
Source Project: vertx-codegen   Source File: Helper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Return the type of a type parameter element of a given type element when that type parameter
 * element is parameterized by a sub type, directly or indirectly. When the type parameter cannot
 * be resolve, null is returned.
 *
 * @param type the sub type for which the type parameter is parameterized
 * @param typeParam the type parameter to resolve
 * @return the type parameterizing the type parameter
 */
public static <T> Type resolveTypeParameter(Type type, java.lang.reflect.TypeVariable<java.lang.Class<T>> typeParam) {
  if (type instanceof Class<?>) {
    Class<?> classType = (Class<?>) type;
    if (Stream.of(classType.getTypeParameters()).filter(tp -> tp.equals(typeParam)).findFirst().isPresent()) {
      return typeParam;
    }
    List<Type> superTypes = new ArrayList<>();
    if (classType.getGenericSuperclass() != null) {
      superTypes.add(classType.getGenericSuperclass());
    }
    Collections.addAll(superTypes, classType.getGenericInterfaces());
    for (Type superType : superTypes) {
      Type resolved = resolveTypeParameter(superType, typeParam);
      if (resolved != null) {
        return resolved;
      }
    }
  } else if (type instanceof ParameterizedType) {
    ParameterizedType parameterizedType = (ParameterizedType) type;
    Type rawType = parameterizedType.getRawType();
    Type resolvedType = resolveTypeParameter(rawType, typeParam);
    if (resolvedType instanceof java.lang.reflect.TypeVariable<?>) {
      GenericDeclaration owner = ((java.lang.reflect.TypeVariable) resolvedType).getGenericDeclaration();
      if (owner.equals(rawType)) {
        java.lang.reflect.TypeVariable<?>[] typeParams = owner.getTypeParameters();
        for (int i = 0;i < typeParams.length;i++) {
          if (typeParams[i].equals(resolvedType)) {
            return parameterizedType.getActualTypeArguments()[i];
          }
        }
      }
    }
  } else {
    throw new UnsupportedOperationException("Todo " + type.getTypeName() + " " + type.getClass().getName());
  }
  return null;
}
 
Example 22
Source Project: generics-resolver   Source File: UnknownGenericException.java    License: MIT License 5 votes vote down vote up
private UnknownGenericException(final Class<?> contextType,
                                final String genericName, final GenericDeclaration genericSource,
                                final Throwable cause) {
    super(String.format("Generic '%s'%s is not declared %s",
            genericName, formatSource(genericSource),
            contextType == null ? "" : "on type " + contextType.getName()), cause);
    this.contextType = contextType;
    this.genericName = genericName;
    this.genericSource = genericSource;
}
 
Example 23
Source Project: Bytecoder   Source File: TypeVariableImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (o instanceof TypeVariable &&
            o.getClass() == TypeVariableImpl.class) {
        TypeVariable<?> that = (TypeVariable<?>) o;

        GenericDeclaration thatDecl = that.getGenericDeclaration();
        String thatName = that.getName();

        return Objects.equals(genericDeclaration, thatDecl) &&
            Objects.equals(name, thatName);

    } else
        return false;
}
 
Example 24
private static void check2(Type t, String what) {
    if (t instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) t;
        check(pt.getActualTypeArguments(), "type argument", what);
    } else if (t instanceof TypeVariable) {
        TypeVariable<?> tv = (TypeVariable<?>) t;
        check(tv.getBounds(), "bound", what);
        GenericDeclaration gd = tv.getGenericDeclaration();
        if (gd instanceof Type)
            check((Type) gd, "declaration containing " + what);
    } else if (t instanceof WildcardType) {
        WildcardType wt = (WildcardType) t;
        check(wt.getLowerBounds(), "lower bound", "wildcard type in " + what);
        check(wt.getUpperBounds(), "upper bound", "wildcard type in " + what);
    } else if (t instanceof Class<?>) {
        Class<?> c = (Class<?>) t;
        check(c.getGenericInterfaces(), "superinterface", c.toString());
        check(c.getGenericSuperclass(), "superclass of " + c);
        check(c.getTypeParameters(), "type parameter", c.toString());
    } else if (t instanceof GenericArrayType) {
        GenericArrayType gat = (GenericArrayType) t;
        Type comp = gat.getGenericComponentType();
        if (comp instanceof Class) {
            fail("Type " + t + " uses GenericArrayType when plain " +
                    "array would do, in " + what);
        } else
            check(comp, "component type of " + what);
    } else {
        fail("TEST BUG: mutant Type " + t + " (a " + t.getClass().getName() + ")");
    }
}
 
Example 25
private static void check2(Type t, String what) {
    if (t instanceof ParameterizedType) {
        ParameterizedType pt = (ParameterizedType) t;
        check(pt.getActualTypeArguments(), "type argument", what);
    } else if (t instanceof TypeVariable) {
        TypeVariable<?> tv = (TypeVariable<?>) t;
        check(tv.getBounds(), "bound", what);
        GenericDeclaration gd = tv.getGenericDeclaration();
        if (gd instanceof Type)
            check((Type) gd, "declaration containing " + what);
    } else if (t instanceof WildcardType) {
        WildcardType wt = (WildcardType) t;
        check(wt.getLowerBounds(), "lower bound", "wildcard type in " + what);
        check(wt.getUpperBounds(), "upper bound", "wildcard type in " + what);
    } else if (t instanceof Class<?>) {
        Class<?> c = (Class<?>) t;
        check(c.getGenericInterfaces(), "superinterface", c.toString());
        check(c.getGenericSuperclass(), "superclass of " + c);
        check(c.getTypeParameters(), "type parameter", c.toString());
    } else if (t instanceof GenericArrayType) {
        GenericArrayType gat = (GenericArrayType) t;
        Type comp = gat.getGenericComponentType();
        if (comp instanceof Class) {
            fail("Type " + t + " uses GenericArrayType when plain " +
                    "array would do, in " + what);
        } else
            check(comp, "component type of " + what);
    } else {
        fail("TEST BUG: mutant Type " + t + " (a " + t.getClass().getName() + ")");
    }
}
 
Example 26
Source Project: gson   Source File: $Gson$Types.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the declaring class of {@code typeVariable}, or {@code null} if it was not declared by
 * a class.
 */
private static Class<?> declaringClassOf(TypeVariable<?> typeVariable) {
  GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
  return genericDeclaration instanceof Class
      ? (Class<?>) genericDeclaration
      : null;
}
 
Example 27
private CoreReflectionFactory(GenericDeclaration d, Scope s) {
    decl = d;
    scope = s;
}
 
Example 28
Source Project: ldp4j   Source File: ClassDescription.java    License: Apache License 2.0 4 votes vote down vote up
public GenericDeclarationWrapper(GenericDeclaration element) {
	super(element);
}
 
Example 29
public BinderArg(GenericDeclaration decl, Type[] args) {
    this(decl.getTypeParameters(), args);
}
 
Example 30
private CoreReflectionFactory(GenericDeclaration d, Scope s) {
    decl = d;
    scope = s;
}