Permalink
Browse files

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
  • Loading branch information...
1 parent 2b6a5c0 commit eeccf0beae1705cb8b84b394611e59314132c3c7 dreiss committed Oct 29, 2008
Showing with 29 additions and 10 deletions.
  1. +7 −10 compiler/cpp/src/generate/t_java_generator.cc
  2. +22 −0 compiler/cpp/src/generate/t_oop_generator.h
@@ -580,6 +580,7 @@ void t_java_generator::generate_java_struct_definition(ofstream &out,
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 @@ void t_java_generator::generate_java_bean_boilerplate(ofstream& out,
}
// 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 @@ void t_java_generator::generate_java_bean_boilerplate(ofstream& out,
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 @@ string t_java_generator::type_to_enum(t_type* type) {
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");
}
}
@@ -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 @@ class t_oop_generator : public t_generator {
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!

0 comments on commit eeccf0b

Please sign in to comment.