All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.toolisticon.aptk.annotationwrapper.test.annotationonpackage.TestDefaultsAnnotationWrapper Maven / Gradle / Ivy

The newest version!
package io.toolisticon.aptk.annotationwrapper.test.annotationonpackage;
import io.toolisticon.aptk.annotationwrapper.test.TestDefaultsAnnotation;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.ArrayType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import io.toolisticon.aptk.tools.AnnotationUtils;
import io.toolisticon.aptk.tools.TypeMirrorWrapper;
import io.toolisticon.aptk.tools.TypeUtils;
import io.toolisticon.aptk.tools.wrapper.CompileMessageWriter;
import io.toolisticon.aptk.tools.wrapper.ElementWrapper;



/**
 * Wrapper class to read attribute values from Annotation TestDefaultsAnnotation.
 */
class TestDefaultsAnnotationWrapper {

    private final Element annotatedElement;
    private final AnnotationMirror annotationMirror;

    /**
     * Private constructor.
     * Used to read annotation from Element.
     * @param annotatedElement the annotated Element to annotated with this wrapper annotation
     */
    private TestDefaultsAnnotationWrapper (Element annotatedElement) {
        this.annotatedElement = annotatedElement;
        this.annotationMirror = AnnotationUtils.getAnnotationMirror(annotatedElement, TestDefaultsAnnotation.class);
    }

    /**
     * Private constructor.
     * Mainly used for embedded annotations.
     * @param element the element related with the passed annotationMirror
     * @param annotationMirror the AnnotationMirror to wrap
     */
    private TestDefaultsAnnotationWrapper (Element element, AnnotationMirror annotationMirror) {
        this.annotatedElement = element;
        this.annotationMirror = annotationMirror;
    }

    /**
     * Gets the element on which the wrapped annotation is used.
     */
    Element _annotatedElement() {
        return this.annotatedElement;
    }

    /**
     * Gets the wrapped AnnotationMirror.
     */
     AnnotationMirror _annotationMirror() {
        return this.annotationMirror;
     }


    /**
     * Gets the TestDefaultsAnnotation.withDefault from wrapped annotation as AnnotationValue.
     * @return the attributes AnnotationValue
     */
    AnnotationValue withDefaultAsAnnotationValue() {
        return AnnotationUtils.getAnnotationValueOfAttributeWithDefaults(annotationMirror, "withDefault");
    }

    /**
     * The Wrapper type for the annotation attribute 'withDefault'.
     */
    class TestDefaultsAnnotationAttributewithDefaultWrapper{

        
        /**
         * Gets the TestDefaultsAnnotation.withDefault from wrapped annotation.
         * @return the attribute value
         */
        String getValue() {
            return TestDefaultsAnnotationWrapper.this.withDefault();
        }


        /**
         * Writes compiler message and binds them to annotation.
         * @return a compiler message builder
         */
        CompileMessageWriter.CompileMessageWriterStart compilerMessage() {
            return CompileMessageWriter.at(TestDefaultsAnnotationWrapper.this.annotatedElement, TestDefaultsAnnotationWrapper.this.annotationMirror, withDefaultAsAnnotationValue());
        }

    }

    /**
     * Gets the TestDefaultsAnnotation.withDefault as wrapped attribute from wrapped annotation.
     * @return the attribute value
     */
    TestDefaultsAnnotationAttributewithDefaultWrapper withDefaultAsAttributeWrapper() {
        return new TestDefaultsAnnotationAttributewithDefaultWrapper();
    }

    /**
     * Gets the TestDefaultsAnnotation.withDefault from wrapped annotation.
     * @return the attribute value
     */
    String withDefault() {
        return (String)withDefaultAsAnnotationValue().getValue();
    }


