Java Code Examples for org.jboss.jandex.AnnotationTarget#asField()
The following examples show how to use
org.jboss.jandex.AnnotationTarget#asField() .
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: IgnoreResolver.java From smallrye-open-api with Apache License 2.0 | 6 votes |
@Override public boolean shouldIgnore(AnnotationTarget target, PathEntry parentPathEntry) { if (target.kind() == AnnotationTarget.Kind.FIELD) { FieldInfo field = target.asField(); // If field has transient modifier, e.g. `transient String foo;`, then hide it. if (Modifier.isTransient(field.flags())) { // Unless field is annotated with @Schema to explicitly un-hide it. AnnotationInstance schemaAnnotation = TypeUtil.getSchemaAnnotation(target); if (schemaAnnotation != null) { return JandexUtil.booleanValue(schemaAnnotation, SchemaConstant.PROP_HIDDEN).orElse(true); } return true; } } return false; }
Example 2
Source File: StockMethodsAdder.java From quarkus with Apache License 2.0 | 6 votes |
/** * Given an annotation target, generate the bytecode that is needed to obtain its value * either by reading the field or by calling the method. * Meant to be called for annotations alike {@code @Id} or {@code @Version} */ private ResultHandle generateObtainValue(MethodCreator methodCreator, DotName entityDotName, ResultHandle entity, AnnotationTarget annotationTarget) { if (annotationTarget instanceof FieldInfo) { FieldInfo fieldInfo = annotationTarget.asField(); if (Modifier.isPublic(fieldInfo.flags())) { return methodCreator.readInstanceField(FieldDescriptor.of(fieldInfo), entity); } String getterMethodName = JavaBeanUtil.getGetterName(fieldInfo.name(), fieldInfo.type().name()); return methodCreator.invokeVirtualMethod( MethodDescriptor.ofMethod(entityDotName.toString(), getterMethodName, fieldInfo.type().name().toString()), entity); } MethodInfo methodInfo = annotationTarget.asMethod(); return methodCreator.invokeVirtualMethod( MethodDescriptor.ofMethod(entityDotName.toString(), methodInfo.name(), methodInfo.returnType().name().toString()), entity); }
Example 3
Source File: JpaSecurityDefinition.java From quarkus with Apache License 2.0 | 6 votes |
public static FieldOrMethod getFieldOrMethod(Index index, ClassInfo annotatedClass, AnnotationTarget annotatedFieldOrMethod, boolean isPanache) { switch (annotatedFieldOrMethod.kind()) { case FIELD: // try to find a getter for this field FieldInfo field = annotatedFieldOrMethod.asField(); return new FieldOrMethod(field, findGetter(index, annotatedClass, field, Modifier.isPublic(field.flags()) && isPanache)); case METHOD: // skip the field entirely return new FieldOrMethod(null, annotatedFieldOrMethod.asMethod()); default: throw new IllegalArgumentException( "annotatedFieldOrMethod must be a field or method: " + annotatedFieldOrMethod); } }
Example 4
Source File: ValueResolverGenerator.java From quarkus with Apache License 2.0 | 5 votes |
static boolean defaultFilter(AnnotationTarget target) { // Always ignore constructors, static and non-public members, synthetic and void methods switch (target.kind()) { case METHOD: MethodInfo method = target.asMethod(); return Modifier.isPublic(method.flags()) && !Modifier.isStatic(method.flags()) && !isSynthetic(method.flags()) && method.returnType().kind() != org.jboss.jandex.Type.Kind.VOID && !method.name().equals("<init>") && !method.name().equals("<clinit>"); case FIELD: FieldInfo field = target.asField(); return Modifier.isPublic(field.flags()) && !Modifier.isStatic(field.flags()); default: throw new IllegalArgumentException("Unsupported annotation target"); } }
Example 5
Source File: StockMethodsAdder.java From quarkus with Apache License 2.0 | 5 votes |
private FieldInfo getIdField(AnnotationTarget idAnnotationTarget) { if (idAnnotationTarget instanceof FieldInfo) { return idAnnotationTarget.asField(); } MethodInfo methodInfo = idAnnotationTarget.asMethod(); String propertyName = JavaBeanUtil.getPropertyNameFromGetter(methodInfo.name()); ClassInfo entityClass = methodInfo.declaringClass(); FieldInfo field = entityClass.field(propertyName); if (field == null) { throw new IllegalArgumentException("Entity " + entityClass + " does not appear to have a field backing method" + methodInfo.name() + " which is annotated with @Id"); } return field; }
Example 6
Source File: CamelDeploymentSettingsBuilderProcessor.java From wildfly-camel with Apache License 2.0 | 5 votes |
private boolean annotationTargetIsCamelApi(AnnotationTarget target) { /** * Verify whether an annotation is applied to org.apache.camel types. If the declaring class * has the org.apache.camel package prefix, it is ignored since we are only interested in * annotations declared within user classes. */ if (target != null) { if (target.kind().equals(Kind.CLASS)) { ClassInfo classInfo = target.asClass(); if (isCamelApi(classInfo.name())) { return false; } Type superType = classInfo.superClassType(); if (superType != null && isCamelApi(superType.name())) { return true; } return classInfo.interfaceNames().stream().anyMatch(interfaceName -> isCamelApi(interfaceName)); } else if (target.kind().equals(Kind.FIELD)) { FieldInfo fieldInfo = target.asField(); return !isCamelApi(fieldInfo.declaringClass().name()) && isCamelApi(fieldInfo.type().name()); } else if (target.kind().equals(Kind.METHOD)) { MethodInfo methodInfo = target.asMethod(); return !isCamelApi(methodInfo.declaringClass().name()) && isCamelApi(methodInfo.returnType().name()); } } return false; }
Example 7
Source File: SmallRyeMetricsProcessor.java From quarkus with Apache License 2.0 | 4 votes |
@BuildStep @Record(RUNTIME_INIT) void registerMetricsFromProducers( SmallRyeMetricsRecorder recorder, ValidationPhaseBuildItem validationPhase, BeanArchiveIndexBuildItem beanArchiveIndex) { IndexView index = beanArchiveIndex.getIndex(); for (io.quarkus.arc.processor.BeanInfo bean : validationPhase.getContext().beans().producers()) { ClassInfo implClazz = bean.getImplClazz(); if (implClazz == null) { continue; } MetricType metricType = getMetricType(implClazz); if (metricType != null) { AnnotationTarget target = bean.getTarget().get(); AnnotationInstance metricAnnotation = null; String memberName = null; if (bean.isProducerField()) { FieldInfo field = target.asField(); metricAnnotation = field.annotation(METRIC); memberName = field.name(); } if (bean.isProducerMethod()) { MethodInfo method = target.asMethod(); metricAnnotation = method.annotation(METRIC); memberName = method.name(); } if (metricAnnotation != null) { String nameValue = metricAnnotation.valueWithDefault(index, "name").asString(); boolean absolute = metricAnnotation.valueWithDefault(index, "absolute").asBoolean(); String metricSimpleName = !nameValue.isEmpty() ? nameValue : memberName; String declaringClassName = bean.getDeclaringBean().getImplClazz().name().toString(); String metricsFinalName = absolute ? metricSimpleName : MetricRegistry.name(declaringClassName, metricSimpleName); recorder.registerMetricFromProducer( bean.getIdentifier(), metricType, metricsFinalName, metricAnnotation.valueWithDefault(index, "tags").asStringArray(), metricAnnotation.valueWithDefault(index, "description").asString(), metricAnnotation.valueWithDefault(index, "displayName").asString(), metricAnnotation.valueWithDefault(index, "unit").asString()); } } } }
Example 8
Source File: HibernateSearchElasticsearchProcessor.java From quarkus with Apache License 2.0 | 4 votes |
private void registerReflection(IndexView index, BuildProducer<ReflectiveClassBuildItem> reflectiveClass, BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy) { Set<DotName> reflectiveClassCollector = new HashSet<>(); if (buildTimeConfig.defaultBackend.analysis.configurer.isPresent()) { reflectiveClass.produce( new ReflectiveClassBuildItem(true, false, buildTimeConfig.defaultBackend.analysis.configurer.get())); } if (buildTimeConfig.defaultBackend.layout.strategy.isPresent()) { reflectiveClass.produce( new ReflectiveClassBuildItem(true, false, buildTimeConfig.defaultBackend.layout.strategy.get())); } if (buildTimeConfig.backgroundFailureHandler.isPresent()) { reflectiveClass.produce( new ReflectiveClassBuildItem(true, false, buildTimeConfig.backgroundFailureHandler.get())); } Set<Type> reflectiveHierarchyCollector = new HashSet<>(); for (AnnotationInstance propertyMappingMetaAnnotationInstance : index .getAnnotations(PROPERTY_MAPPING_META_ANNOTATION)) { for (AnnotationInstance propertyMappingAnnotationInstance : index .getAnnotations(propertyMappingMetaAnnotationInstance.name())) { AnnotationTarget annotationTarget = propertyMappingAnnotationInstance.target(); if (annotationTarget.kind() == Kind.FIELD) { FieldInfo fieldInfo = annotationTarget.asField(); addReflectiveClass(index, reflectiveClassCollector, reflectiveHierarchyCollector, fieldInfo.declaringClass()); addReflectiveType(index, reflectiveClassCollector, reflectiveHierarchyCollector, fieldInfo.type()); } else if (annotationTarget.kind() == Kind.METHOD) { MethodInfo methodInfo = annotationTarget.asMethod(); addReflectiveClass(index, reflectiveClassCollector, reflectiveHierarchyCollector, methodInfo.declaringClass()); addReflectiveType(index, reflectiveClassCollector, reflectiveHierarchyCollector, methodInfo.returnType()); } } } for (AnnotationInstance typeBridgeMappingInstance : index.getAnnotations(TYPE_MAPPING_META_ANNOTATION)) { for (AnnotationInstance typeBridgeInstance : index.getAnnotations(typeBridgeMappingInstance.name())) { addReflectiveClass(index, reflectiveClassCollector, reflectiveHierarchyCollector, typeBridgeInstance.target().asClass()); } } reflectiveClassCollector.addAll(GSON_CLASSES); String[] reflectiveClasses = reflectiveClassCollector.stream().map(DotName::toString).toArray(String[]::new); reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, reflectiveClasses)); for (Type reflectiveHierarchyType : reflectiveHierarchyCollector) { reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem(reflectiveHierarchyType)); } }