Search in sources :

Example 1 with Caching

use of com.github.sviperll.adt4j.Caching in project adt4j by sviperll.

the class ValueClassConfiguration method createInstance.

public static GenerationResult<ValueClassConfiguration> createInstance(VisitorDefinition visitorDefinition, JAnnotationUse annotation, JDefinedClass valueClass) {
    GenerationProcess generation = new GenerationProcess();
    String acceptMethodName = annotation.getParam("acceptMethodName", String.class);
    MemberAccess acceptMethodAccess = annotation.getParam("acceptMethodAccess", MemberAccess.class);
    boolean isPublic = annotation.getParam("isPublic", Boolean.class);
    Caching hashCodeCaching = annotation.getParam("hashCodeCaching", Caching.class);
    int hashCodeBase = annotation.getParam("hashCodeBase", Integer.class);
    boolean isComparable = annotation.getParam("isComparable", Boolean.class);
    float floatEpsilon = annotation.getParam("floatEpsilon", Float.class);
    double doubleEpsilon = annotation.getParam("doubleEpsilon", Double.class);
    FloatCustomization floatCustomization = new FloatCustomization(floatEpsilon, doubleEpsilon);
    Serialization serialization = serialization(annotation);
    ClassCustomization classCustomization = generation.processGenerationResult(classCustomization(annotation, visitorDefinition, valueClass));
    AbstractJClass[] interfaces = annotation.getParam("implementsInterfaces", AbstractJClass[].class);
    AcceptMethodCustomization acceptMethodCustomization = new AcceptMethodCustomization(acceptMethodName, acceptMethodAccess);
    InterfacesCustomization interfaceCustomization = new InterfacesCustomization(isComparable, serialization, interfaces);
    APICustomization apiCustomization = new APICustomization(isPublic, acceptMethodCustomization, interfaceCustomization);
    ImplementationCustomization implementationCustomization = new ImplementationCustomization(hashCodeCaching, hashCodeBase, floatCustomization);
    Customization customiztion = new Customization(classCustomization, apiCustomization, implementationCustomization);
    return generation.createGenerationResult(new ValueClassConfiguration(visitorDefinition, customiztion));
}
Also used : AbstractJClass(com.helger.jcodemodel.AbstractJClass) MemberAccess(com.github.sviperll.adt4j.MemberAccess) Caching(com.github.sviperll.adt4j.Caching) GenerationProcess(com.github.sviperll.adt4j.model.util.GenerationProcess)

Example 2 with Caching

use of com.github.sviperll.adt4j.Caching in project adt4j by sviperll.

the class FinalValueClassModel method createMethodBuilder.

MethodBuilder createMethodBuilder(Serialization serialization) {
    if (isError)
        return new MethodBuilder(null, null);
    else {
        JFieldVar acceptorField = buildAcceptorField();
        Map<String, JDefinedClass> caseClasses;
        try {
            caseClasses = buildCaseClasses(serialization);
        } catch (JClassAlreadyExistsException ex) {
            throw new RuntimeException("Unexpected exception :)", ex);
        }
        Caching hashCode = environment.hashCodeCaching();
        if (!hashCode.enabled())
            return new MethodBuilder(caseClasses, acceptorField);
        else {
            JFieldVar hashCodeField = buildHashCodeCachedValueField(serialization);
            return new MethodBuilder(caseClasses, acceptorField, hashCodeField);
        }
    }
}
Also used : JClassAlreadyExistsException(com.helger.jcodemodel.JClassAlreadyExistsException) Caching(com.github.sviperll.adt4j.Caching) JFieldVar(com.helger.jcodemodel.JFieldVar) JDefinedClass(com.helger.jcodemodel.JDefinedClass)

Aggregations

Caching (com.github.sviperll.adt4j.Caching)2 MemberAccess (com.github.sviperll.adt4j.MemberAccess)1 GenerationProcess (com.github.sviperll.adt4j.model.util.GenerationProcess)1 AbstractJClass (com.helger.jcodemodel.AbstractJClass)1 JClassAlreadyExistsException (com.helger.jcodemodel.JClassAlreadyExistsException)1 JDefinedClass (com.helger.jcodemodel.JDefinedClass)1 JFieldVar (com.helger.jcodemodel.JFieldVar)1