本文整理汇总了Java中java.lang.reflect.GenericDeclaration.getTypeParameters方法的典型用法代码示例。如果您正苦于以下问题:Java GenericDeclaration.getTypeParameters方法的具体用法?Java GenericDeclaration.getTypeParameters怎么用?Java GenericDeclaration.getTypeParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.reflect.GenericDeclaration
的用法示例。
在下文中一共展示了GenericDeclaration.getTypeParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createByParamName
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
private static JavaType createByParamName(final ImplementClass implementClass, final TypeVariable<?> variable) {
GenericDeclaration declaration = variable.getGenericDeclaration();
String name = variable.getName();
TypeVariable<?>[] typeParameters = declaration.getTypeParameters();
for (int index = 0; index < typeParameters.length; index++) {
TypeVariable<?> type = typeParameters[index];
if (name.equals(type.getName())) {
if (declaration instanceof Class) {
Class<?> declarationClass = (Class<?>) declaration;
Class<?> sub = implementClass.getSubclass(declarationClass);
if (sub != null) {
Type genericSuperclass = implementClass.getGenericParentClass(declarationClass);
if (genericSuperclass instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) genericSuperclass;
return create(implementClass, parameterizedType.getActualTypeArguments()[index]);
}
// Generics未指定
}
return new VariableJavaType(implementClass, type);
} else if (declaration instanceof Executable) {
return new VariableJavaType(implementClass, type);
}
}
}
throw new IllegalArgumentException();
}
示例2: getInheritGenericType
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> tv) {
Type type = null;
GenericDeclaration gd = tv.getGenericDeclaration();
do {
type = clazz.getGenericSuperclass();
if (type == null) {
return null;
}
if (type instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) type;
if (ptype.getRawType() == gd) {
TypeVariable<?>[] tvs = gd.getTypeParameters();
Type[] types = ptype.getActualTypeArguments();
for (int i = 0; i < tvs.length; i++) {
if (tvs[i] == tv) return types[i];
}
return null;
}
}
clazz = TypeUtils.getClass(type);
} while (type != null);
return null;
}
示例3: getInheritGenericType
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> tv) {
Type type = null;
GenericDeclaration gd = tv.getGenericDeclaration();
do {
type = clazz.getGenericSuperclass();
if (type == null) {
return null;
}
if (type instanceof ParameterizedType) {
ParameterizedType ptype = (ParameterizedType) type;
if (ptype.getRawType() == gd) {
TypeVariable<?>[] tvs = gd.getTypeParameters();
Type[] types = ptype.getActualTypeArguments();
for (int i = 0; i < tvs.length; i++) {
if (tvs[i] == tv)
return types[i];
}
return null;
}
}
clazz = TypeUtils.getClass(type);
} while (type != null);
return null;
}
示例4: resolve
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
Type resolve()
{
GenericDeclaration d = decl;
while (d != null)
{
for (TypeVariable t : d.getTypeParameters())
{
if (t.getName().equals(name))
{
return t;
}
}
d = getParent(d);
}
throw new MalformedParameterizedTypeException();
}
示例5: resolve
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
private static Type resolve(TypeVariable<? extends GenericDeclaration> value, Set<ParameterizedType> types) {
GenericDeclaration genericDeclaration = value.getGenericDeclaration();
if (genericDeclaration instanceof Class<?>) {
Class<?> clazz = (Class<?>) genericDeclaration;
Optional<ParameterizedType> matching = types.stream()
.filter(type -> type.getRawType() == clazz)
.sorted(Types::byMostConcrete)
.findFirst();
if (matching.isPresent()) {
TypeVariable<?>[] params = genericDeclaration.getTypeParameters();
Type[] actual = matching.get().getActualTypeArguments();
for (int i = 0; i < params.length && i < actual.length; i++) {
if (params[i] == value) {
return actual[i];
}
}
}
}
return value;
}
示例6: getParameterTypeDeclarationIndex
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
public static int getParameterTypeDeclarationIndex(final TypeVariable typeVariable) {
GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
// Ищем наш параметр среди всех параметров того класса, где определен нужный нам параметр.
TypeVariable[] typeVariables = genericDeclaration.getTypeParameters();
Integer actualArgumentIndex = null;
for (int i = 0; i < typeVariables.length; i++) {
if (typeVariables[i].equals(typeVariable)) {
actualArgumentIndex = i;
break;
}
}
if (actualArgumentIndex != null) {
return actualArgumentIndex;
} else {
throw new IllegalStateException("Argument " + typeVariable.toString() + " is not found in "
+ genericDeclaration.toString() + ".");
}
}
示例7: create
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
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();
}
示例8: enhanceGenericDeclaration
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
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));
}
}
}
示例9: visitParameterizedType
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
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;
}
}
示例10: getInheritGenericType
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
public static Type getInheritGenericType(Class<?> clazz, TypeVariable<?> typeVariable) {
Type type = null;
GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration();
do {
type = clazz.getGenericSuperclass();
if (type == null) {
return null;
}
if (type instanceof ParameterizedType) {
ParameterizedType paramType = (ParameterizedType) type;
if (paramType.getRawType() == genericDeclaration) {
TypeVariable<?>[] typeVariables = genericDeclaration.getTypeParameters();
Type[] arguments = paramType.getActualTypeArguments();
String typeVariableName = typeVariable.getName();
for (int i = 0, size = typeVariables.length; i < size; i++) {
// Fix bug on android VM
// It is true while typeVariable==typeVariables[i] on JVM
// But It is false on android VM
if (typeVariableName.equals(typeVariables[i].getName())) {
return arguments[i];
}
}
return null;
}
}
clazz = ReflectUtil.getClass(type);
} while (type != null);
return null;
}
示例11: findFormalVar
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
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;
}
示例12: getTypeParameters
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
public static List<TypeParameterMirror> getTypeParameters(GenericDeclaration decl) {
TypeVariable<?>[] javaTypeParameters = decl.getTypeParameters();
List<TypeParameterMirror> typeParameters = new ArrayList<TypeParameterMirror>(javaTypeParameters.length);
for(Type javaTypeParameter : javaTypeParameters)
typeParameters.add(new ReflectionTypeParameter(javaTypeParameter));
return typeParameters;
}
示例13: hasGenericDeclaration
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
/**
* This auxiliary method returns true if the particular type variable
* is defined in the specified generic declaration.
*
* @param typeVariableName a name of a type variable.
* @param declaration a generic declaration to check.
* @return true if the specified declaration defines the specified type variable, false otherwise.
*/
private static boolean hasGenericDeclaration(String typeVariableName, GenericDeclaration declaration) {
TypeVariable[] vars = declaration.getTypeParameters();
if (vars != null) {
for (TypeVariable var : vars) {
if (var.getName().equals(typeVariableName)) {
return true;
}
}
}
return false;
}
示例14: findTypeVariableInDeclaration
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
/**
* This auxiliary method returns TypeVariable corresponding to the name
* of type variable in the specified declaration.
*
* @param typeVariableName a name of a type variable.
* @param declaration a generic declaration to check.
* @return the found type variable.
*/
private static TypeVariable findTypeVariableInDeclaration(String typeVariableName, GenericDeclaration declaration) {
TypeVariable variable = TypeVariableRepository.findTypeVariable(typeVariableName, declaration);
if (variable != null) return variable;
TypeVariable[] vars = declaration.getTypeParameters();
if (vars != null) {
for (TypeVariable var : vars) {
if (var.getName().equals(typeVariableName)) {
/*
* Yes, it may be very inefficient now (for example, getTypeParameters()
* invokation above can just registry a TV but we need to recheck it in
* this line) but after all the TV-repository's functionality implementation
* it will be time to improvement.
* So, it was placed in repository just after an TV-instance creation but
* then it was removed (since we did not find it into the invoking method
* of this method look there at line with
* TypeVariableRepository.findTypeVariable(...) method invokation and also
* we did not find it in just above if-condition).
* As a consequence, we should reregistry it again as long as it become
* so popular again.
*/
if (TypeVariableRepository.findTypeVariable(typeVariableName, declaration) == null) {
TypeVariableRepository.registerTypeVariable(var, typeVariableName, declaration);
}
return var;
}
}
}
return null;
}
示例15: getTypeParameterIndex
import java.lang.reflect.GenericDeclaration; //导入方法依赖的package包/类
private int getTypeParameterIndex(
GenericDeclaration genericDeclaration,
TypeVariable<?> typeVariable) {
Type[] types = genericDeclaration.getTypeParameters();
for (int i = 0, len = types.length; i < len; i++) {
if (types[i] == typeVariable) {
return i;
}
}
return 0;
}