@Override public List<MethodModel> getInterfaceMethods() { ImmutableList.Builder<MethodModel> methodBuilder = ImmutableList.builder(); for (Method method : getInterface().getMethods()) { methodBuilder.add(new ProtoMethodModel(method)); } return methodBuilder.build(); }
public static long getTimeoutMillis(ProtoMethodModel method, long defaultTimeout) { Model model = method.getProtoMethod().getModel(); for (BackendRule backendRule : model.getServiceConfig().getBackend().getRulesList()) { if (backendRule.getSelector().equals(method.getFullName())) { return (long) Math.ceil(backendRule.getDeadline() * MILLIS_PER_SECOND); } } return defaultTimeout; }
@Override public List<ProtoField> getInputFieldsForResourceNameMethod() { return getInputFields(); }
ProtoMethodModel methodModel = new ProtoMethodModel(method); ProtoField tokenField = methodModel.getInputField(ProtoPagingParameters.nameForPageToken()); ProtoField pageSizeField = methodModel.getInputField(ProtoPagingParameters.nameForPageSize()); ProtoField responseTokenField = methodModel.getOutputField(ProtoPagingParameters.nameForNextPageToken()); if (tokenField != null && responseTokenField != null) { PagingFields pagingFields = SimpleLocation.TOPLEVEL, "Default timeout not found or has invalid value (in method %s)", methodModel.getFullName())); error = true;
for (String parameter : flattenedParams) { ProtoField parameterField = method.getInputField(parameter); if (parameterField == null) { diagCollector.addDiag( SimpleLocation.TOPLEVEL, "Field missing for flattening: method = %s, message type = %s, field = %s", method.getFullName(), method.getInputFullName(), parameter)); return null; "Value from oneof already specifed for flattening:%n" + "method = %s, message type = %s, oneof = %s", method.getFullName(), method.getInputFullName(), oneofName)); return null;
SimpleLocation.TOPLEVEL, "Resources field missing for page streaming: method = %s, message type = %s", method.getFullName(), method.getOutputFullName())); resourcesFieldConfig = null; } else { GapicMethodConfig.defaultResourceNameTreatment( MethodConfigProto.getDefaultInstance(), method.getProtoMethod(), protoParser, defaultPackageName);
/** The Method for which this object is a transformation context. */ public Method getMethod() { return ((ProtoMethodModel) getMethodModel()).getProtoMethod(); }
public Method getMethod() { return ((ProtoMethodModel) getMethodModel()).getProtoMethod(); }
/** Returns a list of methods for this interface that have method configs. Memoize the result. */ @Override public List<MethodModel> getInterfaceConfigMethods() { if (interfaceMethods != null) { return interfaceMethods; } ImmutableList.Builder<MethodModel> methodBuilder = ImmutableList.builder(); for (MethodConfig methodConfig : getInterfaceConfig().getMethodConfigs()) { methodBuilder.add(new ProtoMethodModel(((GapicMethodConfig) methodConfig).getMethod())); } interfaceMethods = methodBuilder.build(); return interfaceMethods; }
protoParser.getMethodSignatures(methodModel.getProtoMethod()); for (MethodSignature signature : methodSignatures) { if (signature.getFieldsCount() == 0) {
@Override public List<MethodModel> getMethods() { ImmutableList.Builder<MethodModel> methods = ImmutableList.builder(); for (Method method : protoInterface.getMethods()) { methods.add(new ProtoMethodModel(method)); } SymbolTable symbolTable = protoInterface.getModel().getSymbolTable(); for (Mixin mixin : protoInterface.getConfig().getMixinsList()) { Interface mixinInterface = symbolTable.lookupInterface(mixin.getName()); for (Method method : mixinInterface.getMethods()) { methods.add(new ProtoMethodModel(method)); } } return methods.build(); }
@Test public void testGetExampleImportsClientStream() { MethodModel method = new ProtoMethodModel(getMethod(context.getInterface(), "ClientStreamMethod")); transformer.addXExampleImports(context, Collections.singletonList(method)); assertThat(context.getImportTypeTable().getImports()).doesNotContainKey("io"); }
@Test public void testGetImportsNotLro() { MethodModel method = new ProtoMethodModel(getMethod(context.getInterface(), "NotLroMethod")); transformer.addXApiImports(context, Collections.singletonList(method)); assertThat(context.getImportTypeTable().getImports()) .doesNotContainKey("cloud.google.com/go/longrunning"); }
@Test public void testGetExampleImportsServerStream() { MethodModel method = new ProtoMethodModel(getMethod(context.getInterface(), "ServerStreamMethod")); transformer.addXExampleImports(context, Collections.singletonList(method)); assertThat(context.getImportTypeTable().getImports()).containsKey("io"); }
@Test public void testGetExampleImportsBidiStream() { MethodModel method = new ProtoMethodModel(getMethod(context.getInterface(), "BidiStreamMethod")); transformer.addXExampleImports(context, Collections.singletonList(method)); assertThat(context.getImportTypeTable().getImports()).containsKey("io"); }
@Test public void testGetImportsPageStream() { MethodModel method = new ProtoMethodModel(getMethod(context.getInterface(), "PageStreamMethod")); transformer.addXApiImports(context, Collections.singletonList(method)); transformer.generateRetryConfigDefinitions(context, Collections.singletonList(method)); assertThat(context.getImportTypeTable().getImports()).containsKey("math"); assertThat(context.getImportTypeTable().getImports()) .doesNotContainKey("cloud.google.com/go/longrunning"); }
@Test public void testGetImportsRetry() { MethodModel method = new ProtoMethodModel(getMethod(context.getInterface(), "RetryMethod")); transformer.addXApiImports(context, Collections.singletonList(method)); transformer.generateRetryConfigDefinitions(context, Collections.singletonList(method)); assertThat(context.getImportTypeTable().getImports()).containsKey("time"); assertThat(context.getImportTypeTable().getImports()) .doesNotContainKey("cloud.google.com/go/longrunning"); }
@Test public void testGetImportsLro() { MethodModel method = new ProtoMethodModel(getMethod(context.getInterface(), "LroMethod")); transformer.addXApiImports(context, Collections.singletonList(method)); transformer.generateRetryConfigDefinitions(context, Collections.singletonList(method)); assertThat(context.getImportTypeTable().getImports()).doesNotContainKey("math"); assertThat(context.getImportTypeTable().getImports()) .containsKey("cloud.google.com/go/longrunning"); }
@Test public void testGetImportsPlain() { MethodModel method = new ProtoMethodModel(getMethod(context.getInterface(), "SimpleMethod")); transformer.addXApiImports(context, Collections.singletonList(method)); transformer.generateRetryConfigDefinitions(context, Collections.singletonList(method)); assertThat(context.getImportTypeTable().getImports()).doesNotContainKey("time"); assertThat(context.getImportTypeTable().getImports()) .doesNotContainKey("cloud.google.com/go/longrunning"); }
@Test public void testCreateFlattenings() { ProtoMethodModel methodModel = new ProtoMethodModel(createShelvesMethod); Field bookField = Mockito.mock(Field.class); Mockito.when(bookField.getType()).thenReturn(TypeRef.of(bookType));