Search in sources :

Example 6 with TypeName

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);
}
Also used : TypeName(com.google.api.codegen.util.TypeName)

Example 7 with TypeName

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);
}
Also used : TypeName(com.google.api.codegen.util.TypeName)

Example 8 with TypeName

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);
}
Also used : TypeName(com.google.api.codegen.util.TypeName)

Example 9 with TypeName

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);
}
Also used : TypeName(com.google.api.codegen.util.TypeName) ProtoElement(com.google.api.tools.framework.model.ProtoElement) ProtoFile(com.google.api.tools.framework.model.ProtoFile) MessageType(com.google.api.tools.framework.model.MessageType)

Example 10 with TypeName

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);
    }
}
Also used : TypeName(com.google.api.codegen.util.TypeName)

Aggregations

TypeName (com.google.api.codegen.util.TypeName)19 MessageType (com.google.api.tools.framework.model.MessageType)2 ProtoElement (com.google.api.tools.framework.model.ProtoElement)2 FieldModel (com.google.api.codegen.config.FieldModel)1 Schema (com.google.api.codegen.discovery.Schema)1 ImportTypeTable (com.google.api.codegen.transformer.ImportTypeTable)1 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)1 TypeNameConverter (com.google.api.codegen.util.TypeNameConverter)1 ProtoFile (com.google.api.tools.framework.model.ProtoFile)1