Search in sources :

Example 6 with JAnnotationUse

use of com.helger.jcodemodel.JAnnotationUse in project androidannotations by androidannotations.

the class APTCodeModelHelper method copyAnnotation.

public void copyAnnotation(IJAnnotatable annotatable, AnnotationMirror annotationMirror) {
    Map<? extends ExecutableElement, ? extends AnnotationValue> parameters = annotationMirror.getElementValues();
    if (!hasAnnotation(annotatable, annotationMirror)) {
        AbstractJClass annotation = typeMirrorToJClass(annotationMirror.getAnnotationType());
        JAnnotationUse annotate = annotatable.annotate(annotation);
        for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> param : parameters.entrySet()) {
            param.getValue().accept(new AnnotationParamExtractor(annotate, this), param.getKey().getSimpleName().toString());
        }
    }
}
Also used : JAnnotationUse(com.helger.jcodemodel.JAnnotationUse) AbstractJClass(com.helger.jcodemodel.AbstractJClass) AnnotationParamExtractor(org.androidannotations.internal.helper.AnnotationParamExtractor) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with JAnnotationUse

use of com.helger.jcodemodel.JAnnotationUse in project adt4j by sviperll.

the class Stage0ValueClassModelFactory method createStage0Model.

public Stage0ValueClassModel createStage0Model(JDefinedClass bootModel, Visitor visitorAnnotation) {
    GenerationProcess generation = new GenerationProcess();
    JAnnotationUse annotation = null;
    for (JAnnotationUse anyAnnotation : bootModel.annotations()) {
        AbstractJClass annotationClass = anyAnnotation.getAnnotationClass();
        if (!annotationClass.isError()) {
            String fullName = annotationClass.fullName();
            if (fullName != null && fullName.equals(GenerateValueClassForVisitor.class.getName()))
                annotation = anyAnnotation;
        }
    }
    if (annotation == null)
        throw new IllegalStateException("ValueClassModelFactory can't be run for interface without " + GenerateValueClassForVisitor.class + " annotation");
    VisitorDefinition visitorModel = generation.processGenerationResult(VisitorDefinition.createInstance(bootModel, visitorAnnotation));
    ValueClassConfiguration configuration = generation.processGenerationResult(ValueClassConfiguration.createInstance(visitorModel, annotation));
    int mods = configuration.isValueClassPublic() ? JMod.PUBLIC : JMod.NONE;
    JDefinedClass valueClass;
    try {
        valueClass = factory.defineClass(bootModel._package().name(), mods, configuration.valueClassName());
    } catch (JClassAlreadyExistsException ex) {
        return new Stage0ValueClassModel("Class " + configuration.valueClassName() + " already exists");
    }
    JAnnotationUse generatedAnnotation = valueClass.annotate(Generated.class);
    generatedAnnotation.param("value", GenerateValueClassForVisitorProcessor.class.getName());
    Source.annotateParametersAreNonnullByDefault(valueClass);
    return new Stage0ValueClassModel(valueClass);
}
Also used : ValueClassConfiguration(com.github.sviperll.adt4j.model.config.ValueClassConfiguration) VisitorDefinition(com.github.sviperll.adt4j.model.config.VisitorDefinition) JDefinedClass(com.helger.jcodemodel.JDefinedClass) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) JAnnotationUse(com.helger.jcodemodel.JAnnotationUse) GenerateValueClassForVisitor(com.github.sviperll.adt4j.GenerateValueClassForVisitor) GenerationProcess(com.github.sviperll.adt4j.model.util.GenerationProcess) GenerateValueClassForVisitorProcessor(com.github.sviperll.adt4j.GenerateValueClassForVisitorProcessor)

Example 8 with JAnnotationUse

use of com.helger.jcodemodel.JAnnotationUse in project adt4j by sviperll.

the class FieldReader method readGetter.

GenerationResult<Void> readGetter(MethodUsage interfaceMethod, VariableDeclaration param, AbstractJType paramType, boolean isVarArg) {
    GenerationProcess generation = new GenerationProcess();
    for (JAnnotationUse annotationUsage : param.annotations()) {
        AbstractJClass annotationClass = annotationUsage.getAnnotationClass();
        if (!annotationClass.isError()) {
            String annotationClassName = annotationClass.fullName();
            if (annotationClassName != null && annotationClassName.equals(Getter.class.getName())) {
                String getterName = annotationUsage.getParam("name", String.class);
                if (getterName == null || getterName.equals(":auto"))
                    getterName = param.name();
                MemberAccess accessLevel = annotationUsage.getParam("access", MemberAccess.class);
                boolean isNullable = Source.isNullable(param);
                FieldFlags flags = new FieldFlags(isNullable, isVarArg, accessLevel);
                FieldConfiguration configuration = new FieldConfiguration(getterName, paramType, flags);
                generation.processGenerationResult(read(interfaceMethod, param, configuration));
            }
        }
    }
    return generation.<Void>createGenerationResult(null);
}
Also used : MemberAccess(com.github.sviperll.adt4j.MemberAccess) JAnnotationUse(com.helger.jcodemodel.JAnnotationUse) AbstractJClass(com.helger.jcodemodel.AbstractJClass) GenerationProcess(com.github.sviperll.adt4j.model.util.GenerationProcess)

