You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2008/07/14 21:35:50 UTC

svn commit: r676699 - /incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc

Author: dreiss
Date: Mon Jul 14 12:35:50 2008
New Revision: 676699

URL: http://svn.apache.org/viewvc?rev=676699&view=rev
Log:
java: Add nocamel option to not CamelCase field accessors [THRIFT-42]

Modified:
    incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc

Modified: incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc?rev=676699&r1=676698&r2=676699&view=diff
==============================================================================
--- incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc (original)
+++ incubator/thrift/trunk/compiler/cpp/src/generate/t_java_generator.cc Mon Jul 14 12:35:50 2008
@@ -35,6 +35,9 @@
     iter = parsed_options.find("beans");
     bean_style_ = (iter != parsed_options.end());
 
+    iter = parsed_options.find("nocamel");
+    nocamel_style_ = (iter != parsed_options.end());
+
     iter = parsed_options.find("hashcode");
     gen_hash_code_ = (iter != parsed_options.end());
 
@@ -179,6 +182,7 @@
   std::string package_dir_;
 
   bool bean_style_;
+  bool nocamel_style_;
   bool gen_hash_code_;
 
 };
@@ -391,7 +395,11 @@
       indent(out) << name << ".";
       if (bean_style_) {
         std::string cap_name = v_iter->first->get_string();
-        cap_name[0] = toupper(cap_name[0]);
+        if (nocamel_style_) {
+          cap_name = "_" + cap_name;
+        } else {
+          cap_name[0] = toupper(cap_name[0]);
+        }
         out << "set" << cap_name << "(" << val << ")";
       } else {
         out << v_iter->first->get_string() << " = " << val;
@@ -1033,7 +1041,11 @@
     t_type* type = get_true_type(field->get_type());
     std::string field_name = field->get_name();
     std::string cap_name = field_name;
-    cap_name[0] = toupper(cap_name[0]);
+    if (nocamel_style_) {
+      cap_name = "_" + cap_name;
+    } else {
+      cap_name[0] = toupper(cap_name[0]);
+    }
 
     if (type->is_container()) {
       // Method to return the size of the collection
@@ -2352,5 +2364,6 @@
 
 THRIFT_REGISTER_GENERATOR(java, "Java",
 "    beans:           Generate bean-style output files.\n"
+"    nocamel:         Do not use CamelCase field accessors with beans.\n"
 "    hashcode:        Generate quality hashCode methods.\n"
 );