use of com.github.sviperll.adt4j.model.config.VisitorDefinition in project adt4j by sviperll.
the class Stage0ValueClassModel method createStage1Model.
public GenerationResult<Stage1ValueClassModel> createStage1Model(JDefinedClass jVisitorModel, Visitor visitorAnnotation) {
GenerationProcess generation = new GenerationProcess();
if (error != null) {
generation.reportError(error);
return generation.createGenerationResult(null);
} else {
JAnnotationUse annotation = null;
for (JAnnotationUse anyAnnotation : jVisitorModel.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(jVisitorModel, visitorAnnotation));
ValueClassConfiguration configuration = generation.processGenerationResult(ValueClassConfiguration.createInstance(visitorModel, annotation, valueClass));
Stage1ValueClassModel result = createStage1Model(configuration);
return generation.createGenerationResult(result);
}
}
use of com.github.sviperll.adt4j.model.config.VisitorDefinition 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);
}
Aggregations