Search in sources :

Example 1 with SnippetsFileView

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

the class CSharpGapicSnippetsTransformer method transform.

@Override
public List<ViewModel> transform(ApiModel model, GapicProductConfig productConfig) {
    List<ViewModel> surfaceDocs = new ArrayList<>();
    SurfaceNamer namer = new CSharpSurfaceNamer(productConfig.getPackageName());
    for (InterfaceModel apiInterface : model.getInterfaces()) {
        GapicInterfaceContext context = GapicInterfaceContext.create(apiInterface, productConfig, csharpCommonTransformer.createTypeTable(namer.getExamplePackageName()), namer, new CSharpFeatureConfig());
        csharpCommonTransformer.addCommonImports(context);
        context.getImportTypeTable().saveNicknameFor("Google.Protobuf.Bytestring");
        context.getImportTypeTable().saveNicknameFor("System.Linq.__import__");
        SnippetsFileView snippets = generateSnippets(context);
        surfaceDocs.add(snippets);
    }
    return surfaceDocs;
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ArrayList(java.util.ArrayList) GapicInterfaceContext(com.google.api.codegen.transformer.GapicInterfaceContext) ViewModel(com.google.api.codegen.viewmodel.ViewModel) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) SnippetsFileView(com.google.api.codegen.viewmodel.SnippetsFileView)

Example 2 with SnippetsFileView

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

the class CSharpGapicSnippetsTransformer method generateSnippets.

private SnippetsFileView generateSnippets(GapicInterfaceContext context) {
    SurfaceNamer namer = context.getNamer();
    String name = namer.getApiSnippetsClassName(context.getInterfaceConfig());
    SnippetsFileView.Builder snippetsBuilder = SnippetsFileView.newBuilder();
    snippetsBuilder.templateFileName(SNIPPETS_TEMPLATE_FILENAME);
    String outputPath = pathMapper.getOutputPath(context.getInterface().getFullName(), context.getProductConfig());
    snippetsBuilder.outputPath(outputPath + File.separator + name.replace("Generated", "") + ".g.cs");
    snippetsBuilder.name(name);
    snippetsBuilder.snippetMethods(generateMethods(context));
    // must be done as the last step to catch all imports
    snippetsBuilder.fileHeader(fileHeaderTransformer.generateFileHeader(context));
    return snippetsBuilder.build();
}
Also used : SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) SnippetsFileView(com.google.api.codegen.viewmodel.SnippetsFileView)

Aggregations

SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)2 SnippetsFileView (com.google.api.codegen.viewmodel.SnippetsFileView)2 InterfaceModel (com.google.api.codegen.config.InterfaceModel)1 GapicInterfaceContext (com.google.api.codegen.transformer.GapicInterfaceContext)1 ViewModel (com.google.api.codegen.viewmodel.ViewModel)1 ArrayList (java.util.ArrayList)1