THRIFT-178. java, csharp, cpp: Final Keyword
The lexer has been changed to make "final" a non-reserved word, and the java, csharp, and cpp compilers now look for the final annotation and amend their class declarations appropriately.
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@739788 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc
index 4cb3538..318c36b 100644
--- a/compiler/cpp/src/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/generate/t_cpp_generator.cc
@@ -680,9 +680,11 @@
scope_down(out);
}
- out <<
- endl <<
- indent() << "virtual ~" << tstruct->get_name() << "() throw() {}" << endl << endl;
+ if (tstruct->annotations_.find("final") == tstruct->annotations_.end()) {
+ out <<
+ endl <<
+ indent() << "virtual ~" << tstruct->get_name() << "() throw() {}" << endl << endl;
+ }
// Pointer to this structure's reflection local typespec.
if (gen_dense_) {
diff --git a/compiler/cpp/src/generate/t_csharp_generator.cc b/compiler/cpp/src/generate/t_csharp_generator.cc
index 088a025..ee56f5e 100644
--- a/compiler/cpp/src/generate/t_csharp_generator.cc
+++ b/compiler/cpp/src/generate/t_csharp_generator.cc
@@ -393,7 +393,9 @@
out << endl;
indent(out) << "[Serializable]" << endl;
- indent(out) << "public class " << tstruct->get_name() << " : ";
+ bool is_final = (tstruct->annotations_.find("final") != tstruct->annotations_.end());
+
+ indent(out) << "public " << (is_final ? "sealed " : "") << "class " << tstruct->get_name() << " : ";
if (is_exception) {
out << "Exception, ";
diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc
index 30e7f78..3d24ece 100644
--- a/compiler/cpp/src/generate/t_java_generator.cc
+++ b/compiler/cpp/src/generate/t_java_generator.cc
@@ -596,8 +596,11 @@
bool is_result) {
generate_java_doc(out, tstruct);
+ bool is_final = (tstruct->annotations_.find("final") != tstruct->annotations_.end());
+
indent(out) <<
- "public " << (in_class ? "static " : "") << "class " << tstruct->get_name() << " ";
+ "public " << (is_final ? "final " : "") <<
+ (in_class ? "static " : "") << "class " << tstruct->get_name() << " ";
if (is_exception) {
out << "extends Exception ";
diff --git a/compiler/cpp/src/thriftl.ll b/compiler/cpp/src/thriftl.ll
index 62cdb16..1051e27 100644
--- a/compiler/cpp/src/thriftl.ll
+++ b/compiler/cpp/src/thriftl.ll
@@ -141,7 +141,6 @@
"except" { thrift_reserved_keyword(yytext); }
"exec" { thrift_reserved_keyword(yytext); }
"false" { thrift_reserved_keyword(yytext); }
-"final" { thrift_reserved_keyword(yytext); }
"finally" { thrift_reserved_keyword(yytext); }
"float" { thrift_reserved_keyword(yytext); }
"for" { thrift_reserved_keyword(yytext); }