aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/java
diff options
context:
space:
mode:
authorGravatar Yifei Feng <yifeif@google.com>2018-05-29 12:57:14 -0700
committerGravatar Yifei Feng <yifeif@google.com>2018-05-29 12:57:14 -0700
commit48d13f510b70e48b61a435011f78bfef4df55c9b (patch)
treefbf5d2505e3bf2aa8121053a16a8f74aa74ae018 /tensorflow/java
parentbaa794b4c02db5a5d4c115383564a271dd8f875d (diff)
parent7b5c87e20ccdd1b3194a517e2b7fbf11581293dd (diff)
Merge commit for internal changes
Diffstat (limited to 'tensorflow/java')
-rw-r--r--tensorflow/java/BUILD10
-rw-r--r--tensorflow/java/src/gen/cc/java_defs.h22
-rw-r--r--tensorflow/java/src/gen/cc/op_gen_main.cc10
-rw-r--r--tensorflow/java/src/gen/cc/op_generator.cc179
-rw-r--r--tensorflow/java/src/gen/cc/op_generator.h7
-rw-r--r--tensorflow/java/src/gen/cc/source_writer.cc14
-rw-r--r--tensorflow/java/src/gen/cc/source_writer.h14
-rw-r--r--tensorflow/java/src/gen/cc/source_writer_test.cc99
8 files changed, 187 insertions, 168 deletions
diff --git a/tensorflow/java/BUILD b/tensorflow/java/BUILD
index 50d5dcef54..19d2133a55 100644
--- a/tensorflow/java/BUILD
+++ b/tensorflow/java/BUILD
@@ -60,9 +60,7 @@ java_library(
filegroup(
name = "java_op_sources",
- srcs = glob(["src/main/java/org/tensorflow/op/**/*.java"]) + [
- ":java_op_gen_sources",
- ],
+ srcs = glob(["src/main/java/org/tensorflow/op/**/*.java"]) + [":java_op_gen_sources"],
visibility = [
"//tensorflow/java:__pkg__",
],
@@ -87,6 +85,9 @@ tf_cc_binary(
linkstatic = 1,
deps = [
":java_op_gen_lib",
+ "//tensorflow/core:framework",
+ "//tensorflow/core:framework_internal",
+ "//tensorflow/core:lib",
"//tensorflow/core:ops",
],
)
@@ -111,6 +112,8 @@ cc_library(
"//tensorflow/core:lib",
"//tensorflow/core:lib_internal",
"//tensorflow/core:op_gen_lib",
+ "//tensorflow/core:protos_all_cc",
+ "@com_googlesource_code_re2//:re2",
],
)
@@ -303,6 +306,7 @@ tf_cc_test(
],
deps = [
":java_op_gen_lib",
+ "//tensorflow/core:lib",
"//tensorflow/core:test",
"//tensorflow/core:test_main",
],
diff --git a/tensorflow/java/src/gen/cc/java_defs.h b/tensorflow/java/src/gen/cc/java_defs.h
index 62575f6683..f5f54bf4d3 100644
--- a/tensorflow/java/src/gen/cc/java_defs.h
+++ b/tensorflow/java/src/gen/cc/java_defs.h
@@ -26,12 +26,12 @@ namespace java {
// An enumeration of different modifiers commonly used in Java
enum Modifier {
- PACKAGE = 0,
- PUBLIC = (1 << 0),
+ PACKAGE = 0,
+ PUBLIC = (1 << 0),
PROTECTED = (1 << 1),
- PRIVATE = (1 << 2),
- STATIC = (1 << 3),
- FINAL = (1 << 4),
+ PRIVATE = (1 << 2),
+ STATIC = (1 << 3),
+ FINAL = (1 << 4),
};
class Annotation;
@@ -75,12 +75,8 @@ class Type {
// Reflection API does
return Type(Type::PRIMITIVE, "void");
}
- static Type Generic(const string& name) {
- return Type(Type::GENERIC, name);
- }
- static Type Wildcard() {
- return Type(Type::GENERIC, "");
- }
+ static Type Generic(const string& name) { return Type(Type::GENERIC, name); }
+ static Type Wildcard() { return Type(Type::GENERIC, ""); }
static Type Class(const string& name, const string& package = "") {
return Type(Type::CLASS, name, package);
}
@@ -226,9 +222,7 @@ class Method {
// A definition of a documentation bloc for a Java element (JavaDoc)
class Javadoc {
public:
- static Javadoc Create(const string& brief = "") {
- return Javadoc(brief);
- }
+ static Javadoc Create(const string& brief = "") { return Javadoc(brief); }
const string& brief() const { return brief_; }
const string& details() const { return details_; }
Javadoc& details(const string& details) {
diff --git a/tensorflow/java/src/gen/cc/op_gen_main.cc b/tensorflow/java/src/gen/cc/op_gen_main.cc
index 6c35cd9595..0d9e0883af 100644
--- a/tensorflow/java/src/gen/cc/op_gen_main.cc
+++ b/tensorflow/java/src/gen/cc/op_gen_main.cc
@@ -41,7 +41,7 @@ const char kUsageHeader[] =
"using an appropriate annotation processor.\n\n"
"The '--base_package' overrides the default parent package under which "
"the generated subpackage and classes are to be located.\n\n"
- "Finally, the `--api_dirs` argument takes a list of comma-seperated "
+ "Finally, the `--api_dirs` argument takes a list of comma-separated "
"directories of API definitions can be provided to override default\n"
"values found in the ops definitions. Directories are ordered by priority "
"(the last having precedence over the first).\n\n";
@@ -55,10 +55,12 @@ int main(int argc, char* argv[]) {
tensorflow::string api_dirs_str;
std::vector<tensorflow::Flag> flag_list = {
tensorflow::Flag("output_dir", &output_dir,
- "Root directory into which output files are generated"),
- tensorflow::Flag("base_package", &base_package,
+ "Root directory into which output files are generated"),
+ tensorflow::Flag(
+ "base_package", &base_package,
"Package parent to the generated subpackage and classes"),
- tensorflow::Flag("api_dirs", &api_dirs_str,
+ tensorflow::Flag(
+ "api_dirs", &api_dirs_str,
"List of directories that contains the ops api definitions")};
tensorflow::string usage = tensorflow::java::kUsageHeader;
usage += tensorflow::Flags::Usage(argv[0], flag_list);
diff --git a/tensorflow/java/src/gen/cc/op_generator.cc b/tensorflow/java/src/gen/cc/op_generator.cc
index 284f675c94..940390bfcf 100644
--- a/tensorflow/java/src/gen/cc/op_generator.cc
+++ b/tensorflow/java/src/gen/cc/op_generator.cc
@@ -17,39 +17,43 @@ limitations under the License.
#include <map>
#include <vector>
#include <list>
+#include <map>
#include <memory>
#include <set>
+#include <string>
+#include <vector>
+#include "tensorflow/core/framework/op_gen_lib.h"
#include "tensorflow/core/lib/core/errors.h"
-#include "tensorflow/core/lib/strings/str_util.h"
#include "tensorflow/core/lib/io/path.h"
#include "tensorflow/core/platform/logging.h"
#include "tensorflow/core/platform/env.h"
#include "tensorflow/core/framework/op_gen_lib.h"
#include "tensorflow/java/src/gen/cc/java_defs.h"
-#include "tensorflow/java/src/gen/cc/source_writer.h"
#include "tensorflow/java/src/gen/cc/op_generator.h"
#include "tensorflow/java/src/gen/cc/op_specs.h"
+#include "tensorflow/java/src/gen/cc/source_writer.h"
namespace tensorflow {
namespace java {
namespace {
const char* kLicense =
- "/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.\n"
- "\n"
- "Licensed under the Apache License, Version 2.0 (the \"License\");\n"
- "you may not use this file except in compliance with the License.\n"
- "You may obtain a copy of the License at\n"
- "\n"
- " http://www.apache.org/licenses/LICENSE-2.0\n"
- "\n"
- "Unless required by applicable law or agreed to in writing, software\n"
- "distributed under the License is distributed on an \"AS IS\" BASIS,\n"
- "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
- "See the License for the specific language governing permissions and\n"
- "limitations under the License.\n"
- "=======================================================================*/\n";
+ "/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.\n"
+ "\n"
+ "Licensed under the Apache License, Version 2.0 (the \"License\");\n"
+ "you may not use this file except in compliance with the License.\n"
+ "You may obtain a copy of the License at\n"
+ "\n"
+ " http://www.apache.org/licenses/LICENSE-2.0\n"
+ "\n"
+ "Unless required by applicable law or agreed to in writing, software\n"
+ "distributed under the License is distributed on an \"AS IS\" BASIS,\n"
+ "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"
+ "See the License for the specific language governing permissions and\n"
+ "limitations under the License.\n"
+ "=======================================================================*/"
+ "\n";
// There is three different modes to render an op class, depending on the
// number and type of outputs it has:
@@ -64,20 +68,16 @@ const char* kLicense =
// allowing an instance to be passed directly as a list input to
// another operation
//
-enum RenderMode {
- DEFAULT,
- OPERAND,
- LIST_OPERAND
-};
+enum RenderMode { DEFAULT, OPERAND, LIST_OPERAND };
void AddArgument(const Variable& var, const string& description,
- Method* method_out, Javadoc* javadoc_out) {
+ Method* method_out, Javadoc* javadoc_out) {
method_out->add_argument(var);
javadoc_out->add_param_tag(var.name(), description);
}
void CollectOpDependencies(const OpSpec& op, RenderMode mode,
- std::list<Type>* out) {
+ std::list<Type>* out) {
out->push_back(Type::Class("Operation", "org.tensorflow"));
out->push_back(Type::Class("OperationBuilder", "org.tensorflow"));
out->push_back(Type::Class("Scope", "org.tensorflow.op"));
@@ -110,7 +110,7 @@ void CollectOpDependencies(const OpSpec& op, RenderMode mode,
}
void WriteSetAttrDirective(const AttributeSpec& attr, bool optional,
- SourceWriter* writer) {
+ SourceWriter* writer) {
string var_name = optional ? "opts." + attr.var().name() : attr.var().name();
if (attr.iterable()) {
string array_name = attr.var().name() + "Array";
@@ -143,11 +143,11 @@ void WriteSetAttrDirective(const AttributeSpec& attr, bool optional,
}
void RenderFactoryMethods(const OpSpec& op, const Type& op_class,
- SourceWriter* writer) {
+ SourceWriter* writer) {
Method factory = Method::Create("create", op_class);
- Javadoc factory_doc = Javadoc::Create(
- "Factory method to create a class to wrap a new " + op_class.name()
- + " operation to the graph.");
+ Javadoc factory_doc =
+ Javadoc::Create("Factory method to create a class to wrap a new " +
+ op_class.name() + " operation to the graph.");
Variable scope =
Variable::Create("scope", Type::Class("Scope", "org.tensorflow.op"));
AddArgument(scope, "current graph scope", &factory, &factory_doc);
@@ -159,23 +159,23 @@ void RenderFactoryMethods(const OpSpec& op, const Type& op_class,
}
if (!op.optional_attributes().empty()) {
AddArgument(Variable::Varargs("options", Type::Class("Options")),
- "carries optional attributes values", &factory, &factory_doc);
+ "carries optional attributes values", &factory, &factory_doc);
}
factory_doc.add_tag("return", "a new instance of " + op_class.name());
- writer->BeginMethod(factory, PUBLIC|STATIC, &factory_doc);
- writer->Append("OperationBuilder opBuilder = scope.graph().opBuilder(\""
- + op.graph_op_name() + "\", scope.makeOpName(\""
- + op_class.name() + "\"));");
+ writer->BeginMethod(factory, PUBLIC | STATIC, &factory_doc);
+ writer->Append("OperationBuilder opBuilder = scope.graph().opBuilder(\"" +
+ op.graph_op_name() + "\", scope.makeOpName(\"" +
+ op_class.name() + "\"));");
writer->EndLine();
for (const ArgumentSpec& input : op.inputs()) {
if (input.iterable()) {
- writer->Append("opBuilder.addInputList(Operands.asOutputs("
- + input.var().name() + "));");
+ writer->Append("opBuilder.addInputList(Operands.asOutputs(" +
+ input.var().name() + "));");
writer->EndLine();
} else {
- writer->Append("opBuilder.addInput(" + input.var().name()
- + ".asOutput());");
+ writer->Append("opBuilder.addInput(" + input.var().name() +
+ ".asOutput());");
writer->EndLine();
}
}
@@ -200,7 +200,7 @@ void RenderFactoryMethods(const OpSpec& op, const Type& op_class,
}
void RenderConstructor(const OpSpec& op, const Type& op_class,
- SourceWriter* writer) {
+ SourceWriter* writer) {
Variable operation =
Variable::Create("operation", Type::Class("Operation", "org.tensorflow"));
Method constructor = Method::ConstructorFor(op_class).add_argument(operation);
@@ -214,15 +214,14 @@ void RenderConstructor(const OpSpec& op, const Type& op_class,
writer->BeginMethod(constructor, PRIVATE)
.Append("super(operation);")
.EndLine();
- if (op.outputs().size() > 0) {
- writer->Append("int outputIdx = 0;")
- .EndLine();
+ if (!op.outputs().empty()) {
+ writer->Append("int outputIdx = 0;").EndLine();
for (const ArgumentSpec& output : op.outputs()) {
if (output.iterable()) {
string var_length = output.var().name() + "Length";
writer->Append("int " + var_length)
- .Append(" = operation.outputListLength(\"" + output.op_def_name()
- + "\");")
+ .Append(" = operation.outputListLength(\"" + output.op_def_name() +
+ "\");")
.EndLine()
.Append(output.var().name() + " = Arrays.asList(");
if (!output.type().wildcard()) {
@@ -235,8 +234,8 @@ void RenderConstructor(const OpSpec& op, const Type& op_class,
.Append("outputIdx += " + var_length + ";")
.EndLine();
} else {
- writer->Append(output.var().name()
- + " = operation.output(outputIdx++);")
+ writer
+ ->Append(output.var().name() + " = operation.output(outputIdx++);")
.EndLine();
}
}
@@ -246,13 +245,12 @@ void RenderConstructor(const OpSpec& op, const Type& op_class,
void RenderGettersAndSetters(const OpSpec& op, SourceWriter* writer) {
for (const AttributeSpec& attr : op.optional_attributes()) {
- Method setter =
- Method::Create(attr.var().name(), Type::Class("Options"));
+ Method setter = Method::Create(attr.var().name(), Type::Class("Options"));
Javadoc setter_doc = Javadoc::Create();
AddArgument(attr.var(), attr.description(), &setter, &setter_doc);
- writer->BeginMethod(setter, PUBLIC|STATIC, &setter_doc)
- .Append("return new Options()." + attr.var().name() + "("
- + attr.var().name() + ");")
+ writer->BeginMethod(setter, PUBLIC | STATIC, &setter_doc)
+ .Append("return new Options()." + attr.var().name() + "(" +
+ attr.var().name() + ");")
.EndLine()
.EndMethod();
}
@@ -267,15 +265,16 @@ void RenderGettersAndSetters(const OpSpec& op, SourceWriter* writer) {
}
void RenderInterfaceImpl(const OpSpec& op, RenderMode mode,
- SourceWriter* writer) {
+ SourceWriter* writer) {
ArgumentSpec output = op.outputs().front();
if (mode == OPERAND) {
bool cast2obj = output.type().wildcard();
- Type return_type = Type::Class("Output", "org.tensorflow")
- .add_parameter(cast2obj ? Type::Class("Object") : output.type());
+ Type return_type =
+ Type::Class("Output", "org.tensorflow")
+ .add_parameter(cast2obj ? Type::Class("Object") : output.type());
Method as_output = Method::Create("asOutput", return_type)
- .add_annotation(Annotation::Create("Override"));
+ .add_annotation(Annotation::Create("Override"));
if (cast2obj) {
as_output.add_annotation(
Annotation::Create("SuppressWarnings").attributes("\"unchecked\""));
@@ -286,9 +285,7 @@ void RenderInterfaceImpl(const OpSpec& op, RenderMode mode,
} else {
writer->Append("return ");
}
- writer->Append(output.var().name() + ";")
- .EndLine()
- .EndMethod();
+ writer->Append(output.var().name() + ";").EndLine().EndMethod();
} else if (mode == LIST_OPERAND) {
Type operand = Type::Interface("Operand", "org.tensorflow");
@@ -297,12 +294,13 @@ void RenderInterfaceImpl(const OpSpec& op, RenderMode mode,
} else {
operand.add_parameter(output.type());
}
- Type return_type = Type::Interface("Iterator", "java.util")
- .add_parameter(operand);
- Method iterator = Method::Create("iterator", return_type)
- .add_annotation(Annotation::Create("Override"))
- .add_annotation(Annotation::Create("SuppressWarnings")
- .attributes("{\"rawtypes\", \"unchecked\"}"));
+ Type return_type =
+ Type::Interface("Iterator", "java.util").add_parameter(operand);
+ Method iterator =
+ Method::Create("iterator", return_type)
+ .add_annotation(Annotation::Create("Override"))
+ .add_annotation(Annotation::Create("SuppressWarnings")
+ .attributes("{\"rawtypes\", \"unchecked\"}"));
// cast the output list using a raw List
writer->BeginMethod(iterator, PUBLIC)
.Append("return (" + return_type.name() + ") ")
@@ -313,10 +311,10 @@ void RenderInterfaceImpl(const OpSpec& op, RenderMode mode,
}
void RenderOptionsClass(const OpSpec& op, const Type& op_class,
- SourceWriter* writer) {
+ SourceWriter* writer) {
Type options_class = Type::Class("Options");
- Javadoc options_doc = Javadoc::Create(
- "Optional attributes for {@link " + op_class.canonical_name() + "}");
+ Javadoc options_doc = Javadoc::Create("Optional attributes for {@link " +
+ op_class.canonical_name() + "}");
writer->BeginInnerType(options_class, PUBLIC | STATIC, &options_doc);
for (const AttributeSpec& attr : op.optional_attributes()) {
Method setter = Method::Create(attr.var().name(), options_class);
@@ -339,24 +337,27 @@ void RenderOptionsClass(const OpSpec& op, const Type& op_class,
}
inline Type ClassOf(const EndpointSpec& endpoint, const string& base_package) {
- return Type::Class(endpoint.name(),
+ return Type::Class(
+ endpoint.name(),
base_package + "." + str_util::Lowercase(endpoint.package()));
}
void GenerateOp(const OpSpec& op, const EndpointSpec& endpoint,
- const string& base_package, const string& output_dir, Env* env) {
- Type op_class(ClassOf(endpoint, base_package)
- .add_supertype(Type::Class("PrimitiveOp", "org.tensorflow.op")));
+ const string& base_package, const string& output_dir,
+ Env* env) {
+ Type op_class(
+ ClassOf(endpoint, base_package)
+ .add_supertype(Type::Class("PrimitiveOp", "org.tensorflow.op")));
Javadoc op_javadoc(endpoint.javadoc());
// op interfaces
RenderMode mode = DEFAULT;
if (op.outputs().size() == 1) {
const ArgumentSpec& output = op.outputs().front();
- Type operand_type(output.type().wildcard() ?
- Type::Class("Object") : output.type());
+ Type operand_type(output.type().wildcard() ? Type::Class("Object")
+ : output.type());
Type operand_inf(Type::Interface("Operand", "org.tensorflow")
- .add_parameter(operand_type));
+ .add_parameter(operand_type));
if (output.iterable()) {
mode = LIST_OPERAND;
op_class.add_supertype(Type::IterableOf(operand_inf));
@@ -368,10 +369,11 @@ void GenerateOp(const OpSpec& op, const EndpointSpec& endpoint,
// op generic parameters
std::set<string> generics;
for (const ArgumentSpec& output : op.outputs()) {
- if (output.type().kind() == Type::GENERIC && !output.type().wildcard()
- && generics.find(output.type().name()) == generics.end()) {
+ if (output.type().kind() == Type::GENERIC && !output.type().wildcard() &&
+ generics.find(output.type().name()) == generics.end()) {
op_class.add_parameter(output.type());
- op_javadoc.add_param_tag("<" + output.type().name() + ">",
+ op_javadoc.add_param_tag(
+ "<" + output.type().name() + ">",
"data type for {@code " + output.var().name() + "()} output");
generics.insert(output.type().name());
}
@@ -384,9 +386,10 @@ void GenerateOp(const OpSpec& op, const EndpointSpec& endpoint,
op_class.add_annotation(Annotation::Create("Deprecated"));
string explanation;
if (!op.endpoints().front().deprecated()) {
- explanation = "use {@link " +
- ClassOf(op.endpoints().front(), base_package).canonical_name()
- + "} instead";
+ explanation =
+ "use {@link " +
+ ClassOf(op.endpoints().front(), base_package).canonical_name() +
+ "} instead";
} else {
explanation = op.deprecation_explanation();
}
@@ -396,27 +399,27 @@ void GenerateOp(const OpSpec& op, const EndpointSpec& endpoint,
// expose the op in the Ops Graph API only if it is visible
op_class.add_annotation(
Annotation::Create("Operator", "org.tensorflow.op.annotation")
- .attributes("group = \"" + endpoint.package() + "\""));
+ .attributes("group = \"" + endpoint.package() + "\""));
}
// create op class file
- const string op_dir_name = io::JoinPath(output_dir,
- str_util::StringReplace(op_class.package(), ".", "/", true));
+ const string op_dir_name = io::JoinPath(
+ output_dir, str_util::StringReplace(op_class.package(), ".", "/", true));
if (!env->FileExists(op_dir_name).ok()) {
TF_CHECK_OK(Env::Default()->RecursivelyCreateDir(op_dir_name))
<< op_dir_name;
}
const string op_file_name = op_class.name() + ".java";
std::unique_ptr<tensorflow::WritableFile> op_file;
- TF_CHECK_OK(env->NewWritableFile(
- io::JoinPath(op_dir_name, op_file_name), &op_file)) << op_file_name;
+ TF_CHECK_OK(
+ env->NewWritableFile(io::JoinPath(op_dir_name, op_file_name), &op_file))
+ << op_file_name;
// render endpoint source code
SourceFileWriter writer(op_file.get());
std::list<Type> dependencies;
CollectOpDependencies(op, mode, &dependencies);
- writer.Write(kLicense)
- .EndLine()
- .BeginType(op_class, PUBLIC|FINAL, &dependencies, &op_javadoc);
+ writer.Write(kLicense).EndLine().BeginType(op_class, PUBLIC | FINAL,
+ &dependencies, &op_javadoc);
if (!op.optional_attributes().empty()) {
RenderOptionsClass(op, op_class, &writer);
}
@@ -448,7 +451,7 @@ bool CanGenerateOp(const OpDef& op_def, const ApiDef& api_def) {
} // namespace
Status OpGenerator::Run(const OpList& op_list, const string& base_package,
- const string& output_dir) {
+ const string& output_dir) {
ApiDefMap api_map(op_list);
if (!api_dirs_.empty()) {
// Only load api files that correspond to the requested "op_list"
diff --git a/tensorflow/java/src/gen/cc/op_generator.h b/tensorflow/java/src/gen/cc/op_generator.h
index cfe842070a..759d800ecf 100644
--- a/tensorflow/java/src/gen/cc/op_generator.h
+++ b/tensorflow/java/src/gen/cc/op_generator.h
@@ -21,7 +21,7 @@ limitations under the License.
#include "tensorflow/core/framework/op_def.pb.h"
#include "tensorflow/core/framework/api_def.pb.h"
-#include "tensorflow/core/platform/env.h"
+#include "tensorflow/core/framework/op_def.pb.h"
#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/java/src/gen/cc/op_specs.h"
@@ -37,14 +37,15 @@ namespace java {
class OpGenerator {
public:
explicit OpGenerator(const std::vector<string>& api_dirs,
- Env* env = Env::Default()) : api_dirs_(api_dirs), env_(env) {}
+ Env* env = Env::Default())
+ : api_dirs_(api_dirs), env_(env) {}
// Generates wrappers for the given list of 'ops'.
//
// Output files are generated in <output_dir>/<base_package>/<op_package>,
// where 'op_package' is derived from ops endpoints.
Status Run(const OpList& op_list, const string& base_package,
- const string& output_dir);
+ const string& output_dir);
private:
const std::vector<string> api_dirs_;
diff --git a/tensorflow/java/src/gen/cc/source_writer.cc b/tensorflow/java/src/gen/cc/source_writer.cc
index 56806cbb6d..8e5fba7e32 100644
--- a/tensorflow/java/src/gen/cc/source_writer.cc
+++ b/tensorflow/java/src/gen/cc/source_writer.cc
@@ -16,6 +16,7 @@ limitations under the License.
#include <string>
#include <algorithm>
#include <list>
+#include <string>
#include "tensorflow/java/src/gen/cc/source_writer.h"
@@ -123,7 +124,7 @@ SourceWriter& SourceWriter::EndBlock() {
}
SourceWriter& SourceWriter::BeginMethod(const Method& method, int modifiers,
- const Javadoc* javadoc) {
+ const Javadoc* javadoc) {
GenericNamespace* generic_namespace = PushGenericNamespace(modifiers);
if (!method.constructor()) {
generic_namespace->Visit(method.return_type());
@@ -165,7 +166,8 @@ SourceWriter& SourceWriter::EndMethod() {
}
SourceWriter& SourceWriter::BeginType(const Type& type, int modifiers,
- const std::list<Type>* extra_dependencies, const Javadoc* javadoc) {
+ const std::list<Type>* extra_dependencies,
+ const Javadoc* javadoc) {
if (!type.package().empty()) {
Append("package ").Append(type.package()).Append(";").EndLine();
}
@@ -186,7 +188,7 @@ SourceWriter& SourceWriter::BeginType(const Type& type, int modifiers,
}
SourceWriter& SourceWriter::BeginInnerType(const Type& type, int modifiers,
- const Javadoc* javadoc) {
+ const Javadoc* javadoc) {
GenericNamespace* generic_namespace = PushGenericNamespace(modifiers);
generic_namespace->Visit(type);
EndLine();
@@ -226,7 +228,7 @@ SourceWriter& SourceWriter::EndType() {
}
SourceWriter& SourceWriter::WriteField(const Variable& field, int modifiers,
- const Javadoc* javadoc) {
+ const Javadoc* javadoc) {
// If present, write field javadoc only as one brief line
if (javadoc != nullptr && !javadoc->brief().empty()) {
Append("/** ").Append(javadoc->brief()).Append(" */").EndLine();
@@ -345,8 +347,8 @@ void SourceWriter::TypeVisitor::Visit(const Type& type) {
void SourceWriter::GenericNamespace::DoVisit(const Type& type) {
// ignore non-generic parameters, wildcards and generics already declared
- if (type.kind() == Type::GENERIC && !type.wildcard()
- && generic_names_.find(type.name()) == generic_names_.end()) {
+ if (type.kind() == Type::GENERIC && !type.wildcard() &&
+ generic_names_.find(type.name()) == generic_names_.end()) {
declared_types_.push_back(&type);
generic_names_.insert(type.name());
}
diff --git a/tensorflow/java/src/gen/cc/source_writer.h b/tensorflow/java/src/gen/cc/source_writer.h
index 1f0febe9a3..de0113bd5b 100644
--- a/tensorflow/java/src/gen/cc/source_writer.h
+++ b/tensorflow/java/src/gen/cc/source_writer.h
@@ -93,7 +93,7 @@ class SourceWriter {
// This method appends a new opening brace to the current data and indent the
// next lines according to Google Java Style Guide. The block can optionally
// be preceded by an expression (e.g. Append("if(true)").BeginBlock();)
- SourceWriter& BeginBlock(const string& expr = "");
+ SourceWriter& BeginBlock(const string& expression = "");
// Ends the current block of source code.
//
@@ -108,7 +108,7 @@ class SourceWriter {
// in parameter to define the access scope of this method and, optionally,
// a Javadoc.
SourceWriter& BeginMethod(const Method& method, int modifiers,
- const Javadoc* javadoc = nullptr);
+ const Javadoc* javadoc = nullptr);
// Ends the current method.
//
@@ -125,9 +125,9 @@ class SourceWriter {
//
// If not null, all types found in the 'extra_dependencies' list will be
// imported before declaring the new type.
- SourceWriter& BeginType(const Type& clazz, int modifiers,
- const std::list<Type>* extra_dependencies = nullptr,
- const Javadoc* javadoc = nullptr);
+ SourceWriter& BeginType(const Type& type, int modifiers,
+ const std::list<Type>* extra_dependencies = nullptr,
+ const Javadoc* javadoc = nullptr);
// Begins to write a new inner type.
//
@@ -136,7 +136,7 @@ class SourceWriter {
// in parameter to define the accesses and the scope of this type and,
// optionally, a Javadoc.
SourceWriter& BeginInnerType(const Type& type, int modifiers,
- const Javadoc* javadoc = nullptr);
+ const Javadoc* javadoc = nullptr);
// Ends the current type.
//
@@ -150,7 +150,7 @@ class SourceWriter {
// or BeginInnerType()). Modifiers are also be passed in parameter to define
// the accesses and the scope of this field and, optionally, a Javadoc.
SourceWriter& WriteField(const Variable& field, int modifiers,
- const Javadoc* javadoc = nullptr);
+ const Javadoc* javadoc = nullptr);
protected:
virtual void DoAppend(const StringPiece& str) = 0;
diff --git a/tensorflow/java/src/gen/cc/source_writer_test.cc b/tensorflow/java/src/gen/cc/source_writer_test.cc
index b9a5fee9be..fb8fc64dff 100644
--- a/tensorflow/java/src/gen/cc/source_writer_test.cc
+++ b/tensorflow/java/src/gen/cc/source_writer_test.cc
@@ -245,12 +245,17 @@ TEST(StreamTest, Types) {
SourceBufferWriter writer;
Type generic = Type::Generic("T").add_supertype(Type::Class("Number"));
- writer.AppendType(Type::Int()).Append(", ")
- .AppendType(Type::Class("String")).Append(", ")
- .AppendType(generic).Append(", ")
- .AppendType(Type::ListOf(generic)).Append(", ")
- .AppendType(Type::ListOf(Type::IterableOf(generic))).Append(", ")
- .AppendType(Type::ListOf(Type::Wildcard()));
+ writer.AppendType(Type::Int())
+ .Append(", ")
+ .AppendType(Type::Class("String"))
+ .Append(", ")
+ .AppendType(generic)
+ .Append(", ")
+ .AppendType(Type::ListOf(generic))
+ .Append(", ")
+ .AppendType(Type::ListOf(Type::IterableOf(generic)))
+ .Append(", ")
+ .AppendType(Type::ListOf(Type::Wildcard()));
const char* expected =
"int, String, T, List<T>, List<Iterable<T>>, List<?>";
@@ -314,7 +319,7 @@ TEST(WriteType, AnnotatedAndDocumentedClass) {
SourceBufferWriter writer;
Type clazz = Type::Class("Test", "org.tensorflow");
Javadoc clazz_doc = Javadoc::Create("Javadoc test")
- .details("This is a\nmultiline description.");
+ .details("This is a\nmultiline description.");
clazz.add_annotation(Annotation::Create("Bean"));
clazz.add_annotation(Annotation::Create("SuppressWarnings")
.attributes("\"rawtypes\""));
@@ -380,10 +385,10 @@ TEST(WriteType, ParameterizedClassFields) {
Javadoc field3_doc = Javadoc::Create("This variable is documented");
writer.BeginType(clazz, PUBLIC)
- .WriteField(field1, STATIC | PUBLIC | FINAL)
- .WriteField(field2, PRIVATE)
- .WriteField(field3, PRIVATE, &field3_doc)
- .EndType();
+ .WriteField(field1, STATIC | PUBLIC | FINAL)
+ .WriteField(field2, PRIVATE)
+ .WriteField(field3, PRIVATE, &field3_doc)
+ .EndType();
const char* expected =
"package org.tensorflow;\n\n"
@@ -402,9 +407,9 @@ TEST(WriteType, SimpleInnerClass) {
Type inner_class = Type::Class("InnerTest");
writer.BeginType(clazz, PUBLIC)
- .BeginInnerType(inner_class, PUBLIC)
- .EndType()
- .EndType();
+ .BeginInnerType(inner_class, PUBLIC)
+ .EndType()
+ .EndType();
const char* expected =
"package org.tensorflow;\n\n"
@@ -425,9 +430,9 @@ TEST(WriteType, StaticParameterizedInnerClass) {
inner_class.add_parameter(type_t);
writer.BeginType(clazz, PUBLIC)
- .BeginInnerType(inner_class, PUBLIC | STATIC)
- .EndType()
- .EndType();
+ .BeginInnerType(inner_class, PUBLIC | STATIC)
+ .EndType()
+ .EndType();
const char* expected =
"package org.tensorflow;\n\n"
@@ -445,8 +450,9 @@ TEST(WriteMethod, SimpleMethod) {
Method method = Method::Create("doNothing", Type::Void());
writer.BeginType(clazz, PUBLIC)
- .BeginMethod(method, PUBLIC).EndMethod()
- .EndType();
+ .BeginMethod(method, PUBLIC)
+ .EndMethod()
+ .EndType();
const char* expected =
"package org.tensorflow;\n\n"
@@ -462,15 +468,17 @@ TEST(WriteMethod, AnnotatedAndDocumentedMethod) {
SourceBufferWriter writer;
Type clazz = Type::Class("Test", "org.tensorflow");
Method method = Method::Create("doNothing", Type::Void());
- Javadoc method_doc = Javadoc::Create("Javadoc test")
- .details("This method has a\nmultiline description.");
+ Javadoc method_doc =
+ Javadoc::Create("Javadoc test")
+ .details("This method has a\nmultiline description.");
method.add_annotation(Annotation::Create("Override"));
method.add_annotation(Annotation::Create("SuppressWarnings")
.attributes("\"rawtypes\""));
writer.BeginType(clazz, PUBLIC)
- .BeginMethod(method, PUBLIC, &method_doc).EndMethod()
- .EndType();
+ .BeginMethod(method, PUBLIC, &method_doc)
+ .EndMethod()
+ .EndType();
const char* expected =
"package org.tensorflow;\n\n"
@@ -497,20 +505,23 @@ TEST(WriteMethod, DocumentedMethodWithArguments) {
Method method = Method::Create("boolToInt", Type::Int());
method.add_argument(Variable::Create("b", Type::Boolean()));
method.add_argument(reverse);
- Javadoc method_doc = Javadoc::Create("Converts a boolean to an int")
- .details("This method will convert\na boolean to an int")
- .add_param_tag(reverse.name(), "if true, value is reversed")
- .add_tag("return", "int value for this boolean");
+ Javadoc method_doc =
+ Javadoc::Create("Converts a boolean to an int")
+ .details("This method will convert\na boolean to an int")
+ .add_param_tag(reverse.name(), "if true, value is reversed")
+ .add_tag("return", "int value for this boolean");
writer.BeginType(clazz, PUBLIC)
- .BeginMethod(method, PUBLIC, &method_doc)
- .Append("if (b && !reverse)")
- .BeginBlock()
- .Append("return 1;").EndLine()
- .EndBlock()
- .Append("return 0;").EndLine()
- .EndMethod()
- .EndType();
+ .BeginMethod(method, PUBLIC, &method_doc)
+ .Append("if (b && !reverse)")
+ .BeginBlock()
+ .Append("return 1;")
+ .EndLine()
+ .EndBlock()
+ .Append("return 0;")
+ .EndLine()
+ .EndMethod()
+ .EndType();
const char* expected =
"package org.tensorflow;\n\n"
@@ -543,10 +554,11 @@ TEST(WriteMethod, ParameterizedMethod) {
Method method = Method::Create("doNothing", type_t);
writer.BeginType(clazz, PUBLIC)
- .BeginMethod(method, PUBLIC)
- .Append("return null;").EndLine()
- .EndMethod()
- .EndType();
+ .BeginMethod(method, PUBLIC)
+ .Append("return null;")
+ .EndLine()
+ .EndMethod()
+ .EndType();
const char* expected =
"package org.tensorflow;\n\n"
@@ -567,10 +579,11 @@ TEST(WriteMethod, StaticParameterizedMethod) {
Method method = Method::Create("doNothing", type_t);
writer.BeginType(clazz, PUBLIC)
- .BeginMethod(method, PUBLIC | STATIC)
- .Append("return null;").EndLine()
- .EndMethod()
- .EndType();
+ .BeginMethod(method, PUBLIC | STATIC)
+ .Append("return null;")
+ .EndLine()
+ .EndMethod()
+ .EndType();
const char* expected =
"package org.tensorflow;\n\n"