Search in sources :

Example 1 with ProtoFile

use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.

the class NodeJSGapicSurfaceDocTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel apiModel, GapicProductConfig productConfig) {
    Model model = ((ProtoApiModel) apiModel).getProtoModel();
    ImmutableList.Builder<ViewModel> surfaceDocs = ImmutableList.builder();
    for (ProtoFile file : new ProtoFileView().getElementIterable(model)) {
        surfaceDocs.add(generateDoc(file, productConfig));
    }
    return surfaceDocs.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ProtoFileView(com.google.api.codegen.ProtoFileView) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) ApiModel(com.google.api.codegen.config.ApiModel) ViewModel(com.google.api.codegen.viewmodel.ViewModel) Model(com.google.api.tools.framework.model.Model) ProtoFile(com.google.api.tools.framework.model.ProtoFile) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 2 with ProtoFile

use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.

the class PhpModelTypeNameConverter method getTypeNameString.

/**
 * This function determines the type name as follows: If the proto type name is in TYPE_NAME_MAP,
 * return that value. Else, split on ".", prepend '\' and capitalize each component of the
 * namespace except the message name
 */
private static String getTypeNameString(ProtoElement elem) {
    String fullName = elem.getFullName();
    if (TYPE_NAME_MAP.containsKey(fullName)) {
        return TYPE_NAME_MAP.get(fullName);
    }
    String[] components = fullName.split("\\.");
    String shortName = components[components.length - 1];
    StringBuilder builder = new StringBuilder();
    ProtoElement parentElem = elem.getParent();
    if (parentElem != null && parentElem instanceof ProtoFile) {
        ProtoFile protoFile = (ProtoFile) parentElem;
        String namespace = protoFile.getProto().getOptions().getPhpNamespace();
        if (Strings.isNullOrEmpty(namespace)) {
            for (int index = 0; index < components.length - 1; index++) {
                builder.append('\\').append(components[index].substring(0, 1).toUpperCase()).append(components[index].substring(1));
            }
        } else {
            builder.append('\\').append(CharMatcher.is('\\').trimFrom(namespace));
        }
    }
    builder.append('\\').append(shortName);
    return builder.toString();
}
Also used : ProtoElement(com.google.api.tools.framework.model.ProtoElement) ProtoFile(com.google.api.tools.framework.model.ProtoFile)

Example 3 with ProtoFile

use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.

the class RubyGapicSurfaceDocTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ViewModel> surfaceDocs = ImmutableList.builder();
    for (ProtoFile file : new ProtoFileView().getElementIterable(((ProtoApiModel) model).getProtoModel())) {
        surfaceDocs.add(generateDoc(file, productConfig));
    }
    surfaceDocs.add(generateOverview(model, productConfig));
    return surfaceDocs.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ProtoFileView(com.google.api.codegen.ProtoFileView) ProtoFile(com.google.api.tools.framework.model.ProtoFile) ViewModel(com.google.api.codegen.viewmodel.ViewModel)

Example 4 with ProtoFile

use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.

the class InitCodeTransformer method createInitValueView.

private InitValueView createInitValueView(MethodContext context, FieldConfig fieldConfig, SurfaceNamer namer, ImportTypeTable typeTable, InitCodeNode item, boolean convertToString) {
    SingleResourceNameConfig singleResourceNameConfig;
    switch(fieldConfig.getResourceNameType()) {
        case ANY:
            singleResourceNameConfig = Iterables.get(context.getProductConfig().getSingleResourceNameConfigs(), 0);
            InterfaceModel interfaceModel = context.getInterfaceModel();
            if (interfaceModel instanceof ProtoInterfaceModel) {
                ProtoFile protoFile = ((ProtoInterfaceModel) interfaceModel).getInterface().getFile();
                singleResourceNameConfig = singleResourceNameConfig.toBuilder().setAssignedProtoFile(protoFile).build();
            }
            FieldConfig anyResourceNameFieldConfig = fieldConfig.withResourceNameConfig(singleResourceNameConfig);
            return createResourceNameInitValueView(context, anyResourceNameFieldConfig, item).convertToString(convertToString).build();
        case FIXED:
            throw new UnsupportedOperationException("entity name invalid");
        case ONEOF:
            return createResourceNameOneofInitValueView(context, fieldConfig, item, convertToString);
        case SINGLE:
            return createResourceNameInitValueView(context, fieldConfig, item).convertToString(convertToString).build();
        case NONE:
        // Fall-through
        default:
            throw new UnsupportedOperationException("unexpected entity name type '" + fieldConfig.getResourceNameType() + "'");
    }
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) FieldConfig(com.google.api.codegen.config.FieldConfig) ProtoFile(com.google.api.tools.framework.model.ProtoFile) SingleResourceNameConfig(com.google.api.codegen.config.SingleResourceNameConfig)

Example 5 with ProtoFile

use of com.google.api.tools.framework.model.ProtoFile in project toolkit by googleapis.

the class ProtoFiles method getFilesForMessage.

private static Set<ProtoFile> getFilesForMessage(MessageType messageType, boolean messageOnly) {
    Set<ProtoFile> files = newFileSet();
    files.add(messageType.getFile());
    if (messageOnly) {
        return files;
    }
    for (Field field : messageType.getFields()) {
        TypeRef type = field.getType();
        if (type.isMessage()) {
            files.addAll(getFilesForMessage(type.getMessageType(), type.isCyclic()));
        }
    }
    return files;
}
Also used : Field(com.google.api.tools.framework.model.Field) TypeRef(com.google.api.tools.framework.model.TypeRef) ProtoTypeRef(com.google.api.codegen.config.ProtoTypeRef) ProtoFile(com.google.api.tools.framework.model.ProtoFile)

Aggregations

ProtoFile (com.google.api.tools.framework.model.ProtoFile)19 MessageType (com.google.api.tools.framework.model.MessageType)9 Field (com.google.api.tools.framework.model.Field)5 TypeRef (com.google.api.tools.framework.model.TypeRef)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 ArrayList (java.util.ArrayList)4 ResourceDescriptor (com.google.api.ResourceDescriptor)3 ProtoElement (com.google.api.tools.framework.model.ProtoElement)3 HashSet (java.util.HashSet)3 ProtoFileView (com.google.api.codegen.ProtoFileView)2 ResourceNameMessageConfigProto (com.google.api.codegen.ResourceNameMessageConfigProto)2 ProtoTypeRef (com.google.api.codegen.config.ProtoTypeRef)2 ViewModel (com.google.api.codegen.viewmodel.ViewModel)2 Interface (com.google.api.tools.framework.model.Interface)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 List (java.util.List)2 Map (java.util.Map)2