Example 9 with JAnnotationUse

use of com.helger.jcodemodel.JAnnotationUse in project adt4j by sviperll.

the class PredicatesReader method read.

GenerationResult<Void> read(JMethod interfaceMethod, JAnnotationUse annotationUsage) {
    GenerationProcess generation = new GenerationProcess();
    String annotationClassName = annotationUsage.getAnnotationClass().fullName();
    if (annotationClassName != null) {
        if (annotationClassName.equals(GeneratePredicate.class.getName())) {
            String predicateName = annotationUsage.getParam("name", String.class);
            MemberAccess accessLevel = annotationUsage.getParam("access", MemberAccess.class);
            generation.processGenerationResult(read(interfaceMethod, predicateName, accessLevel));
        } else if (annotationClassName.equals(GeneratePredicates.class.getName())) {
            JAnnotationUse[] annotations = annotationUsage.getParam("value", JAnnotationUse[].class);
            if (annotations != null) {
                for (JAnnotationUse annotation : annotations) {
                    generation.processGenerationResult(read(interfaceMethod, annotation));
                }
            }
        }
    }
    return generation.createGenerationResult(null);
}
Also used : MemberAccess(com.github.sviperll.adt4j.MemberAccess) JAnnotationUse(com.helger.jcodemodel.JAnnotationUse) GenerationProcess(com.github.sviperll.adt4j.model.util.GenerationProcess) GeneratePredicate(com.github.sviperll.adt4j.GeneratePredicate)

Example 10 with JAnnotationUse

use of com.helger.jcodemodel.JAnnotationUse in project adt4j by sviperll.

the class ValueClassConfiguration method getPredicates.

public GenerationResult<Map<String, PredicateConfigutation>> getPredicates() {
    GenerationProcess generation = new GenerationProcess();
    Map<String, PredicateConfigutation> predicates = new TreeMap<>();
    PredicatesReader predicatesReader = new PredicatesReader(predicates);
    for (JMethod interfaceMethod : visitorDefinition.methodDefinitions()) {
        for (JAnnotationUse annotationUsage : interfaceMethod.annotations()) {
            generation.processGenerationResult(predicatesReader.read(interfaceMethod, annotationUsage));
        }
    }
    return generation.createGenerationResult(predicates);
}
Also used : JAnnotationUse(com.helger.jcodemodel.JAnnotationUse) GenerationProcess(com.github.sviperll.adt4j.model.util.GenerationProcess) TreeMap(java.util.TreeMap) JMethod(com.helger.jcodemodel.JMethod)

Aggregations

JAnnotationUse (com.helger.jcodemodel.JAnnotationUse)11 AbstractJClass (com.helger.jcodemodel.AbstractJClass)8 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)7 MemberAccess (com.github.sviperll.adt4j.MemberAccess)3 JDefinedClass (com.helger.jcodemodel.JDefinedClass)3 GenerateValueClassForVisitor (com.github.sviperll.adt4j.GenerateValueClassForVisitor)2 ValueClassConfiguration (com.github.sviperll.adt4j.model.config.ValueClassConfiguration)2 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)2 JAnnotationArrayMember (com.helger.jcodemodel.JAnnotationArrayMember)2 JMethod (com.helger.jcodemodel.JMethod)2 JTypeVar (com.helger.jcodemodel.JTypeVar)2 GeneratePredicate (com.github.sviperll.adt4j.GeneratePredicate)1 GenerateValueClassForVisitorProcessor (com.github.sviperll.adt4j.GenerateValueClassForVisitorProcessor)1 WrapsGeneratedValueClass (com.github.sviperll.adt4j.WrapsGeneratedValueClass)1 AbstractJAnnotationValue (com.helger.jcodemodel.AbstractJAnnotationValue)1 JClassAlreadyExistsException (com.helger.jcodemodel.JClassAlreadyExistsException)1 JFieldVar (com.helger.jcodemodel.JFieldVar)1 JFormatter (com.helger.jcodemodel.JFormatter)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1