THRIFT-179. java: Include per-field docstrings in generated code
This also involves refactoring a bit of the functionality into
t_oop_generator.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@708737 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc
index 60ad2fb..2941a39 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -580,6 +580,7 @@
if (bean_style_) {
indent(out) << "private ";
} else {
+ generate_java_doc(out, *m_iter);
indent(out) << "public ";
}
out << declare_field(*m_iter, false) << endl;
@@ -1235,6 +1236,7 @@
}
// Simple getter
+ generate_java_doc(out, field);
indent(out) << "public " << type_name(type);
if (type->is_base_type() &&
((t_base_type*)type)->get_base() == t_base_type::TYPE_BOOL) {
@@ -1249,6 +1251,7 @@
indent(out) << "}" << endl << endl;
// Simple setter
+ generate_java_doc(out, field);
indent(out) << "public void set" << cap_name << "(" << type_name(type) <<
" " << field_name << ") {" << endl;
indent_up();
@@ -2484,16 +2487,10 @@
void t_java_generator::generate_java_doc(ofstream &out,
t_doc* tdoc) {
if (tdoc->has_doc()) {
- indent(out) << "/**" << endl;
- stringstream docs(tdoc->get_doc(), ios_base::in);
- while (!docs.eof()) {
- char line[1024];
- docs.getline(line, 1024);
- if (strlen(line) > 0 || !docs.eof()) { // skip the empty last line
- indent(out) << " * " << line << endl;
- }
- }
- indent(out) << " */" << endl;
+ generate_docstring_comment(out,
+ "/**\n",
+ " * ", tdoc->get_doc(),
+ " */\n");
}
}
diff --git a/compiler/cpp/src/generate/t_oop_generator.h b/compiler/cpp/src/generate/t_oop_generator.h
index 46fb8fb..fb4585c 100644
--- a/compiler/cpp/src/generate/t_oop_generator.h
+++ b/compiler/cpp/src/generate/t_oop_generator.h
@@ -7,6 +7,11 @@
#ifndef T_OOP_GENERATOR_H
#define T_OOP_GENERATOR_H
+#include <sstream>
+#include <string>
+#include <fstream>
+#include <iostream>
+
#include "globals.h"
#include "t_generator.h"
@@ -42,6 +47,23 @@
return original;
}
+ void generate_docstring_comment(std::ofstream& out,
+ std::string comment_start,
+ std::string line_prefix,
+ std::string contents,
+ std::string comment_end) {
+ if (comment_start != "") indent(out) << comment_start;
+ std::stringstream docs(contents, std::ios_base::in);
+ while (!docs.eof()) {
+ char line[1024];
+ docs.getline(line, 1024);
+ if (strlen(line) > 0 || !docs.eof()) { // skip the empty last line
+ indent(out) << line_prefix << line << std::endl;
+ }
+ }
+ if (comment_end != "") indent(out) << comment_end;
+ }
+
/**
* Generates a comment about this code being autogenerated, using C++ style
* comments, which are also fair game in Java / PHP, yay!