當前位置: 首頁>>代碼示例>>Java>>正文


Java GenericDeclaration.getTypeParameters方法代碼示例

本文整理匯總了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();
}
 
開發者ID:future-architect,項目名稱:uroborosql,代碼行數:27,代碼來源:JavaType.java

示例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;
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:24,代碼來源:FieldInfo.java

示例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;
}
 
開發者ID:BigAppOS,項目名稱:BigApp_Discuz_Android,代碼行數:25,代碼來源:FieldInfo.java

示例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();
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:17,代碼來源:GenericSignatureParser.java

示例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;
}
 
開發者ID:almondtools,項目名稱:testrecorder,代碼行數:21,代碼來源:Types.java

示例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() + ".");
    }
}
 
開發者ID:spiffykahuna,項目名稱:TIJ4-code_idea,代碼行數:20,代碼來源:ReflectionUtils.java

示例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();
}
 
開發者ID:vert-x3,項目名稱:vertx-codegen,代碼行數:19,代碼來源:TypeParamInfo.java

示例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));
		}
	}
}
 
開發者ID:eclipse,項目名稱:xtext-extras,代碼行數:10,代碼來源:ReflectionTypeFactory.java

示例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;
  }
}
 
開發者ID:baratine,項目名稱:baratine,代碼行數:40,代碼來源:TypeRefBase.java

示例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;
}
 
開發者ID:wavinsun,項目名稱:MUtils,代碼行數:30,代碼來源:ReflectUtil.java

示例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;
}
 
開發者ID:Sellegit,項目名稱:j2objc,代碼行數:11,代碼來源:TypeVariableImpl.java

示例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;
}
 
開發者ID:ceylon,項目名稱:ceylon-model,代碼行數:8,代碼來源:ReflectionUtils.java

示例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;
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:20,代碼來源:AuxiliaryFinder.java

示例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;
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:38,代碼來源:AuxiliaryFinder.java

示例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;
}
 
開發者ID:domaframework,項目名稱:doma,代碼行數:12,代碼來源:GenericsUtil.java


注:本文中的java.lang.reflect.GenericDeclaration.getTypeParameters方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。