THRIFT-1813 java: Add @Generated annotation to generated classes
Patch: Arvind Jayaprakash and Andrew Gaul
diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc
index ec9e1fc..9b48df0 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -18,6 +18,7 @@
*/
#include <cassert>
+#include <ctime>
#include <sstream>
#include <string>
@@ -177,6 +178,7 @@
void generate_java_struct_tuple_reader(ofstream& out, t_struct* tstruct);
void generate_java_struct_tuple_writer(ofstream& out, t_struct* tstruct);
+ void generate_javax_generated_annotation(ofstream& out);
/**
* Serialization constructs
*/
@@ -396,6 +398,7 @@
"import java.util.BitSet;\n" +
"import java.nio.ByteBuffer;\n"
"import java.util.Arrays;\n" +
+ "import javax.annotation.Generated;\n" +
"import org.slf4j.Logger;\n" +
"import org.slf4j.LoggerFactory;\n\n";
}
@@ -1281,6 +1284,10 @@
bool is_final = (tstruct->annotations_.find("final") != tstruct->annotations_.end());
+ if (!in_class) {
+ generate_javax_generated_annotation(out);
+ }
+
indent(out) <<
"public " << (is_final ? "final " : "") <<
(in_class ? "static " : "") << "class " << tstruct->get_name() << " ";
@@ -2241,6 +2248,7 @@
java_package() <<
java_type_imports();
+ generate_javax_generated_annotation(f_service_);
f_service_ << "public class " << service_name_ << " {" << endl << endl;
indent_up();
@@ -4518,6 +4526,15 @@
out << indent() << "}" << endl << endl;
}
+void t_java_generator::generate_javax_generated_annotation(ofstream& out){
+ time_t seconds = time(NULL);
+ struct tm *now = localtime(&seconds);
+ indent(out) << "@Generated(value = \"" << autogen_summary()
+ << "\", date = \"" << (now->tm_year + 1900)
+ << "-" << (now->tm_mon + 1) << "-" << now->tm_mday
+ << "\")" << endl;
+}
+
THRIFT_REGISTER_GENERATOR(java, "Java",
" beans: Members will be private, and setter methods will return void.\n"
" private-members: Members will be private, but setter methods will return 'this' like usual.\n"
diff --git a/compiler/cpp/src/generate/t_oop_generator.h b/compiler/cpp/src/generate/t_oop_generator.h
index 20b73b2..0cf2dce 100644
--- a/compiler/cpp/src/generate/t_oop_generator.h
+++ b/compiler/cpp/src/generate/t_oop_generator.h
@@ -67,12 +67,17 @@
virtual std::string autogen_comment() {
return
std::string("/**\n") +
- " * Autogenerated by Thrift Compiler (" + THRIFT_VERSION + ")\n" +
+ " * " + autogen_summary() + "\n" +
" *\n" +
" * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n" +
" * @generated\n" +
" */\n";
}
+
+ virtual std::string autogen_summary() {
+ return
+ std::string("Autogenerated by Thrift Compiler (") + THRIFT_VERSION + ")";
+ }
};
#endif