Java Code Examples for org.springframework.core.annotation.AnnotationUtils#synthesizeAnnotation()
The following examples show how to use
org.springframework.core.annotation.AnnotationUtils#synthesizeAnnotation() .
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: StreamListenerAnnotationBeanPostProcessorOverrideTest.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
/** * Overrides the default {@link StreamListenerAnnotationBeanPostProcessor}. */ @Bean(name = STREAM_LISTENER_ANNOTATION_BEAN_POST_PROCESSOR_NAME) public static StreamListenerAnnotationBeanPostProcessor streamListenerAnnotationBeanPostProcessor() { return new StreamListenerAnnotationBeanPostProcessor() { @Override protected StreamListener postProcessAnnotation( StreamListener originalAnnotation, Method annotatedMethod) { Map<String, Object> attributes = new HashMap<>( AnnotationUtils.getAnnotationAttributes(originalAnnotation)); attributes.put("condition", "headers['type']=='" + originalAnnotation.condition() + "'"); return AnnotationUtils.synthesizeAnnotation(attributes, StreamListener.class, annotatedMethod); } }; }
Example 2
Source File: AnnotationExtractorTest.java From eclair with Apache License 2.0 | 6 votes |
@Test public void synthesizeLogOut() { // given Map<String, Object> attributes = new HashMap<>(); attributes.put("level", ERROR); attributes.put("ifEnabled", WARN); attributes.put("verbose", INFO); attributes.put("printer", "printer"); attributes.put("logger", "logger"); Log log = AnnotationUtils.synthesizeAnnotation(attributes, Log.class, null); // when Log.out logOut = annotationExtractor.synthesizeLogOut(log); // then assertThat(logOut.level(), is(ERROR)); assertThat(logOut.ifEnabled(), is(WARN)); assertThat(logOut.verbose(), is(INFO)); assertThat(logOut.printer(), is("printer")); assertThat(logOut.logger(), is("logger")); }
Example 3
Source File: AnnotationExtractorTest.java From eclair with Apache License 2.0 | 6 votes |
@Test public void synthesizeLogIn() { // given Map<String, Object> attributes = new HashMap<>(); attributes.put("level", ERROR); attributes.put("ifEnabled", WARN); attributes.put("verbose", INFO); attributes.put("printer", "printer"); attributes.put("logger", "logger"); Log log = AnnotationUtils.synthesizeAnnotation(attributes, Log.class, null); // when Log.in logIn = annotationExtractor.synthesizeLogIn(log); // then assertThat(logIn.level(), is(ERROR)); assertThat(logIn.ifEnabled(), is(WARN)); assertThat(logIn.verbose(), is(INFO)); assertThat(logIn.printer(), is("printer")); assertThat(logIn.logger(), is("logger")); }
Example 4
Source File: SpringMvcContract.java From spring-cloud-openfeign with Apache License 2.0 | 6 votes |
private Annotation synthesizeWithMethodParameterNameAsFallbackValue( Annotation parameterAnnotation, Method method, int parameterIndex) { Map<String, Object> annotationAttributes = AnnotationUtils .getAnnotationAttributes(parameterAnnotation); Object defaultValue = AnnotationUtils.getDefaultValue(parameterAnnotation); if (defaultValue instanceof String && defaultValue.equals(annotationAttributes.get(AnnotationUtils.VALUE))) { Type[] parameterTypes = method.getGenericParameterTypes(); String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(method); if (shouldAddParameterName(parameterIndex, parameterTypes, parameterNames)) { annotationAttributes.put(AnnotationUtils.VALUE, parameterNames[parameterIndex]); } } return AnnotationUtils.synthesizeAnnotation(annotationAttributes, parameterAnnotation.annotationType(), null); }
Example 5
Source File: SpringMvcContract.java From raptor with Apache License 2.0 | 6 votes |
private Annotation synthesizeWithMethodParameterNameAsFallbackValue( Annotation parameterAnnotation, Method method, int parameterIndex) { Map<String, Object> annotationAttributes = AnnotationUtils .getAnnotationAttributes(parameterAnnotation); Object defaultValue = AnnotationUtils.getDefaultValue(parameterAnnotation); if (defaultValue instanceof String && defaultValue.equals(annotationAttributes.get(AnnotationUtils.VALUE))) { Type[] parameterTypes = method.getGenericParameterTypes(); String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(method); if (shouldAddParameterName(parameterIndex, parameterTypes, parameterNames)) { annotationAttributes.put(AnnotationUtils.VALUE, parameterNames[parameterIndex]); } } return AnnotationUtils.synthesizeAnnotation(annotationAttributes, parameterAnnotation.annotationType(), null); }
Example 6
Source File: VenusSpringMvcContract.java From venus-cloud-feign with Apache License 2.0 | 6 votes |
private Annotation synthesizeWithMethodParameterNameAsFallbackValue( Annotation parameterAnnotation, Method method, int parameterIndex) { Map<String, Object> annotationAttributes = AnnotationUtils .getAnnotationAttributes(parameterAnnotation); Object defaultValue = AnnotationUtils.getDefaultValue(parameterAnnotation); if (defaultValue instanceof String && defaultValue.equals(annotationAttributes.get(AnnotationUtils.VALUE))) { Type[] parameterTypes = method.getGenericParameterTypes(); String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(method); if (shouldAddParameterName(parameterIndex, parameterTypes, parameterNames)) { annotationAttributes.put(AnnotationUtils.VALUE, parameterNames[parameterIndex]); } } return AnnotationUtils.synthesizeAnnotation(annotationAttributes, parameterAnnotation.annotationType(), null); }
Example 7
Source File: MethodMdcsValidatorTest.java From eclair with Apache License 2.0 | 5 votes |
@Test(expected = AnnotationUsageException.class) public void validateEmptyWithoutParameters() { // given Mdc mdc = AnnotationUtils.synthesizeAnnotation(Mdc.class); Collection<Mdc> target = singletonList(mdc); // when methodMdcsValidator.validate(method, target); // then expected exception }
Example 8
Source File: OptimizedFlywayTestExecutionListener.java From embedded-database-spring-test with Apache License 2.0 | 5 votes |
private static FlywayTest copyAnnotation(FlywayTest annotation, boolean invokeCleanDB, boolean invokeBaselineDB, boolean invokeMigrateDB) { Map<String, Object> attributes = AnnotationUtils.getAnnotationAttributes(annotation); attributes.put("invokeCleanDB", invokeCleanDB); attributes.put("invokeBaselineDB", invokeBaselineDB); attributes.put("invokeMigrateDB", invokeMigrateDB); return AnnotationUtils.synthesizeAnnotation(attributes, FlywayTest.class, null); }
Example 9
Source File: MdcsValidatorTest.java From eclair with Apache License 2.0 | 5 votes |
@Test(expected = AnnotationUsageException.class) public void validateEmptyDuplicate() { // given Mdc mdc = AnnotationUtils.synthesizeAnnotation(singletonMap("key", ""), Mdc.class, null); Mdc mdc1 = AnnotationUtils.synthesizeAnnotation(singletonMap("key", ""), Mdc.class, null); Collection<Mdc> target = asList(mdc, mdc1); // when mdcsValidator.validate(method, target); // then expected exception }
Example 10
Source File: MdcsValidatorTest.java From eclair with Apache License 2.0 | 5 votes |
@Test(expected = AnnotationUsageException.class) public void validateDuplicate() { // given Mdc mdc = AnnotationUtils.synthesizeAnnotation(singletonMap("key", "key"), Mdc.class, null); Mdc mdc1 = AnnotationUtils.synthesizeAnnotation(singletonMap("key", "key"), Mdc.class, null); Collection<Mdc> target = asList(mdc, mdc1); // when mdcsValidator.validate(method, target); // then expected exception }
Example 11
Source File: MergedMdcsValidatorTest.java From eclair with Apache License 2.0 | 5 votes |
@Test(expected = AnnotationUsageException.class) public void validateDuplicate() { // given Mdc mdc = AnnotationUtils.synthesizeAnnotation(singletonMap("key", "key"), Mdc.class, null); Mdc mdc1 = AnnotationUtils.synthesizeAnnotation(singletonMap("key", "key"), Mdc.class, null); Collection<Mdc> target = asList(mdc, mdc1); // when mergedMdcsValidator.validate(method, target); // then expected exception }
Example 12
Source File: LogValidatorTest.java From eclair with Apache License 2.0 | 5 votes |
@Test(expected = AnnotationUsageException.class) public void validatePrinter() { // given PrinterResolver printerResolver = new AliasedPrinterResolver(emptyMap(), emptyMap()); LogValidator<Log> logValidator = new LogValidator<>(printerResolver); Log log = AnnotationUtils.synthesizeAnnotation(singletonMap("printer", "unknown"), Log.class, null); // when logValidator.validate(method, log); // then expected exception }
Example 13
Source File: LogValidatorTest.java From eclair with Apache License 2.0 | 5 votes |
@Test(expected = AnnotationUsageException.class) public void validateLevels() { // given PrinterResolver printerResolver = new AliasedPrinterResolver(emptyMap(), emptyMap()); LogValidator<Log> logValidator = new LogValidator<>(printerResolver); Log log = AnnotationUtils.synthesizeAnnotation(singletonMap("ifEnabled", DEBUG), Log.class, null); // when logValidator.validate(method, log); // then expected exception }
Example 14
Source File: HandlerMethodResolverWrapper.java From summerframework with Apache License 2.0 | 5 votes |
@Override public Annotation[] getParameterAnnotations() { Annotation[][] annotationArray = this.interfaceMethod.getParameterAnnotations(); if (this.getParameterIndex() >= 0 && this.getParameterIndex() < annotationArray.length) { this.parameterAnnotations = annotationArray[this.getParameterIndex()]; for (int i = 0; i < this.parameterAnnotations.length; i++) { this.parameterAnnotations[i] = AnnotationUtils.synthesizeAnnotation(this.parameterAnnotations[i], null); } } else { this.parameterAnnotations = new Annotation[0]; } return this.parameterAnnotations; }
Example 15
Source File: OpenFeignAutoConfiguration.java From summerframework with Apache License 2.0 | 5 votes |
@Override public Annotation[] getParameterAnnotations() { Annotation[][] annotationArray = this.interfaceMethod.getParameterAnnotations(); if (this.getParameterIndex() >= 0 && this.getParameterIndex() < annotationArray.length) { this.parameterAnnotations = annotationArray[this.getParameterIndex()]; for (int i = 0; i < this.parameterAnnotations.length; i++) { this.parameterAnnotations[i] = AnnotationUtils.synthesizeAnnotation(this.parameterAnnotations[i], null); } } else { this.parameterAnnotations = new Annotation[0]; } return this.parameterAnnotations; }
Example 16
Source File: OpenFeignSpringMvcContract.java From summerframework with Apache License 2.0 | 5 votes |
protected Annotation synthesizeWithMethodParameterNameAsFallbackValue(Annotation parameterAnnotation, Method method, int parameterIndex) { Map<String, Object> annotationAttributes = AnnotationUtils.getAnnotationAttributes(parameterAnnotation); Object defaultValue = AnnotationUtils.getDefaultValue(parameterAnnotation); if (defaultValue instanceof String && defaultValue.equals(annotationAttributes.get(AnnotationUtils.VALUE))) { Type[] parameterTypes = method.getGenericParameterTypes(); String[] parameterNames = PARAMETER_NAME_DISCOVERER.getParameterNames(method); if (shouldAddParameterName(parameterIndex, parameterTypes, parameterNames)) { annotationAttributes.put(AnnotationUtils.VALUE, parameterNames[parameterIndex]); } } return AnnotationUtils.synthesizeAnnotation(annotationAttributes, parameterAnnotation.annotationType(), null); }
Example 17
Source File: BindingBeansRegistrar.java From spring-cloud-stream with Apache License 2.0 | 4 votes |
private Class<?>[] collectClasses(AnnotationAttributes attrs, String className) { EnableBinding enableBinding = AnnotationUtils.synthesizeAnnotation(attrs, EnableBinding.class, ClassUtils.resolveClassName(className, null)); return enableBinding.value(); }
Example 18
Source File: MetaAnnotationUtils.java From spring-analysis-note with MIT License | 2 votes |
/** * Synthesize the merged {@link #getAnnotationAttributes AnnotationAttributes} * in this descriptor back into an annotation of the target * {@linkplain #getAnnotationType annotation type}. * @since 4.2 * @see #getAnnotationAttributes() * @see #getAnnotationType() * @see AnnotationUtils#synthesizeAnnotation(java.util.Map, Class, java.lang.reflect.AnnotatedElement) */ @SuppressWarnings("unchecked") public T synthesizeAnnotation() { return AnnotationUtils.synthesizeAnnotation( getAnnotationAttributes(), (Class<T>) getAnnotationType(), getRootDeclaringClass()); }
Example 19
Source File: MetaAnnotationUtils.java From spring4-understanding with Apache License 2.0 | 2 votes |
/** * Synthesize the merged {@link #getAnnotationAttributes AnnotationAttributes} * in this descriptor back into an annotation of the target * {@linkplain #getAnnotationType annotation type}. * @since 4.2 * @see #getAnnotationAttributes() * @see #getAnnotationType() * @see AnnotationUtils#synthesizeAnnotation(java.util.Map, Class, java.lang.reflect.AnnotatedElement) */ @SuppressWarnings("unchecked") public T synthesizeAnnotation() { return AnnotationUtils.synthesizeAnnotation(getAnnotationAttributes(), (Class<T>) getAnnotationType(), getRootDeclaringClass()); }
Example 20
Source File: MetaAnnotationUtils.java From java-technology-stack with MIT License | 2 votes |
/** * Synthesize the merged {@link #getAnnotationAttributes AnnotationAttributes} * in this descriptor back into an annotation of the target * {@linkplain #getAnnotationType annotation type}. * @since 4.2 * @see #getAnnotationAttributes() * @see #getAnnotationType() * @see AnnotationUtils#synthesizeAnnotation(java.util.Map, Class, java.lang.reflect.AnnotatedElement) */ @SuppressWarnings("unchecked") public T synthesizeAnnotation() { return AnnotationUtils.synthesizeAnnotation( getAnnotationAttributes(), (Class<T>) getAnnotationType(), getRootDeclaringClass()); }