| 417 | } |
| 418 | |
| 419 | void GenerateOp(const OpSpec& op, const EndpointSpec& endpoint, |
| 420 | const string& base_package, const string& output_dir, |
| 421 | Env* env) { |
| 422 | Type op_class( |
| 423 | ClassOf(endpoint, base_package) |
| 424 | .add_supertype(Type::Class("PrimitiveOp", "org.tensorflow.op"))); |
| 425 | Javadoc op_javadoc(endpoint.javadoc()); |
| 426 | |
| 427 | // op interfaces |
| 428 | RenderMode mode = DEFAULT; |
| 429 | if (op.outputs().size() == 1) { |
| 430 | const ArgumentSpec& output = op.outputs().front(); |
| 431 | Type operand_type(output.type().wildcard() ? Type::Class("Object") |
| 432 | : output.type()); |
| 433 | Type operand_inf(Type::Interface("Operand", "org.tensorflow") |
| 434 | .add_parameter(operand_type)); |
| 435 | if (output.iterable()) { |
| 436 | mode = LIST_OPERAND; |
| 437 | op_class.add_supertype(Type::IterableOf(operand_inf)); |
| 438 | } else { |
| 439 | mode = OPERAND; |
| 440 | op_class.add_supertype(operand_inf); |
| 441 | } |
| 442 | } |
| 443 | // op generic parameters |
| 444 | std::set<string> generics; |
| 445 | for (const ArgumentSpec& output : op.outputs()) { |
| 446 | if (output.type().kind() == Type::GENERIC && !output.type().wildcard() && |
| 447 | generics.find(output.type().name()) == generics.end()) { |
| 448 | op_class.add_parameter(output.type()); |
| 449 | op_javadoc.add_param_tag( |
| 450 | "<" + output.type().name() + ">", |
| 451 | "data type for {@code " + output.var().name() + "()} output"); |
| 452 | generics.insert(output.type().name()); |
| 453 | } |
| 454 | } |
| 455 | // op annotations |
| 456 | if (endpoint.deprecated()) { |
| 457 | op_class.add_annotation(Annotation::Create("Deprecated")); |
| 458 | string explanation; |
| 459 | if (!op.endpoints().front().deprecated()) { |
| 460 | explanation = |
| 461 | "use {@link " + |
| 462 | ClassOf(op.endpoints().front(), base_package).canonical_name() + |
| 463 | "} instead"; |
| 464 | } else { |
| 465 | explanation = op.deprecation_explanation(); |
| 466 | } |
| 467 | op_javadoc.add_tag("deprecated", explanation); |
| 468 | } |
| 469 | if (!op.hidden()) { |
| 470 | // expose the op in the Ops Graph API only if it is visible |
| 471 | Annotation oper_annot = |
| 472 | Annotation::Create("Operator", "org.tensorflow.op.annotation"); |
| 473 | if (endpoint.package() != kDefaultEndpointPackage) { |
| 474 | oper_annot.attributes("group = \"" + endpoint.package() + "\""); |
| 475 | } |
| 476 | op_class.add_annotation(oper_annot); |
no test coverage detected