Search in sources :

Example 11 with ClassTemplateSpec

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;
}
Also used : ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec) FinderBuilderSpec(com.linkedin.restli.tools.clientgen.builderspec.FinderBuilderSpec)

Example 12 with ClassTemplateSpec

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;
}
Also used : NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) FixedDataSchema(com.linkedin.data.schema.FixedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) ComplexDataSchema(com.linkedin.data.schema.ComplexDataSchema) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) EnumDataSchema(com.linkedin.data.schema.EnumDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) PrimitiveDataSchema(com.linkedin.data.schema.PrimitiveDataSchema) ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec)

Example 13 with ClassTemplateSpec

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);
}
Also used : ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec)

Example 14 with ClassTemplateSpec

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;
}
Also used : ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec)

Example 15 with ClassTemplateSpec

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;
}
Also used : ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) ClassTemplateSpec(com.linkedin.pegasus.generator.spec.ClassTemplateSpec) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema)

Aggregations

ClassTemplateSpec (com.linkedin.pegasus.generator.spec.ClassTemplateSpec)17 NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)5 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)4 DataSchema (com.linkedin.data.schema.DataSchema)4 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)4 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)4 ComplexDataSchema (com.linkedin.data.schema.ComplexDataSchema)3 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)3 FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)3 PrimitiveDataSchema (com.linkedin.data.schema.PrimitiveDataSchema)3 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)3 MapDataSchema (com.linkedin.data.schema.MapDataSchema)2 CustomInfoSpec (com.linkedin.pegasus.generator.spec.CustomInfoSpec)2 ParameterSchema (com.linkedin.restli.restspec.ParameterSchema)2 FinderBuilderSpec (com.linkedin.restli.tools.clientgen.builderspec.FinderBuilderSpec)2 DataMap (com.linkedin.data.DataMap)1 DataSchemaLocation (com.linkedin.data.schema.DataSchemaLocation)1 RecordTemplateSpec (com.linkedin.pegasus.generator.spec.RecordTemplateSpec)1 FinderSchema (com.linkedin.restli.restspec.FinderSchema)1 ActionBuilderSpec (com.linkedin.restli.tools.clientgen.builderspec.ActionBuilderSpec)1