java.lang.reflect.GenericDeclaration Java Examples
The following examples show how to use
java.lang.reflect.GenericDeclaration.
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 File: GenericSignatureParser.java From j2objc with Apache License 2.0 | 6 votes |
/** * 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
Source File: SServicesMap.java From BIMserver with GNU Affero General Public License v3.0 | 6 votes |
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 File: TypeParamInfo.java From vertx-codegen with Apache License 2.0 | 6 votes |
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 File: TestPlainArrayNotGeneric.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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 #5
Source File: $Gson$Types.java From framework with GNU Affero General Public License v3.0 | 5 votes |
/** * 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 File: JavaWriter.java From baratine with GNU General Public License v2.0 | 5 votes |
/** * 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 #7
Source File: GenericSignatureParser.java From j2objc with Apache License 2.0 | 5 votes |
/** * 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 #8
Source File: TestPlainArrayNotGeneric.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
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 #9
Source File: TypeVariableImpl.java From j2objc with Apache License 2.0 | 5 votes |
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 #10
Source File: $Gson$Types.java From gson with Apache License 2.0 | 5 votes |
/** * 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 #11
Source File: TestPlainArrayNotGeneric.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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 File: InjectionUtils.java From cxf with Apache License 2.0 | 5 votes |
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 #13
Source File: Main.java From Java-Coding-Problems with MIT License | 5 votes |
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 #14
Source File: TypeVariableImpl.java From Bytecoder with Apache License 2.0 | 5 votes |
@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 #15
Source File: ReflectionTypeFactory.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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 #16
Source File: UnknownGenericException.java From generics-resolver with MIT License | 5 votes |
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 #17
Source File: Helper.java From vertx-codegen with Apache License 2.0 | 5 votes |
/** * 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 #18
Source File: Types.java From google-http-java-client with Apache License 2.0 | 5 votes |
/** * 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 #19
Source File: TypeRefBase.java From baratine with GNU General Public License v2.0 | 5 votes |
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 #20
Source File: TestPlainArrayNotGeneric.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
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 #21
Source File: $Gson$Types.java From GVGAI_GYM with Apache License 2.0 | 5 votes |
/** * 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 #22
Source File: ReflectionTypeFactory.java From xtext-extras with Eclipse Public License 2.0 | 5 votes |
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 #23
Source File: TypeVariableImpl.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@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
Source File: OperationMapper.java From jade-plugin-sql with Apache License 2.0 | 5 votes |
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 #25
Source File: TypeVariableImpl.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * 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 #26
Source File: TestPlainArrayNotGeneric.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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 #27
Source File: ReflectionNavigator.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public BinderArg(GenericDeclaration decl, Type[] args) { this(decl.getTypeParameters(), args); }
Example #28
Source File: CoreReflectionFactory.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
private CoreReflectionFactory(GenericDeclaration d, Scope s) { decl = d; scope = s; }
Example #29
Source File: Types.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
private static <D extends GenericDeclaration> TypeVariable<D> newTypeVariableImpl(D genericDeclaration, String name, Type[] bounds) { TypeVariableImpl<D> typeVariableImpl = new TypeVariableImpl<D>(genericDeclaration, name, bounds); @SuppressWarnings("unchecked") TypeVariable<D> typeVariable = Reflection.newProxy(TypeVariable.class, new TypeVariableInvocationHandler(typeVariableImpl)); return typeVariable; }
Example #30
Source File: TypeUtils.java From BaseProject with Apache License 2.0 | 4 votes |
/** 判断是否传入泛型 */ private static Class<?> declaringClassOf(TypeVariable<?> typeVariable) { GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration(); return genericDeclaration instanceof Class ? (Class<?>) genericDeclaration : null; }