public FileHeaderView generateFileHeader(TransformationContext context) { return generateFileHeader(context, null); }
public FileHeaderView generateFileHeader(TransformationContext context, String className) { return generateFileHeader( context.getProductConfig(), importSectionTransformer.generateImportSection(context, className), context.getNamer()); }
private SimpleInitFileView generateCsproj(GapicInterfaceContext context) { GapicProductConfig productConfig = context.getProductConfig(); String outputPath = pathMapper.getOutputPath(context.getInterface().getFullName(), productConfig); return SimpleInitFileView.create( templateFilename, outputPath + File.separator + productConfig.getPackageName() + fileBaseSuffix, fileHeaderTransformer.generateFileHeader(context)); } }
private ViewModel generateNoxFile(ApiModel model, GapicProductConfig productConfig) { PackageMetadataNamer namer = new PackageMetadataNamer(); SurfaceNamer surfaceNamer = new PythonSurfaceNamer(productConfig.getPackageName()); String outputPath = "nox.py"; return generateMetadataView( model, productConfig, NOX_TEMPLATE_FILE, namer, surfaceNamer, outputPath) .fileHeader( fileHeaderTransformer.generateFileHeader( productConfig, importSectionTransformer.generateNoxImportSection(), new PythonSurfaceNamer(productConfig.getPackageName()))) .build(); }
private ViewModel generateTypesView(Model model, GapicProductConfig productConfig) { SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName()); ImportSectionView imports = importSectionTransformer.generateTypesImportSection(model, productConfig); return VersionIndexView.newBuilder() .templateFileName(TYPES_TEMPLATE_FILENAME) .outputPath(typesOutputFile(namer)) .requireViews(ImmutableList.<VersionIndexRequireView>of()) .apiVersion(namer.getApiWrapperModuleVersion()) .namespace(namer.getVersionedDirectoryNamespace()) .fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, imports, namer)) .build(); }
private GrpcDocView generateEnumView( GapicProductConfig productConfig, ModelTypeTable typeTable, SurfaceNamer namer, List<ProtoFile> files) { String subPath = pathMapper.getOutputPath(null, productConfig); GrpcDocView.Builder enumFile = GrpcDocView.newBuilder(); enumFile.templateFileName(ENUM_TEMPLATE_FILENAME); enumFile.outputPath(subPath + File.separator + "enums.py"); enumFile.fileHeader( fileHeaderTransformer.generateFileHeader( productConfig, ImportSectionView.newBuilder().build(), namer)); enumFile.elementDocs(generateEnumFileElements(typeTable, namer, files)); return enumFile.build(); }
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(); }
private StaticLangApiMessageFileView generateSchemaFile( SchemaTransformationContext context, StaticLangApiMessageView messageView) { StaticLangApiMessageFileView.Builder apiFile = StaticLangApiMessageFileView.newBuilder(); apiFile.templateFileName(SCHEMA_TEMPLATE_FILENAME); addApiImports(context.getSchemaTypeTable()); apiFile.schema(messageView); String outputPath = pathMapper.getOutputPath(null, context.getDocContext().getProductConfig()); apiFile.outputPath(outputPath + File.separator + messageView.innerTypeName() + ".java"); // must be done as the last step to catch all imports apiFile.fileHeader(fileHeaderTransformer.generateFileHeader(context)); return apiFile.build(); }
private StaticLangApiMessageFileView generateRequestFile( SchemaTransformationContext context, StaticLangApiMessageView messageView) { StaticLangApiMessageFileView.Builder apiFile = StaticLangApiMessageFileView.newBuilder(); apiFile.templateFileName(REQUEST_TEMPLATE_FILENAME); addApiImports(context.getImportTypeTable()); apiFile.schema(messageView); String outputPath = pathMapper.getOutputPath(null, context.getDocContext().getProductConfig()); apiFile.outputPath(outputPath + File.separator + messageView.typeName() + ".java"); // must be done as the last step to catch all imports apiFile.fileHeader(fileHeaderTransformer.generateFileHeader(context)); return apiFile.build(); }
private StaticLangApiResourceNameFileView generateResourceNameFile( SchemaTransformationContext context, StaticLangApiResourceNameView messageView) { StaticLangApiResourceNameFileView.Builder apiFile = StaticLangApiResourceNameFileView.newBuilder(); apiFile.templateFileName(RESOURCE_NAME_TEMPLATE_FILENAME); addResourceNameClassImports(context.getImportTypeTable()); apiFile.resourceName(messageView); String outputPath = pathMapper.getOutputPath(null, context.getDocContext().getProductConfig()); apiFile.outputPath(outputPath + File.separator + messageView.typeName() + ".java"); apiFile.fileHeader(fileHeaderTransformer.generateFileHeader(context, messageView.typeName())); return apiFile.build(); }
private StaticLangFileView<StaticLangApiView> generateApiFile( InterfaceContext context, GapicProductConfig productConfig) { StaticLangFileView.Builder<StaticLangApiView> apiFile = StaticLangFileView.newBuilder(); apiFile.templateFileName(API_TEMPLATE_FILENAME); apiFile.classView(generateApiClass(context, productConfig)); String outputPath = pathMapper.getOutputPath( context.getInterfaceModel().getFullName(), context.getProductConfig()); String className = context.getNamer().getApiWrapperClassName(context.getInterfaceConfig()); apiFile.outputPath(outputPath + File.separator + className + ".java"); // must be done as the last step to catch all imports apiFile.fileHeader(fileHeaderTransformer.generateFileHeader(context, className)); return apiFile.build(); }
private StaticLangFileView<StaticLangStubInterfaceView> generateStubInterfaceFile( InterfaceContext context, GapicProductConfig productConfig) { StaticLangFileView.Builder<StaticLangStubInterfaceView> fileView = StaticLangFileView.newBuilder(); fileView.classView(generateStubInterface(context, productConfig)); fileView.templateFileName(STUB_INTERFACE_TEMPLATE_FILENAME); String outputPath = pathMapper.getOutputPath( context.getInterfaceModel().getFullName(), context.getProductConfig()); String className = context.getNamer().getApiStubInterfaceName(context.getInterfaceConfig()); fileView.outputPath(outputPath + File.separator + className + ".java"); // must be done as the last step to catch all imports fileView.fileHeader(fileHeaderTransformer.generateFileHeader(context, className)); return fileView.build(); }
private StaticLangFileView<StaticLangStubSettingsView> generateStubSettingsFile( InterfaceContext context, GapicProductConfig productConfig, StaticLangApiMethodView exampleApiMethod) { StaticLangFileView.Builder<StaticLangStubSettingsView> settingsFile = StaticLangFileView.newBuilder(); settingsFile.classView(generateStubSettingsClass(context, productConfig, exampleApiMethod)); settingsFile.templateFileName(STUB_SETTINGS_TEMPLATE_FILENAME); String outputPath = pathMapper.getOutputPath( context.getInterfaceModel().getFullName(), context.getProductConfig()); String className = context.getNamer().getApiStubSettingsClassName(context.getInterfaceConfig()); settingsFile.outputPath(outputPath + File.separator + className + ".java"); // must be done as the last step to catch all imports settingsFile.fileHeader(fileHeaderTransformer.generateFileHeader(context, className)); return settingsFile.build(); }
private StaticLangFileView<StaticLangCallableFactoryView> generateCallableFactoryClassFile( InterfaceContext context, GapicProductConfig productConfig) { StaticLangFileView.Builder<StaticLangCallableFactoryView> fileView = StaticLangFileView.newBuilder(); fileView.classView(generateCallableFactoryClass(context, productConfig)); fileView.templateFileName(callableFactoryTemplateFilename); String outputPath = pathMapper.getOutputPath( context.getInterfaceModel().getFullName(), context.getProductConfig()); String className = context .getNamer() .getCallableFactoryClassName( context.getInterfaceConfig(), productConfig.getTransportProtocol()); fileView.outputPath(outputPath + File.separator + className + ".java"); // must be done as the last step to catch all imports fileView.fileHeader(fileHeaderTransformer.generateFileHeader(context, className)); return fileView.build(); }
private ViewModel generateTopLevelEntryPoint( ProtoApiModel apiModel, ProductConfig productConfig) { SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName()); boolean packageHasEnums = packageHasEnums(apiModel.getProtoModel()); ImportSectionView imports = importSectionTransformer.generateTopLeveEntryPointImportSection( apiModel, productConfig, namer, packageHasEnums); return VersionIndexView.newBuilder() .templateFileName(TOP_LEVEL_ENTRY_POINT_FILENAME) .outputPath(topLevelEntryPointFileName(namer)) .requireViews(topLevelRequireViews(apiModel, productConfig, namer)) .apiVersion(namer.getApiWrapperModuleVersion()) .namespace(namer.getVersionedDirectoryNamespace()) .fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, imports, namer)) .packageHasEnums(packageHasEnums) .build(); }
private MockServiceView createMockServiceView(InterfaceContext context) { addMockServiceImports(context); SurfaceNamer namer = context.getNamer(); String outputPath = pathMapper.getOutputPath( context.getInterfaceModel().getFullName(), context.getProductConfig()); String name = namer.getMockServiceClassName(context.getInterfaceModel()); MockServiceView.Builder mockService = MockServiceView.newBuilder(); mockService.name(name); mockService.serviceImplClassName(namer.getMockGrpcServiceImplName(context.getInterfaceModel())); mockService.outputPath(namer.getSourceFilePath(outputPath, name)); mockService.templateFileName(MOCK_SERVICE_FILE); // Imports must be done as the last step to catch all imports. FileHeaderView fileHeader = fileHeaderTransformer.generateFileHeader(context); mockService.fileHeader(fileHeader); return mockService.build(); }
private ViewModel generateVersionedInitView(ProtoApiModel apiModel, ProductConfig productConfig) { SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName()); boolean packageHasEnums = packageHasEnums(apiModel.getProtoModel()); ImportSectionView imports = importSectionTransformer.generateVersionedInitImportSection( apiModel, productConfig, namer, packageHasEnums); return VersionIndexView.newBuilder() .templateFileName(VERSIONED_INIT_TEMPLATE_FILENAME) .outputPath(versionedInitOutputFile(namer)) .requireViews(versionedInitRequireViews(apiModel, productConfig, namer)) .apiVersion(namer.getApiWrapperModuleVersion()) .namespace(namer.getVersionedDirectoryNamespace()) .fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, imports, namer)) .packageHasEnums(packageHasEnums) .build(); }
private StaticLangApiAndSettingsFileView generateApiAndSettingsView( GapicInterfaceContext context) { StaticLangApiAndSettingsFileView.Builder fileView = StaticLangApiAndSettingsFileView.newBuilder(); fileView.templateFileName(API_TEMPLATE_FILENAME); fileView.api(generateApiClass(context)); fileView.settings(generateSettingsClass(context)); String outputPath = pathMapper.getOutputPath(context.getInterface().getFullName(), context.getProductConfig()); String name = context.getNamer().getApiWrapperClassName(context.getInterfaceConfig()); fileView.outputPath(outputPath + File.separator + name + ".cs"); // must be done as the last step to catch all imports csharpCommonTransformer.addCommonImports(context); context.getImportTypeTable().saveNicknameFor("Google.Protobuf.SomeKindOfProtobuf"); fileView.fileHeader(fileHeaderTransformer.generateFileHeader(context)); return fileView.build(); }
public FileHeaderView generateFileHeader( ProductConfig productConfig, ImportSectionView importSection, SurfaceNamer namer, ImmutableList<String> apiModules) { FileHeaderView.Builder fileHeader = FileHeaderView.newBuilder(); fileHeader.copyrightLines(productConfig.getCopyrightLines()); fileHeader.licenseLines(productConfig.getLicenseLines()); fileHeader.packageName(namer.getPackageName()); fileHeader.examplePackageName(namer.getExamplePackageName()); fileHeader.localPackageName(namer.getLocalPackageName()); fileHeader.localExamplePackageName(namer.getLocalExamplePackageName()); fileHeader.importSection(importSection); fileHeader.version(namer.getApiWrapperModuleVersion()); fileHeader.modules(apiModules); return fileHeader.build(); } }
private ViewModel generateDoc(ProtoFile file, GapicProductConfig productConfig) { ModelTypeTable typeTable = new ModelTypeTable( new JSTypeTable(productConfig.getPackageName()), new NodeJSModelTypeNameConverter(productConfig.getPackageName())); // Use file path for package name to get file-specific package instead of package for the API. SurfaceNamer namer = new NodeJSSurfaceNamer(productConfig.getPackageName(), NodeJSUtils.isGcloud(productConfig)); JSCommentReformatter commentReformatter = new JSCommentReformatter(); GrpcDocView.Builder doc = GrpcDocView.newBuilder(); doc.templateFileName(DOC_TEMPLATE_FILENAME); doc.outputPath(getOutputPath(namer, file)); doc.fileHeader( fileHeaderTransformer.generateFileHeader( productConfig, ImportSectionView.newBuilder().build(), namer)); doc.elementDocs( grpcElementDocTransformer.generateElementDocs(productConfig, typeTable, namer, file)); return doc.build(); }