/** * Get the output type of the underlying method. */ public TypeRef getOutputType() { return method.getOutputType(); }
/** * Get the output type of the underlying method. */ public TypeRef getOutputType() { return method.getOutputType(); }
@Override public String getAndSaveResponseTypeName(ImportTypeTable typeTable, SurfaceNamer surfaceNamer) { return ((ModelTypeTable) typeTable).getAndSaveNicknameFor(method.getOutputType()); }
private List<String> responseStreamingReturnDocLines(Method method) { return ImmutableList.<String>builder() .add( "@returns {Stream}", " An object stream which emits " + commentReformatter.getLinkedElementName(method.getOutputType().getMessageType()) + " on 'data' event.") .build(); }
@Override public List<ProtoField> getOutputFields() { if (outputFields != null) { return outputFields; } ImmutableList.Builder<ProtoField> fieldsBuilder = ImmutableList.builder(); for (Field field : method.getOutputType().getMessageType().getFields()) { fieldsBuilder.add(new ProtoField(field)); } outputFields = fieldsBuilder.build(); return outputFields; }
@Override public boolean isOutputTypeEmpty() { return new ServiceMessages().isEmptyType(method.getOutputType()); }
@Override public String getOutputTypeSimpleName() { return method.getOutputType().getMessageType().getSimpleName(); }
@Override public String getOutputFullName() { return method.getOutputType().getMessageType().getFullName(); }
public ProtoMethodModel(Method method) { Preconditions.checkNotNull(method); this.method = method; this.inputType = ProtoTypeRef.create(method.getInputType()); this.outputType = ProtoTypeRef.create(method.getOutputType()); }
private List<String> bidiStreamingReturnDocLines(Method method) { return ImmutableList.<String>builder() .add( "@returns {Stream}", " An object stream which is both readable and writable. It accepts objects", " representing " + commentReformatter.getLinkedElementName(method.getInputType().getMessageType()) + " for write() method, and", " will emit objects representing " + commentReformatter.getLinkedElementName(method.getOutputType().getMessageType()) + " on 'data' event asynchronously.") .build(); }
@Override public ProtoField getOutputField(String fieldName) { Field outputField = method.getOutputType().getMessageType().lookupField(fieldName); return outputField == null ? null : new ProtoField(outputField); }
@Override public TypeName getOutputTypeName(ImportTypeTable typeTable) { return typeTable .getTypeTable() .getTypeName(((ModelTypeTable) typeTable).getFullNameFor(method.getOutputType())); }
/** * Creates an instance of GrpcStreamingConfig for gRPC response streaming, based on * PageStreamingConfigProto, linking it up with the provided method. On errors, null will be * returned, and diagnostics are reported to the diag collector. * * <p>TODO: Create a separate GrpcStreamingConfigProto */ @Nullable public static GrpcStreamingConfig createGrpcStreaming( DiagCollector diagCollector, PageStreamingConfigProto pageStreaming, Method method) { String resourcesFieldName = pageStreaming.getResponse().getResourcesField(); Field resourcesField = method.getOutputType().getMessageType().lookupField(resourcesFieldName); GrpcStreamingType type = getGrpcStreamingType(diagCollector, method); if (type == null) { return null; } return new GrpcStreamingConfig(resourcesField, type); }
ResourceTypeSelector(Model model, Iterable<RestMethod> methods) { this.model = model; for (RestMethod method : methods) { switch (method.getRestKind()) { case GET: // Response type of REST GET method is likely a resource type. incrementRank(method.getBaseMethod().getOutputType()); break; case CREATE: case UPDATE: // Request body type of REST CREATE or UPDATE method is likely a resource type. TypeRef type = getSingleBodyType(method.getBaseMethod()); if (type != null) { incrementRank(type); } break; default: break; } } }
ResourceTypeSelector(Model model, Iterable<RestMethod> methods) { this.model = model; for (RestMethod method : methods) { switch (method.getRestKind()) { case GET: // Response type of REST GET method is likely a resource type. incrementRank(method.getBaseMethod().getOutputType()); break; case CREATE: case UPDATE: // Request body type of REST CREATE or UPDATE method is likely a resource type. TypeRef type = getSingleBodyType(method.getBaseMethod()); if (type != null) { incrementRank(type); } break; default: break; } } }
private void startMergeMethod(Interface including, Method method) { // Check conditions implied by mixin configuration. Method redeclared = including.lookupMethod(method.getSimpleName()); if (redeclared == null) { error( including.getLocation(), "The API '%s' does not redeclare method '%s' as required by the mixin configuration.", including.getFullName(), method); return; } if (!method.getInputType().equals(redeclared.getInputType())) { error( redeclared.getLocation(), "The method '%s' must have request type '%s' as required by the mixin configuration.", redeclared, method.getInputMessage()); return; } if (!method.getOutputType().equals(redeclared.getOutputType())) { error( redeclared.getLocation(), "The method '%s' must have response type '%s' as required by the mixin configuration.", redeclared, method.getOutputType()); return; } // Add attribute. redeclared.addAttribute(ImplementsAttribute.KEY, ImplementsAttribute.create(method)); }
private void startMergeMethod(Interface including, Method method) { // Check conditions implied by mixin configuration. Method redeclared = including.lookupMethod(method.getSimpleName()); if (redeclared == null) { error( including.getLocation(), "The API '%s' does not redeclare method '%s' as required by the mixin configuration.", including.getFullName(), method); return; } if (!method.getInputType().equals(redeclared.getInputType())) { error( redeclared.getLocation(), "The method '%s' must have request type '%s' as required by the mixin configuration.", redeclared, method.getInputMessage()); return; } if (!method.getOutputType().equals(redeclared.getOutputType())) { error( redeclared.getLocation(), "The method '%s' must have response type '%s' as required by the mixin configuration.", redeclared, method.getOutputType()); return; } // Add attribute. redeclared.addAttribute(ImplementsAttribute.KEY, ImplementsAttribute.create(method)); }
private String returnTypeDoc(ImportTypeTable typeTable, GapicMethodConfig methodConfig) { String returnTypeDoc = ""; if (methodConfig.isPageStreaming()) { returnTypeDoc = "Array of "; FieldModel resourcesType = methodConfig.getPageStreaming().getResourcesField(); if (resourcesType.isMessage()) { returnTypeDoc += commentReformatter.getLinkedElementName( ((ProtoTypeRef) resourcesType.getType()).getProtoType().getMessageType()); } else if (resourcesType.isEnum()) { returnTypeDoc += commentReformatter.getLinkedElementName( ((ProtoTypeRef) resourcesType.getType()).getProtoType().getEnumType()); } else { // Converting to lowercase because "String" is capitalized in NodeJSModelTypeNameConverter. returnTypeDoc += getParamTypeNoCardinality(typeTable, resourcesType.getType()).toLowerCase(); } } else if (methodConfig.isLongRunningOperation()) { returnTypeDoc = "a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object"; } else { returnTypeDoc = getTypeNameDoc(typeTable, ProtoTypeRef.create(methodConfig.getMethod().getOutputType())); } return returnTypeDoc; }
@VisitsBefore void normalize(Interface iface) { Api.Builder coreApiBuilder = Api.newBuilder().setName(iface.getFullName()); coreApiBuilder.setSourceContext( SourceContext.newBuilder().setFileName(iface.getFile().getLocation().getDisplayString())); coreApiBuilder.setSyntax(iface.getSyntax()); for (Method method : iface.getReachableMethods()) { com.google.protobuf.Method.Builder coreMethodBuilder = com.google.protobuf.Method.newBuilder() .setName(method.getSimpleName()) .setRequestTypeUrl(generateTypeUrl(method.getInputType())) .setResponseTypeUrl(generateTypeUrl(method.getOutputType())); coreMethodBuilder.setRequestStreaming(method.getRequestStreaming()); coreMethodBuilder.setResponseStreaming(method.getResponseStreaming()); coreMethodBuilder.addAllOptions( DescriptorNormalization.getMethodOptions( method.getOptionFields(), false, includeDefaults)); coreApiBuilder.addMethods(coreMethodBuilder); } coreApiBuilder.addAllOptions( DescriptorNormalization.getOptions(iface.getProto(), includeDefaults)); coreApiBuilder.setVersion(iface.getAttribute(VersionAttribute.KEY).majorVersion()); apis.add(coreApiBuilder.build()); }
@VisitsBefore void normalize(Interface iface) { Api.Builder coreApiBuilder = Api.newBuilder().setName(iface.getFullName()); coreApiBuilder.setSourceContext( SourceContext.newBuilder().setFileName(iface.getFile().getLocation().getDisplayString())); coreApiBuilder.setSyntax(iface.getSyntax()); for (Method method : iface.getReachableMethods()) { com.google.protobuf.Method.Builder coreMethodBuilder = com.google.protobuf.Method.newBuilder() .setName(method.getSimpleName()) .setRequestTypeUrl(generateTypeUrl(method.getInputType())) .setResponseTypeUrl(generateTypeUrl(method.getOutputType())); coreMethodBuilder.setRequestStreaming(method.getRequestStreaming()); coreMethodBuilder.setResponseStreaming(method.getResponseStreaming()); coreMethodBuilder.addAllOptions( DescriptorNormalization.getMethodOptions( method.getOptionFields(), false, includeDefaults)); coreApiBuilder.addMethods(coreMethodBuilder); } coreApiBuilder.addAllOptions( DescriptorNormalization.getOptions(iface.getProto(), includeDefaults)); coreApiBuilder.setVersion(iface.getAttribute(VersionAttribute.KEY).majorVersion()); apis.add(coreApiBuilder.build()); }