| 385 | } |
| 386 | |
| 387 | void RenderOptionsClass(const OpSpec& op, const Type& op_class, |
| 388 | SourceWriter* writer) { |
| 389 | Type options_class = Type::Class("Options"); |
| 390 | Javadoc options_doc = Javadoc::Create("Optional attributes for {@link " + |
| 391 | op_class.canonical_name() + "}"); |
| 392 | writer->BeginInnerType(options_class, PUBLIC | STATIC, &options_doc); |
| 393 | for (const AttributeSpec& attr : op.optional_attributes()) { |
| 394 | Method setter = Method::Create(attr.var().name(), options_class); |
| 395 | Javadoc setter_doc = Javadoc::Create(); |
| 396 | AddArgument(attr.var(), attr.description(), &setter, &setter_doc); |
| 397 | writer->BeginMethod(setter, PUBLIC, &setter_doc) |
| 398 | .Append("this." + attr.var().name() + " = " + attr.var().name() + ";") |
| 399 | .EndLine() |
| 400 | .Append("return this;") |
| 401 | .EndLine() |
| 402 | .EndMethod(); |
| 403 | } |
| 404 | writer->EndLine(); |
| 405 | for (const AttributeSpec& optional_attribute : op.optional_attributes()) { |
| 406 | writer->WriteField(optional_attribute.var(), PRIVATE); |
| 407 | } |
| 408 | Method constructor = Method::ConstructorFor(options_class); |
| 409 | writer->BeginMethod(constructor, PRIVATE).EndMethod(); |
| 410 | writer->EndType(); |
| 411 | } |
| 412 | |
| 413 | inline Type ClassOf(const EndpointSpec& endpoint, const string& base_package) { |
| 414 | return Type::Class( |
no test coverage detected