Java Code Examples for org.jboss.jandex.ClassInfo#typeParameters()
The following examples show how to use
org.jboss.jandex.ClassInfo#typeParameters() .
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: TypeResolver.java From smallrye-open-api with Apache License 2.0 | 6 votes |
private static Map<String, Type> buildParamTypeResolutionMap(ClassInfo klazz, ParameterizedType parameterizedType) { List<TypeVariable> typeVariables = klazz.typeParameters(); List<Type> arguments = parameterizedType.arguments(); if (arguments.size() != typeVariables.size()) { DataObjectLogging.log.classNotAvailable(typeVariables, arguments); } Map<String, Type> resolutionMap = new LinkedHashMap<>(); for (int i = 0; i < arguments.size(); i++) { TypeVariable typeVar = typeVariables.get(i); Type arg = arguments.get(i); resolutionMap.put(typeVar.identifier(), arg); } return resolutionMap; }
Example 2
Source File: Types.java From quarkus with Apache License 2.0 | 6 votes |
static Type resolveTypeParam(Type typeParam, Map<TypeVariable, Type> resolvedTypeParameters, IndexView index) { if (typeParam.kind() == Kind.TYPE_VARIABLE) { return resolvedTypeParameters.getOrDefault(typeParam, typeParam); } else if (typeParam.kind() == Kind.PARAMETERIZED_TYPE) { ParameterizedType parameterizedType = typeParam.asParameterizedType(); ClassInfo classInfo = getClassByName(index, parameterizedType.name()); if (classInfo != null) { List<TypeVariable> typeParameters = classInfo.typeParameters(); List<Type> arguments = parameterizedType.arguments(); Map<TypeVariable, Type> resolvedMap = buildResolvedMap(arguments, typeParameters, resolvedTypeParameters, index); Type[] typeParams = new Type[typeParameters.size()]; for (int i = 0; i < typeParameters.size(); i++) { typeParams[i] = resolveTypeParam(arguments.get(i), resolvedMap, index); } return ParameterizedType.create(parameterizedType.name(), typeParams, null); } } return typeParam; }
Example 3
Source File: Types.java From quarkus with Apache License 2.0 | 6 votes |
static Type resolveTypeParam(Type typeParam, Map<TypeVariable, Type> resolvedTypeParameters, IndexView index) { if (typeParam.kind() == Kind.TYPE_VARIABLE) { return resolvedTypeParameters.getOrDefault(typeParam, typeParam); } else if (typeParam.kind() == Kind.PARAMETERIZED_TYPE) { ParameterizedType parameterizedType = typeParam.asParameterizedType(); ClassInfo classInfo = index.getClassByName(parameterizedType.name()); if (classInfo != null) { List<TypeVariable> typeParameters = classInfo.typeParameters(); List<Type> arguments = parameterizedType.arguments(); Type[] typeParams = new Type[typeParameters.size()]; for (int i = 0; i < typeParameters.size(); i++) { typeParams[i] = resolveTypeParam(arguments.get(i), resolvedTypeParameters, index); } return ParameterizedType.create(parameterizedType.name(), typeParams, null); } } return typeParam; }
Example 4
Source File: Types.java From quarkus with Apache License 2.0 | 5 votes |
static Type getProviderType(ClassInfo classInfo) { List<TypeVariable> typeParameters = classInfo.typeParameters(); if (!typeParameters.isEmpty()) { return ParameterizedType.create(classInfo.name(), typeParameters.toArray(new Type[] {}), null); } else { return Type.create(classInfo.name(), Kind.CLASS); } }
Example 5
Source File: Types.java From quarkus with Apache License 2.0 | 5 votes |
static Set<Type> getClassBeanTypeClosure(ClassInfo classInfo, BeanDeployment beanDeployment) { Set<Type> types; List<TypeVariable> typeParameters = classInfo.typeParameters(); if (typeParameters.isEmpty()) { types = getTypeClosure(classInfo, null, Collections.emptyMap(), beanDeployment, null); } else { types = getTypeClosure(classInfo, null, buildResolvedMap(typeParameters, typeParameters, Collections.emptyMap(), beanDeployment.getIndex()), beanDeployment, null); } return restrictBeanTypes(types, beanDeployment.getAnnotations(classInfo)); }
Example 6
Source File: JandexUtil.java From quarkus with Apache License 2.0 | 5 votes |
/** * Creates a type for a ClassInfo */ private static Type getType(ClassInfo inputClassInfo, IndexView index) { List<TypeVariable> typeParameters = inputClassInfo.typeParameters(); if (typeParameters.isEmpty()) return ClassType.create(inputClassInfo.name(), Kind.CLASS); Type owner = null; // ignore owners for non-static classes if (inputClassInfo.enclosingClass() != null && !Modifier.isStatic(inputClassInfo.flags())) { owner = getType(fetchFromIndex(inputClassInfo.enclosingClass(), index), index); } return ParameterizedType.create(inputClassInfo.name(), typeParameters.toArray(new Type[0]), owner); }
Example 7
Source File: JandexUtil.java From quarkus with Apache License 2.0 | 4 votes |
/** * Maps any type parameters in typeArgumentsFromSupertype from the type parameters declared in appliedType's declaration * to the type arguments we passed in appliedType */ private static List<Type> mapTypeArguments(Type appliedType, List<Type> typeArgumentsFromSupertype, IndexView index) { // no type arguments to map if (typeArgumentsFromSupertype.isEmpty()) { return typeArgumentsFromSupertype; } // extra easy if all the type args don't contain any type parameters if (!containsTypeParameters(typeArgumentsFromSupertype)) { return typeArgumentsFromSupertype; } // this can't fail since we got a result ClassInfo superType = fetchFromIndex(appliedType.name(), index); // if our supertype has no type parameters, we don't need any mapping if (superType.typeParameters().isEmpty()) { return typeArgumentsFromSupertype; } // figure out which arguments we passed to the supertype List<Type> appliedArguments; // we passed them explicitely if (appliedType.kind() == Kind.PARAMETERIZED_TYPE) { appliedArguments = appliedType.asParameterizedType().arguments(); } else { // raw supertype: use bounds appliedArguments = new ArrayList<>(superType.typeParameters().size()); for (TypeVariable typeVariable : superType.typeParameters()) { if (!typeVariable.bounds().isEmpty()) { appliedArguments.add(typeVariable.bounds().get(0)); } else { appliedArguments.add(ClassType.create(DOTNAME_OBJECT, Kind.CLASS)); } } } // it's a problem if we got different arguments to the parameters declared if (appliedArguments.size() != superType.typeParameters().size()) { throw new IllegalArgumentException("Our supertype instance " + appliedType + " does not match supertype declared arguments: " + superType.typeParameters()); } // build the mapping Map<String, Type> mapping = new HashMap<>(); for (int i = 0; i < superType.typeParameters().size(); i++) { TypeVariable typeParameter = superType.typeParameters().get(i); mapping.put(typeParameter.identifier(), appliedArguments.get(i)); } // and map return mapGenerics(typeArgumentsFromSupertype, mapping); }