Search in sources :

Example 1 with TypeNameConverter

use of com.google.api.codegen.util.TypeNameConverter in project toolkit by googleapis.

the class DiscoGapicNamer method getRequestMessageFullName.

/**
 * Get the language-independent request message name from a method.
 */
public String getRequestMessageFullName(Method method, String defaultPackageName) {
    // TODO remove reference to Java formatting - it is accidental that the fully-qualified
    // message type matches the fully-qualified Java type
    TypeNameConverter typeNameConverter = new JavaTypeTable(defaultPackageName);
    JavaNameFormatter nameFormatter = new JavaNameFormatter();
    return typeNameConverter.getTypeNameInImplicitPackage(nameFormatter.publicClassName(DiscoGapicParser.getRequestName(method))).getFullName();
}
Also used : JavaNameFormatter(com.google.api.codegen.util.java.JavaNameFormatter) JavaTypeTable(com.google.api.codegen.util.java.JavaTypeTable) TypeNameConverter(com.google.api.codegen.util.TypeNameConverter)

Example 2 with TypeNameConverter

use of com.google.api.codegen.util.TypeNameConverter in project toolkit by googleapis.

the class CSharpSurfaceNamer method getOptionalFieldDefaultValue.

@Override
public String getOptionalFieldDefaultValue(FieldConfig fieldConfig, MethodContext context) {
    // Need to provide defaults for primitives, enums, strings, and repeated (including maps)
    FieldModel type = fieldConfig.getField();
    if (context.getFeatureConfig().useResourceNameFormatOption(fieldConfig)) {
        if (type.isRepeated()) {
            TypeNameConverter typeNameConverter = getTypeNameConverter();
            TypeName elementTypeName = typeNameConverter.getTypeName(getResourceTypeName(fieldConfig.getResourceNameConfig()));
            TypeName enumerableTypeName = typeNameConverter.getTypeName("System.Linq.Enumerable");
            TypeName emptyTypeName = new TypeName(enumerableTypeName.getFullName(), enumerableTypeName.getNickname(), "%s.Empty<%i>", elementTypeName);
            return TypedValue.create(emptyTypeName, "%s()").getValueAndSaveTypeNicknameIn((CSharpTypeTable) typeNameConverter);
        } else {
            return null;
        }
    } else {
        if (type.isPrimitive() || type.isEnum() || type.isRepeated()) {
            return context.getTypeTable().getImplZeroValueAndSaveNicknameFor(type);
        } else {
            return null;
        }
    }
}
Also used : TypeName(com.google.api.codegen.util.TypeName) TypeNameConverter(com.google.api.codegen.util.TypeNameConverter) FieldModel(com.google.api.codegen.config.FieldModel)

Aggregations

TypeNameConverter (com.google.api.codegen.util.TypeNameConverter)2 FieldModel (com.google.api.codegen.config.FieldModel)1 TypeName (com.google.api.codegen.util.TypeName)1 JavaNameFormatter (com.google.api.codegen.util.java.JavaNameFormatter)1 JavaTypeTable (com.google.api.codegen.util.java.JavaTypeTable)1