Search in sources :

Example 6 with ImportFileView

use of com.google.api.codegen.viewmodel.ImportFileView in project toolkit by googleapis.

the class RubyImportSectionTransformer method generateRakefileAcceptanceTaskImportSection.

public ImportSectionView generateRakefileAcceptanceTaskImportSection(List<GapicInterfaceContext> contexts) {
    List<ImportFileView> none = ImmutableList.of();
    ImportSectionView.Builder importSection = ImportSectionView.newBuilder();
    importSection.standardImports(none);
    importSection.externalImports(none);
    Set<ImportFileView> credentialsImports = new HashSet<>();
    for (GapicInterfaceContext context : contexts) {
        credentialsImports.add(createImport(context.getNamer().getCredentialsClassImportName()));
    }
    importSection.appImports(ImmutableList.copyOf(credentialsImports));
    importSection.serviceImports(none);
    return importSection.build();
}
Also used : ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView) HashSet(java.util.HashSet)

Example 7 with ImportFileView

use of com.google.api.codegen.viewmodel.ImportFileView in project toolkit by googleapis.

the class RubyImportSectionTransformer method generateTestAppImports.

private List<ImportFileView> generateTestAppImports(GapicInterfaceContext context) {
    ImmutableList.Builder<ImportFileView> imports = ImmutableList.builder();
    SurfaceNamer namer = context.getNamer();
    if (RubyUtil.hasMajorVersion(context.getProductConfig().getPackageName())) {
        imports.add(createImport(namer.getTopLevelIndexFileImportName()));
    } else {
        imports.add(createImport(namer.getVersionIndexFileImportName()));
    }
    // Import the client class directly so the client class is in scope for the static class methods
    // used in the in the init code such as the path methods. This is not necessary for method
    // samples since the client is initialized before the init code, and the initialization
    // requires the client class file.
    imports.add(createImport(namer.getServiceFileName(context.getInterfaceConfig())));
    for (String filename : generateImportFilenames(context)) {
        imports.add(createImport(namer.getServiceFileImportName(filename)));
    }
    if (context.getInterfaceConfig().hasLongRunningOperations()) {
        imports.add(createImport("google/longrunning/operations_pb"));
    }
    return imports.build();
}
Also used : ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) ImmutableList(com.google.common.collect.ImmutableList) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 8 with ImportFileView

use of com.google.api.codegen.viewmodel.ImportFileView in project toolkit by googleapis.

the class GoImportSectionTransformer method generateImportSection.

public ImportSectionView generateImportSection(Map<String, TypeAlias> typeImports) {
    ImmutableList.Builder<ImportFileView> standardImports = ImmutableList.builder();
    ImmutableList.Builder<ImportFileView> externalImports = ImmutableList.builder();
    for (TypeAlias alias : typeImports.values()) {
        String importPath = alias.getFullName();
        ImportTypeView.Builder imp = ImportTypeView.newBuilder();
        imp.fullName('"' + importPath + '"');
        imp.nickname(alias.getNickname());
        imp.type(alias.getImportType());
        ImmutableList.Builder<ImportFileView> target = isStandardImport(importPath) ? standardImports : externalImports;
        target.add(ImportFileView.newBuilder().types(ImmutableList.of(imp.build())).build());
    }
    return ImportSectionView.newBuilder().standardImports(standardImports.build()).externalImports(externalImports.build()).build();
}
Also used : ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) ImmutableList(com.google.common.collect.ImmutableList) ImportTypeView(com.google.api.codegen.viewmodel.ImportTypeView) TypeAlias(com.google.api.codegen.util.TypeAlias)

Example 9 with ImportFileView

use of com.google.api.codegen.viewmodel.ImportFileView 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 10 with ImportFileView

use of com.google.api.codegen.viewmodel.ImportFileView in project toolkit by googleapis.

the class PythonImportSectionTransformer method generateTypesProtoImports.

private List<ImportFileView> generateTypesProtoImports(Model model, GapicProductConfig productConfig) {
    ModelTypeTable typeTable = emptyTypeTable(productConfig);
    Set<ImportFileView> imports = new TreeSet<>(importFileViewComparator());
    // Save proto file import names to the type table for disambiguation.
    List<ProtoFile> protoFileDependencies = model.getFiles();
    populateTypeTable(protoFileDependencies, typeTable);
    // Get disambiguated imports.
    for (Map.Entry<String, TypeAlias> entry : typeTable.getImports().entrySet()) {
        imports.add(generateAppImport(entry.getKey(), entry.getValue().getNickname()));
    }
    return ImmutableList.<ImportFileView>builder().addAll(imports).build();
}
Also used : ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) TreeSet(java.util.TreeSet) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) ProtoFile(com.google.api.tools.framework.model.ProtoFile) TypeAlias(com.google.api.codegen.util.TypeAlias) Map(java.util.Map)

Aggregations

ImportFileView (com.google.api.codegen.viewmodel.ImportFileView)10 ImmutableList (com.google.common.collect.ImmutableList)5 TypeAlias (com.google.api.codegen.util.TypeAlias)4 ImportTypeView (com.google.api.codegen.viewmodel.ImportTypeView)3 TreeSet (java.util.TreeSet)3 InterfaceView (com.google.api.codegen.InterfaceView)2 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)2 Interface (com.google.api.tools.framework.model.Interface)2 Map (java.util.Map)2 InterfaceConfig (com.google.api.codegen.config.InterfaceConfig)1 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)1 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)1 ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)1 ProtoFile (com.google.api.tools.framework.model.ProtoFile)1 HashSet (java.util.HashSet)1