use of org.jboss.jandex.Type in project wildfly by wildfly.
the class PassivationAnnotationParsingProcessor method processPassivation.
private void processPassivation(final EEModuleDescription eeModuleDescription, final AnnotationTarget target, final DotName annotationType, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
if (!(target instanceof MethodInfo)) {
throw EeLogger.ROOT_LOGGER.methodOnlyAnnotation(annotationType);
}
final MethodInfo methodInfo = MethodInfo.class.cast(target);
final ClassInfo classInfo = methodInfo.declaringClass();
final EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
final Type[] args = methodInfo.args();
if (args.length > 1) {
ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidNumberOfArguments(methodInfo.name(), annotationType, classInfo.name()));
return;
} else if (args.length == 1 && !args[0].name().toString().equals(InvocationContext.class.getName())) {
ROOT_LOGGER.warn(EeLogger.ROOT_LOGGER.invalidSignature(methodInfo.name(), annotationType, classInfo.name(), "void methodName(InvocationContext ctx)"));
return;
}
final MethodIdentifier methodIdentifier;
if (args.length == 0) {
methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name());
} else {
methodIdentifier = MethodIdentifier.getIdentifier(Void.TYPE, methodInfo.name(), InvocationContext.class);
}
final InterceptorClassDescription.Builder builder = InterceptorClassDescription.builder(classDescription.getInterceptorClassDescription());
if (annotationType == POST_ACTIVATE) {
builder.setPostActivate(methodIdentifier);
} else {
builder.setPrePassivate(methodIdentifier);
}
classDescription.setInterceptorClassDescription(builder.build());
}
use of org.jboss.jandex.Type in project wildfly-swarm by wildfly-swarm.
the class OpenApiDataObjectScanner method readSchemaAnnotatedField.
private Schema readSchemaAnnotatedField(AnnotationInstance annotation, String name, Type type, TypeResolver typeResolver, Schema parent, Schema schema, PathEntry pathEntry) {
if (annotation == null) {
return parent;
}
LOG.debugv("Processing @Schema annotation {0} on a field {1}", annotation, name);
// Schemas can be hidden. Skip if that's the case.
Boolean isHidden = JandexUtil.booleanValue(annotation, OpenApiConstants.PROP_HIDDEN);
if (isHidden != null && isHidden == Boolean.TRUE) {
return parent;
}
// Required is false by default.
if (JandexUtil.booleanValueWithDefault(annotation, OpenApiConstants.PROP_REQUIRED)) {
parent.addRequired(name);
}
// Type could be replaced (e.g. generics).
Type postProcessedField = processType(type, typeResolver, schema, pathEntry);
// TypeFormat pair contains mappings for Java <-> OAS types and formats.
TypeUtil.TypeWithFormat typeFormat = TypeUtil.getTypeFormat(postProcessedField);
// Provide inferred type and format if relevant.
Map<String, Object> overrides = new HashMap<>();
overrides.put(OpenApiConstants.PROP_TYPE, typeFormat.getSchemaType());
overrides.put(OpenApiConstants.PROP_FORMAT, typeFormat.getFormat().format());
return SchemaFactory.readSchema(index, schema, annotation, overrides);
}
use of org.jboss.jandex.Type in project wildfly-swarm by wildfly-swarm.
the class OpenApiDataObjectScanner method resolveTypeVariable.
private Type resolveTypeVariable(TypeResolver typeResolver, Schema schema, PathEntry pathEntry, Type fieldType) {
// Type variable (e.g. A in Foo<A>)
Type resolvedType = typeResolver.getResolvedType(fieldType);
LOG.debugv("Resolved type {0} -> {1}", fieldType, resolvedType);
if (isTerminalType(resolvedType) || getClassByName(resolvedType) == null) {
LOG.tracev("Is a terminal type {0}", resolvedType);
TypeUtil.TypeWithFormat replacement = TypeUtil.getTypeFormat(resolvedType);
schema.setType(replacement.getSchemaType());
schema.setFormat(replacement.getFormat().format());
} else {
LOG.debugv("Attempting to do TYPE_VARIABLE substitution: {0} -> {1}", fieldType, resolvedType);
if (indexContains(resolvedType)) {
// Look up the resolved type.
ClassInfo klazz = getClassByName(resolvedType);
PathEntry entry = PathEntry.leafNode(pathEntry, klazz, resolvedType, schema);
path.push(entry);
} else {
LOG.debugv("Class for type {0} not available", resolvedType);
}
}
return resolvedType;
}
use of org.jboss.jandex.Type in project wildfly-swarm by wildfly-swarm.
the class OpenApiDataObjectScanner method readUnannotatedField.
private void readUnannotatedField(TypeResolver typeResolver, Type type, Schema schema, PathEntry pathEntry) {
if (!shouldInferUnannotatedFields()) {
return;
}
LOG.debugv("Processing unannotated field {0}", type);
Type processedType = processType(type, typeResolver, schema, pathEntry);
TypeUtil.TypeWithFormat typeFormat = TypeUtil.getTypeFormat(processedType);
schema.setType(typeFormat.getSchemaType());
if (typeFormat.getFormat().hasFormat()) {
schema.setFormat(typeFormat.getFormat().format());
}
}
use of org.jboss.jandex.Type in project wildfly-swarm by wildfly-swarm.
the class OpenApiDataObjectScanner method readParamType.
private Type readParamType(PathEntry pathEntry, Schema schema, ParameterizedType pType, TypeResolver typeResolver) {
LOG.debugv("Processing parameterized type {0}", pType);
// If it's a collection, we should treat it as an array.
if (isA(pType, COLLECTION_TYPE)) {
// TODO maybe also Iterable?
LOG.debugv("Processing Java Collection. Will treat as an array.");
SchemaImpl arraySchema = new SchemaImpl();
schema.type(Schema.SchemaType.ARRAY);
schema.items(arraySchema);
// Should only have one arg for collection.
Type arg = pType.arguments().get(0);
if (isTerminalType(arg)) {
TypeUtil.TypeWithFormat terminalType = TypeUtil.getTypeFormat(arg);
arraySchema.type(terminalType.getSchemaType());
arraySchema.format(terminalType.getFormat().format());
} else if (arg.kind() == Type.Kind.TYPE_VARIABLE || arg.kind() == Type.Kind.UNRESOLVED_TYPE_VARIABLE || arg.kind() == Type.Kind.WILDCARD_TYPE) {
Type resolved = resolveTypeVariable(typeResolver, arraySchema, pathEntry, arg);
if (indexContains(resolved)) {
arraySchema.type(Schema.SchemaType.OBJECT);
}
} else if (indexContains(arg)) {
arraySchema.type(Schema.SchemaType.OBJECT);
pushFieldToPath(pathEntry, arg, arraySchema);
}
// Representing collection as JSON array
return ARRAY_TYPE_OBJECT;
} else if (isA(pType, MAP_TYPE)) {
LOG.debugv("Processing Map. Will treat as an object.");
schema.type(Schema.SchemaType.OBJECT);
if (pType.arguments().size() == 2) {
Type valueType = pType.arguments().get(1);
SchemaImpl propsSchema = new SchemaImpl();
if (isTerminalType(valueType)) {
TypeUtil.TypeWithFormat tf = TypeUtil.getTypeFormat(valueType);
propsSchema.setType(tf.getSchemaType());
propsSchema.setFormat(tf.getFormat().format());
} else if (valueType.kind() == Type.Kind.TYPE_VARIABLE || valueType.kind() == Type.Kind.UNRESOLVED_TYPE_VARIABLE || valueType.kind() == Type.Kind.WILDCARD_TYPE) {
Type resolved = resolveTypeVariable(typeResolver, propsSchema, pathEntry, valueType);
if (indexContains(resolved)) {
propsSchema.type(Schema.SchemaType.OBJECT);
}
} else if (indexContains(valueType)) {
propsSchema.type(Schema.SchemaType.OBJECT);
pushFieldToPath(pathEntry, valueType, propsSchema);
}
schema.additionalProperties(propsSchema);
}
return OBJECT_TYPE;
} else {
// This attempts to allow us to resolve the types generically.
ClassInfo klazz = getClassByName(pType);
// Build mapping of class's type variables (e.g. A, B) to resolved variables
// Resolved variables could be any type (e.g. String, another param type, etc)
PathEntry pair = new PathEntry(pathEntry, klazz, pType, schema);
path.push(pair);
return pType;
}
}
Aggregations