Java Code Examples for org.jboss.jandex.Type.Kind#PARAMETERIZED_TYPE
The following examples show how to use
org.jboss.jandex.Type.Kind#PARAMETERIZED_TYPE .
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: 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 2
Source File: MethodNameParser.java From quarkus with Apache License 2.0 | 6 votes |
private List<ClassInfo> getMappedSuperClassInfos(IndexView indexView, ClassInfo entityClass) { List<ClassInfo> mappedSuperClassInfos = new ArrayList<>(3); Type superClassType = entityClass.superClassType(); while (superClassType != null && !superClassType.name().equals(DotNames.OBJECT)) { ClassInfo superClass = indexView.getClassByName(entityClass.superName()); if (superClass.classAnnotation(DotNames.JPA_MAPPED_SUPERCLASS) != null) { mappedSuperClassInfos.add(superClass); } if (superClassType.kind() == Kind.CLASS) { superClassType = indexView.getClassByName(superClassType.name()).superClassType(); } else if (superClassType.kind() == Kind.PARAMETERIZED_TYPE) { ParameterizedType parameterizedType = superClassType.asParameterizedType(); superClassType = parameterizedType.owner(); } } if (mappedSuperClassInfos.size() > 0) { return mappedSuperClassInfos; } return Collections.emptyList(); }
Example 3
Source File: CustomQueryMethodsAdder.java From quarkus with Apache License 2.0 | 6 votes |
private Type verifyQueryResultType(Type t) { if (isIntLongOrBoolean(t.name())) { return t; } if (t.kind() == Kind.ARRAY) { return verifyQueryResultType(t.asArrayType().component()); } else if (t.kind() == Kind.PARAMETERIZED_TYPE) { List<Type> list = t.asParameterizedType().arguments(); if (list.size() == 1) { return verifyQueryResultType(list.get(0)); } else { for (Type x : list) { verifyQueryResultType(x); } return t; } } else if (!DotNames.OBJECT.equals(t.name())) { ClassInfo typeClassInfo = index.getClassByName(t.name()); if (typeClassInfo == null) { throw new IllegalStateException(t.name() + " was not part of the Quarkus index"); } } return t; }
Example 4
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 5
Source File: IndexClassLookupUtils.java From quarkus with Apache License 2.0 | 5 votes |
/** * * @param index * @param type * @return the class for the given type or {@code null} for primitives, arrays and */ static ClassInfo getClassByName(IndexView index, Type type) { if (type != null && (type.kind() == Kind.CLASS || type.kind() == Kind.PARAMETERIZED_TYPE)) { return getClassByName(index, type.name()); } return null; }
Example 6
Source File: JandexProtoGenerator.java From kogito-runtimes with Apache License 2.0 | 4 votes |
protected ProtoMessage messageFromClass(Proto proto, ClassInfo clazz, IndexView index, String packageName, String messageComment, String fieldComment) throws Exception { if (isHidden(clazz)) { // since class is marked as hidden skip processing of that class return null; } String name = clazz.simpleName(); String altName = getReferenceOfModel(clazz, "name"); if (altName != null) { name = altName; } ProtoMessage message = new ProtoMessage(name, packageName == null ? clazz.name().prefix().toString() : packageName); for (FieldInfo pd : clazz.fields()) { String completeFieldComment = fieldComment; // ignore static and/or transient fields if (Modifier.isStatic(pd.flags()) || Modifier.isTransient(pd.flags())) { continue; } AnnotationInstance variableInfo = pd.annotation(variableInfoAnnotation); if (variableInfo != null) { completeFieldComment = fieldComment + "\n @VariableInfo(tags=\"" + variableInfo.value("tags").asString() + "\")"; } String fieldTypeString = pd.type().name().toString(); DotName fieldType = pd.type().name(); String protoType; if (pd.type().kind() == Kind.PARAMETERIZED_TYPE) { fieldTypeString = "Collection"; List<Type> typeParameters = pd.type().asParameterizedType().arguments(); if (typeParameters.isEmpty()) { throw new IllegalArgumentException("Field " + pd.name() + " of class " + clazz.name().toString() + " uses collection without type information"); } fieldType = typeParameters.get(0).name(); protoType = protoType(fieldType.toString()); } else { protoType = protoType(fieldTypeString); } if (protoType == null) { ClassInfo classInfo = index.getClassByName(fieldType); if (classInfo == null) { throw new IllegalStateException("Cannot find class info in jandex index for " + fieldType); } ProtoMessage another = messageFromClass(proto, classInfo, index, packageName, messageComment, fieldComment); protoType = another.getName(); } message.addField(applicabilityByType(fieldTypeString), protoType, pd.name()).setComment(completeFieldComment); } message.setComment(messageComment); proto.addMessage(message); return message; }
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); }