Search in sources :

Example 1 with PrimitiveTemplateSpec

use of com.linkedin.pegasus.generator.spec.PrimitiveTemplateSpec in project rest.li by linkedin.

the class JavaDataTemplateGenerator method generate.

public JClass generate(ClassTemplateSpec classTemplateSpec) {
    final JClass result;
    if (classTemplateSpec == null) {
        result = null;
    } else {
        if (classTemplateSpec.getSchema() == null) {
            // this is for custom class, package override is not applicable.
            result = getCodeModel().directClass(classTemplateSpec.getFullName());
        } else if (PredefinedJavaClasses.containsKey(classTemplateSpec.getSchema())) {
            final Class<?> nativeJavaClass = PredefinedJavaClasses.get(classTemplateSpec.getSchema());
            result = getCodeModel().ref(nativeJavaClass);
        } else if (classTemplateSpec.getSchema().isPrimitive()) {
            result = generatePrimitive((PrimitiveTemplateSpec) classTemplateSpec);
        } else {
            try {
                final JDefinedClass definedClass = defineClass(classTemplateSpec);
                populateClassContent(classTemplateSpec, definedClass);
                result = definedClass;
            } catch (JClassAlreadyExistsException e) {
                throw new IllegalArgumentException(classTemplateSpec.getFullName());
            }
        }
    }
    return result;
}
Also used : JClassAlreadyExistsException(com.sun.codemodel.JClassAlreadyExistsException) JDefinedClass(com.sun.codemodel.JDefinedClass) JClass(com.sun.codemodel.JClass) PrimitiveTemplateSpec(com.linkedin.pegasus.generator.spec.PrimitiveTemplateSpec) JDefinedClass(com.sun.codemodel.JDefinedClass) JClass(com.sun.codemodel.JClass)

Aggregations

PrimitiveTemplateSpec (com.linkedin.pegasus.generator.spec.PrimitiveTemplateSpec)1 JClass (com.sun.codemodel.JClass)1 JClassAlreadyExistsException (com.sun.codemodel.JClassAlreadyExistsException)1 JDefinedClass (com.sun.codemodel.JDefinedClass)1