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;
}
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;
}
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;
}
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;
}
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);
}
Aggregations