    /**
     * Allows to check if attribute was explicitly set or if default value is used.
     * @return true, if default value is used, otherwise false
     */
    boolean withDefaultIsDefaultValue(){
        return AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror,"withDefault") == null;
    }


    /**
     * Gets the TestDefaultsAnnotation.withoutDefault from wrapped annotation as AnnotationValue.
     * @return the attributes AnnotationValue
     */
    AnnotationValue withoutDefaultAsAnnotationValue() {
        return AnnotationUtils.getAnnotationValueOfAttributeWithDefaults(annotationMirror, "withoutDefault");
    }

    /**
     * The Wrapper type for the annotation attribute 'withoutDefault'.
     */
    class TestDefaultsAnnotationAttributewithoutDefaultWrapper{

        
        /**
         * Gets the TestDefaultsAnnotation.withoutDefault from wrapped annotation.
         * @return the attribute value
         */
        String getValue() {
            return TestDefaultsAnnotationWrapper.this.withoutDefault();
        }


        /**
         * Writes compiler message and binds them to annotation.
         * @return a compiler message builder
         */
        CompileMessageWriter.CompileMessageWriterStart compilerMessage() {
            return CompileMessageWriter.at(TestDefaultsAnnotationWrapper.this.annotatedElement, TestDefaultsAnnotationWrapper.this.annotationMirror, withoutDefaultAsAnnotationValue());
        }

    }

    /**
     * Gets the TestDefaultsAnnotation.withoutDefault as wrapped attribute from wrapped annotation.
     * @return the attribute value
     */
    TestDefaultsAnnotationAttributewithoutDefaultWrapper withoutDefaultAsAttributeWrapper() {
        return new TestDefaultsAnnotationAttributewithoutDefaultWrapper();
    }

    /**
     * Gets the TestDefaultsAnnotation.withoutDefault from wrapped annotation.
     * @return the attribute value
     */
    String withoutDefault() {
        return (String)withoutDefaultAsAnnotationValue().getValue();
    }


    /**
     * Allows to check if attribute was explicitly set or if default value is used.
     * @return true, if default value is used, otherwise false
     */
    boolean withoutDefaultIsDefaultValue(){
        return AnnotationUtils.getAnnotationValueOfAttribute(annotationMirror,"withoutDefault") == null;
    }



    /**
     * Checks if passed element is annotated with this wrapper annotation type : TestDefaultsAnnotation
     * @param element The element to check for wrapped annotation type
     * @return true, if passed element is annotated with TestDefaultsAnnotation annotation, otherwise false
     */
    static boolean isAnnotated(Element element) {
        return element != null && element.getAnnotation(TestDefaultsAnnotation.class) != null;
    }

    /**
     * Writes compiler message and binds them to annotation.
     * @return a compiler message builder
     */
     CompileMessageWriter.CompileMessageWriterStart compilerMessage() {
        return CompileMessageWriter.at(TestDefaultsAnnotationWrapper.this.annotatedElement, TestDefaultsAnnotationWrapper.this.annotationMirror);
    }

     /**
      * Gets the AnnotationMirror from passed element for this wrappers annotation type and creates a wrapper instance.
      * @param element The element to read the annotations from
      * @return The wrapped AnnotationMirror if Element is annotated with this wrappers annotation type, otherwise null.
      */
    static TestDefaultsAnnotationWrapper wrap(Element element) {
        return isAnnotated(element) ? new TestDefaultsAnnotationWrapper(element) : null;
    }
    
     /**
      * Gets the AnnotationMirror from passed element for this wrappers annotation type and creates a wrapper instance.
      * @param element The element to read the annotations from
      * @return The wrapped AnnotationMirror if Element is annotated with this wrappers annotation type, otherwise null.
      */
    static TestDefaultsAnnotationWrapper wrap(ElementWrapper element) {
        return wrap(element.unwrap());
    }

    /**
     * Wraps an AnnotationMirror.
     * Throws an IllegalArgumentException if passed AnnotationMirror type doesn't match the wrapped annotation type.
     * @param annotationMirror The element annotated with the annotation to wrap
     * @return The wrapper instance
     */
    static TestDefaultsAnnotationWrapper wrap(AnnotationMirror annotationMirror) {
        return new TestDefaultsAnnotationWrapper(null, annotationMirror);
    }


   /**
     * Wraps an AnnotationMirror.
     * Throws an IllegalArgumentException if passed AnnotationMirror type doesn't match the wrapped annotation type.
     * @param element the element bound to the usage of passed AnnotationMirror
     * @param annotationMirror The AnnotationMirror to wrap
     * @return The wrapper instance
     */
    static TestDefaultsAnnotationWrapper wrap(Element element, AnnotationMirror annotationMirror) {
        return new TestDefaultsAnnotationWrapper(element, annotationMirror);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy