Search in sources :

Example 11 with Interface

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

the class ProtoInterfaceModel method getMethods.

@Override
public List<MethodModel> getMethods() {
    ImmutableList.Builder<MethodModel> methods = ImmutableList.builder();
    for (Method method : protoInterface.getMethods()) {
        methods.add(new ProtoMethodModel(method));
    }
    SymbolTable symbolTable = protoInterface.getModel().getSymbolTable();
    for (Mixin mixin : protoInterface.getConfig().getMixinsList()) {
        Interface mixinInterface = symbolTable.lookupInterface(mixin.getName());
        for (Method method : mixinInterface.getMethods()) {
            methods.add(new ProtoMethodModel(method));
        }
    }
    return methods.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) SymbolTable(com.google.api.tools.framework.model.SymbolTable) Method(com.google.api.tools.framework.model.Method) Interface(com.google.api.tools.framework.model.Interface) Mixin(com.google.protobuf.Mixin)

Example 12 with Interface

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

the class ProtoInterfaceTransformer method getResourceToEntityNameMap.

@Override
public Map<String, String> getResourceToEntityNameMap(InterfaceModel apiInterface) {
    Interface protoInterface = ((ProtoInterfaceModel) apiInterface).getInterface();
    // Using a map with the string representation of the resource path to avoid duplication
    // of equivalent paths.
    // Using a TreeMap in particular so that the ordering is deterministic
    // (useful for testability).
    Map<String, CollectionPattern> specs = new TreeMap<>();
    for (Method method : protoInterface.getReachableMethods()) {
        for (CollectionPattern collectionPattern : CollectionPattern.getCollectionPatternsFromMethod(method)) {
            String resourcePath = collectionPattern.getTemplatizedResourcePath();
            // If there are multiple field segments with the same resource path, the last
            // one will be used, making the output deterministic. Also, the first field path
            // encountered tends to be simply "name" because it is the corresponding create
            // API method for the type.
            specs.put(resourcePath, collectionPattern);
        }
    }
    Set<String> usedNameSet = new HashSet<>();
    ImmutableMap.Builder<String, String> nameMapBuilder = ImmutableMap.builder();
    for (CollectionPattern collectionPattern : specs.values()) {
        String resourceNameString = collectionPattern.getTemplatizedResourcePath();
        String entityNameString = collectionPattern.getUniqueName(usedNameSet);
        usedNameSet.add(entityNameString);
        nameMapBuilder.put(resourceNameString, entityNameString);
    }
    return nameMapBuilder.build();
}
Also used : ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) Method(com.google.api.tools.framework.model.Method) TreeMap(java.util.TreeMap) Interface(com.google.api.tools.framework.model.Interface) ImmutableMap(com.google.common.collect.ImmutableMap) HashSet(java.util.HashSet)

Example 13 with Interface

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

the class PythonGapicSurfaceTransformer method topLevelRequireViews.

private List<VersionIndexRequireView> topLevelRequireViews(Model model, GapicProductConfig productConfig, SurfaceNamer namer) {
    ImmutableList.Builder<VersionIndexRequireView> views = ImmutableList.builder();
    Iterable<Interface> apiInterfaces = new InterfaceView().getElementIterable(model);
    for (Interface apiInterface : apiInterfaces) {
        views.add(VersionIndexRequireView.newBuilder().clientName(namer.getApiWrapperClassName(productConfig.getInterfaceConfig(apiInterface))).localName(namer.getApiWrapperVariableName(productConfig.getInterfaceConfig(apiInterface))).fileName(namer.getNotImplementedString("VersionIndexRequireView.fileName")).build());
    }
    return views.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) InterfaceView(com.google.api.codegen.InterfaceView) Interface(com.google.api.tools.framework.model.Interface) VersionIndexRequireView(com.google.api.codegen.viewmodel.metadata.VersionIndexRequireView)

Example 14 with Interface

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

the class PythonImportSectionTransformer method generateTopLevelEntryPointAppImports.

