Search in sources :

Example 1 with JavaClassElement

use of io.micronaut.annotation.processing.visitor.JavaClassElement in project micronaut-core by micronaut-projects.

the class ServiceDescriptionProcessor method processGeneratedAnnotation.

private boolean processGeneratedAnnotation(List<io.micronaut.inject.ast.Element> originatingElements, Element element, TypeElement typeElement, String name) {
    Generated generated = element.getAnnotation(Generated.class);
    if (generated != null) {
        String serviceName = generated.service();
        if (StringUtils.isNotEmpty(serviceName)) {
            serviceDescriptors.computeIfAbsent(serviceName, s1 -> new HashSet<>()).add(name);
            originatingElements.add(new JavaClassElement(typeElement, AnnotationMetadata.EMPTY_METADATA, null));
        }
        return true;
    }
    return false;
}
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) Generated(io.micronaut.core.annotation.Generated) JavaClassElement(io.micronaut.annotation.processing.visitor.JavaClassElement) HashSet(java.util.HashSet)

Example 2 with JavaClassElement

use of io.micronaut.annotation.processing.visitor.JavaClassElement 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)2 ApplicationContextConfigurer (io.micronaut.context.ApplicationContextConfigurer)2 ContextConfigurer (io.micronaut.context.annotation.ContextConfigurer)2 ContextConfigurerVisitor (io.micronaut.context.visitor.ContextConfigurerVisitor)2 AnnotationMetadata (io.micronaut.core.annotation.AnnotationMetadata)2 AnnotationValue (io.micronaut.core.annotation.AnnotationValue)2 Generated (io.micronaut.core.annotation.Generated)2 StringUtils (io.micronaut.core.util.StringUtils)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Set (java.util.Set)2 RoundEnvironment (javax.annotation.processing.RoundEnvironment)2 SupportedOptions (javax.annotation.processing.SupportedOptions)2 Element (javax.lang.model.element.Element)2 TypeElement (javax.lang.model.element.TypeElement)2