Search in sources :

Example 1 with ImportFileView

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

the class StandardImportSectionTransformer method generateImportSection.

public ImportSectionView generateImportSection(Map<String, TypeAlias> typeImports, String className) {
    ImmutableList.Builder<ImportFileView> appImports = ImmutableList.builder();
    for (TypeAlias alias : typeImports.values()) {
        if (excludeAppImport(alias, className)) {
            continue;
        }
        ImportTypeView.Builder imp = ImportTypeView.newBuilder();
        imp.fullName(alias.getFullName());
        imp.nickname(alias.getNickname());
        imp.type(alias.getImportType());
        appImports.add(ImportFileView.newBuilder().types(ImmutableList.of(imp.build())).build());
    }
    return ImportSectionView.newBuilder().appImports(appImports.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 2 with ImportFileView

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

the class NodeJSImportSectionTransformer method generateExternalImports.

private List<ImportFileView> generateExternalImports(InterfaceContext context) {
    ImmutableList.Builder<ImportFileView> imports = ImmutableList.builder();
    InterfaceModel apiInterface = context.getInterfaceModel();
    InterfaceConfig interfaceConfig = context.getInterfaceConfig();
    String configModule = context.getNamer().getClientConfigPath(interfaceConfig);
    imports.add(createImport("gapicConfig", "./" + configModule));
    imports.add(createImport("gax", "google-gax"));
    imports.add(createImport("merge", "lodash.merge"));
    imports.add(createImport("path", "path"));
    if (context.getInterfaceConfig().hasLongRunningOperations() || context.getInterfaceConfig().hasBatchingMethods()) {
        imports.add(createImport("protobuf", "protobufjs"));
    }
    return imports.build();
}
Also used : InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList)

Example 3 with ImportFileView

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

the class PhpImportSectionTransformer method generateImportSection.

/**
 * Package-private for use in PhpGapicSurfaceTestTransformer
 */
ImportSectionView generateImportSection(Map<String, TypeAlias> typeImports) {
    ImmutableList.Builder<ImportFileView> appImports = ImmutableList.builder();
    for (Map.Entry<String, TypeAlias> entry : typeImports.entrySet()) {
        String key = entry.getKey();
        TypeAlias alias = entry.getValue();
        // Remove leading backslash because it is not required by PHP use statements
        String fullName = key.startsWith("\\") ? key.substring(1) : key;
        ImportTypeView.Builder imp = ImportTypeView.newBuilder();
        imp.fullName(fullName);
        imp.nickname(alias.getNickname());
        imp.type(alias.getImportType());
        appImports.add(ImportFileView.newBuilder().types(ImmutableList.of(imp.build())).build());
    }
    return ImportSectionView.newBuilder().appImports(appImports.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) Map(java.util.Map)

Example 4 with ImportFileView

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

the class PythonImportSectionTransformer method generateMainAppImports.

private List<ImportFileView> generateMainAppImports(InterfaceContext context) {
    List<ImportFileView> imports = generateFileHeaderAppImports(context.getImportTypeTable().getImports());
    SurfaceNamer namer = context.getNamer();
    imports.add(createImport(namer.getPackageName(), namer.getClientConfigName(context.getInterfaceConfig())));
    Collections.sort(imports, importFileViewComparator());
    return imports;
}
Also used : ImportFileView(com.google.api.codegen.viewmodel.ImportFileView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer)

Example 5 with ImportFileView

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

the class PythonImportSectionTransformer method generateVersionedInitAppImports.

private List<ImportFileView> generateVersionedInitAppImports(Model model, GapicProductConfig productConfig, SurfaceNamer namer, boolean packageHasEnums) {
    Set<ImportFileView> imports = new TreeSet<>(importFileViewComparator());
    for (Interface apiInterface : new InterfaceView().getElementIterable(model)) {
        imports.add(createImport(productConfig.getPackageName(), namer.getApiWrapperVariableName(productConfig.getInterfaceConfig(apiInterface))));
    }
    if (packageHasEnums) {
        imports.add(createImport(productConfig.getPackageName(), "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)

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