Search in sources :

Example 21 with Type

use of org.jboss.jandex.Type in project wildfly-swarm by wildfly-swarm.

the class TypeResolver method buildParamTypeResolutionMap.

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()) {
        LOG.errorv("Unanticipated mismatch between type arguments and type variables \n" + "Args: {0}\n Vars:{1}", arguments, typeVariables);
    }
    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;
}
Also used : Type(org.jboss.jandex.Type) ParameterizedType(org.jboss.jandex.ParameterizedType) TypeVariable(org.jboss.jandex.TypeVariable) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with Type

use of org.jboss.jandex.Type in project wildfly-swarm by wildfly-swarm.

the class TypeResolver method getAllFields.

public static Map<FieldInfo, TypeResolver> getAllFields(IndexView index, Type leaf, ClassInfo leafKlazz) {
    Map<FieldInfo, TypeResolver> fields = new LinkedHashMap<>();
    Type currentType = leaf;
    ClassInfo currentClass = leafKlazz;
    Deque<Map<String, Type>> stack = new ArrayDeque<>();
    do {
        if (currentType.kind() == Type.Kind.PARAMETERIZED_TYPE) {
            Map<String, Type> resMap = buildParamTypeResolutionMap(currentClass, currentType.asParameterizedType());
            stack.push(resMap);
        }
        for (FieldInfo field : currentClass.fields()) {
            TypeResolver resolver = new TypeResolver(field.type(), new ArrayDeque<>(stack));
            fields.put(field, resolver);
        }
        currentType = currentClass.superClassType();
        if (currentType == null) {
            break;
        }
        currentClass = getClassByName(index, currentType);
        if (currentClass == null) {
            break;
        }
    } while (currentClass.superClassType() != null);
    return fields;
}
Also used : Type(org.jboss.jandex.Type) ParameterizedType(org.jboss.jandex.ParameterizedType) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) FieldInfo(org.jboss.jandex.FieldInfo) ArrayDeque(java.util.ArrayDeque) LinkedHashMap(java.util.LinkedHashMap) ClassInfo(org.jboss.jandex.ClassInfo)

Example 23 with Type

use of org.jboss.jandex.Type in project wildfly-swarm by wildfly-swarm.

the class SchemaFactory method readClassSchemas.

private static List<Schema> readClassSchemas(IndexView index, AnnotationValue value) {
    if (value == null) {
        return null;
    }
    Type[] classArray = value.asClassArray();
    List<Schema> schemas = new ArrayList<>(classArray.length);
    for (Type type : classArray) {
        ClassType ctype = (ClassType) type;
        Schema schema = introspectClassToSchema(index, ctype);
        schemas.add(schema);
    }
    return schemas;
}
Also used : Type(org.jboss.jandex.Type) ClassType(org.jboss.jandex.ClassType) Schema(org.eclipse.microprofile.openapi.models.media.Schema) ArrayList(java.util.ArrayList) ClassType(org.jboss.jandex.ClassType)

Example 24 with Type

use of org.jboss.jandex.Type in project wildfly-swarm by wildfly-swarm.

the class TypeUtil method hasSuper.

private static boolean hasSuper(IndexView index, ClassInfo testSubject, Type testObject) {
    Type superKlazzType = testSubject.superClassType();
    while (superKlazzType != null) {
        if (getName(superKlazzType).equals(getName(testObject))) {
            return true;
        }
        ClassInfo superKlazz = index.getClassByName(getName(superKlazzType));
        if (superKlazz == null) {
            try {
                Class<?> subjectKlazz = TypeUtil.getClass(testSubject.name().toString());
                Class<?> objectKlazz = TypeUtil.getClass(testObject);
                return objectKlazz.isAssignableFrom(subjectKlazz);
            } catch (ClassNotFoundException nfe) {
                return false;
            }
        }
        superKlazzType = superKlazz.superClassType();
    }
    return false;
}
Also used : PrimitiveType(org.jboss.jandex.PrimitiveType) Type(org.jboss.jandex.Type) SchemaType(org.eclipse.microprofile.openapi.models.media.Schema.SchemaType) WildcardType(org.jboss.jandex.WildcardType) ClassInfo(org.jboss.jandex.ClassInfo)

Example 25 with Type

use of org.jboss.jandex.Type in project wildfly-swarm by wildfly-swarm.

the class ExpectationTests method genericFieldTest.

@Test
public void genericFieldTest() throws IOException, JSONException {
    String name = GenericTypeTestContainer.class.getName();
    Type pType = getFieldFromKlazz(name, "genericContainer").type();
    OpenApiDataObjectScanner scanner = new OpenApiDataObjectScanner(index, pType);
    Schema result = scanner.process();
    printToConsole(name, result);
    assertJsonEquals(name, "generic.fields.expected.json", result);
}
Also used : Type(org.jboss.jandex.Type) ClassType(org.jboss.jandex.ClassType) Schema(org.eclipse.microprofile.openapi.models.media.Schema) Test(org.junit.Test)

Aggregations

Type (org.jboss.jandex.Type)28 Schema (org.eclipse.microprofile.openapi.models.media.Schema)15 Test (org.junit.Test)11 ClassType (org.jboss.jandex.ClassType)10 ClassInfo (org.jboss.jandex.ClassInfo)9 ParameterizedType (org.jboss.jandex.ParameterizedType)7 PrimitiveType (org.jboss.jandex.PrimitiveType)6 ArrayType (org.jboss.jandex.ArrayType)5 MethodInfo (org.jboss.jandex.MethodInfo)4 TypeUtil (org.wildfly.swarm.microprofile.openapi.runtime.util.TypeUtil)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 MediaType (org.eclipse.microprofile.openapi.models.media.MediaType)3 EEModuleClassDescription (org.jboss.as.ee.component.EEModuleClassDescription)3 InterceptorClassDescription (org.jboss.as.ee.component.interceptors.InterceptorClassDescription)3 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)3 FieldInfo (org.jboss.jandex.FieldInfo)3 RefType (org.wildfly.swarm.microprofile.openapi.runtime.util.JandexUtil.RefType)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2