use of org.jboss.jandex.FieldInfo in project wildfly-swarm by wildfly-swarm.
the class OpenApiDataObjectScanner method processType.
private Type processType(Type fieldType, TypeResolver typeResolver, Schema schema, PathEntry pathEntry) {
// If it's a terminal type.
if (isTerminalType(fieldType)) {
return fieldType;
}
if (fieldType.kind() == Type.Kind.WILDCARD_TYPE) {
fieldType = TypeUtil.resolveWildcard(fieldType.asWildcardType());
}
if (fieldType.kind() == Type.Kind.ARRAY) {
LOG.debugv("Processing an array {0}", fieldType);
ArrayType arrayType = fieldType.asArrayType();
// TODO handle multi-dimensional arrays.
// Array-type schema
SchemaImpl arrSchema = new SchemaImpl();
schema.type(Schema.SchemaType.ARRAY);
schema.items(arrSchema);
// Only use component (excludes the special name formatting for arrays).
TypeUtil.TypeWithFormat typeFormat = TypeUtil.getTypeFormat(arrayType.component());
arrSchema.setType(typeFormat.getSchemaType());
arrSchema.setFormat(typeFormat.getFormat().format());
// If it's not a terminal type, then push for later inspection.
if (!isTerminalType(arrayType.component()) && indexContains(fieldType)) {
ClassInfo klazz = getClassByName(fieldType);
pushPathPair(pathEntry, fieldType, klazz, arrSchema);
}
return arrayType;
}
if (isA(fieldType, ENUM_TYPE) && indexContains(fieldType)) {
LOG.debugv("Processing an enum {0}", fieldType);
ClassInfo enumKlazz = getClassByName(fieldType);
for (FieldInfo enumField : enumKlazz.fields()) {
// Ignore the hidden enum array as it's not accessible. Add fields that look like enums (of type enumKlazz)
if (!enumField.name().endsWith("$VALUES") && TypeUtil.getName(enumField.type()).equals(enumKlazz.name())) {
// Enum's value fields.
schema.addEnumeration(enumField.name());
}
}
return STRING_TYPE;
}
if (fieldType.kind() == Type.Kind.PARAMETERIZED_TYPE) {
// Parameterised type (e.g. Foo<A, B>)
return readParamType(pathEntry, schema, fieldType.asParameterizedType(), typeResolver);
}
if (fieldType.kind() == Type.Kind.TYPE_VARIABLE || fieldType.kind() == Type.Kind.UNRESOLVED_TYPE_VARIABLE) {
// Resolve type variable to real variable.
return resolveTypeVariable(typeResolver, schema, pathEntry, fieldType);
}
// Raw Collection
if (isA(fieldType, COLLECTION_TYPE)) {
return ARRAY_TYPE_OBJECT;
}
// Raw Map
if (isA(fieldType, MAP_TYPE)) {
return OBJECT_TYPE;
}
// Simple case: bare class or primitive type.
if (indexContains(fieldType)) {
pushFieldToPath(pathEntry, fieldType, schema);
} else {
// If the type is not in Jandex then we don't have easy access to it.
// Future work could consider separate code to traverse classes reachable from this classloader.
LOG.debugv("Encountered type not in Jandex index that is not well-known type. " + "Will not traverse it: {0}", fieldType);
}
return fieldType;
}
use of org.jboss.jandex.FieldInfo in project wildfly by wildfly.
the class JPAAnnotationProcessor method processPersistenceAnnotations.
private void processPersistenceAnnotations(final DeploymentUnit deploymentUnit, final EEModuleDescription eeModuleDescription, List<AnnotationInstance> persistenceContexts, final EEApplicationClasses applicationClasses) throws DeploymentUnitProcessingException {
for (AnnotationInstance annotation : persistenceContexts) {
ClassInfo declaringClass;
final AnnotationTarget annotationTarget = annotation.target();
if (annotationTarget instanceof FieldInfo) {
FieldInfo fieldInfo = (FieldInfo) annotationTarget;
declaringClass = fieldInfo.declaringClass();
EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString());
this.processField(deploymentUnit, annotation, fieldInfo, eeModuleClassDescription);
} else if (annotationTarget instanceof MethodInfo) {
MethodInfo methodInfo = (MethodInfo) annotationTarget;
declaringClass = methodInfo.declaringClass();
EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString());
this.processMethod(deploymentUnit, annotation, methodInfo, eeModuleClassDescription);
} else if (annotationTarget instanceof ClassInfo) {
declaringClass = (ClassInfo) annotationTarget;
EEModuleClassDescription eeModuleClassDescription = eeModuleDescription.addOrGetLocalClassDescription(declaringClass.name().toString());
this.processClass(deploymentUnit, annotation, eeModuleClassDescription);
}
}
}
use of org.jboss.jandex.FieldInfo in project wildfly by wildfly.
the class JandexAnnotationRepositoryImpl method getAnnotation.
@Override
public Collection<Annotation> getAnnotation(Class<?> annotationClass) {
List<AnnotationInstance> instances = backingRepository.getAnnotations(DotName.createSimple(annotationClass.getName()));
ArrayList<Annotation> annotations = new ArrayList<Annotation>(instances.size());
for (AnnotationInstance instance : instances) {
AnnotationTarget target = instance.target();
Annotation annotation = null;
if (target instanceof MethodInfo) {
MethodInfo m = (MethodInfo) target;
List<String> parameterTypes = new ArrayList<String>(m.args().length);
for (Type type : m.args()) {
parameterTypes.add(type.toString());
}
String declaringClass = m.declaringClass().name().toString();
annotation = new AnnotationImpl(declaringClass, cl, parameterTypes, m.name(), true, false, annotationClass);
}
if (target instanceof FieldInfo) {
FieldInfo f = (FieldInfo) target;
String declaringClass = f.declaringClass().name().toString();
annotation = new AnnotationImpl(declaringClass, cl, null, f.name(), false, true, annotationClass);
}
if (target instanceof ClassInfo) {
ClassInfo c = (ClassInfo) target;
annotation = new AnnotationImpl(c.name().toString(), cl, null, null, false, false, annotationClass);
}
if (annotation != null) {
annotations.add(annotation);
}
}
annotations.trimToSize();
if (annotations.isEmpty()) {
return null;
} else {
return Collections.unmodifiableList(annotations);
}
}
use of org.jboss.jandex.FieldInfo in project wildfly by wildfly.
the class ResourceInjectionAnnotationParsingProcessor method deploy.
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
final PropertyReplacer replacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
if (module == null) {
return;
}
final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(RESOURCE_ANNOTATION_NAME);
for (AnnotationInstance annotation : resourceAnnotations) {
final AnnotationTarget annotationTarget = annotation.target();
final AnnotationValue nameValue = annotation.value("name");
final String name = (nameValue != null) ? replacer.replaceProperties(nameValue.asString()) : null;
final AnnotationValue typeValue = annotation.value("type");
final String type = typeValue != null ? typeValue.asClass().name().toString() : null;
if (annotationTarget instanceof FieldInfo) {
final FieldInfo fieldInfo = (FieldInfo) annotationTarget;
final ClassInfo classInfo = fieldInfo.declaringClass();
EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
processFieldResource(phaseContext, fieldInfo, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
} else if (annotationTarget instanceof MethodInfo) {
final MethodInfo methodInfo = (MethodInfo) annotationTarget;
ClassInfo classInfo = methodInfo.declaringClass();
EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
processMethodResource(phaseContext, methodInfo, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
} else if (annotationTarget instanceof ClassInfo) {
final ClassInfo classInfo = (ClassInfo) annotationTarget;
EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
processClassResource(phaseContext, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
}
}
final List<AnnotationInstance> resourcesAnnotations = index.getAnnotations(RESOURCES_ANNOTATION_NAME);
for (AnnotationInstance outerAnnotation : resourcesAnnotations) {
final AnnotationTarget annotationTarget = outerAnnotation.target();
if (annotationTarget instanceof ClassInfo) {
final ClassInfo classInfo = (ClassInfo) annotationTarget;
final AnnotationInstance[] values = outerAnnotation.value("value").asNestedArray();
for (AnnotationInstance annotation : values) {
final AnnotationValue nameValue = annotation.value("name");
final String name = (nameValue != null) ? replacer.replaceProperties(nameValue.asString()) : null;
final AnnotationValue typeValue = annotation.value("type");
final String type = (typeValue != null) ? typeValue.asClass().name().toString() : null;
EEModuleClassDescription classDescription = eeModuleDescription.addOrGetLocalClassDescription(classInfo.name().toString());
processClassResource(phaseContext, name, type, classDescription, annotation, eeModuleDescription, module, applicationClasses, replacer);
}
}
}
}
use of org.jboss.jandex.FieldInfo in project wildfly by wildfly.
the class EjbResourceInjectionAnnotationProcessor method deploy.
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
final CompositeIndex index = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.COMPOSITE_ANNOTATION_INDEX);
final List<AnnotationInstance> resourceAnnotations = index.getAnnotations(EJB_ANNOTATION_NAME);
PropertyReplacer propertyReplacer = EJBAnnotationPropertyReplacement.propertyReplacer(deploymentUnit);
for (AnnotationInstance annotation : resourceAnnotations) {
final AnnotationTarget annotationTarget = annotation.target();
final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(annotation, propertyReplacer);
if (annotationTarget instanceof FieldInfo) {
processField(deploymentUnit, annotationWrapper, (FieldInfo) annotationTarget, moduleDescription);
} else if (annotationTarget instanceof MethodInfo) {
processMethod(deploymentUnit, annotationWrapper, (MethodInfo) annotationTarget, moduleDescription);
} else if (annotationTarget instanceof ClassInfo) {
processClass(deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
}
}
final List<AnnotationInstance> ejbsAnnotations = index.getAnnotations(EJBS_ANNOTATION_NAME);
for (AnnotationInstance annotation : ejbsAnnotations) {
final AnnotationTarget annotationTarget = annotation.target();
if (annotationTarget instanceof ClassInfo) {
final AnnotationValue annotationValue = annotation.value();
final AnnotationInstance[] ejbAnnotations = annotationValue.asNestedArray();
for (AnnotationInstance ejbAnnotation : ejbAnnotations) {
final EJBResourceWrapper annotationWrapper = new EJBResourceWrapper(ejbAnnotation, propertyReplacer);
processClass(deploymentUnit, annotationWrapper, (ClassInfo) annotationTarget, moduleDescription);
}
} else {
throw EjbLogger.ROOT_LOGGER.annotationOnlyAllowedOnClass(EJBs.class.getName(), annotation.target());
}
}
}
Aggregations