use of com.google.api.codegen.config.MethodContext in project toolkit by googleapis.
the class CSharpGapicClientTransformer method generateModifyMethods.
private List<ModifyMethodView> generateModifyMethods(GapicInterfaceContext context) {
SurfaceNamer namer = context.getNamer();
List<ModifyMethodView> modifyMethods = new ArrayList<>();
Set<String> modifyTypeNames = new HashSet<>();
for (MethodModel method : csharpCommonTransformer.getSupportedMethods(context)) {
MethodContext methodContext = context.asRequestMethodContext(method);
String inputTypeFullName = methodContext.getMethodModel().getInputFullName();
if (modifyTypeNames.contains(inputTypeFullName)) {
continue;
}
modifyTypeNames.add(inputTypeFullName);
MethodConfig methodConfig = methodContext.getMethodConfig();
ModifyMethodView.Builder builder = ModifyMethodView.builder();
builder.name(namer.getModifyMethodName(methodContext));
builder.requestTypeName(method.getAndSaveRequestTypeName(context.getImportTypeTable(), context.getNamer()));
builder.grpcStreamingType(methodConfig.getGrpcStreamingType());
modifyMethods.add(builder.build());
}
return modifyMethods;
}
use of com.google.api.codegen.config.MethodContext in project toolkit by googleapis.
the class OutputTransformer method arrayLoopView.
private OutputView.ArrayLoopView arrayLoopView(ResponseStatementProto.LoopStatement loop, MethodContext methodContext, SampleContext sampleContext, OutputContext outputContext) {
ScopeTable scope = outputContext.scopeTable();
String loopVariable = loop.getVariable();
assertIdentifierNotUsed(loopVariable, methodContext, sampleContext);
OutputView.VariableView accessor = accessorNewVariable(new Scanner(loop.getCollection()), methodContext, sampleContext, scope, loopVariable, true);
return OutputView.ArrayLoopView.newBuilder().variableType(scope.getTypeName(loopVariable)).variableName(methodContext.getNamer().localVarName(Name.from(loopVariable))).collection(accessor).body(loop.getBodyList().stream().map(body -> toView(body, methodContext, sampleContext, outputContext)).collect(ImmutableList.toImmutableList())).build();
}
use of com.google.api.codegen.config.MethodContext in project toolkit by googleapis.
the class MockServiceTransformer method createMockGrpcMethodViews.
public List<MockGrpcMethodView> createMockGrpcMethodViews(InterfaceContext context) {
if (!context.getProductConfig().getTransportProtocol().equals(TransportProtocol.GRPC)) {
return ImmutableList.of();
}
List<? extends MethodModel> methods = context.getInterfaceMethods();
ArrayList<MockGrpcMethodView> mocks = new ArrayList<>(methods.size());
for (MethodModel method : methods) {
if (context.getMethodConfig(method) == null || !context.isSupported(method)) {
continue;
}
MethodContext methodContext = context.asRequestMethodContext(method);
String requestTypeName = method.getAndSaveRequestTypeName(methodContext.getTypeTable(), methodContext.getNamer());
String responseTypeName = method.getAndSaveResponseTypeName(methodContext.getTypeTable(), methodContext.getNamer());
MethodConfig methodConfig = methodContext.getMethodConfig();
mocks.add(MockGrpcMethodView.newBuilder().name(methodContext.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)).requestTypeName(requestTypeName).responseTypeName(responseTypeName).grpcStreamingType(methodConfig.getGrpcStreamingType()).streamHandleTypeName(methodContext.getNamer().getStreamingServerName(method)).build());
}
return mocks;
}
use of com.google.api.codegen.config.MethodContext in project toolkit by googleapis.
the class DynamicLangGapicSamplesTransformer method getSampleContexts.
public List<SampleContext> getSampleContexts(List<InterfaceContext> interfaceContexts, GapicProductConfig productConfig) {
SurfaceNamer namer = newSurfaceNamer.apply(productConfig);
ImmutableTable<String, String, ImmutableList<SampleConfig>> sampleConfigTable = productConfig.getSampleConfigTable();
ImmutableList.Builder<SampleContext> sampleContexts = ImmutableList.builder();
// Loop through sample configs and and map each sample ID to its matching calling forms.
// We need this information when we need to create, in a language-specific way, unique
// sample ids when one sample id has multiple matching calling forms
Map<String, List<CallingForm>> configsAndMatchingForms = new HashMap<>();
for (InterfaceContext interfaceContext : interfaceContexts) {
for (MethodModel method : interfaceContext.getSupportedMethods()) {
MethodContext methodContext = interfaceContext.asRequestMethodContext(method);
String interfaceName = interfaceContext.getInterfaceConfig().getInterfaceModel().getFullName();
String methodName = method.getSimpleName();
List<SampleConfig> sampleConfigs = sampleConfigTable.get(interfaceName, methodName);
sampleConfigs = firstNonNull(sampleConfigs, ImmutableList.<SampleConfig>of());
for (SampleConfig config : sampleConfigs) {
List<CallingForm> allMatchingCallingForms = namer.getMatchingCallingForms(methodContext, config.callingPattern());
List<CallingForm> existingForms = configsAndMatchingForms.get(config.id());
if (existingForms == null) {
existingForms = new ArrayList<>();
configsAndMatchingForms.put(config.id(), existingForms);
}
existingForms.addAll(allMatchingCallingForms);
}
}
}
SampleFileRegistry registry = new SampleFileRegistry(namer, configsAndMatchingForms);
for (InterfaceContext interfaceContext : interfaceContexts) {
for (MethodModel method : interfaceContext.getSupportedMethods()) {
MethodContext methodContext = interfaceContext.asRequestMethodContext(method);
String interfaceName = interfaceContext.getInterfaceConfig().getInterfaceModel().getFullName();
String methodName = method.getSimpleName();
ImmutableList<SampleConfig> sampleConfigs = sampleConfigTable.get(interfaceName, methodName);
if (sampleConfigs == null) {
continue;
}
for (SampleConfig sampleConfig : sampleConfigs) {
List<CallingForm> allMatchingCallingForms = configsAndMatchingForms.get(sampleConfig.id());
for (CallingForm form : allMatchingCallingForms) {
InitCodeOutputType initCodeOutputType = methodContext.getMethodModel().getRequestStreaming() ? InitCodeOutputType.SingleObject : InitCodeOutputType.FieldList;
SampleContext sampleContext = SampleContext.newBuilder().uniqueSampleId(registry.getUniqueSampleId(sampleConfig, form)).sampleType(SampleSpec.SampleType.STANDALONE).callingForm(form).sampleConfig(sampleConfig).initCodeOutputType(initCodeOutputType).methodContext(methodContext).build();
sampleContexts.add(sampleContext);
}
}
}
}
return sampleContexts.build();
}
use of com.google.api.codegen.config.MethodContext in project toolkit by googleapis.
the class JavaSurfaceTestTransformer method createTestCaseViews.
private List<TestCaseView> createTestCaseViews(InterfaceContext context) {
ArrayList<TestCaseView> testCaseViews = new ArrayList<>();
SymbolTable testNameTable = new SymbolTable();
for (MethodModel method : context.getSupportedMethods()) {
MethodConfig methodConfig = context.getMethodConfig(method);
if (methodConfig.isGrpcStreaming()) {
if (methodConfig.getGrpcStreamingType() == GrpcStreamingType.ClientStreaming) {
// Issue: https://github.com/googleapis/toolkit/issues/946
continue;
}
addGrpcStreamingTestImports(context, methodConfig.getGrpcStreamingType());
MethodContext methodContext = context.asRequestMethodContext(method);
InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), methodConfig.getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, ClientMethodType.CallableMethod));
} else if (methodConfig.isFlattening()) {
MethodContext defaultMethodContext = context.asRequestMethodContext(method);
for (FlatteningConfig flatteningGroup : FlatteningConfigs.getRepresentativeFlatteningConfigs(FlatteningConfig.withRepeatedResourceInSampleOnly(methodConfig.getFlatteningConfigs()))) {
MethodContext methodContext = context.asFlattenedMethodContext(defaultMethodContext, flatteningGroup);
ClientMethodType clientMethodType = getClientMethodType(methodContext);
InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), flatteningGroup.getFlattenedFieldConfigs().values(), InitCodeOutputType.FieldList, valueGenerator);
testCaseViews.add(testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType, Synchronicity.Sync, null, null, TargetLanguage.JAVA));
}
} else {
MethodContext methodContext = context.asRequestMethodContext(method);
ClientMethodType clientMethodType = getClientMethodType(methodContext);
InitCodeContext initCodeContext = initCodeTransformer.createRequestInitCodeContext(methodContext, new SymbolTable(), methodConfig.getRequiredFieldConfigs(), InitCodeOutputType.SingleObject, valueGenerator);
TestCaseView testCaseView = testCaseTransformer.createTestCaseView(methodContext, testNameTable, initCodeContext, clientMethodType, Synchronicity.Sync, null, null, TargetLanguage.JAVA);
testCaseViews.add(testCaseView);
}
}
return testCaseViews;
}
Aggregations