@Override public String getFullNameFor(InterfaceModel type) { return type.getFullName(); }
@Override public String getFullNameFor(InterfaceModel type) { return type.getFullName(); }
/** True if contains an InterfaceConfig for the specified API interface */ @Override public boolean hasInterfaceConfig(InterfaceModel apiInterface) { return getInterfaceConfigMap().containsKey(apiInterface.getFullName()); }
/** Returns the InterfaceConfig for the given API interface. */ @Override public InterfaceConfig getInterfaceConfig(InterfaceModel apiInterface) { return getInterfaceConfigMap().get(apiInterface.getFullName()); }
@Override public TypeName getTypeName(InterfaceModel interfaceModel) { return new TypeName(interfaceModel.getFullName()); }
@Override public String getGrpcStubCallString(InterfaceModel apiInterface, MethodModel method) { return '/' + apiInterface.getFullName() + '/' + getGrpcMethodName(method); }
public String interfaceName() { return getInterfaceModel().getFullName(); }
public List<GrpcStubView> generateGrpcStubs(InterfaceContext context) { List<GrpcStubView> stubs = new ArrayList<>(); Map<String, InterfaceModel> interfaces = new TreeMap<>(); Map<String, List<MethodModel>> methods = new TreeMap<>(); for (MethodModel method : context.getSupportedMethods()) { InterfaceModel targetInterface = context.asRequestMethodContext(method).getTargetInterface(); interfaces.put(targetInterface.getFullName(), targetInterface); if (methods.containsKey(targetInterface.getFullName())) { methods.get(targetInterface.getFullName()).add(method); } else { methods.put(targetInterface.getFullName(), new ArrayList<>(Arrays.asList(method))); } } for (Map.Entry<String, InterfaceModel> entry : interfaces.entrySet()) { InterfaceModel apiInterface = entry.getValue(); stubs.add(generateGrpcStub(context, apiInterface, methods.get(entry.getKey()))); } return stubs; }
public Map<String, InterfaceModel> getGrpcInterfacesForService( ApiModel model, GapicProductConfig productConfig, InterfaceModel apiInterface) { if (!productConfig.getTransportProtocol().equals(TransportProtocol.GRPC)) { return ImmutableMap.of(); } Map<String, InterfaceModel> interfaces = new LinkedHashMap<>(); interfaces.put(apiInterface.getFullName(), apiInterface); InterfaceConfig interfaceConfig = productConfig.getInterfaceConfig(apiInterface); for (MethodConfig methodConfig : interfaceConfig.getMethodConfigs()) { String reroute = methodConfig.getRerouteToGrpcInterface(); if (!Strings.isNullOrEmpty(reroute)) { InterfaceModel targetInterface = model.getInterface(reroute); interfaces.put(reroute, targetInterface); } } return interfaces; }
@Override public DiscoInterfaceModel getTargetInterface() { return new DiscoInterfaceModel( getInterfaceModel().getFullName(), getSurfaceInterfaceContext().getApiModel()); }
private List<ImportFileView> generateGrpcTransportAppImports(GapicInterfaceContext context) { Map<String, InterfaceModel> interfaces = new TreeMap<>(); for (MethodModel method : context.getSupportedMethods()) { InterfaceModel targetInterface = context.asRequestMethodContext(method).getTargetInterface(); interfaces.put(targetInterface.getFullName(), targetInterface); } ModelTypeTable typeTable = context.getImportTypeTable().cloneEmpty(); for (InterfaceModel targetInterface : interfaces.values()) { context.getNamer().getAndSaveNicknameForGrpcClientTypeName(typeTable, targetInterface); } return generateFileHeaderAppImports(typeTable.getImports()); }
private ListItemConfigNode generateInterfaceNode(int startLine, InterfaceModel apiInterface) { Map<String, String> collectionNameMap = interfaceTransformer.getResourceToEntityNameMap(apiInterface); ListItemConfigNode interfaceNode = new ListItemConfigNode(startLine); FieldConfigNode nameNode = FieldConfigNode.createStringPair(startLine, "name", apiInterface.getFullName()) .setComment(new DefaultComment("The fully qualified name of the API interface.")); interfaceNode.setChild(nameNode); ConfigNode collectionsNode = collectionMerger.generateCollectionsNode(nameNode, collectionNameMap); ConfigNode retryParamsDefNode = retryMerger.generateRetryDefinitionsNode(collectionsNode); methodMerger.generateMethodsNode(interfaceNode, apiInterface, collectionNameMap); return interfaceNode; } }
private SmokeTestClassView createSmokeTestClassView(InterfaceContext context) { String outputPath = pathMapper.getOutputPath( context.getInterfaceModel().getFullName(), context.getProductConfig()); SurfaceNamer namer = context.getNamer(); String name = namer.getSmokeTestClassName(context.getInterfaceConfig()); SmokeTestClassView.Builder testClass = createSmokeTestClassViewBuilder(context); testClass.name(name); testClass.outputPath(namer.getSourceFilePath(outputPath, name)); return testClass.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<StaticLangSettingsView> generateSettingsFile( InterfaceContext context, GapicProductConfig productConfig, StaticLangApiMethodView exampleApiMethod, StaticLangStubSettingsView stubSettingsView) { StaticLangFileView.Builder<StaticLangSettingsView> settingsFile = StaticLangFileView.newBuilder(); settingsFile.classView( generateSettingsClass(context, productConfig, exampleApiMethod, stubSettingsView)); settingsFile.templateFileName(SETTINGS_TEMPLATE_FILENAME); String outputPath = pathMapper.getOutputPath( context.getInterfaceModel().getFullName(), context.getProductConfig()); String className = context.getNamer().getApiSettingsClassName(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 StaticLangFileView<StaticLangRpcStubView> generateRpcStubClassFile( InterfaceContext context, GapicProductConfig productConfig) { StaticLangFileView.Builder<StaticLangRpcStubView> fileView = StaticLangFileView.newBuilder(); fileView.classView(generateRpcStubClass(context, productConfig)); fileView.templateFileName(rpcStubTemplateFilename); String outputPath = pathMapper.getOutputPath( context.getInterfaceModel().getFullName(), context.getProductConfig()); String className = context .getNamer() .getApiRpcStubClassName( context.getInterfaceConfig().getInterfaceModel(), 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 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(); }