Make the Java generator dynamic.
- Modify the Java generator constructor to fit the new generic interface.
- Register the Java genrator with the central registry.
- Deprecate the old way of invoking the Java generator.
- main.cc no longer includes t_java_generator.h.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665510 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 ea91f66..07ef330 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -2022,3 +2022,8 @@
indent(out) << " */" << endl;
}
}
+
+
+THRIFT_REGISTER_GENERATOR(java, "Java",
+" beans: Generate bean-style output files.\n"
+);
diff --git a/compiler/cpp/src/generate/t_java_generator.h b/compiler/cpp/src/generate/t_java_generator.h
index fe0a481..ea3e1e8 100644
--- a/compiler/cpp/src/generate/t_java_generator.h
+++ b/compiler/cpp/src/generate/t_java_generator.h
@@ -21,9 +21,16 @@
*/
class t_java_generator : public t_oop_generator {
public:
- t_java_generator(t_program* program, bool bean_style=false) :
- t_oop_generator(program),
- bean_style_(bean_style) {
+ t_java_generator(
+ t_program* program,
+ const std::map<std::string, std::string>& parsed_options,
+ const std::string& option_string)
+ : t_oop_generator(program)
+ {
+ std::map<std::string, std::string>::const_iterator iter;
+
+ iter = parsed_options.find("beans");
+ bean_style_ = (iter != parsed_options.end());
out_dir_base_ = (bean_style_ ? "gen-javabean" : "gen-java");
}
diff --git a/compiler/cpp/src/main.cc b/compiler/cpp/src/main.cc
index 375c4a0..75d23e2 100644
--- a/compiler/cpp/src/main.cc
+++ b/compiler/cpp/src/main.cc
@@ -34,7 +34,6 @@
#include "main.h"
#include "parse/t_program.h"
#include "parse/t_scope.h"
-#include "generate/t_java_generator.h"
#include "generate/t_php_generator.h"
#include "generate/t_py_generator.h"
#include "generate/t_rb_generator.h"
@@ -601,8 +600,6 @@
void usage() {
fprintf(stderr, "Usage: thrift [options] file\n");
fprintf(stderr, "Options:\n");
- fprintf(stderr, " -java Generate Java output files\n");
- fprintf(stderr, " -javabean Generate Java bean-style output files\n");
fprintf(stderr, " -php Generate PHP output files\n");
fprintf(stderr, " -phpi Generate PHP inlined files\n");
fprintf(stderr, " -phps Generate PHP server stubs (with -php)\n");
@@ -868,20 +865,6 @@
// Compute fingerprints.
generate_all_fingerprints(program);
- if (gen_java) {
- pverbose("Generating Java\n");
- t_java_generator* java = new t_java_generator(program, false);
- java->generate_program();
- delete java;
- }
-
- if (gen_javabean) {
- pverbose("Generating Java Beans\n");
- t_java_generator* java = new t_java_generator(program, true);
- java->generate_program();
- delete java;
- }
-
if (gen_php) {
pverbose("Generating PHP\n");
t_php_generator* php = new t_php_generator(program, false, gen_rest, gen_phps, gen_phpa, gen_phpo);
@@ -1150,8 +1133,17 @@
}
generator_strings.push_back(gen_string);
}
+ if (gen_java) {
+ pwarning(1, "-java is deprecated. Use --gen java");
+ generator_strings.push_back("java");
+ }
+ if (gen_javabean) {
+ pwarning(1, "-javabean is deprecated. Use --gen java:beans");
+ generator_strings.push_back("java:beans");
+ }
+
// You gotta generate something!
- if (!gen_java && !gen_javabean && !gen_php && !gen_phpi && !gen_py && !gen_rb && !gen_xsd && !gen_perl && !gen_erl && !gen_ocaml && !gen_hs && !gen_cocoa && !gen_st && !gen_csharp && generator_strings.empty()) {
+ if (!gen_php && !gen_phpi && !gen_py && !gen_rb && !gen_xsd && !gen_perl && !gen_erl && !gen_ocaml && !gen_hs && !gen_cocoa && !gen_st && !gen_csharp && generator_strings.empty()) {
fprintf(stderr, "!!! No output language(s) specified\n\n");
usage();
}