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);
}
Aggregations