Search in sources :

Example 11 with GenerationProcess

use of com.github.sviperll.adt4j.model.util.GenerationProcess 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 12 with GenerationProcess

use of com.github.sviperll.adt4j.model.util.GenerationProcess in project adt4j by sviperll.

the class FieldReader method read.

GenerationResult<Void> read(MethodUsage interfaceMethod, VariableDeclaration param, FieldConfiguration configuration) {
    GenerationProcess generation = new GenerationProcess();
    FieldConfiguration existingConfiguration = fieldMap.get(configuration.name());
    if (existingConfiguration == null) {
        existingConfiguration = configuration;
        fieldMap.put(configuration.name(), configuration);
    }
    try {
        existingConfiguration.merge(interfaceMethod, param.name(), configuration);
    } catch (FieldConfigurationException ex) {
        generation.reportError(MessageFormat.format("Unable to configure {0} getter: {1}", configuration.name(), ex.getMessage()));
    }
    return generation.<Void>createGenerationResult(null);
}
Also used : GenerationProcess(com.github.sviperll.adt4j.model.util.GenerationProcess)

Example 13 with GenerationProcess

use of com.github.sviperll.adt4j.model.util.GenerationProcess 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 14 with GenerationProcess

use of com.github.sviperll.adt4j.model.util.GenerationProcess 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)

Example 15 with GenerationProcess

use of com.github.sviperll.adt4j.model.util.GenerationProcess in project adt4j by sviperll.

the class ValueClassConfiguration method getUpdatersConfiguration.

public GenerationResult<Map<String, FieldConfiguration>> getUpdatersConfiguration(JDefinedClass valueClass, Types types) {
    GenerationProcess generation = new GenerationProcess();
    AbstractJClass usedValueClassType = Source.narrowType(valueClass, valueClass.typeParams());
    Map<String, FieldConfiguration> updatersMap = new TreeMap<>();
    FieldReader reader = new FieldReader(updatersMap);
    VisitorDefinition.VisitorUsage narrowed = visitorDefinition.narrowed(usedValueClassType, visitorDefinition.getResultTypeParameter(), types._RuntimeException);
    for (MethodUsage interfaceMethod : narrowed.methods()) {
        for (VariableDeclaration param : interfaceMethod.params()) {
            generation.processGenerationResult(reader.readUpdater(interfaceMethod, param, param.type().declarable(), false));
        }
        VariableDeclaration param = interfaceMethod.varParam();
        if (param != null) {
            generation.processGenerationResult(reader.readUpdater(interfaceMethod, param, param.type().declarable(), true));
        }
    }
    return generation.createGenerationResult(updatersMap);
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) GenerationProcess(com.github.sviperll.adt4j.model.util.GenerationProcess) VariableDeclaration(com.github.sviperll.adt4j.model.config.VariableDeclaration) MethodUsage(com.github.sviperll.adt4j.model.config.VisitorDefinition.MethodUsage) TreeMap(java.util.TreeMap)

Aggregations

GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)15 AbstractJClass (com.helger.jcodemodel.AbstractJClass)9 JAnnotationUse (com.helger.jcodemodel.JAnnotationUse)7 MemberAccess (com.github.sviperll.adt4j.MemberAccess)4 JMethod (com.helger.jcodemodel.JMethod)4 TreeMap (java.util.TreeMap)4 JDefinedClass (com.helger.jcodemodel.JDefinedClass)3 JTypeVar (com.helger.jcodemodel.JTypeVar)3 GenerateValueClassForVisitor (com.github.sviperll.adt4j.GenerateValueClassForVisitor)2 ValueClassConfiguration (com.github.sviperll.adt4j.model.config.ValueClassConfiguration)2 VariableDeclaration (com.github.sviperll.adt4j.model.config.VariableDeclaration)2 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)2 MethodUsage (com.github.sviperll.adt4j.model.config.VisitorDefinition.MethodUsage)2 JClassAlreadyExistsException (com.helger.jcodemodel.JClassAlreadyExistsException)2 Caching (com.github.sviperll.adt4j.Caching)1 GeneratePredicate (com.github.sviperll.adt4j.GeneratePredicate)1 GenerateValueClassForVisitorProcessor (com.github.sviperll.adt4j.GenerateValueClassForVisitorProcessor)1 WrapsGeneratedValueClass (com.github.sviperll.adt4j.WrapsGeneratedValueClass)1 FieldConfiguration (com.github.sviperll.adt4j.model.config.FieldConfiguration)1 PredicateConfigutation (com.github.sviperll.adt4j.model.config.PredicateConfigutation)1