Example usage for org.springframework.core.type AnnotationMetadata getAnnotatedMethods

List of usage examples for org.springframework.core.type AnnotationMetadata getAnnotatedMethods

Introduction

In this page you can find the example usage for org.springframework.core.type AnnotationMetadata getAnnotatedMethods.

Prototype

Set<MethodMetadata> getAnnotatedMethods(String annotationName);

Source Link

Document

Retrieve the method metadata for all methods that are annotated (or meta-annotated) with the given annotation type.

Usage

From source file:org.fishwife.jrugged.spring.AnnotatedMethodFilter.java

/**
 * {@inheritDoc}/*from  w w  w .  ja va  2  s.c  om*/
 */
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory)
        throws IOException {
    AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
    Set<MethodMetadata> annotatedMethods = annotationMetadata
            .getAnnotatedMethods(annotatedClass.getCanonicalName());
    return !annotatedMethods.isEmpty();
}

From source file:io.neba.core.selftests.SelftestRegistrar.java

private Set<MethodMetadata> getSelfTestMethods(AnnotationMetadata metadata) {
    return metadata.getAnnotatedMethods(this.selftestAnnotationName);
}

From source file:org.duracloud.account.db.util.security.impl.AnnotationParserImpl.java

private Set<MethodMetadata> getAnnotatedMethods(AnnotationMetadata metadata, Class<?> annotationClass) {
    if (null == metadata) {
        throw new DuraCloudRuntimeException("Arg metadata is null: {}", annotationClass.getName());
    }/*from   ww w  .ja  va 2s .  co m*/
    return metadata.getAnnotatedMethods(annotationClass.getName());
}

From source file:org.springframework.context.annotation.ConfigurationClassParser.java

/**
 * Retrieve the metadata for all <code>@Bean</code> methods.
 *//*w  ww  .j a  va  2 s  . com*/
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;
}