Java Code Examples for org.jboss.jandex.AnnotationValue#asClassArray()
The following examples show how to use
org.jboss.jandex.AnnotationValue#asClassArray() .
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 Set<Type> restrictBeanTypes(Set<Type> types, Collection<AnnotationInstance> annotations) { AnnotationInstance typed = annotations.stream().filter(a -> a.name().equals(DotNames.TYPED)) .findFirst().orElse(null); if (typed != null) { AnnotationValue typedValue = typed.value(); if (typedValue == null) { types.clear(); types.add(OBJECT_TYPE); } else { Set<DotName> typedClasses = new HashSet<>(); for (Type type : typedValue.asClassArray()) { typedClasses.add(type.name()); } for (Iterator<Type> iterator = types.iterator(); iterator.hasNext();) { Type nextType = iterator.next(); if (!typedClasses.contains(nextType.name()) && !DotNames.OBJECT.equals(nextType.name())) { iterator.remove(); } } } } return types; }
Example 2
Source File: BeanValidationScanner.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Retrieves a constraint {@link AnnotationInstance} from the current * target. If the annotation is found and applies to multiple bean * validation groups or to a single group other than the {@link Default}, * returns null. * * @param target * the object from which to retrieve the constraint annotation * @param annotationName * name of the annotation * @return the first occurrence of the named constraint if no groups or only * the {@link Default} group is specified, or null */ AnnotationInstance getConstraint(AnnotationTarget target, DotName annotationName) { AnnotationInstance constraint = getAnnotation(target, annotationName); if (constraint != null) { AnnotationValue groupValue = constraint.value("groups"); if (groupValue == null) { return constraint; } Type[] groups = groupValue.asClassArray(); switch (groups.length) { case 0: return constraint; case 1: if (groups[0].name().equals(BV_DEFAULT_GROUP)) { return constraint; } break; default: break; } } return null; }
Example 3
Source File: AnnotationLiteralGenerator.java From quarkus with Apache License 2.0 | 5 votes |
private static void generateStaticFieldsWithDefaultValues(ClassCreator annotationLiteral, List<MethodInfo> defaultOfClassType) { if (defaultOfClassType.isEmpty()) { return; } MethodCreator staticConstructor = annotationLiteral.getMethodCreator(Methods.CLINIT, void.class); staticConstructor.setModifiers(ACC_STATIC); for (MethodInfo method : defaultOfClassType) { Type returnType = method.returnType(); String returnTypeName = returnType.name().toString(); AnnotationValue defaultValue = method.defaultValue(); FieldCreator fieldCreator = annotationLiteral.getFieldCreator(defaultValueStaticFieldName(method), returnTypeName); fieldCreator.setModifiers(ACC_PUBLIC | ACC_STATIC | ACC_FINAL); if (defaultValue.kind() == AnnotationValue.Kind.ARRAY) { Type[] clazzArray = defaultValue.asClassArray(); ResultHandle array = staticConstructor.newArray(returnTypeName, clazzArray.length); for (int i = 0; i < clazzArray.length; ++i) { staticConstructor.writeArrayValue(array, staticConstructor.load(i), staticConstructor.loadClass(clazzArray[i].name().toString())); } staticConstructor.writeStaticField(fieldCreator.getFieldDescriptor(), array); } else { staticConstructor.writeStaticField(fieldCreator.getFieldDescriptor(), staticConstructor.loadClass(defaultValue.asClass().name().toString())); } } staticConstructor.returnValue(null); }
Example 4
Source File: UndertowWebsocketProcessor.java From quarkus with Apache License 2.0 | 5 votes |
private void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflection, AnnotationValue types) { if (types != null && types.asClassArray() != null) { for (Type type : types.asClassArray()) { reflection.produce(new ReflectiveClassBuildItem(true, false, type.name().toString())); } } }
Example 5
Source File: RegisterForReflectionBuildStep.java From quarkus with Apache License 2.0 | 5 votes |
@BuildStep public void build() { for (AnnotationInstance i : combinedIndexBuildItem.getIndex() .getAnnotations(DotName.createSimple(RegisterForReflection.class.getName()))) { boolean methods = getBooleanValue(i, "methods"); boolean fields = getBooleanValue(i, "fields"); boolean ignoreNested = getBooleanValue(i, "ignoreNested"); AnnotationValue targetsValue = i.value("targets"); AnnotationValue classNamesValue = i.value("classNames"); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (targetsValue == null && classNamesValue == null) { ClassInfo classInfo = i.target().asClass(); registerClass(classLoader, classInfo.name().toString(), methods, fields, ignoreNested); continue; } if (targetsValue != null) { Type[] targets = targetsValue.asClassArray(); for (Type type : targets) { registerClass(classLoader, type.name().toString(), methods, fields, ignoreNested); } } if (classNamesValue != null) { String[] classNames = classNamesValue.asStringArray(); for (String className : classNames) { registerClass(classLoader, className, methods, fields, ignoreNested); } } } }
Example 6
Source File: SmallRyeOpenApiProcessor.java From quarkus with Apache License 2.0 | 4 votes |
private void registerReflectionForApiResponseSchemaSerialization(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy, Collection<AnnotationInstance> apiResponseAnnotationInstances) { for (AnnotationInstance apiResponseAnnotationInstance : apiResponseAnnotationInstances) { AnnotationValue contentAnnotationValue = apiResponseAnnotationInstance.value(OPENAPI_RESPONSE_CONTENT); if (contentAnnotationValue == null) { continue; } AnnotationInstance[] contents = contentAnnotationValue.asNestedArray(); for (AnnotationInstance content : contents) { AnnotationValue annotationValue = content.value(OPENAPI_RESPONSE_SCHEMA); if (annotationValue == null) { continue; } AnnotationInstance schema = annotationValue.asNested(); AnnotationValue schemaImplementationClass = schema.value(OPENAPI_SCHEMA_IMPLEMENTATION); if (schemaImplementationClass != null) { reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(schemaImplementationClass.asClass(), IgnoreDotNames.IGNORE_FOR_REFLECTION_PREDICATE)); } AnnotationValue schemaNotClass = schema.value(OPENAPI_SCHEMA_NOT); if (schemaNotClass != null) { reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, schemaNotClass.asString())); } AnnotationValue schemaOneOfClasses = schema.value(OPENAPI_SCHEMA_ONE_OF); if (schemaOneOfClasses != null) { for (Type schemaOneOfClass : schemaOneOfClasses.asClassArray()) { reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(schemaOneOfClass, IgnoreDotNames.IGNORE_FOR_REFLECTION_PREDICATE)); } } AnnotationValue schemaAnyOfClasses = schema.value(OPENAPI_SCHEMA_ANY_OF); if (schemaAnyOfClasses != null) { for (Type schemaAnyOfClass : schemaAnyOfClasses.asClassArray()) { reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(schemaAnyOfClass, IgnoreDotNames.IGNORE_FOR_REFLECTION_PREDICATE)); } } AnnotationValue schemaAllOfClasses = schema.value(OPENAPI_SCHEMA_ALL_OF); if (schemaAllOfClasses != null) { for (Type schemaAllOfClass : schemaAllOfClasses.asClassArray()) { reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(schemaAllOfClass, IgnoreDotNames.IGNORE_FOR_REFLECTION_PREDICATE)); } } } } }
Example 7
Source File: BytecodeRecorderImpl.java From quarkus with Apache License 2.0 | 4 votes |
static ResultHandle arrayValue(AnnotationValue value, BytecodeCreator valueMethod, MethodInfo method, ClassInfo annotationClass) { ResultHandle retValue; switch (value.componentKind()) { case CLASS: Type[] classArray = value.asClassArray(); retValue = valueMethod.newArray(componentType(method), valueMethod.load(classArray.length)); for (int i = 0; i < classArray.length; i++) { valueMethod.writeArrayValue(retValue, i, valueMethod.loadClass(classArray[i].name().toString())); } break; case STRING: String[] stringArray = value.asStringArray(); retValue = valueMethod.newArray(componentType(method), valueMethod.load(stringArray.length)); for (int i = 0; i < stringArray.length; i++) { valueMethod.writeArrayValue(retValue, i, valueMethod.load(stringArray[i])); } break; case INTEGER: int[] intArray = value.asIntArray(); retValue = valueMethod.newArray(componentType(method), valueMethod.load(intArray.length)); for (int i = 0; i < intArray.length; i++) { valueMethod.writeArrayValue(retValue, i, valueMethod.load(intArray[i])); } break; case LONG: long[] longArray = value.asLongArray(); retValue = valueMethod.newArray(componentType(method), valueMethod.load(longArray.length)); for (int i = 0; i < longArray.length; i++) { valueMethod.writeArrayValue(retValue, i, valueMethod.load(longArray[i])); } break; case BYTE: byte[] byteArray = value.asByteArray(); retValue = valueMethod.newArray(componentType(method), valueMethod.load(byteArray.length)); for (int i = 0; i < byteArray.length; i++) { valueMethod.writeArrayValue(retValue, i, valueMethod.load(byteArray[i])); } break; case CHARACTER: char[] charArray = value.asCharArray(); retValue = valueMethod.newArray(componentType(method), valueMethod.load(charArray.length)); for (int i = 0; i < charArray.length; i++) { valueMethod.writeArrayValue(retValue, i, valueMethod.load(charArray[i])); } break; case ENUM: String[] enumArray = value.asEnumArray(); retValue = valueMethod.newArray(componentType(method), valueMethod.load(enumArray.length)); String enumType = componentType(method); for (int i = 0; i < enumArray.length; i++) { valueMethod.writeArrayValue(retValue, i, valueMethod.readStaticField(FieldDescriptor.of(enumType, enumArray[i], enumType))); } break; // TODO: handle other less common types of array components default: // Return empty array for empty arrays and unsupported types // For an empty array the component kind is UNKNOWN retValue = valueMethod.newArray(componentType(method), valueMethod.load(0)); } return retValue; }