org.jboss.jandex.AnnotationTarget Java Examples
The following examples show how to use
org.jboss.jandex.AnnotationTarget.
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: GoogleCalendarProcessor.java From camel-quarkus with Apache License 2.0 | 6 votes |
@BuildStep void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, BuildProducer<UnbannedReflectiveBuildItem> unbannedClass, CombinedIndexBuildItem combinedIndex) { IndexView index = combinedIndex.getIndex(); // Google calendar component configuration class reflection Collection<AnnotationInstance> uriParams = index .getAnnotations(DotName.createSimple("org.apache.camel.spi.UriParams")); String[] googleDriveConfigClasses = uriParams.stream() .map(annotation -> annotation.target()) .filter(annotationTarget -> annotationTarget.kind().equals(AnnotationTarget.Kind.CLASS)) .map(annotationTarget -> annotationTarget.asClass().name().toString()) .filter(className -> className.startsWith("org.apache.camel.component.google.calendar")) .toArray(String[]::new); reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, googleDriveConfigClasses)); unbannedClass.produce(new UnbannedReflectiveBuildItem(googleDriveConfigClasses)); }
Example #2
Source File: BeanValidationScanner.java From smallrye-open-api with Apache License 2.0 | 6 votes |
void decimalMax(AnnotationTarget target, Schema schema) { AnnotationInstance constraint = getConstraint(target, BV_DECIMAL_MAX); if (constraint != null && schema.getMaximum() == null) { String decimalValue = stringValue(constraint, VALUE); try { BigDecimal decimal = new BigDecimal(decimalValue); schema.setMaximum(decimal); Optional<Boolean> inclusive = booleanValue(constraint, INCLUSIVE); if (schema.getExclusiveMaximum() == null && inclusive.isPresent() && !inclusive.get()) { schema.setExclusiveMaximum(Boolean.TRUE); } } catch (@SuppressWarnings("unused") NumberFormatException e) { DataObjectLogging.log.invalidAnnotationFormat(decimalValue); } } }
Example #3
Source File: ParameterProcessor.java From smallrye-open-api with Apache License 2.0 | 6 votes |
boolean haveSameAnnotatedTarget(ParameterContext context, AnnotationTarget target, String name) { /* * Consider names to match if one is unspecified or they are equal. */ boolean nameMatches = (context.name == null || name == null || Objects.equals(context.name, name)); if (target.equals(context.target)) { /* * The name must match for annotations on a method because it is * ambiguous which parameters is being referenced. */ return nameMatches || target.kind() != Kind.METHOD; } if (nameMatches && target.kind() == Kind.METHOD && context.target.kind() == Kind.METHOD_PARAMETER) { return context.target.asMethodParameter().method().equals(target); } return false; }
Example #4
Source File: Beans.java From quarkus with Apache License 2.0 | 6 votes |
private static String initStereotypeName(List<StereotypeInfo> stereotypes, AnnotationTarget target) { if (stereotypes.isEmpty()) { return null; } for (StereotypeInfo stereotype : stereotypes) { if (stereotype.isNamed()) { switch (target.kind()) { case CLASS: return getDefaultName(target.asClass()); case FIELD: return target.asField() .name(); case METHOD: return getDefaultName(target.asMethod()); default: break; } } } return null; }
Example #5
Source File: Injection.java From quarkus with Apache License 2.0 | 6 votes |
/** * * @param beanTarget * @param beanDeployment * @return the list of injections */ static List<Injection> forBean(AnnotationTarget beanTarget, BeanInfo declaringBean, BeanDeployment beanDeployment, InjectionPointModifier transformer) { if (Kind.CLASS.equals(beanTarget.kind())) { List<Injection> injections = new ArrayList<>(); forClassBean(beanTarget.asClass(), beanTarget.asClass(), beanDeployment, injections, transformer, false); Set<AnnotationTarget> injectConstructors = injections.stream().filter(Injection::isConstructor) .map(Injection::getTarget).collect(Collectors.toSet()); if (injectConstructors.size() > 1) { throw new DefinitionException( "Multiple @Inject constructors found on " + beanTarget.asClass().name() + ":\n" + injectConstructors.stream().map(Object::toString).collect(Collectors.joining("\n"))); } return injections; } else if (Kind.METHOD.equals(beanTarget.kind())) { if (beanTarget.asMethod().parameters().isEmpty()) { return Collections.emptyList(); } // All parameters are injection points return Collections.singletonList( new Injection(beanTarget.asMethod(), InjectionPointInfo.fromMethod(beanTarget.asMethod(), declaringBean.getImplClazz(), beanDeployment, transformer))); } throw new IllegalArgumentException("Unsupported annotation target"); }
Example #6
Source File: HibernateOrmProcessor.java From quarkus with Apache License 2.0 | 6 votes |
private boolean isUserDefinedProducerMissing(IndexView index, DotName annotationName) { for (AnnotationInstance annotationInstance : index.getAnnotations(annotationName)) { if (annotationInstance.target().kind() == AnnotationTarget.Kind.METHOD) { if (annotationInstance.target().asMethod().hasAnnotation(PRODUCES)) { return false; } } else if (annotationInstance.target().kind() == AnnotationTarget.Kind.FIELD) { for (AnnotationInstance i : annotationInstance.target().asField().annotations()) { if (i.name().equals(PRODUCES)) { return false; } } } } return true; }
Example #7
Source File: ParameterProcessor.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Scan and parse a Spring DefaultValue property on the mapping annotation. * If the target is a Java primitive, the value will be parsed into an equivalent * wrapper object. * * @param target target annotated with a Spring mapping * @return the default value */ static Object getDefaultValue(AnnotationTarget target) { AnnotationInstance defaultValueAnno = TypeUtil.getAnnotation(target, SpringConstants.QUERY_PARAM); Object defaultValue = null; if (defaultValueAnno != null) { AnnotationValue value = defaultValueAnno.value("defaultValue"); if (value != null && !value.asString().isEmpty()) { String defaultValueString = value.asString(); defaultValue = defaultValueString; Type targetType = getType(target); if (targetType != null && targetType.kind() == Type.Kind.PRIMITIVE) { Primitive primitive = targetType.asPrimitiveType().primitive(); Object primitiveValue = primitiveToObject(primitive, defaultValueString); if (primitiveValue != null) { defaultValue = primitiveValue; } } } } return defaultValue; }
Example #8
Source File: TypeUtil.java From smallrye-open-api with Apache License 2.0 | 6 votes |
public static ClassInfo getDeclaringClass(AnnotationTarget type) { switch (type.kind()) { case FIELD: return type.asField().declaringClass(); case METHOD: return type.asMethod().declaringClass(); case METHOD_PARAMETER: MethodParameterInfo parameter = type.asMethodParameter(); return parameter.method().declaringClass(); case CLASS: case TYPE: break; } return null; }
Example #9
Source File: ParameterProcessor.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Find the full path of the target. Method-level targets will include * both the path to the resource and the path to the method joined with a '/'. * * @param target target item for which the path is being generated * @return full path (excluding application path) of the target */ static String fullPathOf(AnnotationTarget target) { String pathSegment = null; switch (target.kind()) { case FIELD: pathSegment = pathOf(target.asField().declaringClass()); break; case METHOD: pathSegment = methodPath(target.asMethod()); break; case METHOD_PARAMETER: pathSegment = methodPath(target.asMethodParameter().method()); break; default: break; } return pathSegment; }
Example #10
Source File: Beans.java From quarkus with Apache License 2.0 | 6 votes |
private static Integer initAlternativePriority(AnnotationTarget target, Integer alternativePriority, List<StereotypeInfo> stereotypes, BeanDeployment deployment) { if (alternativePriority == null) { // No @Priority or @AlernativePriority used - try stereotypes alternativePriority = initStereotypeAlternativePriority(stereotypes); } Integer computedPriority = deployment.computeAlternativePriority(target, stereotypes); if (computedPriority != null) { if (alternativePriority != null) { LOGGER.infof( "Computed priority [%s] overrides the priority [%s] declared via @Priority or @AlernativePriority", computedPriority, alternativePriority); } alternativePriority = computedPriority; } return alternativePriority; }
Example #11
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 #12
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 #13
Source File: SpringDIProcessor.java From quarkus with Apache License 2.0 | 6 votes |
@BuildStep SpringBeanNameToDotNameBuildItem createBeanNamesMap(BeanArchiveIndexBuildItem beanArchiveIndexBuildItem) { final Map<String, DotName> result = new HashMap<>(); final IndexView index = beanArchiveIndexBuildItem.getIndex(); final Collection<AnnotationInstance> stereotypeInstances = new ArrayList<>(); stereotypeInstances.addAll(index.getAnnotations(SPRING_COMPONENT)); stereotypeInstances.addAll(index.getAnnotations(SPRING_REPOSITORY)); stereotypeInstances.addAll(index.getAnnotations(SPRING_SERVICE)); for (AnnotationInstance stereotypeInstance : stereotypeInstances) { if (stereotypeInstance.target().kind() != AnnotationTarget.Kind.CLASS) { continue; } result.put(getBeanNameFromStereotypeInstance(stereotypeInstance), stereotypeInstance.target().asClass().name()); } for (AnnotationInstance beanInstance : index.getAnnotations(BEAN_ANNOTATION)) { if (beanInstance.target().kind() != AnnotationTarget.Kind.METHOD) { continue; } result.put(getBeanNameFromBeanInstance(beanInstance), beanInstance.target().asMethod().returnType().name()); } return new SpringBeanNameToDotNameBuildItem(result); }
Example #14
Source File: GoogleSheetsProcessor.java From camel-quarkus with Apache License 2.0 | 6 votes |
@BuildStep void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, BuildProducer<UnbannedReflectiveBuildItem> unbannedClass, CombinedIndexBuildItem combinedIndex) { IndexView index = combinedIndex.getIndex(); // Google sheets component configuration class reflection Collection<AnnotationInstance> uriParams = index .getAnnotations(DotName.createSimple("org.apache.camel.spi.UriParams")); String[] googleMailConfigClasses = uriParams.stream() .map(annotation -> annotation.target()) .filter(annotationTarget -> annotationTarget.kind().equals(AnnotationTarget.Kind.CLASS)) .map(annotationTarget -> annotationTarget.asClass().name().toString()) .filter(className -> className.startsWith("org.apache.camel.component.google.sheets")) .toArray(String[]::new); reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, googleMailConfigClasses)); unbannedClass.produce(new UnbannedReflectiveBuildItem(googleMailConfigClasses)); }
Example #15
Source File: GoogleDriveProcessor.java From camel-quarkus with Apache License 2.0 | 6 votes |
@BuildStep void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass, BuildProducer<UnbannedReflectiveBuildItem> unbannedClass, CombinedIndexBuildItem combinedIndex) { IndexView index = combinedIndex.getIndex(); // Google drive component configuration class reflection Collection<AnnotationInstance> uriParams = index .getAnnotations(DotName.createSimple("org.apache.camel.spi.UriParams")); String[] googleDriveConfigClasses = uriParams.stream() .map(annotation -> annotation.target()) .filter(annotationTarget -> annotationTarget.kind().equals(AnnotationTarget.Kind.CLASS)) .map(annotationTarget -> annotationTarget.asClass().name().toString()) .filter(className -> className.startsWith("org.apache.camel.component.google.drive")) .toArray(String[]::new); reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, googleDriveConfigClasses)); unbannedClass.produce(new UnbannedReflectiveBuildItem(googleDriveConfigClasses)); }
Example #16
Source File: MicroProfileHealthProcessor.java From camel-quarkus with Apache License 2.0 | 6 votes |
@BuildStep void disableCamelMicroProfileHealthChecks(BuildProducer<AnnotationsTransformerBuildItem> transformers, CamelMicroProfileHealthConfig config) { if (!config.enabled) { // Veto the Camel MicroProfile checks to disable them transformers.produce(new AnnotationsTransformerBuildItem(context -> { if (context.isClass()) { AnnotationTarget target = context.getTarget(); if (isCamelMicroProfileHealthCheck(target.asClass())) { AnnotationInstance annotationInstance = AnnotationInstance.create(VETOED_DOTNAME, target, new AnnotationValue[0]); context.transform().add(annotationInstance).done(); } } })); } }
Example #17
Source File: TypeResolver.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Determine the name of the instance's property. The name may be overridden by * one of several annotations, selected in the following order: * * <ol> * <li>MP Open API <code>@Schema</code> * <li>JSON-B <code>@JsonbProperty</code> * <li>Jackson <code>@JsonProperty</code> * <li>JAXB <code>@XmlElement</code> * <li>JAXB <code>@XmlAttribute</code> * </ol> * * If no elements have been selected, the default Java bean property name will * be returned. * * @return name of property */ public String getPropertyName() { AnnotationTarget target = getAnnotationTarget(); String name; if ((name = TypeUtil.getAnnotationValue(target, SchemaConstant.DOTNAME_SCHEMA, SchemaConstant.PROP_NAME)) != null) { return name; } if ((name = TypeUtil.getAnnotationValue(target, JsonbConstants.JSONB_PROPERTY, JsonbConstants.PROP_VALUE)) != null) { return name; } if ((name = TypeUtil.getAnnotationValue(target, JacksonConstants.JSON_PROPERTY, JacksonConstants.PROP_VALUE)) != null) { return name; } if ((name = TypeUtil.getAnnotationValue(target, JaxbConstants.XML_ELEMENT, JaxbConstants.PROP_NAME)) != null) { return name; } if ((name = TypeUtil.getAnnotationValue(target, JaxbConstants.XML_ATTRIBUTE, JaxbConstants.PROP_NAME)) != null) { return name; } return this.propertyName; }
Example #18
Source File: ResteasyCommonProcessor.java From quarkus with Apache License 2.0 | 5 votes |
private Set<String> getUserSuppliedJsonProducerBeans(IndexView index, DotName jsonImplementation) { Set<String> result = new HashSet<>(); for (AnnotationInstance annotation : index.getAnnotations(DotNames.PRODUCES)) { if (annotation.target().kind() != AnnotationTarget.Kind.METHOD) { continue; } if (jsonImplementation.equals(annotation.target().asMethod().returnType().name())) { result.add(annotation.target().asMethod().declaringClass().name().toString()); } } return result; }
Example #19
Source File: BeanValidationScanner.java From smallrye-open-api with Apache License 2.0 | 5 votes |
void positiveOrZero(AnnotationTarget target, Schema schema) { AnnotationInstance constraint = getConstraint(target, BV_POSITIVE_OR_ZERO); if (constraint != null && schema.getMinimum() == null) { Boolean exclusive = schema.getExclusiveMinimum(); if (exclusive != null && exclusive) { schema.setMinimum(NEGATIVE_ONE); } else { schema.setMinimum(BigDecimal.ZERO); } } }
Example #20
Source File: BeanInfo.java From quarkus with Apache License 2.0 | 5 votes |
BeanInfo(AnnotationTarget target, BeanDeployment beanDeployment, ScopeInfo scope, Set<Type> types, Set<AnnotationInstance> qualifiers, List<Injection> injections, BeanInfo declaringBean, DisposerInfo disposer, Integer alternativePriority, List<StereotypeInfo> stereotypes, String name, boolean isDefaultBean) { this(null, null, target, beanDeployment, scope, types, qualifiers, injections, declaringBean, disposer, alternativePriority, stereotypes, name, isDefaultBean, null, null, Collections.emptyMap(), true); }
Example #21
Source File: BeanValidationScanner.java From smallrye-open-api with Apache License 2.0 | 5 votes |
void notNull(AnnotationTarget target, Schema schema, String propertyKey, RequirementHandler handler) { AnnotationInstance constraint = getConstraint(target, BV_NOT_NULL); if (constraint != null) { if (schema.getNullable() == null) { schema.setNullable(Boolean.FALSE); } if (handler != null && propertyKey != null) { handler.setRequired(target, propertyKey); } } }
Example #22
Source File: AnnotationStore.java From quarkus with Apache License 2.0 | 5 votes |
private Collection<AnnotationInstance> getOriginalAnnotations(AnnotationTarget target) { switch (target.kind()) { case CLASS: return target.asClass().classAnnotations(); case METHOD: // Note that the returning collection also contains method params annotations return target.asMethod().annotations(); case FIELD: return target.asField().annotations(); default: throw new IllegalArgumentException("Unsupported annotation target"); } }
Example #23
Source File: CacheAnnotationsTransformer.java From quarkus with Apache License 2.0 | 5 votes |
private AnnotationInstance createCacheResultBinding(MethodInfo method, AnnotationInstance annotation, AnnotationTarget target) { List<AnnotationValue> parameters = new ArrayList<>(); parameters.add(getCacheName(annotation)); findCacheKeyParameters(method).ifPresent(parameters::add); findLockTimeout(annotation).ifPresent(parameters::add); return createBinding(CacheResultInterceptorBinding.class, target, toArray(parameters)); }
Example #24
Source File: MicroInnerDeployer.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
Class<?> getTarget (AnnotationTarget target) { try { if (target.kind() == CLASS) { return Class.forName( target.asClass().toString(), true, Thread.currentThread().getContextClassLoader()); } return Class.forName( target.asMethod().declaringClass().toString(), true, Thread.currentThread().getContextClassLoader()); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } }
Example #25
Source File: BeanValidationScanner.java From smallrye-open-api with Apache License 2.0 | 5 votes |
private static void applyStringConstraints(AnnotationTarget target, Schema schema, String propertyKey, RequirementHandler handler) { INSTANCE.decimalMax(target, schema); INSTANCE.decimalMin(target, schema); INSTANCE.digits(target, schema); INSTANCE.notBlank(target, schema); INSTANCE.notNull(target, schema, propertyKey, handler); INSTANCE.sizeString(target, schema); INSTANCE.notEmptyString(target, schema); }
Example #26
Source File: AnnotationTargetProcessor.java From smallrye-open-api with Apache License 2.0 | 5 votes |
public AnnotationTargetProcessor(AugmentedIndexView index, DataObjectDeque objectStack, DataObjectDeque.PathEntry parentPathEntry, TypeResolver typeResolver, AnnotationTarget annotationTarget, Type entityType) { this.index = index; this.objectStack = objectStack; this.parentPathEntry = parentPathEntry; this.typeResolver = typeResolver; this.entityType = entityType; this.annotationTarget = annotationTarget; }
Example #27
Source File: OpenApiDataObjectScanner.java From smallrye-open-api with Apache License 2.0 | 5 votes |
OpenApiDataObjectScanner(IndexView index, AnnotationTarget annotationTarget, Type classType) { this.index = new AugmentedIndexView(index); this.objectStack = new DataObjectDeque(this.index); this.ignoreResolver = new IgnoreResolver(this.index); this.rootClassType = classType; this.rootSchema = new SchemaImpl(); this.rootClassInfo = initialType(classType); this.rootAnnotationTarget = annotationTarget; }
Example #28
Source File: JpaSecurityDefinition.java From quarkus with Apache License 2.0 | 5 votes |
public JpaSecurityDefinition(Index index, ClassInfo annotatedClass, boolean isPanache, AnnotationTarget usernameFieldOrMethod, AnnotationTarget passwordFieldOrMethod, AnnotationTarget rolesFieldOrMethod) { this.annotatedClass = annotatedClass; this.username = getFieldOrMethod(index, annotatedClass, usernameFieldOrMethod, isPanache); this.password = getFieldOrMethod(index, annotatedClass, passwordFieldOrMethod, isPanache); this.roles = getFieldOrMethod(index, annotatedClass, rolesFieldOrMethod, isPanache); }
Example #29
Source File: ObserverInfo.java From quarkus with Apache License 2.0 | 5 votes |
public ObserverTransformationContext(BuildContext buildContext, AnnotationTarget target, Type observedType, Set<AnnotationInstance> qualifiers, Reception reception, TransactionPhase transactionPhase, Integer priority, boolean async) { super(buildContext, target, qualifiers); this.observedType = observedType; this.reception = reception; this.transactionPhase = transactionPhase; this.priority = priority; this.async = async; }
Example #30
Source File: TypeUtil.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Convenience method to retrieve the named parameter from an annotation bound to the target. * The value will be unwrapped from its containing {@link AnnotationValue}. * * @param <T> the type of the parameter being retrieved * @param target the target object annotated with the annotation named by annotationName * @param annotationName name of the annotation from which to retrieve the value * @param propertyName the name of the parameter/property in the annotation * @param defaultValue a default value to return if either the annotation or the value are missing * @return an unwrapped annotation parameter value */ public static <T> T getAnnotationValue(AnnotationTarget target, DotName annotationName, String propertyName, T defaultValue) { AnnotationInstance annotation = getAnnotation(target, annotationName); if (annotation != null) { return JandexUtil.value(annotation, propertyName); } return defaultValue; }