use of com.google.api.codegen.util.TypeName in project toolkit by googleapis.
the class RubySurfaceNamer method getMessagePropertyTypeName.
/**
* The type name for the message property
*/
@Override
public String getMessagePropertyTypeName(ImportTypeTable importTypeTable, FieldModel fieldModel) {
if (fieldModel.isMap()) {
String keyTypeName = importTypeTable.getFullNameForElementType(fieldModel.getMapKeyField());
String valueTypeName = importTypeTable.getFullNameForElementType(fieldModel.getMapValueField());
return new TypeName(importTypeTable.getFullNameFor(fieldModel), importTypeTable.getNicknameFor(fieldModel), "%s{%i => %i}", new TypeName(keyTypeName), new TypeName(valueTypeName)).getFullName();
}
if (fieldModel.isRepeated()) {
String elementTypeName = importTypeTable.getFullNameForElementType(fieldModel);
return new TypeName(importTypeTable.getFullNameFor(fieldModel), importTypeTable.getNicknameFor(fieldModel), "%s<%i>", new TypeName(elementTypeName)).getFullName();
}
return importTypeTable.getFullNameForElementType(fieldModel);
}
use of com.google.api.codegen.util.TypeName in project toolkit by googleapis.
the class CSharpTypeTable method getContainerTypeName.
@Override
public TypeName getContainerTypeName(String containerFullName, String... elementFullNames) {
TypeName containerTypeName = getTypeName(containerFullName);
TypeName[] elementTypeNames = new TypeName[elementFullNames.length];
for (int i = 0; i < elementTypeNames.length; i++) {
elementTypeNames[i] = getTypeName(elementFullNames[i]);
}
String argPattern = Joiner.on(", ").join(Collections.nCopies(elementTypeNames.length, "%i"));
String pattern = "%s<" + argPattern + ">";
return new TypeName(containerTypeName.getFullName(), containerTypeName.getNickname(), pattern, elementTypeNames);
}
use of com.google.api.codegen.util.TypeName in project toolkit by googleapis.
the class JavaTypeTable method getContainerTypeName.
@Override
public TypeName getContainerTypeName(String containerFullName, String... elementFullNames) {
TypeName containerTypeName = getTypeName(containerFullName);
TypeName[] elementTypeNames = new TypeName[elementFullNames.length];
for (int i = 0; i < elementTypeNames.length; i++) {
elementTypeNames[i] = getTypeName(elementFullNames[i]);
}
String argPattern = Joiner.on(",").join(Collections.nCopies(elementTypeNames.length, "%i"));
String pattern = "%s<" + argPattern + ">";
return new TypeName(containerTypeName.getFullName(), containerTypeName.getNickname(), pattern, elementTypeNames);
}
use of com.google.api.codegen.util.TypeName in project toolkit by googleapis.
the class CSharpModelTypeNameConverter method getTypeName.
@Override
public TypeName getTypeName(ProtoElement elem) {
// Handle nested types, construct the required type prefix
ProtoElement parentEl = elem.getParent();
String shortNamePrefix = "";
while (parentEl != null && parentEl instanceof MessageType) {
shortNamePrefix = parentEl.getSimpleName() + "+Types+" + shortNamePrefix;
parentEl = parentEl.getParent();
}
String prefix = "";
if (parentEl instanceof ProtoFile) {
ProtoFile protoFile = (ProtoFile) parentEl;
String namespace = protoFile.getProto().getOptions().getCsharpNamespace();
if (Strings.isNullOrEmpty(namespace)) {
for (String name : Splitter.on('.').split(parentEl.getFullName())) {
prefix += Name.from(name).toUpperCamelAndDigits() + ".";
}
} else {
prefix = namespace + ".";
}
}
String shortName = shortNamePrefix + elem.getSimpleName();
return new TypeName(prefix + shortName, shortName);
}
use of com.google.api.codegen.util.TypeName in project toolkit by googleapis.
the class CSharpModelTypeNameConverter method getTypeName.
@Override
public TypeName getTypeName(TypeRef type) {
if (type.isMap()) {
TypeName mapTypeName = typeNameConverter.getTypeName("System.Collections.Generic.IDictionary");
TypeName keyTypeName = getTypeNameForElementType(type.getMapKeyField().getType());
TypeName valueTypeName = getTypeNameForElementType(type.getMapValueField().getType());
return new TypeName(mapTypeName.getFullName(), mapTypeName.getNickname(), "%s<%i, %i>", keyTypeName, valueTypeName);
} else if (type.isRepeated()) {
TypeName listTypeName = typeNameConverter.getTypeName("System.Collections.Generic.IEnumerable");
TypeName elementTypeName = getTypeNameForElementType(type);
return new TypeName(listTypeName.getFullName(), listTypeName.getNickname(), "%s<%i>", elementTypeName);
} else {
return getTypeNameForElementType(type);
}
}
Aggregations