Java Code Examples for java.lang.reflect.ParameterizedType#getOwnerType()
The following examples show how to use
java.lang.reflect.ParameterizedType#getOwnerType() .
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: ParameterizedTypeImpl.java From deltaspike with Apache License 2.0 | 6 votes |
@Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (obj instanceof ParameterizedType) { ParameterizedType that = (ParameterizedType) obj; Type thatOwnerType = that.getOwnerType(); Type thatRawType = that.getRawType(); return (ownerType == null ? thatOwnerType == null : ownerType.equals(thatOwnerType)) && (rawType == null ? thatRawType == null : rawType.equals(thatRawType)) && Arrays.equals(actualTypeArguments, that.getActualTypeArguments()); } else { return false; } }
Example 2
Source File: $Gson$Types.java From sagetv with Apache License 2.0 | 6 votes |
/** * Returns a type that is functionally equal but not necessarily equal * according to {@link Object#equals(Object) Object.equals()}. The returned * type is {@link java.io.Serializable}. */ public static Type canonicalize(Type type) { if (type instanceof Class) { Class<?> c = (Class<?>) type; return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c; } else if (type instanceof ParameterizedType) { ParameterizedType p = (ParameterizedType) type; return new ParameterizedTypeImpl(p.getOwnerType(), p.getRawType(), p.getActualTypeArguments()); } else if (type instanceof GenericArrayType) { GenericArrayType g = (GenericArrayType) type; return new GenericArrayTypeImpl(g.getGenericComponentType()); } else if (type instanceof WildcardType) { WildcardType w = (WildcardType) type; return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds()); } else { // type is either serializable as-is or unsupported return type; } }
Example 3
Source File: ReflectionNavigator.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public Type onParameterizdType(ParameterizedType p, BinderArg args) { Type[] params = p.getActualTypeArguments(); boolean different = false; for (int i = 0; i < params.length; i++) { Type t = params[i]; params[i] = visit(t, args); different |= t != params[i]; } Type newOwner = p.getOwnerType(); if (newOwner != null) { newOwner = visit(newOwner, args); } different |= p.getOwnerType() != newOwner; if (!different) { return p; } return new ParameterizedTypeImpl((Class<?>) p.getRawType(), params, newOwner); }
Example 4
Source File: $Gson$Types.java From framework with GNU Affero General Public License v3.0 | 6 votes |
/** * Returns a type that is functionally equal but not necessarily equal * according to {@link Object#equals(Object) Object.equals()}. The returned * type is {@link Serializable}. */ public static Type canonicalize(Type type) { if (type instanceof Class) { Class<?> c = (Class<?>) type; return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c; } else if (type instanceof ParameterizedType) { ParameterizedType p = (ParameterizedType) type; return new ParameterizedTypeImpl(p.getOwnerType(), p.getRawType(), p.getActualTypeArguments()); } else if (type instanceof GenericArrayType) { GenericArrayType g = (GenericArrayType) type; return new GenericArrayTypeImpl(g.getGenericComponentType()); } else if (type instanceof WildcardType) { WildcardType w = (WildcardType) type; return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds()); } else { // type is either serializable as-is or unsupported return type; } }
Example 5
Source File: ReflectionNavigator.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
public Type onParameterizdType(ParameterizedType p, BinderArg args) { Type[] params = p.getActualTypeArguments(); boolean different = false; for (int i = 0; i < params.length; i++) { Type t = params[i]; params[i] = visit(t, args); different |= t != params[i]; } Type newOwner = p.getOwnerType(); if (newOwner != null) { newOwner = visit(newOwner, args); } different |= p.getOwnerType() != newOwner; if (!different) { return p; } return new ParameterizedTypeImpl((Class<?>) p.getRawType(), params, newOwner); }
Example 6
Source File: ResolvableType.java From lams with GNU General Public License v2.0 | 6 votes |
private ResolvableType resolveVariable(TypeVariable<?> variable) { if (this.type instanceof TypeVariable) { return resolveType().resolveVariable(variable); } if (this.type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) this.type; TypeVariable<?>[] variables = resolve().getTypeParameters(); for (int i = 0; i < variables.length; i++) { if (ObjectUtils.nullSafeEquals(variables[i].getName(), variable.getName())) { Type actualType = parameterizedType.getActualTypeArguments()[i]; return forType(actualType, this.variableResolver); } } if (parameterizedType.getOwnerType() != null) { return forType(parameterizedType.getOwnerType(), this.variableResolver).resolveVariable(variable); } } if (this.variableResolver != null) { return this.variableResolver.resolveVariable(variable); } return null; }
Example 7
Source File: ReflectionNavigator.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public Type onParameterizdType(ParameterizedType p, BinderArg args) { Type[] params = p.getActualTypeArguments(); boolean different = false; for (int i = 0; i < params.length; i++) { Type t = params[i]; params[i] = visit(t, args); different |= t != params[i]; } Type newOwner = p.getOwnerType(); if (newOwner != null) { newOwner = visit(newOwner, args); } different |= p.getOwnerType() != newOwner; if (!different) { return p; } return new ParameterizedTypeImpl((Class<?>) p.getRawType(), params, newOwner); }
Example 8
Source File: b.java From letv with Apache License 2.0 | 6 votes |
public static Type a(Type type) { if (type instanceof Class) { c cVar; Class cls = (Class) type; if (cls.isArray()) { cVar = new c(a(cls.getComponentType())); } else { Object obj = cls; } return cVar; } else if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType) type; return new d(parameterizedType.getOwnerType(), parameterizedType.getRawType(), parameterizedType.getActualTypeArguments()); } else if (type instanceof GenericArrayType) { return new c(((GenericArrayType) type).getGenericComponentType()); } else { if (!(type instanceof WildcardType)) { return type; } WildcardType wildcardType = (WildcardType) type; return new e(wildcardType.getUpperBounds(), wildcardType.getLowerBounds()); } }
Example 9
Source File: ResolvableType.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof ParameterizedType)) { return false; } ParameterizedType otherType = (ParameterizedType) other; return (otherType.getOwnerType() == null && this.rawType.equals(otherType.getRawType()) && Arrays.equals(this.typeArguments, otherType.getActualTypeArguments())); }
Example 10
Source File: ParameterizedTypeImpl.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Override public boolean equals(Object o) { if (o instanceof ParameterizedType) { // Check that information is equivalent ParameterizedType that = (ParameterizedType) o; if (this == that) return true; Type thatOwner = that.getOwnerType(); Type thatRawType = that.getRawType(); if (false) { // Debugging boolean ownerEquality = (ownerType == null ? thatOwner == null : ownerType.equals(thatOwner)); boolean rawEquality = (rawType == null ? thatRawType == null : rawType.equals(thatRawType)); boolean typeArgEquality = Arrays.equals(actualTypeArguments, // avoid clone that.getActualTypeArguments()); for (Type t : actualTypeArguments) { System.out.printf("\t\t%s%s%n", t, t.getClass()); } System.out.printf("\towner %s\traw %s\ttypeArg %s%n", ownerEquality, rawEquality, typeArgEquality); return ownerEquality && rawEquality && typeArgEquality; } return Objects.equals(ownerType, thatOwner) && Objects.equals(rawType, thatRawType) && Arrays.equals(actualTypeArguments, // avoid clone that.getActualTypeArguments()); } else return false; }
Example 11
Source File: HierarchyDiscovery.java From deltaspike with Apache License 2.0 | 5 votes |
private Type resolveParameterizedType(ParameterizedType beanType, ParameterizedType parameterizedType) { Type rawType = parameterizedType.getRawType(); Type[] actualTypes = parameterizedType.getActualTypeArguments(); Type resolvedRawType = resolveType(beanType, beanType, rawType); Type[] resolvedActualTypes = new Type[actualTypes.length]; for (int i = 0; i < actualTypes.length; i++) { resolvedActualTypes[i] = resolveType(beanType, beanType, actualTypes[i]); } // reconstruct ParameterizedType by types resolved TypeVariable. return new ParameterizedTypeImpl(resolvedRawType, resolvedActualTypes, parameterizedType.getOwnerType()); }
Example 12
Source File: Lang_15_TypeUtils_s.java From coming with MIT License | 5 votes |
/** * <p>Performs a mapping of type variables.</p> * * @param <T> the generic type of the class in question * @param cls the class in question * @param parameterizedType the parameterized type * @param typeVarAssigns the map to be filled */ private static <T> void mapTypeVariablesToArguments(Class<T> cls, ParameterizedType parameterizedType, Map<TypeVariable<?>, Type> typeVarAssigns) { // capture the type variables from the owner type that have assignments Type ownerType = parameterizedType.getOwnerType(); if (ownerType instanceof ParameterizedType) { // recursion to make sure the owner's owner type gets processed mapTypeVariablesToArguments(cls, (ParameterizedType) ownerType, typeVarAssigns); } // parameterizedType is a generic interface/class (or it's in the owner // hierarchy of said interface/class) implemented/extended by the class // cls. Find out which type variables of cls are type arguments of // parameterizedType: Type[] typeArgs = parameterizedType.getActualTypeArguments(); // of the cls's type variables that are arguments of parameterizedType, // find out which ones can be determined from the super type's arguments TypeVariable<?>[] typeVars = getRawType(parameterizedType).getTypeParameters(); // use List view of type parameters of cls so the contains() method can be used: List<TypeVariable<Class<T>>> typeVarList = Arrays.asList(cls .getTypeParameters()); for (int i = 0; i < typeArgs.length; i++) { TypeVariable<?> typeVar = typeVars[i]; Type typeArg = typeArgs[i]; // argument of parameterizedType is a type variable of cls if (typeVarList.contains(typeArg) // type variable of parameterizedType has an assignment in // the super type. && typeVarAssigns.containsKey(typeVar)) { // map the assignment to the cls's type variable typeVarAssigns.put((TypeVariable<?>) typeArg, typeVarAssigns.get(typeVar)); } } }
Example 13
Source File: TypeResolver.java From quarkus with Apache License 2.0 | 5 votes |
/** * Resolves a given parameterized type. If the parameterized type contains no type variables it is returned untouched. * Otherwise, a new {@link ParameterizedType} instance is returned in which each type variable is resolved using * {@link #resolveType(TypeVariable)}. */ public Type resolveType(ParameterizedType type) { Type[] unresolvedTypeArguments = type.getActualTypeArguments(); /* * Indicates whether we managed to resolve any of type arguments. If we did not then there is no need to create a new * ParameterizedType with the old parameters. Instead, we return the original type. */ boolean modified = false; Type[] resolvedTypeArguments = new Type[unresolvedTypeArguments.length]; for (int i = 0; i < unresolvedTypeArguments.length; i++) { Type resolvedType = unresolvedTypeArguments[i]; if (resolvedType instanceof TypeVariable<?>) { resolvedType = resolveType((TypeVariable<?>) resolvedType); } if (resolvedType instanceof ParameterizedType) { resolvedType = resolveType((ParameterizedType) resolvedType); } resolvedTypeArguments[i] = resolvedType; // This identity check is intentional. A different identity indicates that the type argument was resolved within #resolveType(). if (unresolvedTypeArguments[i] != resolvedType) { modified = true; } } if (modified) { return new ParameterizedTypeImpl(type.getRawType(), resolvedTypeArguments, type.getOwnerType()); } else { return type; } }
Example 14
Source File: ParameterizedTypeImpl.java From Bytecoder with Apache License 2.0 | 5 votes |
@Override public boolean equals(Object o) { if (o instanceof ParameterizedType) { // Check that information is equivalent ParameterizedType that = (ParameterizedType) o; if (this == that) return true; Type thatOwner = that.getOwnerType(); Type thatRawType = that.getRawType(); if (false) { // Debugging boolean ownerEquality = (ownerType == null ? thatOwner == null : ownerType.equals(thatOwner)); boolean rawEquality = (rawType == null ? thatRawType == null : rawType.equals(thatRawType)); boolean typeArgEquality = Arrays.equals(actualTypeArguments, // avoid clone that.getActualTypeArguments()); for (Type t : actualTypeArguments) { System.out.printf("\t\t%s%s%n", t, t.getClass()); } System.out.printf("\towner %s\traw %s\ttypeArg %s%n", ownerEquality, rawEquality, typeArgEquality); return ownerEquality && rawEquality && typeArgEquality; } return Objects.equals(ownerType, thatOwner) && Objects.equals(rawType, thatRawType) && Arrays.equals(actualTypeArguments, // avoid clone that.getActualTypeArguments()); } else return false; }
Example 15
Source File: MoreTypes.java From soabase-halva with Apache License 2.0 | 5 votes |
/** * Returns a type that is functionally equal but not necessarily equal * according to {@link Object#equals(Object) Object.equals()}. The returned * type is {@link Serializable}. */ public static Type canonicalize(Type type) { if (type instanceof Class) { Class<?> c = (Class<?>) type; return c.isArray() ? new GenericArrayTypeImpl(canonicalize(c.getComponentType())) : c; } else if (type instanceof CompositeType) { return type; } else if (type instanceof ParameterizedType) { ParameterizedType p = (ParameterizedType) type; return new ParameterizedTypeImpl(p.getOwnerType(), p.getRawType(), p.getActualTypeArguments()); } else if (type instanceof GenericArrayType) { GenericArrayType g = (GenericArrayType) type; return new GenericArrayTypeImpl(g.getGenericComponentType()); } else if (type instanceof WildcardType) { WildcardType w = (WildcardType) type; return new WildcardTypeImpl(w.getUpperBounds(), w.getLowerBounds()); } else { // type is either serializable as-is or unsupported return type; } }
Example 16
Source File: ParameterizedTypeImpl.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
@Override public boolean equals(Object o) { if (o instanceof ParameterizedType) { // Check that information is equivalent ParameterizedType that = (ParameterizedType) o; if (this == that) return true; Type thatOwner = that.getOwnerType(); Type thatRawType = that.getRawType(); /* if (false) { // Debugging boolean ownerEquality = (ownerType == null ? thatOwner == null : ownerType.equals(thatOwner)); boolean rawEquality = (rawType == null ? thatRawType == null : rawType.equals(thatRawType)); boolean typeArgEquality = Arrays.equals(actualTypeArguments, // avoid clone that.getActualTypeArguments()); for (Type t : actualTypeArguments) { System.out.printf("\t\t%s%s%n", t, t.getClass()); } System.out.printf("\towner %s\traw %s\ttypeArg %s%n", ownerEquality, rawEquality, typeArgEquality); return ownerEquality && rawEquality && typeArgEquality; } */ return (ownerType == null ? thatOwner == null : ownerType.equals(thatOwner)) && (rawType == null ? thatRawType == null : rawType.equals(thatRawType)) && Arrays.equals(actualTypeArguments, // avoid clone that.getActualTypeArguments()); } else return false; }
Example 17
Source File: ParameterizedTypeImpl.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Override public boolean equals(Object o) { if (o instanceof ParameterizedType) { // Check that information is equivalent ParameterizedType that = (ParameterizedType) o; if (this == that) return true; Type thatOwner = that.getOwnerType(); Type thatRawType = that.getRawType(); /* if (false) { // Debugging boolean ownerEquality = (ownerType == null ? thatOwner == null : ownerType.equals(thatOwner)); boolean rawEquality = (rawType == null ? thatRawType == null : rawType.equals(thatRawType)); boolean typeArgEquality = Arrays.equals(actualTypeArguments, // avoid clone that.getActualTypeArguments()); for (Type t : actualTypeArguments) { System.out.printf("\t\t%s%s%n", t, t.getClass()); } System.out.printf("\towner %s\traw %s\ttypeArg %s%n", ownerEquality, rawEquality, typeArgEquality); return ownerEquality && rawEquality && typeArgEquality; } */ return (ownerType == null ? thatOwner == null : ownerType.equals(thatOwner)) && (rawType == null ? thatRawType == null : rawType.equals(thatRawType)) && Arrays.equals(actualTypeArguments, // avoid clone that.getActualTypeArguments()); } else return false; }
Example 18
Source File: ManagerUtil.java From netbeans with Apache License 2.0 | 4 votes |
public static String typeToString(Type type) { if (type instanceof ParameterizedType) { ParameterizedType paramType = (ParameterizedType)type; if (paramType.getOwnerType() != null) return null; Type rawType = paramType.getRawType(); if (!(rawType instanceof Class)) { return null; } Class rawClass = (Class)rawType; Type[] argTypes = paramType.getActualTypeArguments(); if (argTypes == null || argTypes.length == 0) { return null; } StringBuffer arguments = new StringBuffer(); for (int i = 0; i < argTypes.length; i++) { String argument = typeToString(argTypes[0]); if (argument == null) { return null; }else { arguments.append(argument); } if (i != argTypes.length - 1) { arguments.append(','); } } return rawClass.getCanonicalName() + "<" + arguments.toString() + ">"; }else if (type instanceof GenericArrayType) { String component = typeToString(((GenericArrayType)type).getGenericComponentType()); if (component != null) { return component + "[]"; } }else if (type instanceof Class) { return ((Class)type).getCanonicalName(); } return null; }
Example 19
Source File: TypeUtils.java From dolphin-platform with Apache License 2.0 | 4 votes |
/** * <p>Return a map of the type arguments of a parameterized type in the context of {@code toClass}.</p> * * @param parameterizedType the parameterized type * @param toClass the class * @param subtypeVarAssigns a map with type variables * @return the {@code Map} with type arguments */ private static Map<TypeVariable<?>, Type> getTypeArguments( final ParameterizedType parameterizedType, final Class<?> toClass, final Map<TypeVariable<?>, Type> subtypeVarAssigns) { final Class<?> cls = getRawType(parameterizedType); // make sure they're assignable if (!isAssignable(cls, toClass)) { return null; } final Type ownerType = parameterizedType.getOwnerType(); Map<TypeVariable<?>, Type> typeVarAssigns; if (ownerType instanceof ParameterizedType) { // get the owner type arguments first final ParameterizedType parameterizedOwnerType = (ParameterizedType) ownerType; typeVarAssigns = getTypeArguments(parameterizedOwnerType, getRawType(parameterizedOwnerType), subtypeVarAssigns); } else { // no owner, prep the type variable assignments map typeVarAssigns = subtypeVarAssigns == null ? new HashMap<TypeVariable<?>, Type>() : new HashMap<>(subtypeVarAssigns); } // get the subject parameterized type's arguments final Type[] typeArgs = parameterizedType.getActualTypeArguments(); // and get the corresponding type variables from the raw class final TypeVariable<?>[] typeParams = cls.getTypeParameters(); // map the arguments to their respective type variables for (int i = 0; i < typeParams.length; i++) { final Type typeArg = typeArgs[i]; typeVarAssigns.put(typeParams[i], typeVarAssigns.containsKey(typeArg) ? typeVarAssigns .get(typeArg) : typeArg); } if (toClass.equals(cls)) { // target class has been reached. Done. return typeVarAssigns; } // walk the inheritance hierarchy until the target class is reached return getTypeArguments(getClosestParentType(cls, toClass), toClass, typeVarAssigns); }
Example 20
Source File: TypeUtil.java From blueocean-plugin with MIT License | 4 votes |
@Override public boolean equals(Object o) { if (o instanceof ParameterizedType) { // Check that information is equivalent ParameterizedType that = (ParameterizedType) o; if (this == that) return true; Type thatOwner = that.getOwnerType(); Type thatRawType = that.getRawType(); if (false) { // Debugging boolean ownerEquality = (ownerType == null ? thatOwner == null : ownerType.equals(thatOwner)); boolean rawEquality = (rawType == null ? thatRawType == null : rawType.equals(thatRawType)); boolean typeArgEquality = Arrays.equals(actualTypeArguments, // avoid clone that.getActualTypeArguments()); for (Type t : actualTypeArguments) { System.out.printf("\t\t%s%s%n", t, t.getClass()); } System.out.printf("\towner %s\traw %s\ttypeArg %s%n", ownerEquality, rawEquality, typeArgEquality); return ownerEquality && rawEquality && typeArgEquality; } return (ownerType == null ? thatOwner == null : ownerType.equals(thatOwner)) && (rawType == null ? thatRawType == null : rawType.equals(thatRawType)) && Arrays.equals(actualTypeArguments, // avoid clone that.getActualTypeArguments()); } else return false; }