Search in sources :

Example 1 with ContextConfigurer

use of io.micronaut.context.annotation.ContextConfigurer in project micronaut-core by micronaut-projects.

the class ServiceDescriptionProcessor method processContextConfigurerAnnotation.

private void processContextConfigurerAnnotation(List<io.micronaut.inject.ast.Element> originatingElements, Element element, TypeElement typeElement) {
    AnnotationMetadata annotationMetadata = annotationUtils.getAnnotationMetadata(element);
    Optional<AnnotationValue<ContextConfigurer>> ann = annotationMetadata.findAnnotation(ContextConfigurer.class);
    if (ann.isPresent()) {
        JavaClassElement javaClassElement = javaVisitorContext.getElementFactory().newClassElement(typeElement, annotationMetadata);
        ContextConfigurerVisitor.assertNoConstructorForContextAnnotation(javaClassElement);
        List<? extends TypeMirror> interfaces = typeElement.getInterfaces();
        for (TypeMirror interfaceType : interfaces) {
            if (interfaceType instanceof DeclaredType) {
                String serviceName = modelUtils.resolveTypeName(interfaceType);
                String serviceImpl = modelUtils.resolveTypeName(element.asType());
                if (SUPPORTED_SERVICE_TYPES.contains(serviceName)) {
                    serviceDescriptors.computeIfAbsent(serviceName, s1 -> new HashSet<>()).add(serviceImpl);
                    originatingElements.add(new JavaClassElement(typeElement, AnnotationMetadata.EMPTY_METADATA, null));
                }
            }
        }
    }
    AnnotationUtils.invalidateCache();
}
Also used : SupportedOptions(javax.annotation.processing.SupportedOptions) ContextConfigurer(io.micronaut.context.annotation.ContextConfigurer) Set(java.util.Set) HashMap(java.util.HashMap) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ArrayList(java.util.ArrayList) JavaClassElement(io.micronaut.annotation.processing.visitor.JavaClassElement) HashSet(java.util.HashSet) StringUtils(io.micronaut.core.util.StringUtils) List(java.util.List) TypeMirror(javax.lang.model.type.TypeMirror) RoundEnvironment(javax.annotation.processing.RoundEnvironment) Map(java.util.Map) DeclaredType(javax.lang.model.type.DeclaredType) AnnotationValue(io.micronaut.core.annotation.AnnotationValue) Generated(io.micronaut.core.annotation.Generated) Optional(java.util.Optional) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) ApplicationContextConfigurer(io.micronaut.context.ApplicationContextConfigurer) Collections(java.util.Collections) ContextConfigurerVisitor(io.micronaut.context.visitor.ContextConfigurerVisitor) TypeMirror(javax.lang.model.type.TypeMirror) AnnotationValue(io.micronaut.core.annotation.AnnotationValue) JavaClassElement(io.micronaut.annotation.processing.visitor.JavaClassElement) AnnotationMetadata(io.micronaut.core.annotation.AnnotationMetadata) DeclaredType(javax.lang.model.type.DeclaredType) HashSet(java.util.HashSet)

Aggregations

JavaClassElement (io.micronaut.annotation.processing.visitor.JavaClassElement)1 ApplicationContextConfigurer (io.micronaut.context.ApplicationContextConfigurer)1 ContextConfigurer (io.micronaut.context.annotation.ContextConfigurer)1 ContextConfigurerVisitor (io.micronaut.context.visitor.ContextConfigurerVisitor)1 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)1 AnnotationValue (io.micronaut.core.annotation.AnnotationValue)1 Generated (io.micronaut.core.annotation.Generated)1 StringUtils (io.micronaut.core.util.StringUtils)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 RoundEnvironment (javax.annotation.processing.RoundEnvironment)1 SupportedOptions (javax.annotation.processing.SupportedOptions)1 Element (javax.lang.model.element.Element)1 TypeElement (javax.lang.model.element.TypeElement)1