Java Code Examples for org.springframework.core.annotation.AnnotatedElementUtils#findAllMergedAnnotations()
The following examples show how to use
org.springframework.core.annotation.AnnotatedElementUtils#findAllMergedAnnotations() .
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: SpringCacheAnnotationParser.java From spring-analysis-note with MIT License | 6 votes |
@Nullable private Collection<CacheOperation> parseCacheAnnotations( DefaultCacheConfig cachingConfig, AnnotatedElement ae, boolean localOnly) { Collection<? extends Annotation> anns = (localOnly ? AnnotatedElementUtils.getAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS) : AnnotatedElementUtils.findAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS)); if (anns.isEmpty()) { return null; } final Collection<CacheOperation> ops = new ArrayList<>(1); anns.stream().filter(ann -> ann instanceof Cacheable).forEach( ann -> ops.add(parseCacheableAnnotation(ae, cachingConfig, (Cacheable) ann))); anns.stream().filter(ann -> ann instanceof CacheEvict).forEach( ann -> ops.add(parseEvictAnnotation(ae, cachingConfig, (CacheEvict) ann))); anns.stream().filter(ann -> ann instanceof CachePut).forEach( ann -> ops.add(parsePutAnnotation(ae, cachingConfig, (CachePut) ann))); anns.stream().filter(ann -> ann instanceof Caching).forEach( ann -> parseCachingAnnotation(ae, cachingConfig, (Caching) ann, ops)); return ops; }
Example 2
Source File: BootstrapUtils.java From spring-analysis-note with MIT License | 6 votes |
@Nullable private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) { Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); if (annotations.isEmpty()) { return null; } if (annotations.size() == 1) { return annotations.iterator().next().value(); } // Allow directly-present annotation to override annotations that are meta-present. BootstrapWith bootstrapWith = testClass.getDeclaredAnnotation(BootstrapWith.class); if (bootstrapWith != null) { return bootstrapWith.value(); } throw new IllegalStateException(String.format( "Configuration error: found multiple declarations of @BootstrapWith for test class [%s]: %s", testClass.getName(), annotations)); }
Example 3
Source File: SpringCacheAnnotationParser.java From java-technology-stack with MIT License | 6 votes |
@Nullable private Collection<CacheOperation> parseCacheAnnotations( DefaultCacheConfig cachingConfig, AnnotatedElement ae, boolean localOnly) { Collection<? extends Annotation> anns = (localOnly ? AnnotatedElementUtils.getAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS) : AnnotatedElementUtils.findAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS)); if (anns.isEmpty()) { return null; } final Collection<CacheOperation> ops = new ArrayList<>(1); anns.stream().filter(ann -> ann instanceof Cacheable).forEach( ann -> ops.add(parseCacheableAnnotation(ae, cachingConfig, (Cacheable) ann))); anns.stream().filter(ann -> ann instanceof CacheEvict).forEach( ann -> ops.add(parseEvictAnnotation(ae, cachingConfig, (CacheEvict) ann))); anns.stream().filter(ann -> ann instanceof CachePut).forEach( ann -> ops.add(parsePutAnnotation(ae, cachingConfig, (CachePut) ann))); anns.stream().filter(ann -> ann instanceof Caching).forEach( ann -> parseCachingAnnotation(ae, cachingConfig, (Caching) ann, ops)); return ops; }
Example 4
Source File: BootstrapUtils.java From java-technology-stack with MIT License | 6 votes |
@Nullable private static Class<?> resolveExplicitTestContextBootstrapper(Class<?> testClass) { Set<BootstrapWith> annotations = AnnotatedElementUtils.findAllMergedAnnotations(testClass, BootstrapWith.class); if (annotations.isEmpty()) { return null; } if (annotations.size() == 1) { return annotations.iterator().next().value(); } // Allow directly-present annotation to override annotations that are meta-present. BootstrapWith bootstrapWith = testClass.getDeclaredAnnotation(BootstrapWith.class); if (bootstrapWith != null) { return bootstrapWith.value(); } throw new IllegalStateException(String.format( "Configuration error: found multiple declarations of @BootstrapWith for test class [%s]: %s", testClass.getName(), annotations)); }
Example 5
Source File: AbstractRequestBuilder.java From springdoc-openapi with Apache License 2.0 | 5 votes |
/** * Gets api parameters. * * @param method the method * @return the api parameters */ private Map<String, io.swagger.v3.oas.annotations.Parameter> getApiParameters(Method method) { Class<?> declaringClass = method.getDeclaringClass(); Set<io.swagger.v3.oas.annotations.Parameters> apiParametersDoc = AnnotatedElementUtils .findAllMergedAnnotations(method, io.swagger.v3.oas.annotations.Parameters.class); LinkedHashMap<String, io.swagger.v3.oas.annotations.Parameter> apiParametersMap = apiParametersDoc.stream() .flatMap(x -> Stream.of(x.value())).collect(Collectors.toMap(io.swagger.v3.oas.annotations.Parameter::name, x -> x, (e1, e2) -> e2, LinkedHashMap::new)); Set<io.swagger.v3.oas.annotations.Parameters> apiParametersDocDeclaringClass = AnnotatedElementUtils .findAllMergedAnnotations(declaringClass, io.swagger.v3.oas.annotations.Parameters.class); LinkedHashMap<String, io.swagger.v3.oas.annotations.Parameter> apiParametersDocDeclaringClassMap = apiParametersDocDeclaringClass.stream() .flatMap(x -> Stream.of(x.value())).collect(Collectors.toMap(io.swagger.v3.oas.annotations.Parameter::name, x -> x, (e1, e2) -> e2, LinkedHashMap::new)); apiParametersMap.putAll(apiParametersDocDeclaringClassMap); Set<io.swagger.v3.oas.annotations.Parameter> apiParameterDoc = AnnotatedElementUtils .findAllMergedAnnotations(method, io.swagger.v3.oas.annotations.Parameter.class); LinkedHashMap<String, io.swagger.v3.oas.annotations.Parameter> apiParameterDocMap = apiParameterDoc.stream() .collect(Collectors.toMap(io.swagger.v3.oas.annotations.Parameter::name, x -> x, (e1, e2) -> e2, LinkedHashMap::new)); apiParametersMap.putAll(apiParameterDocMap); Set<io.swagger.v3.oas.annotations.Parameter> apiParameterDocDeclaringClass = AnnotatedElementUtils .findAllMergedAnnotations(declaringClass, io.swagger.v3.oas.annotations.Parameter.class); LinkedHashMap<String, io.swagger.v3.oas.annotations.Parameter> apiParameterDocDeclaringClassMap = apiParameterDocDeclaringClass.stream() .collect(Collectors.toMap(io.swagger.v3.oas.annotations.Parameter::name, x -> x, (e1, e2) -> e2, LinkedHashMap::new)); apiParametersMap.putAll(apiParameterDocDeclaringClassMap); return apiParametersMap; }
Example 6
Source File: OpenFeignSpringMvcContract.java From summerframework with Apache License 2.0 | 5 votes |
private String defaultValue(Method method, String pathVariable) { Set<ApiImplicitParam> apiImplicitParams = AnnotatedElementUtils.findAllMergedAnnotations(method, ApiImplicitParam.class); for (ApiImplicitParam apiImplicitParam : apiImplicitParams) { if (pathVariable.equals(apiImplicitParam.name())) { return apiImplicitParam.allowableValues().split(",")[0].trim(); } } throw new IllegalArgumentException("no default value for " + pathVariable); }
Example 7
Source File: VenusSpringMvcContract.java From venus-cloud-feign with Apache License 2.0 | 5 votes |
private String defaultValue(Method method, String pathVariable) { Set<ApiImplicitParam> apiImplicitParams = AnnotatedElementUtils.findAllMergedAnnotations(method, ApiImplicitParam.class); for (ApiImplicitParam apiImplicitParam : apiImplicitParams) { if (pathVariable.equals(apiImplicitParam.name())) { return apiImplicitParam.allowableValues().split(",")[0].trim(); } } throw new IllegalArgumentException("no default value for " + pathVariable); }
Example 8
Source File: TestModuleInitializer.java From spring-init with Apache License 2.0 | 5 votes |
@Override public void initialize(GenericApplicationContext context) { if (!ClassUtils.isPresent("org.springframework.boot.test.context.ImportsContextCustomizer", context.getClassLoader()) || !context.getEnvironment().getProperty("spring.functional.enabled", Boolean.class, true)) { // Only used in tests - could move to separate jar return; } ImportRegistrars registrars; // TODO: extract this logic and share with FunctionalInstallerListener? if (!context.getBeanFactory().containsSingleton(ConditionService.class.getName())) { if (!context.getBeanFactory().containsSingleton(MetadataReaderFactory.class.getName())) { context.getBeanFactory().registerSingleton(MetadataReaderFactory.class.getName(), new CachingMetadataReaderFactory(context.getClassLoader())); } context.getBeanFactory().registerSingleton(ConditionService.class.getName(), new SimpleConditionService(context, context.getBeanFactory(), context.getEnvironment(), context)); registrars = new FunctionalInstallerImportRegistrars(context); context.registerBean(ImportRegistrars.class, () -> registrars); } else { registrars = context.getBean(ImportRegistrars.class.getName(), ImportRegistrars.class); } for (String name : context.getBeanFactory().getBeanDefinitionNames()) { BeanDefinition definition = context.getBeanFactory().getBeanDefinition(name); if (definition.getBeanClassName().contains("ImportsContextCustomizer$ImportsConfiguration")) { SimpleConditionService.EXCLUDES_ENABLED = true; Class<?> testClass = (definition != null) ? (Class<?>) definition.getAttribute("testClass") : null; if (testClass != null) { Set<Import> merged = AnnotatedElementUtils.findAllMergedAnnotations(testClass, Import.class); for (Import ann : merged) { for (Class<?> imported : ann.value()) { registrars.add(testClass, imported); } } } } } }