THRIFT-3220 Option to suppress @Generated Annotation entirely
Client: Java
Patch: notona <notona@gmail.com> & Jens Geyer
This closes #540
This change contains:
- the work of notona from GitHub PR 540
- additional changes I made to align THRIFT-3220 and THRIFT-3193
diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc
index d5b46f9..c4cbc45 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -91,8 +91,14 @@
iter = parsed_options.find("option_type");
use_option_type_ = (iter != parsed_options.end());
- iter = parsed_options.find("undated_generated_annotations");
- undated_generated_annotations_ = (iter != parsed_options.end());
+ iter = parsed_options.find("generated_annotations");
+ if (iter != parsed_options.end()) {
+ undated_generated_annotations_ = (iter->second.compare("undated") == 0);
+ suppress_generated_annotations_ = (iter->second.compare("suppress") == 0);
+ } else {
+ undated_generated_annotations_ = false;
+ suppress_generated_annotations_ = false;
+ }
out_dir_base_ = (bean_style_ ? "gen-javabean" : "gen-java");
}
@@ -347,6 +353,8 @@
bool reuse_objects_;
bool use_option_type_;
bool undated_generated_annotations_;
+ bool suppress_generated_annotations_;
+
};
/**
@@ -396,6 +404,8 @@
string t_java_generator::java_type_imports() {
string hash_builder;
string tree_set_and_map;
+ string annotation_generated;
+
string option;
if (sorted_containers_) {
tree_set_and_map = string() + "import java.util.TreeSet;\n" + "import java.util.TreeMap;\n";
@@ -405,6 +415,11 @@
option = string() + "import org.apache.thrift.Option;\n";
}
+ // android does not support @Generated Annotation
+ if (!suppress_generated_annotations_) {
+ annotation_generated = string() + "import javax.annotation.Generated;\n";
+ }
+
return string() + hash_builder + "import org.apache.thrift.scheme.IScheme;\n"
+ "import org.apache.thrift.scheme.SchemeFactory;\n"
+ "import org.apache.thrift.scheme.StandardScheme;\n\n"
@@ -421,7 +436,7 @@
+ "import java.util.HashSet;\n" + "import java.util.EnumSet;\n" + tree_set_and_map
+ "import java.util.Collections;\n" + "import java.util.BitSet;\n"
+ "import java.nio.ByteBuffer;\n"
- "import java.util.Arrays;\n" + "import javax.annotation.Generated;\n"
+ + "import java.util.Arrays;\n" + annotation_generated
+ "import org.slf4j.Logger;\n" + "import org.slf4j.LoggerFactory;\n\n";
}
@@ -1333,7 +1348,7 @@
bool is_final = (tstruct->annotations_.find("final") != tstruct->annotations_.end());
- if (!in_class) {
+ if (!in_class && !suppress_generated_annotations_) {
generate_javax_generated_annotation(out);
}
@@ -2635,7 +2650,9 @@
f_service_ << autogen_comment() << java_package() << java_type_imports() << java_suppressions();
- generate_javax_generated_annotation(f_service_);
+ if (!suppress_generated_annotations_) {
+ generate_javax_generated_annotation(f_service_);
+ }
f_service_ << "public class " << service_name_ << " {" << endl << endl;
indent_up();
@@ -5124,5 +5141,6 @@
" sorted_containers:\n"
" Use TreeSet/TreeMap instead of HashSet/HashMap as a implementation of "
"set/map.\n"
- " undated_generated_annotations:\n"
- " Do not generate the date for the @Generated annotation")
+ " generated_annotations=[undated|suppress]:\n"
+ " undated: suppress the date at @Generated annotations\n"
+ " suppress: suppress @Generated annotations entirely\n")