Search in sources :

Example 1 with FieldConfiguration

use of com.github.sviperll.adt4j.model.config.FieldConfiguration in project adt4j by sviperll.

the class Stage1ValueClassModel method createResult.

public GenerationResult<JDefinedClass> createResult() {
    GenerationProcess generation = new GenerationProcess();
    generation.reportAllErrors(validateInterfaces());
    Map<String, FieldConfiguration> gettersConfigutation = generation.processGenerationResult(configuration.getGettersConfigutation(valueClass, types));
    Map<String, FieldConfiguration> updatersConfiguration = generation.processGenerationResult(configuration.getUpdatersConfiguration(valueClass, types));
    Map<String, PredicateConfigutation> predicates = generation.processGenerationResult(configuration.getPredicates());
    FinalValueClassModel result;
    if (generation.hasErrors()) {
        FinalValueClassModelEnvironment environment = new FinalValueClassModelEnvironment(valueClass, null, configuration);
        result = FinalValueClassModel.createErrorModel(environment, types);
    } else {
        JDefinedClass acceptingInterface;
        try {
            acceptingInterface = createAcceptingInterface();
        } catch (JClassAlreadyExistsException ex) {
            throw new RuntimeException("Unexpected exception", ex);
        }
        if (configuration.isValueClassSerializable()) {
            acceptingInterface._extends(types._Serializable);
        }
        FinalValueClassModelEnvironment environment = new FinalValueClassModelEnvironment(valueClass, acceptingInterface, configuration);
        result = FinalValueClassModel.createModel(environment, types);
    }
    result.buildSerialVersionUID();
    FinalValueClassModel.MethodBuilder methodBuilder = result.createMethodBuilder(configuration.serialization());
    Map<String, JMethod> constructorMethods = methodBuilder.buildConstructorMethods(configuration.serialization());
    methodBuilder.buildPrivateConstructor();
    if (configuration.isValueClassSerializable())
        methodBuilder.buildReadObjectMethod();
    methodBuilder.buildProtectedConstructor(configuration.serialization());
    methodBuilder.buildAcceptMethod();
    for (FieldConfiguration getter : gettersConfigutation.values()) {
        methodBuilder.generateGetter(getter);
    }
    for (FieldConfiguration updater : updatersConfiguration.values()) {
        methodBuilder.generateUpdater(updater);
    }
    for (Map.Entry<String, PredicateConfigutation> predicate : predicates.entrySet()) {
        methodBuilder.generatePredicate(predicate.getKey(), predicate.getValue());
    }
    if (configuration.isValueClassComparable()) {
        methodBuilder.buildCompareTo();
    }
    methodBuilder.buildEqualsMethod();
    methodBuilder.buildHashCodeMethod(configuration.hashCodeBase());
    methodBuilder.buildToStringMethod();
    try {
        result.buildFactory(constructorMethods);
    } catch (JClassAlreadyExistsException ex) {
        throw new RuntimeException("Unexpected exception :)", ex);
    }
    return generation.createGenerationResult(valueClass);
}
Also used : JDefinedClass(com.helger.jcodemodel.JDefinedClass) JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) PredicateConfigutation(com.github.sviperll.adt4j.model.config.PredicateConfigutation) GenerationProcess(com.github.sviperll.adt4j.model.util.GenerationProcess) JMethod(com.helger.jcodemodel.JMethod) Map(java.util.Map) FieldConfiguration(com.github.sviperll.adt4j.model.config.FieldConfiguration)

Aggregations

FieldConfiguration (com.github.sviperll.adt4j.model.config.FieldConfiguration)1 PredicateConfigutation (com.github.sviperll.adt4j.model.config.PredicateConfigutation)1 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)1 JClassAlreadyExistsException (com.helger.jcodemodel.JClassAlreadyExistsException)1 JDefinedClass (com.helger.jcodemodel.JDefinedClass)1 JMethod (com.helger.jcodemodel.JMethod)1 Map (java.util.Map)1