Search in sources :

Example 1 with ValueClassConfiguration

use of com.github.sviperll.adt4j.model.config.ValueClassConfiguration 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);
    }
}
Also used : ValueClassConfiguration(com.github.sviperll.adt4j.model.config.ValueClassConfiguration) VisitorDefinition(com.github.sviperll.adt4j.model.config.VisitorDefinition) JAnnotationUse(com.helger.jcodemodel.JAnnotationUse) GenerateValueClassForVisitor(com.github.sviperll.adt4j.GenerateValueClassForVisitor) AbstractJClass(com.helger.jcodemodel.AbstractJClass) GenerationProcess(com.github.sviperll.adt4j.model.util.GenerationProcess)

Example 2 with ValueClassConfiguration

use of com.github.sviperll.adt4j.model.config.ValueClassConfiguration 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);
}
Also used : ValueClassConfiguration(com.github.sviperll.adt4j.model.config.ValueClassConfiguration) VisitorDefinition(com.github.sviperll.adt4j.model.config.VisitorDefinition) JDefinedClass(com.helger.jcodemodel.JDefinedClass) AbstractJClass(com.helger.jcodemodel.AbstractJClass) JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) JAnnotationUse(com.helger.jcodemodel.JAnnotationUse) GenerateValueClassForVisitor(com.github.sviperll.adt4j.GenerateValueClassForVisitor) GenerationProcess(com.github.sviperll.adt4j.model.util.GenerationProcess) GenerateValueClassForVisitorProcessor(com.github.sviperll.adt4j.GenerateValueClassForVisitorProcessor)

Aggregations

GenerateValueClassForVisitor (com.github.sviperll.adt4j.GenerateValueClassForVisitor)2 ValueClassConfiguration (com.github.sviperll.adt4j.model.config.ValueClassConfiguration)2 VisitorDefinition (com.github.sviperll.adt4j.model.config.VisitorDefinition)2 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)2 AbstractJClass (com.helger.jcodemodel.AbstractJClass)2 JAnnotationUse (com.helger.jcodemodel.JAnnotationUse)2 GenerateValueClassForVisitorProcessor (com.github.sviperll.adt4j.GenerateValueClassForVisitorProcessor)1 JClassAlreadyExistsException (com.helger.jcodemodel.JClassAlreadyExistsException)1 JDefinedClass (com.helger.jcodemodel.JDefinedClass)1