use of com.linkedin.pegasus.generator.spec.ClassTemplateSpec in project rest.li by linkedin.
the class RequestBuilderSpecGenerator method generateFinderRequestBuilder.
private FinderBuilderSpec generateFinderRequestBuilder(ResourceSchema resource, String baseBuilderClass, String keyClass, String valueClass, String requestBuilderName, String clientPackage, String finderName, FinderSchema schema) {
// this method applies to finder
FinderBuilderSpec finderBuilderClass = new FinderBuilderSpec(clientPackage, requestBuilderName, baseBuilderClass, resource);
finderBuilderClass.setAnnotations(schema.getAnnotations() == null ? null : schema.getAnnotations().data());
final ClassTemplateSpec keyClassSpec = classToTemplateSpec(keyClass);
finderBuilderClass.setKeyClass(keyClassSpec);
final ClassTemplateSpec valueClassSpec = classToTemplateSpec(valueClass);
finderBuilderClass.setValueClass(valueClassSpec);
finderBuilderClass.setFinderName(finderName);
registerBuilderSpec(finderBuilderClass);
return finderBuilderClass;
}
use of com.linkedin.pegasus.generator.spec.ClassTemplateSpec in project rest.li by linkedin.
the class TemplateSpecGenerator method classInfoForUnnamed.
/*
* Determine name and class for unnamed types.
*/
private ClassInfo classInfoForUnnamed(ClassTemplateSpec enclosingClass, String name, DataSchema schema) {
assert !(schema instanceof NamedDataSchema);
assert !(schema instanceof PrimitiveDataSchema);
final ClassInfo classInfo = classNameForUnnamedTraverse(enclosingClass, name, schema);
final String className = classInfo.bindingName();
final DataSchema schemaFromClassName = _classNameToSchemaMap.get(className);
if (schemaFromClassName == null) {
final ClassTemplateSpec classTemplateSpec = ClassTemplateSpec.createFromDataSchema(schema);
if (enclosingClass != null && classInfo.namespace.equals(enclosingClass.getFullName())) {
// enclosingClass flag indicates whether a class is nested or not.
classTemplateSpec.setEnclosingClass(enclosingClass);
classTemplateSpec.setClassName(classInfo.name);
classTemplateSpec.setModifiers(ModifierSpec.PUBLIC, ModifierSpec.STATIC, ModifierSpec.FINAL);
} else {
classTemplateSpec.setNamespace(classInfo.namespace);
classTemplateSpec.setClassName(classInfo.name);
classTemplateSpec.setPackage(classInfo.packageName);
classTemplateSpec.setModifiers(ModifierSpec.PUBLIC);
}
classInfo.definedClass = classTemplateSpec;
} else {
checkForClassNameConflict(className, schema);
classInfo.existingClass = _schemaToClassMap.get(schemaFromClassName);
}
return classInfo;
}
use of com.linkedin.pegasus.generator.spec.ClassTemplateSpec in project rest.li by linkedin.
the class TemplateSpecGenerator method registerDefinedSchema.
/**
* Instead of generate spec for the specify {@link DataSchema}, assume it is already defined in the system.
*/
public void registerDefinedSchema(DataSchema schema) {
final ClassTemplateSpec spec = ClassTemplateSpec.createFromDataSchema(schema);
_schemaToClassMap.put(schema, spec);
_classNameToSchemaMap.put(spec.getBindingName(), schema);
}
use of com.linkedin.pegasus.generator.spec.ClassTemplateSpec in project rest.li by linkedin.
the class TemplateSpecGenerator method generate.
/**
* Generate {@link ClassTemplateSpec} from the specified {@link DataSchema} and its location.
*/
public ClassTemplateSpec generate(DataSchema schema, DataSchemaLocation location) {
pushCurrentLocation(location);
final ClassTemplateSpec result = processSchema(schema, null, null);
popCurrentLocation();
return result;
}
use of com.linkedin.pegasus.generator.spec.ClassTemplateSpec in project rest.li by linkedin.
the class JavaRequestBuilderGenerator method getJavaBindingType.
private JavaBinding getJavaBindingType(DataSchema schema, JDefinedClass enclosingClass) {
final JavaBinding binding = new JavaBinding();
if (_generateDataTemplates || schema instanceof ArrayDataSchema) {
final ClassTemplateSpec classSpec = generateClassSpec(schema, enclosingClass);
binding.schemaClass = _javaDataTemplateGenerator.generate(classSpec);
{
_generatedArrayClasses.add(binding.schemaClass);
}
}
binding.schemaClass = getClassRefForSchema(schema, enclosingClass);
binding.valueClass = getClassRefForSchema(schema, enclosingClass);
if (schema instanceof TyperefDataSchema) {
final TyperefDataSchema typerefDataSchema = (TyperefDataSchema) schema;
if (typerefDataSchema.getDereferencedDataSchema().getType() != DataSchema.Type.UNION) {
final String javaClassNameFromSchema = CustomTypeUtil.getJavaCustomTypeClassNameFromSchema(typerefDataSchema);
if (javaClassNameFromSchema != null) {
binding.valueClass = getCodeModel().directClass(javaClassNameFromSchema);
} else {
binding.valueClass = getJavaBindingType(typerefDataSchema.getRef(), enclosingClass).valueClass;
}
}
}
return binding;
}
Aggregations