use of com.google.api.codegen.util.TypeName in project toolkit by googleapis.
the class CSharpModelTypeNameConverter method getImplZeroValue.
@Override
public TypedValue getImplZeroValue(TypeRef type) {
if (type.isMap()) {
TypeName keyTypeName = getTypeNameForElementType(type.getMapKeyField().getType());
TypeName valueTypeName = getTypeNameForElementType(type.getMapValueField().getType());
TypeName emptyMapTypeName = typeNameConverter.getTypeName("Google.Api.Gax.EmptyDictionary");
TypeName genericEmptyMapTypeName = new TypeName(emptyMapTypeName.getFullName(), emptyMapTypeName.getNickname(), "%s<%i, %i>", keyTypeName, valueTypeName);
return TypedValue.create(genericEmptyMapTypeName, "%s.Instance");
} else if (type.isRepeated()) {
TypeName elementTypeName = getTypeNameForElementType(type);
TypeName enumerableTypeName = typeNameConverter.getTypeName("System.Linq.Enumerable");
TypeName emptyTypeName = new TypeName(enumerableTypeName.getFullName(), enumerableTypeName.getNickname(), "%s.Empty<%i>", elementTypeName);
return TypedValue.create(emptyTypeName, "%s()");
} else if (type.isMessage()) {
return TypedValue.create(getTypeName(type), "new %s()");
} else if (type.isEnum()) {
return getEnumValue(type, type.getEnumType().getValues().get(0));
} else {
if (type.getKind() == Type.TYPE_BYTES) {
return TypedValue.create(getTypeName(type), "ByteString.Empty");
} else {
return TypedValue.create(getTypeName(type), PRIMITIVE_ZERO_VALUE.get(type.getKind()));
}
}
}
use of com.google.api.codegen.util.TypeName in project toolkit by googleapis.
the class CSharpModelTypeNameConverter method getEnumValue.
@Override
public TypedValue getEnumValue(TypeRef type, EnumValue value) {
TypeName enumTypeName = getTypeName(type);
List<String> enumTypeNameParts = Splitter.on('+').splitToList(enumTypeName.getNickname());
String enumShortTypeName = enumTypeNameParts.get(enumTypeNameParts.size() - 1);
String enumValueName = enumNamer.getEnumValueName(enumShortTypeName, value.getSimpleName());
return TypedValue.create(enumTypeName, "%s." + enumValueName);
}
use of com.google.api.codegen.util.TypeName 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()) {
TypeName elementTypeName = new TypeName(getResourceTypeNameObject(fieldConfig.getResourceNameConfig()).toUpperCamel());
TypeNameConverter typeNameConverter = getTypeNameConverter();
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;
}
}
}
use of com.google.api.codegen.util.TypeName in project toolkit by googleapis.
the class GoModelTypeNameConverter method getTypeName.
@Override
public TypeName getTypeName(TypeRef type) {
if (type.isMap()) {
TypeName keyTypeName = getTypeNameForElementType(type.getMapKeyField().getType());
TypeName valueTypeName = getTypeNameForElementType(type.getMapValueField().getType());
return new TypeName("", "", "map[%i]%i", keyTypeName, valueTypeName);
} else if (type.isRepeated()) {
TypeName elementTypeName = getTypeNameForElementType(type);
return new TypeName("", "", "[]%i", elementTypeName);
} else {
return getTypeNameForElementType(type);
}
}
use of com.google.api.codegen.util.TypeName in project toolkit by googleapis.
the class JavaSchemaTypeNameConverter method getTypeNameForTypedResourceName.
private TypeName getTypeNameForTypedResourceName(ResourceNameConfig resourceNameConfig, FieldModel type, String typedResourceShortName) {
String packageName = implicitPackageName;
String longName = packageName + "." + typedResourceShortName;
TypeName simpleTypeName = new TypeName(longName, typedResourceShortName);
if (type.isMap()) {
throw new IllegalArgumentException("Map type not supported for typed resource name");
} else if (type.isRepeated()) {
TypeName listTypeName = typeNameConverter.getTypeName("java.util.List");
return new TypeName(listTypeName.getFullName(), listTypeName.getNickname(), "%s<%i>", simpleTypeName);
} else {
return simpleTypeName;
}
}
Aggregations