org.springframework.core.type.MethodMetadata Java Examples
The following examples show how to use
org.springframework.core.type.MethodMetadata.
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: CompositeUtils.java From spring-cloud-config with Apache License 2.0 | 6 votes |
/** * Given a Factory Name return the generic type parameters of the factory (The actual * repository class, and its properties class). * @param beanFactory Spring Bean Factory * @param factoryName name of the factory * @return generic type params of the factory */ public static Type[] getEnvironmentRepositoryFactoryTypeParams( ConfigurableListableBeanFactory beanFactory, String factoryName) { MethodMetadata methodMetadata = (MethodMetadata) beanFactory .getBeanDefinition(factoryName).getSource(); Class<?> factoryClass = null; try { factoryClass = Class.forName(methodMetadata.getReturnTypeName()); } catch (ClassNotFoundException e) { throw new IllegalStateException(e); } Optional<AnnotatedType> annotatedFactoryType = Arrays .stream(factoryClass.getAnnotatedInterfaces()).filter(i -> { ParameterizedType parameterizedType = (ParameterizedType) i.getType(); return parameterizedType.getRawType() .equals(EnvironmentRepositoryFactory.class); }).findFirst(); ParameterizedType factoryParameterizedType = (ParameterizedType) annotatedFactoryType .orElse(factoryClass.getAnnotatedSuperclass()).getType(); return factoryParameterizedType.getActualTypeArguments(); }
Example #2
Source File: FunctionConfiguration.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
private PollableBean extractPollableAnnotation(StreamFunctionProperties functionProperties, GenericApplicationContext context, BindableFunctionProxyFactory proxyFactory) { // here we need to ensure that for cases where composition is defined we only look for supplier method to find Pollable annotation. String supplierFunctionName = StringUtils .delimitedListToStringArray(proxyFactory.getFunctionDefinition().replaceAll(",", "|").trim(), "|")[0]; BeanDefinition bd = context.getBeanDefinition(supplierFunctionName); if (!(bd instanceof RootBeanDefinition)) { return null; } Method factoryMethod = ((RootBeanDefinition) bd).getResolvedFactoryMethod(); if (factoryMethod == null) { Object source = bd.getSource(); if (source instanceof MethodMetadata) { Class<?> factory = ClassUtils.resolveClassName(((MethodMetadata) source).getDeclaringClassName(), null); Class<?>[] params = FunctionContextUtils.getParamTypesFromBeanDefinitionFactory(factory, (RootBeanDefinition) bd); factoryMethod = ReflectionUtils.findMethod(factory, ((MethodMetadata) source).getMethodName(), params); } } Assert.notNull(factoryMethod, "Failed to introspect factory method since it was not discovered for function '" + functionProperties.getDefinition() + "'"); return factoryMethod.getReturnType().isAssignableFrom(Supplier.class) ? AnnotationUtils.findAnnotation(factoryMethod, PollableBean.class) : null; }
Example #3
Source File: DeployerContextUtils.java From spring-cloud-function with Apache License 2.0 | 6 votes |
public static Type findType(BeanFactory beanFactory, String name) { ConfigurableListableBeanFactory registry = (ConfigurableListableBeanFactory) beanFactory; AbstractBeanDefinition definition = (AbstractBeanDefinition) registry.getBeanDefinition(name); Object source = definition.getSource(); Type param = null; if (source instanceof MethodMetadata) { param = findBeanType(definition, ((MethodMetadata) source).getDeclaringClassName(), ((MethodMetadata) source).getMethodName()); } else if (source instanceof Resource) { param = registry.getType(name); } else { ResolvableType type = (ResolvableType) getField(definition, "targetType"); if (type != null) { param = type.getType(); } } return param; }
Example #4
Source File: AbstractRecordController.java From COLA with GNU Lesser General Public License v2.1 | 6 votes |
protected String getClassName(Object bean, BeanDefinition beanDefinition){ String className = null; if(bean instanceof FactoryBean){ className = ((FactoryBean)bean).getObjectType().getName(); }else if(beanDefinition instanceof AnnotatedBeanDefinition){ MethodMetadata methodMetadata = ((AnnotatedBeanDefinition)beanDefinition).getFactoryMethodMetadata(); if(methodMetadata != null){ className = methodMetadata.getReturnTypeName(); }else{ className = ((AnnotatedBeanDefinition)beanDefinition).getMetadata().getClassName(); } }else if(beanDefinition instanceof RootBeanDefinition){ className = bean.getClass().getName(); }else if(bean instanceof Proxy){ className = getClassNameFromProxy(bean); }else{ className = beanDefinition.getBeanClassName(); } return className; }
Example #5
Source File: SimpleConditionService.java From spring-init with Apache License 2.0 | 6 votes |
@Override public boolean matches(Class<?> factory, Class<?> type) { AnnotationMetadata metadata = getMetadata(factory); Set<MethodMetadata> assignable = new HashSet<>(); for (MethodMetadata method : metadata.getAnnotatedMethods(Bean.class.getName())) { Class<?> candidate = ClassUtils.resolveClassName(method.getReturnTypeName(), this.classLoader); // Look for exact match first if (type.equals(candidate)) { return !this.evaluator.shouldSkip(method); } if (type.isAssignableFrom(candidate)) { assignable.add(method); } } if (assignable.size() == 1) { return !this.evaluator.shouldSkip(assignable.iterator().next()); } // TODO: fail if size() > 1 Class<?> base = factory.getSuperclass(); if (AnnotationUtils.isAnnotationDeclaredLocally(Configuration.class, base)) { return matches(base, type); } return false; }
Example #6
Source File: DubboLoadBalancedRestTemplateAutoConfiguration.java From spring-cloud-alibaba with Apache License 2.0 | 6 votes |
/** * Gets the annotation attributes {@link RestTemplate} bean being annotated * {@link DubboTransported @DubboTransported}. * @param beanName the bean name of {@link LoadBalanced @LoadBalanced} * {@link RestTemplate} * @param attributesResolver {@link DubboTransportedAttributesResolver} * @return non-null {@link Map} */ private Map<String, Object> getDubboTranslatedAttributes(String beanName, DubboTransportedAttributesResolver attributesResolver) { Map<String, Object> attributes = Collections.emptyMap(); BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); if (beanDefinition instanceof AnnotatedBeanDefinition) { AnnotatedBeanDefinition annotatedBeanDefinition = (AnnotatedBeanDefinition) beanDefinition; MethodMetadata factoryMethodMetadata = annotatedBeanDefinition .getFactoryMethodMetadata(); attributes = factoryMethodMetadata != null ? Optional .ofNullable(factoryMethodMetadata .getAnnotationAttributes(DUBBO_TRANSPORTED_CLASS_NAME)) .orElse(attributes) : Collections.emptyMap(); } return attributesResolver.resolve(attributes); }
Example #7
Source File: AnnotationMetadataReadingVisitor.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public boolean hasAnnotatedMethods(String annotationName) { for (MethodMetadata methodMetadata : this.methodMetadataSet) { if (methodMetadata.isAnnotated(annotationName)) { return true; } } return false; }
Example #8
Source File: CustomScopeAnnotationConfigurerTest.java From joinfaces with Apache License 2.0 | 5 votes |
@Test public void testDeduceScopeName_nulls() { CustomScopeAnnotationConfigurer customScopeAnnotationConfigurer = new CustomScopeAnnotationConfigurer(); customScopeAnnotationConfigurer.setAnnotationToScopeMappings(null); assertThat(customScopeAnnotationConfigurer.deduceScopeName((AnnotationMetadata) null)).isNull(); assertThat(customScopeAnnotationConfigurer.deduceScopeName((MethodMetadata) null)).isNull(); }
Example #9
Source File: AnnotationMetadataReadingVisitor.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Override public Set<MethodMetadata> getAnnotatedMethods(String annotationName) { Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>(4); for (MethodMetadata methodMetadata : this.methodMetadataSet) { if (methodMetadata.isAnnotated(annotationName)) { annotatedMethods.add(methodMetadata); } } return annotatedMethods; }
Example #10
Source File: ConfigurationClassParser.java From java-technology-stack with MIT License | 5 votes |
/** * Retrieve the metadata for all <code>@Bean</code> methods. */ private Set<MethodMetadata> retrieveBeanMethodMetadata(SourceClass sourceClass) { AnnotationMetadata original = sourceClass.getMetadata(); Set<MethodMetadata> beanMethods = original.getAnnotatedMethods(Bean.class.getName()); if (beanMethods.size() > 1 && original instanceof StandardAnnotationMetadata) { // Try reading the class file via ASM for deterministic declaration order... // Unfortunately, the JVM's standard reflection returns methods in arbitrary // order, even between different runs of the same application on the same JVM. try { AnnotationMetadata asm = this.metadataReaderFactory.getMetadataReader(original.getClassName()).getAnnotationMetadata(); Set<MethodMetadata> asmMethods = asm.getAnnotatedMethods(Bean.class.getName()); if (asmMethods.size() >= beanMethods.size()) { Set<MethodMetadata> selectedMethods = new LinkedHashSet<>(asmMethods.size()); for (MethodMetadata asmMethod : asmMethods) { for (MethodMetadata beanMethod : beanMethods) { if (beanMethod.getMethodName().equals(asmMethod.getMethodName())) { selectedMethods.add(beanMethod); break; } } } if (selectedMethods.size() == beanMethods.size()) { // All reflection-detected methods found in ASM method set -> proceed beanMethods = selectedMethods; } } } catch (IOException ex) { logger.debug("Failed to read class file via ASM for determining @Bean method order", ex); // No worries, let's continue with the reflection metadata we started with... } } return beanMethods; }
Example #11
Source File: MethodMetadataReadingVisitor.java From spring-analysis-note with MIT License | 5 votes |
public MethodMetadataReadingVisitor(String methodName, int access, String declaringClassName, String returnTypeName, @Nullable ClassLoader classLoader, Set<MethodMetadata> methodMetadataSet) { super(SpringAsmInfo.ASM_VERSION); this.methodName = methodName; this.access = access; this.declaringClassName = declaringClassName; this.returnTypeName = returnTypeName; this.classLoader = classLoader; this.methodMetadataSet = methodMetadataSet; }
Example #12
Source File: ConfigurationClassParser.java From spring-analysis-note with MIT License | 5 votes |
/** * Register default methods on interfaces implemented by the configuration class. */ private void processInterfaces(ConfigurationClass configClass, SourceClass sourceClass) throws IOException { for (SourceClass ifc : sourceClass.getInterfaces()) { Set<MethodMetadata> beanMethods = retrieveBeanMethodMetadata(ifc); for (MethodMetadata methodMetadata : beanMethods) { if (!methodMetadata.isAbstract()) { // A default method or other concrete method on a Java 8+ interface... configClass.addBeanMethod(new BeanMethod(methodMetadata, configClass)); } } processInterfaces(configClass, ifc); } }
Example #13
Source File: ConfigurationClassParser.java From spring-analysis-note with MIT License | 5 votes |
/** * Retrieve the metadata for all <code>@Bean</code> methods. */ private Set<MethodMetadata> retrieveBeanMethodMetadata(SourceClass sourceClass) { AnnotationMetadata original = sourceClass.getMetadata(); Set<MethodMetadata> beanMethods = original.getAnnotatedMethods(Bean.class.getName()); if (beanMethods.size() > 1 && original instanceof StandardAnnotationMetadata) { // Try reading the class file via ASM for deterministic declaration order... // Unfortunately, the JVM's standard reflection returns methods in arbitrary // order, even between different runs of the same application on the same JVM. try { AnnotationMetadata asm = this.metadataReaderFactory.getMetadataReader(original.getClassName()).getAnnotationMetadata(); Set<MethodMetadata> asmMethods = asm.getAnnotatedMethods(Bean.class.getName()); if (asmMethods.size() >= beanMethods.size()) { Set<MethodMetadata> selectedMethods = new LinkedHashSet<>(asmMethods.size()); for (MethodMetadata asmMethod : asmMethods) { for (MethodMetadata beanMethod : beanMethods) { if (beanMethod.getMethodName().equals(asmMethod.getMethodName())) { selectedMethods.add(beanMethod); break; } } } if (selectedMethods.size() == beanMethods.size()) { // All reflection-detected methods found in ASM method set -> proceed beanMethods = selectedMethods; } } } catch (IOException ex) { logger.debug("Failed to read class file via ASM for determining @Bean method order", ex); // No worries, let's continue with the reflection metadata we started with... } } return beanMethods; }
Example #14
Source File: SimpleAnnotationMetadata.java From spring-analysis-note with MIT License | 5 votes |
SimpleAnnotationMetadata(String className, int access, @Nullable String enclosingClassName, @Nullable String superClassName, boolean independentInnerClass, String[] interfaceNames, String[] memberClassNames, MethodMetadata[] annotatedMethods, MergedAnnotations annotations) { this.className = className; this.access = access; this.enclosingClassName = enclosingClassName; this.superClassName = superClassName; this.independentInnerClass = independentInnerClass; this.interfaceNames = interfaceNames; this.memberClassNames = memberClassNames; this.annotatedMethods = annotatedMethods; this.annotations = annotations; }
Example #15
Source File: SimpleAnnotationMetadata.java From spring-analysis-note with MIT License | 5 votes |
@Override public Set<MethodMetadata> getAnnotatedMethods(String annotationName) { Set<MethodMetadata> annotatedMethods = null; for (int i = 0; i < this.annotatedMethods.length; i++) { if (this.annotatedMethods[i].isAnnotated(annotationName)) { if (annotatedMethods == null) { annotatedMethods = new LinkedHashSet<>(4); } annotatedMethods.add(this.annotatedMethods[i]); } } return annotatedMethods != null ? annotatedMethods : Collections.emptySet(); }
Example #16
Source File: SimpleAnnotationMetadataReadingVisitor.java From spring-analysis-note with MIT License | 5 votes |
@Override public void visitEnd() { String[] memberClassNames = StringUtils.toStringArray(this.memberClassNames); MethodMetadata[] annotatedMethods = this.annotatedMethods.toArray(new MethodMetadata[0]); MergedAnnotations annotations = MergedAnnotations.of(this.annotations); this.metadata = new SimpleAnnotationMetadata(this.className, this.access, this.enclosingClassName, this.superClassName, this.independentInnerClass, this.interfaceNames, memberClassNames, annotatedMethods, annotations); }
Example #17
Source File: AnnotationMetadataReadingVisitor.java From spring-analysis-note with MIT License | 5 votes |
@Override public boolean hasAnnotatedMethods(String annotationName) { for (MethodMetadata methodMetadata : this.methodMetadataSet) { if (methodMetadata.isAnnotated(annotationName)) { return true; } } return false; }
Example #18
Source File: AnnotationMetadataReadingVisitor.java From spring-analysis-note with MIT License | 5 votes |
@Override public Set<MethodMetadata> getAnnotatedMethods(String annotationName) { Set<MethodMetadata> annotatedMethods = new LinkedHashSet<>(4); for (MethodMetadata methodMetadata : this.methodMetadataSet) { if (methodMetadata.isAnnotated(annotationName)) { annotatedMethods.add(methodMetadata); } } return annotatedMethods; }
Example #19
Source File: ConfigurationClassParser.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Retrieve the metadata for all <code>@Bean</code> methods. */ private Set<MethodMetadata> retrieveBeanMethodMetadata(SourceClass sourceClass) { AnnotationMetadata original = sourceClass.getMetadata(); Set<MethodMetadata> beanMethods = original.getAnnotatedMethods(Bean.class.getName()); if (beanMethods.size() > 1 && original instanceof StandardAnnotationMetadata) { // Try reading the class file via ASM for deterministic declaration order... // Unfortunately, the JVM's standard reflection returns methods in arbitrary // order, even between different runs of the same application on the same JVM. try { AnnotationMetadata asm = this.metadataReaderFactory.getMetadataReader(original.getClassName()).getAnnotationMetadata(); Set<MethodMetadata> asmMethods = asm.getAnnotatedMethods(Bean.class.getName()); if (asmMethods.size() >= beanMethods.size()) { Set<MethodMetadata> selectedMethods = new LinkedHashSet<MethodMetadata>(asmMethods.size()); for (MethodMetadata asmMethod : asmMethods) { for (MethodMetadata beanMethod : beanMethods) { if (beanMethod.getMethodName().equals(asmMethod.getMethodName())) { selectedMethods.add(beanMethod); break; } } } if (selectedMethods.size() == beanMethods.size()) { // All reflection-detected methods found in ASM method set -> proceed beanMethods = selectedMethods; } } } catch (IOException ex) { logger.debug("Failed to read class file via ASM for determining @Bean method order", ex); // No worries, let's continue with the reflection metadata we started with... } } return beanMethods; }
Example #20
Source File: ConfigurationClassParser.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Register default methods on interfaces implemented by the configuration class. */ private void processInterfaces(ConfigurationClass configClass, SourceClass sourceClass) throws IOException { for (SourceClass ifc : sourceClass.getInterfaces()) { Set<MethodMetadata> beanMethods = retrieveBeanMethodMetadata(ifc); for (MethodMetadata methodMetadata : beanMethods) { if (!methodMetadata.isAbstract()) { // A default method or other concrete method on a Java 8+ interface... configClass.addBeanMethod(new BeanMethod(methodMetadata, configClass)); } } processInterfaces(configClass, ifc); } }
Example #21
Source File: AnnotationMetadataReadingVisitor.java From java-technology-stack with MIT License | 5 votes |
@Override public boolean hasAnnotatedMethods(String annotationName) { for (MethodMetadata methodMetadata : this.methodMetadataSet) { if (methodMetadata.isAnnotated(annotationName)) { return true; } } return false; }
Example #22
Source File: AnnotationMetadataReadingVisitor.java From java-technology-stack with MIT License | 5 votes |
@Override public Set<MethodMetadata> getAnnotatedMethods(String annotationName) { Set<MethodMetadata> annotatedMethods = new LinkedHashSet<>(4); for (MethodMetadata methodMetadata : this.methodMetadataSet) { if (methodMetadata.isAnnotated(annotationName)) { annotatedMethods.add(methodMetadata); } } return annotatedMethods; }
Example #23
Source File: MethodMetadataReadingVisitor.java From java-technology-stack with MIT License | 5 votes |
public MethodMetadataReadingVisitor(String methodName, int access, String declaringClassName, String returnTypeName, @Nullable ClassLoader classLoader, Set<MethodMetadata> methodMetadataSet) { super(SpringAsmInfo.ASM_VERSION); this.methodName = methodName; this.access = access; this.declaringClassName = declaringClassName; this.returnTypeName = returnTypeName; this.classLoader = classLoader; this.methodMetadataSet = methodMetadataSet; }
Example #24
Source File: TeiidBeanDefinitionPostProcessor.java From teiid-spring-boot with Apache License 2.0 | 5 votes |
private boolean isMatch(BeanDefinition beanDefinition, String beanName) { String className = beanDefinition.getBeanClassName(); if (className == null) { if (beanDefinition.getFactoryMethodName() != null && beanDefinition.getFactoryMethodName().contentEquals(beanName)) { Object source = beanDefinition.getSource(); if (source instanceof MethodMetadata) { String returnType = ((MethodMetadata) source).getReturnTypeName(); if (returnType.contentEquals("javax.sql.DataSource")) { return true; } if (returnType.startsWith("org.springframework") || returnType.startsWith("io.micrometer") || returnType.startsWith("com.fasterxml.") || returnType.startsWith("org.hibernate.")) { return false; } className = returnType; } } } if (className != null) { try { final Class<?> beanClass = Class.forName(className); if (DataSource.class.isAssignableFrom(beanClass) || BaseConnectionFactory.class.isAssignableFrom(beanClass)) { return true; } } catch (ClassNotFoundException e) { } } return false; }
Example #25
Source File: AnnotationMetadataReadingVisitor.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public boolean hasAnnotatedMethods(String annotationName) { for (MethodMetadata methodMetadata : this.methodMetadataSet) { if (methodMetadata.isAnnotated(annotationName)) { return true; } } return false; }
Example #26
Source File: AnnotationMetadataReadingVisitor.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public Set<MethodMetadata> getAnnotatedMethods(String annotationName) { Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>(4); for (MethodMetadata methodMetadata : this.methodMetadataSet) { if (methodMetadata.isAnnotated(annotationName)) { annotatedMethods.add(methodMetadata); } } return annotatedMethods; }
Example #27
Source File: AnnotationMetadataReadingVisitor.java From thinking-in-spring-boot-samples with Apache License 2.0 | 5 votes |
public boolean hasAnnotatedMethods(String annotationType) { for (MethodMetadata method : this.methodMetadataSet) { if (method.isAnnotated(annotationType)) { return true; } } return false; }
Example #28
Source File: AnnotationMetadataReadingVisitor.java From thinking-in-spring-boot-samples with Apache License 2.0 | 5 votes |
public Set<MethodMetadata> getAnnotatedMethods(String annotationType) { Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>(); for (MethodMetadata method : this.methodMetadataSet) { if (method.isAnnotated(annotationType)) { annotatedMethods.add(method); } } return annotatedMethods; }
Example #29
Source File: MethodMetadataReadingVisitor.java From lams with GNU General Public License v2.0 | 5 votes |
public MethodMetadataReadingVisitor(String methodName, int access, String declaringClassName, String returnTypeName, ClassLoader classLoader, Set<MethodMetadata> methodMetadataSet) { super(SpringAsmInfo.ASM_VERSION); this.methodName = methodName; this.access = access; this.declaringClassName = declaringClassName; this.returnTypeName = returnTypeName; this.classLoader = classLoader; this.methodMetadataSet = methodMetadataSet; }
Example #30
Source File: MethodMetadataReadingVisitor.java From spring4-understanding with Apache License 2.0 | 5 votes |
public MethodMetadataReadingVisitor(String methodName, int access, String declaringClassName, String returnTypeName, ClassLoader classLoader, Set<MethodMetadata> methodMetadataSet) { super(SpringAsmInfo.ASM_VERSION); this.methodName = methodName; this.access = access; this.declaringClassName = declaringClassName; this.returnTypeName = returnTypeName; this.classLoader = classLoader; this.methodMetadataSet = methodMetadataSet; }