private List<ImportFileView> generateTopLevelEntryPointAppImports(Model model, GapicProductConfig productConfig, SurfaceNamer namer, boolean packageHasEnums) {
    Set<ImportFileView> imports = new TreeSet<>(importFileViewComparator());
    for (Interface apiInterface : new InterfaceView().getElementIterable(model)) {
        imports.add(createImport(namer.getVersionedDirectoryNamespace(), namer.getApiWrapperClassName(productConfig.getInterfaceConfig(apiInterface))));
    }
    if (packageHasEnums) {
        imports.add(createImport(namer.getVersionedDirectoryNamespace(), "enums"));
    }
    imports.add(createImport(namer.getVersionedDirectoryNamespace(), "types"));
    return ImmutableList.<ImportFileView>builder().addAll(imports).build();
}
Also used : ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) TreeSet(java.util.TreeSet) InterfaceView(com.google.api.codegen.InterfaceView) Interface(com.google.api.tools.framework.model.Interface)

Example 15 with Interface

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

the class RubyGapicSurfaceDocTransformer method generateTocModuleView.

private TocModuleView generateTocModuleView(ApiModel model, ProtoFile file, ProductConfig productConfig, SurfaceNamer namer, String moduleName) {
    RubyPackageMetadataTransformer metadataTransformer = new RubyPackageMetadataTransformer(packageConfig);
    RubyPackageMetadataNamer packageNamer = new RubyPackageMetadataNamer(productConfig.getPackageName());
    String packageFilePath = file.getFullName().replace(".", File.separator);
    ImmutableList.Builder<TocContentView> tocContents = ImmutableList.builder();
    for (Interface apiInterface : file.getReachableInterfaces()) {
        String description = RubyUtil.getSentence(namer.getDocLines(GapicParser.getDocString(apiInterface)));
        InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(new ProtoInterfaceModel(apiInterface));
        tocContents.add(metadataTransformer.generateTocContent(description, packageNamer, packageFilePath, namer.getApiWrapperClassName(interfaceConfig)));
    }
    tocContents.add(metadataTransformer.generateTocContent("Data types for " + productConfig.getPackageName(), packageNamer, packageFilePath, "Data Types"));
    return TocModuleView.newBuilder().moduleName(moduleName).fullName(model.getTitle()).contents(tocContents.build()).build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ProtoInterfaceModel(com.google.api.codegen.config.ProtoInterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) TocContentView(com.google.api.codegen.viewmodel.metadata.TocContentView) Interface(com.google.api.tools.framework.model.Interface)

Aggregations

Interface (com.google.api.tools.framework.model.Interface)17 InterfaceView (com.google.api.codegen.InterfaceView)7 ImmutableList (com.google.common.collect.ImmutableList)5 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)3 Method (com.google.api.tools.framework.model.Method)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 GapicInterfaceConfig (com.google.api.codegen.config.GapicInterfaceConfig)2 GapicMethodConfig (com.google.api.codegen.config.GapicMethodConfig)2 ProtoInterfaceModel (com.google.api.codegen.config.ProtoInterfaceModel)2 TreeSet (java.util.TreeSet)2 ConfigProto (com.google.api.codegen.ConfigProto)1 InterfaceConfigProto (com.google.api.codegen.InterfaceConfigProto)1 MethodConfigProto (com.google.api.codegen.MethodConfigProto)1 ClientConfigGapicContext (com.google.api.codegen.clientconfig.ClientConfigGapicContext)1 ClientConfigSnippetSetRunner (com.google.api.codegen.clientconfig.ClientConfigSnippetSetRunner)1 PhpClientConfigGapicContext (com.google.api.codegen.clientconfig.php.PhpClientConfigGapicContext)1 MethodConfig (com.google.api.codegen.config.MethodConfig)1 MethodModel (com.google.api.codegen.config.MethodModel)1 NodeJSCodePathMapper (com.google.api.codegen.nodejs.NodeJSCodePathMapper)1 PhpGapicCodePathMapper (com.google.api.codegen.php.PhpGapicCodePathMapper)1