use of com.helger.jcodemodel.JClassAlreadyExistsException 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);
}
use of com.helger.jcodemodel.JClassAlreadyExistsException 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