org.jboss.jandex.AnnotationValue Java Examples
The following examples show how to use
org.jboss.jandex.AnnotationValue.
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: TemplateDataBuilder.java From quarkus with Apache License 2.0 | 6 votes |
public AnnotationInstance build() { AnnotationValue ignoreValue; if (ignores.isEmpty()) { ignoreValue = AnnotationValue.createArrayValue(ValueResolverGenerator.IGNORE, new AnnotationValue[] {}); } else { AnnotationValue[] values = new AnnotationValue[ignores.size()]; for (int i = 0; i < ignores.size(); i++) { values[i] = AnnotationValue.createStringValue(ValueResolverGenerator.IGNORE + i, ignores.get(i)); } ignoreValue = AnnotationValue.createArrayValue(ValueResolverGenerator.IGNORE, values); } AnnotationValue propertiesValue = AnnotationValue.createBooleanValue(ValueResolverGenerator.PROPERTIES, properties); AnnotationValue ignoreSuperclassesValue = AnnotationValue.createBooleanValue(ValueResolverGenerator.IGNORE_SUPERCLASSES, ignoreSuperclasses); return AnnotationInstance.create(ValueResolverGenerator.TEMPLATE_DATA, null, new AnnotationValue[] { ignoreValue, propertiesValue, ignoreSuperclassesValue }); }
Example #3
Source File: SchemaBuilder.java From smallrye-graphql with Apache License 2.0 | 6 votes |
private void addErrors(Schema schema) { Collection<AnnotationInstance> errorAnnotations = ScanningContext.getIndex().getAnnotations(Annotations.ERROR_CODE); if (errorAnnotations != null && !errorAnnotations.isEmpty()) { for (AnnotationInstance errorAnnotation : errorAnnotations) { AnnotationTarget annotationTarget = errorAnnotation.target(); if (annotationTarget.kind().equals(AnnotationTarget.Kind.CLASS)) { ClassInfo exceptionClass = annotationTarget.asClass(); AnnotationValue value = errorAnnotation.value(); if (value != null && value.asString() != null && !value.asString().isEmpty()) { schema.addError(new ErrorInfo(exceptionClass.name().toString(), value.asString())); } else { LOG.warn("Ignoring @ErrorCode on " + annotationTarget.toString() + " - Annotation value is not set"); } } else { LOG.warn("Ignoring @ErrorCode on " + annotationTarget.toString() + " - Wrong target, only apply to CLASS [" + annotationTarget.kind().toString() + "]"); } } } }
Example #4
Source File: JaxRsAnnotationScanner.java From smallrye-open-api with Apache License 2.0 | 6 votes |
static Optional<String[]> getMediaTypes(MethodInfo resourceMethod, DotName annotationName) { AnnotationInstance annotation = resourceMethod.annotation(annotationName); if (annotation == null) { annotation = JandexUtil.getClassAnnotation(resourceMethod.declaringClass(), annotationName); } if (annotation != null) { AnnotationValue annotationValue = annotation.value(); if (annotationValue != null) { return Optional.of(annotationValue.asStringArray()); } return Optional.of(OpenApiConstants.DEFAULT_MEDIA_TYPES.get()); } return Optional.empty(); }
Example #5
Source File: AnnotatedElement.java From gizmo with Apache License 2.0 | 6 votes |
default void addAnnotation(AnnotationInstance annotation) { AnnotationCreator ac = addAnnotation(annotation.name().toString()); for (AnnotationValue member : annotation.values()) { if (member.kind() == AnnotationValue.Kind.NESTED) { throw new RuntimeException("Not Yet Implemented: Cannot generate annotation " + annotation); } else if (member.kind() == AnnotationValue.Kind.BOOLEAN) { ac.addValue(member.name(), member.asBoolean()); } else if (member.kind() == AnnotationValue.Kind.BYTE) { ac.addValue(member.name(), member.asByte()); } else if (member.kind() == AnnotationValue.Kind.SHORT) { ac.addValue(member.name(), member.asShort()); } else if (member.kind() == AnnotationValue.Kind.INTEGER) { ac.addValue(member.name(), member.asInt()); } else if (member.kind() == AnnotationValue.Kind.LONG) { ac.addValue(member.name(), member.asLong()); } else if (member.kind() == AnnotationValue.Kind.FLOAT) { ac.addValue(member.name(), member.asFloat()); } else if (member.kind() == AnnotationValue.Kind.DOUBLE) { ac.addValue(member.name(), member.asDouble()); } else if (member.kind() == AnnotationValue.Kind.STRING) { ac.addValue(member.name(), member.asString()); } else if (member.kind() == AnnotationValue.Kind.ARRAY) { ac.addValue(member.name(), member.value()); } } }
Example #6
Source File: ParameterProcessor.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Read a single annotation that is either {@link @Parameter} or * {@link @Parameters}. The results are stored in the private {@link #params} * collection. * * @param annotation a parameter annotation to be read and processed */ void readParameterAnnotation(AnnotationInstance annotation) { DotName name = annotation.name(); if (ParameterConstant.DOTNAME_PARAMETER.equals(name)) { readAnnotatedType(annotation, null, false); } else if (ParameterConstant.DOTNAME_PARAMETERS.equals(name)) { AnnotationValue annotationValue = annotation.value(); if (annotationValue != null) { /* * Unwrap annotations wrapped by @Parameters and * identify the target as the target of the @Parameters annotation */ for (AnnotationInstance nested : annotationValue.asNestedArray()) { readAnnotatedType(AnnotationInstance.create(nested.name(), annotation.target(), nested.values()), null, false); } } } }
Example #7
Source File: SpringCacheProcessor.java From quarkus with Apache License 2.0 | 6 votes |
private void validateUsage(AnnotationInstance instance) { if (instance.target().kind() != AnnotationTarget.Kind.METHOD) { throw new IllegalArgumentException( "Currently Spring Cache annotations can only be added to methods. Offending instance is annotation '" + instance + "' on " + instance.target() + "'"); } List<AnnotationValue> values = instance.values(); List<String> unsupportedValues = new ArrayList<>(); for (AnnotationValue value : values) { if (CURRENTLY_UNSUPPORTED_ANNOTATION_VALUES.contains(value.name())) { unsupportedValues.add(value.name()); } } if (!unsupportedValues.isEmpty()) { throw new IllegalArgumentException("Annotation '" + instance + "' on '" + instance.target() + "' contains the following currently unsupported annotation values: " + String.join(", ", unsupportedValues)); } }
Example #8
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 #9
Source File: SpringAnnotationScanner.java From smallrye-open-api with Apache License 2.0 | 6 votes |
static Optional<String[]> getMediaTypes(MethodInfo resourceMethod, MediaTypeProperty property) { Set<DotName> annotationNames = SpringConstants.HTTP_METHODS; for (DotName annotationName : annotationNames) { AnnotationInstance annotation = resourceMethod.annotation(annotationName); if (annotation == null || annotation.value(property.name()) == null) { annotation = JandexUtil.getClassAnnotation(resourceMethod.declaringClass(), SpringConstants.REQUEST_MAPPING); } if (annotation != null) { AnnotationValue annotationValue = annotation.value(property.name()); if (annotationValue != null) { return Optional.of(annotationValue.asStringArray()); } return Optional.of(OpenApiConstants.DEFAULT_MEDIA_TYPES.get()); } } return Optional.empty(); }
Example #10
Source File: SpringDIProcessor.java From quarkus with Apache License 2.0 | 6 votes |
/** * Meant to be called with instances of @Bean */ private String getBeanNameFromBeanInstance(AnnotationInstance annotationInstance) { if (annotationInstance.target().kind() != AnnotationTarget.Kind.METHOD) { throw new IllegalStateException( "AnnotationInstance " + annotationInstance + " is an invalid target. Only Method targets are supported"); } String beanName = null; final AnnotationValue beanNameAnnotationValue = annotationInstance.value("name"); if (beanNameAnnotationValue != null) { beanName = determineName(beanNameAnnotationValue); } if (beanName == null || beanName.isEmpty()) { final AnnotationValue beanValueAnnotationValue = annotationInstance.value(); if (beanNameAnnotationValue != null) { beanName = determineName(beanValueAnnotationValue); } } if (beanName == null || beanName.isEmpty()) { beanName = annotationInstance.target().asMethod().name(); } return beanName; }
Example #11
Source File: ExampleReader.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Reads a map of Example annotations. * * @param annotationValue map of {@literal @}ExampleObject annotations * @return Map of Example model */ public static Map<String, Example> readExamples(final AnnotationValue annotationValue) { if (annotationValue == null) { return null; } IoLogging.log.annotationsMap("@ExampleObject"); Map<String, Example> examples = new LinkedHashMap<>(); AnnotationInstance[] nestedArray = annotationValue.asNestedArray(); for (AnnotationInstance nested : nestedArray) { String name = JandexUtil.stringValue(nested, ExampleConstant.PROP_NAME); if (name == null && JandexUtil.isRef(nested)) { name = JandexUtil.nameFromRef(nested); } if (name != null) { examples.put(name, readExample(nested)); } } return examples; }
Example #12
Source File: InfoReader.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Annotation to Info * * @param annotationValue the {@literal @}Info annotation * @return Info model */ public static Info readInfo(final AnnotationValue annotationValue) { if (annotationValue == null) { return null; } IoLogging.log.annotation("@Info"); AnnotationInstance nested = annotationValue.asNested(); Info info = new InfoImpl(); info.setTitle(JandexUtil.stringValue(nested, InfoConstant.PROP_TITLE)); info.setDescription(JandexUtil.stringValue(nested, InfoConstant.PROP_DESCRIPTION)); info.setTermsOfService(JandexUtil.stringValue(nested, InfoConstant.PROP_TERMS_OF_SERVICE)); info.setContact(ContactReader.readContact(nested.value(InfoConstant.PROP_CONTACT))); info.setLicense(LicenseReader.readLicense(nested.value(InfoConstant.PROP_LICENSE))); info.setVersion(JandexUtil.stringValue(nested, InfoConstant.PROP_VERSION)); return info; }
Example #13
Source File: RequestBodyReader.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Reads a map of RequestBody annotations. * * @param context the scanning context * @param annotationValue map of {@literal @}RequestBody annotations * @return Map of RequestBody model */ public static Map<String, RequestBody> readRequestBodies(final AnnotationScannerContext context, final AnnotationValue annotationValue) { if (annotationValue == null) { return null; } IoLogging.log.annotationsMap("@RequestBody"); Map<String, RequestBody> requestBodies = new LinkedHashMap<>(); AnnotationInstance[] nestedArray = annotationValue.asNestedArray(); for (AnnotationInstance nested : nestedArray) { String name = JandexUtil.stringValue(nested, RequestBodyConstant.PROP_NAME); if (name == null && JandexUtil.isRef(nested)) { name = JandexUtil.nameFromRef(nested); } if (name != null) { requestBodies.put(name, readRequestBody(context, nested)); } } return requestBodies; }
Example #14
Source File: LinkReader.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Reads Link annotations * * @param annotationValue map of {@literal @}Link annotations * @return Map of Link model */ public static Map<String, Link> readLinks(final AnnotationValue annotationValue) { if (annotationValue == null) { return null; } IoLogging.log.annotationsMap("@Link"); Map<String, Link> links = new LinkedHashMap<>(); AnnotationInstance[] nestedArray = annotationValue.asNestedArray(); for (AnnotationInstance nested : nestedArray) { String name = JandexUtil.stringValue(nested, LinkConstant.PROP_NAME); if (name == null && JandexUtil.isRef(nested)) { name = JandexUtil.nameFromRef(nested); } if (name != null) { links.put(name, readLink(nested)); } } return links; }
Example #15
Source File: ResponseReader.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Reads an array of APIResponse annotations into an {@link APIResponses} model. * * @param context the scanning context * @param annotationValue {@literal @}APIResponse annotation * @return APIResponses model */ public static APIResponses readResponses(final AnnotationScannerContext context, final AnnotationValue annotationValue) { if (annotationValue == null) { return null; } IoLogging.log.annotationsListInto("@APIResponse", "APIResponses model"); APIResponses responses = new APIResponsesImpl(); AnnotationInstance[] nestedArray = annotationValue.asNestedArray(); for (AnnotationInstance nested : nestedArray) { String responseCode = JandexUtil.stringValue(nested, ResponseConstant.PROP_RESPONSE_CODE); if (responseCode != null) { responses.addAPIResponse(responseCode, ResponseReader.readResponse(context, nested)); } } return responses; }
Example #16
Source File: OAuthReader.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Reads an array of OAuthScope annotations into a Scopes model. * * @param annotationValue {@literal @}OAuthScope annotation * @return Map of name and description of the scope */ // TODO: Update return type and remove warning suppression for MicroProfile OpenAPI 2.0 @SuppressWarnings("deprecation") private static Scopes readOAuthScopes(final AnnotationValue annotationValue) { if (annotationValue == null) { return null; } IoLogging.log.annotationsList("@OAuthScope"); AnnotationInstance[] nestedArray = annotationValue.asNestedArray(); Scopes scopes = new ScopesImpl(); for (AnnotationInstance nested : nestedArray) { String name = JandexUtil.stringValue(nested, SecuritySchemeConstant.PROP_NAME); if (name != null) { String description = JandexUtil.stringValue(nested, SecuritySchemeConstant.PROP_DESCRIPTION); scopes.put(name, description); } } return scopes; }
Example #17
Source File: CallbackReader.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Reads a map of Callback annotations. * * @param context the scanner context * @param annotationValue Map of {@literal @}Callback annotations * @return Map of Callback models */ public static Map<String, Callback> readCallbacks(final AnnotationScannerContext context, final AnnotationValue annotationValue) { if (annotationValue == null) { return null; } IoLogging.log.annotationsMap("@Callback"); Map<String, Callback> callbacks = new LinkedHashMap<>(); AnnotationInstance[] nestedArray = annotationValue.asNestedArray(); for (AnnotationInstance nested : nestedArray) { String name = getCallbackName(nested); if (name == null && JandexUtil.isRef(nested)) { name = JandexUtil.nameFromRef(nested); } if (name != null) { callbacks.put(name, readCallback(context, nested)); } } return callbacks; }
Example #18
Source File: EncodingReader.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Reads an array of Encoding annotations as a Map. * * @param context the scanning context * @param annotationValue Map of {@literal @}Encoding annotations * @return Map of Encoding models */ public static Map<String, Encoding> readEncodings(final AnnotationScannerContext context, final AnnotationValue annotationValue) { if (annotationValue == null) { return null; } IoLogging.log.annotationsMap("@Encoding"); Map<String, Encoding> encodings = new LinkedHashMap<>(); AnnotationInstance[] nestedArray = annotationValue.asNestedArray(); for (AnnotationInstance annotation : nestedArray) { String name = JandexUtil.stringValue(annotation, EncodingConstant.PROP_NAME); if (name != null) { encodings.put(name, readEncoding(context, annotation)); } } return encodings; }
Example #19
Source File: InterceptorResolver.java From quarkus with Apache License 2.0 | 6 votes |
private boolean isInterceptorBinding(AnnotationInstance interceptorBinding, AnnotationInstance candidate) { ClassInfo interceptorBindingClass = beanDeployment.getInterceptorBinding(interceptorBinding.name()); if (candidate.name().equals(interceptorBinding.name())) { // Must have the same annotation member value for each member which is not annotated @Nonbinding boolean matches = true; Set<String> nonBindingFields = beanDeployment.getNonBindingFields(interceptorBinding.name()); for (AnnotationValue value : candidate.valuesWithDefaults(beanDeployment.getIndex())) { String annotationField = value.name(); if (!interceptorBindingClass.method(annotationField).hasAnnotation(DotNames.NONBINDING) && !nonBindingFields.contains(annotationField) && !value.equals(interceptorBinding.valueWithDefault(beanDeployment.getIndex(), annotationField))) { matches = false; break; } } if (matches) { return true; } } return false; }
Example #20
Source File: InterfaceConfigPropertiesUtil.java From quarkus with Apache License 2.0 | 6 votes |
/** * Add a method like this: * * <pre> * @Produces * public SomeConfig produceSomeClass(Config config) { * return new SomeConfigQuarkusImpl(config) * } * </pre> */ static void addProducerMethodForInterfaceConfigProperties(ClassCreator classCreator, DotName interfaceName, String prefix, boolean needsQualifier, String generatedClassName) { String methodName = "produce" + interfaceName.withoutPackagePrefix(); if (needsQualifier) { // we need to differentiate the different producers of the same class methodName = methodName + "WithPrefix" + HashUtil.sha1(prefix); } try (MethodCreator method = classCreator.getMethodCreator(methodName, interfaceName.toString(), Config.class.getName())) { method.addAnnotation(Produces.class); if (needsQualifier) { method.addAnnotation(AnnotationInstance.create(DotNames.CONFIG_PREFIX, null, new AnnotationValue[] { AnnotationValue.createStringValue("value", prefix) })); } else { method.addAnnotation(Default.class); } method.returnValue(method.newInstance(MethodDescriptor.ofConstructor(generatedClassName, Config.class), method.getMethodParam(0))); } }
Example #21
Source File: PathsReader.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Reads the PathItem. * Also used in CallbackOperation * * @param context the scanning context * @param annotationValue the annotation value * @return PathItem model */ public static PathItem readPathItem(final AnnotationScannerContext context, final AnnotationValue annotationValue) { if (annotationValue == null) { return null; } AnnotationInstance[] nestedArray = annotationValue.asNestedArray(); PathItem pathItem = new PathItemImpl(); for (AnnotationInstance operationAnno : nestedArray) { String method = JandexUtil.stringValue(operationAnno, PathsConstant.PROP_METHOD); Operation operation = OperationReader.readOperation(context, operationAnno); if (method == null) { continue; } try { PropertyDescriptor descriptor = new PropertyDescriptor(method.toUpperCase(), pathItem.getClass()); Method mutator = descriptor.getWriteMethod(); mutator.invoke(pathItem, operation); } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { IoLogging.log.readingCallbackOperation(e); } } return pathItem; }
Example #22
Source File: ServerVariableReader.java From smallrye-open-api with Apache License 2.0 | 6 votes |
/** * Reads an array of ServerVariable annotations, returning a new {@link ServerVariable} model. The * annotation value is an array of ServerVariable annotations. * * @param annotationValue an arrays of {@literal @}ServerVariable annotations * @return a Map of Variable name and ServerVariable model */ public static Map<String, ServerVariable> readServerVariables(final AnnotationValue annotationValue) { if (annotationValue == null) { return null; } IoLogging.log.annotationsArray("@ServerVariable"); AnnotationInstance[] nestedArray = annotationValue.asNestedArray(); Map<String, ServerVariable> variables = new LinkedHashMap<>(); for (AnnotationInstance serverVariableAnno : nestedArray) { String name = JandexUtil.stringValue(serverVariableAnno, ServerVariableConstant.PROP_NAME); if (name != null) { variables.put(name, readServerVariable(serverVariableAnno)); } } return variables; }
Example #23
Source File: ResteasyCommonProcessor.java From quarkus with Apache License 2.0 | 6 votes |
private boolean restJsonSupportNeeded(CombinedIndexBuildItem indexBuildItem, DotName mediaTypeAnnotation) { for (AnnotationInstance annotationInstance : indexBuildItem.getIndex().getAnnotations(mediaTypeAnnotation)) { final AnnotationValue annotationValue = annotationInstance.value(); if (annotationValue == null) { continue; } List<String> mediaTypes = Collections.emptyList(); if (annotationValue.kind() == Kind.ARRAY) { mediaTypes = Arrays.asList(annotationValue.asStringArray()); } else if (annotationValue.kind() == Kind.STRING) { mediaTypes = Collections.singletonList(annotationValue.asString()); } return mediaTypes.contains(MediaType.APPLICATION_JSON) || mediaTypes.contains(MediaType.APPLICATION_JSON_PATCH_JSON); } return false; }
Example #24
Source File: SpringCacheUtil.java From quarkus with Apache License 2.0 | 5 votes |
private static String singleName(AnnotationValue annotationValue, AnnotationTarget target) { if (annotationValue.kind() != AnnotationValue.Kind.ARRAY) { // shouldn't happen return null; } String[] strings = annotationValue.asStringArray(); if (strings.length == 0) { return null; } else if (strings.length > 1) { throw new IllegalArgumentException( String.format("Quarkus currently only supports using a single cache name. Offending %s is %s", target.kind() == AnnotationTarget.Kind.METHOD ? "method" : "class", target.toString())); } return strings[0]; }
Example #25
Source File: AddObservesTest.java From quarkus with Apache License 2.0 | 5 votes |
@Override public void transform(TransformationContext transformationContext) { MethodInfo method = transformationContext.getTarget().asMethod(); if (method.name().equals("observe")) { transformationContext.transform() .add(AnnotationInstance.create(DotName.createSimple(Observes.class.getName()), MethodParameterInfo.create(method, (short) 0), new AnnotationValue[] {})) .done(); } }
Example #26
Source File: TypeNameHelper.java From smallrye-graphql with Apache License 2.0 | 5 votes |
private static String getNameForClassType(ClassInfo classInfo, Annotations annotations, DotName typeName, String postFix) { if (annotations.containsKeyAndValidValue(typeName)) { AnnotationValue annotationValue = annotations.getAnnotationValue(typeName); return annotationValue.asString().trim(); } else if (annotations.containsKeyAndValidValue(Annotations.NAME)) { return annotations.getAnnotationValue(Annotations.NAME).asString().trim(); } return classInfo.name().local() + postFix; }
Example #27
Source File: SpringDIProcessor.java From quarkus with Apache License 2.0 | 5 votes |
/** * Translate spring built-in scope identifiers to CDI scopes. * * @param target The annotated element declaring the @Scope * @return A CDI built in (or session) scope that mostly matches * the spring one. Websocket scope is currently mapped to @Dependent * and spring custom scopes are not currently handled. */ private DotName getScope(final AnnotationTarget target) { AnnotationValue value = null; if (target.kind() == AnnotationTarget.Kind.CLASS) { if (target.asClass().classAnnotation(SPRING_SCOPE_ANNOTATION) != null) { value = target.asClass().classAnnotation(SPRING_SCOPE_ANNOTATION).value(); } } else if (target.kind() == AnnotationTarget.Kind.METHOD) { if (target.asMethod().hasAnnotation(SPRING_SCOPE_ANNOTATION)) { value = target.asMethod().annotation(SPRING_SCOPE_ANNOTATION).value(); } } if (value != null) { switch (value.asString()) { case "singleton": return CDI_SINGLETON_ANNOTATION; case "request": return CDI_REQUEST_SCOPED_ANNOTATION; case "global session": case "application": return CDI_APP_SCOPED_ANNOTATION; case "session": return CDI_SESSION_SCOPED_ANNOTATION; case "websocket": case "prototype": return CDI_DEPENDENT_ANNOTATION; } } return null; }
Example #28
Source File: SpringScheduledProcessor.java From quarkus with Apache License 2.0 | 5 votes |
List<AnnotationValue> buildDelayParams(List<AnnotationValue> springAnnotationValues) { List<AnnotationValue> confValues = new ArrayList<>(); long delay = getLongValueFromParam(springAnnotationValues, "initialDelay"); confValues.add(AnnotationValue.createLongValue("delay", delay)); confValues.add(AnnotationValue.createEnumValue("delayUnit", DotName.createSimple("java.util.concurrent.TimeUnit"), TimeUnit.MILLISECONDS.name())); return confValues; }
Example #29
Source File: OAuthReader.java From smallrye-open-api with Apache License 2.0 | 5 votes |
/** * Reads a single OAuthFlow annotation into a model. * * @param annotationValue {@literal @}OAuthFlow annotation * @return OAuthFlow model */ private static OAuthFlow readOAuthFlow(final AnnotationValue annotationValue) { if (annotationValue == null) { return null; } IoLogging.log.singleAnnotation("@OAuthFlow"); AnnotationInstance annotation = annotationValue.asNested(); OAuthFlow flow = new OAuthFlowImpl(); flow.setAuthorizationUrl(JandexUtil.stringValue(annotation, SecuritySchemeConstant.PROP_AUTHORIZATION_URL)); flow.setTokenUrl(JandexUtil.stringValue(annotation, SecuritySchemeConstant.PROP_TOKEN_URL)); flow.setRefreshUrl(JandexUtil.stringValue(annotation, SecuritySchemeConstant.PROP_REFRESH_URL)); flow.setScopes(readOAuthScopes(annotation.value(SecuritySchemeConstant.PROP_SCOPES))); return flow; }
Example #30
Source File: SpringDIProcessorTest.java From quarkus with Apache License 2.0 | 5 votes |
/** * Do not add javax.inject.Singleton, as it is not spring-specific and Arc processor already handles it. * Otherwise it would cause "declares multiple scope type annotations" error. */ @Test public void getAnnotationsToAddBeanMethodExplicitSingleton() { final Map<DotName, Set<DotName>> scopes = processor.getStereotypeScopes(index); final MethodInfo target = index.getClassByName(DotName.createSimple(BeanConfig.class.getName())) .method("explicitSingletonBean"); final Set<AnnotationInstance> ret = processor.getAnnotationsToAdd(target, scopes, null); final Set<AnnotationInstance> expected = setOf( AnnotationInstance.create(DotNames.PRODUCES, target, Collections.emptyList()), AnnotationInstance.create(DotName.createSimple(Named.class.getName()), target, Collections.singletonList(AnnotationValue.createStringValue("value", "explicitSingletonBean")))); assertEquals(expected, ret); }