From 98e962bf24b7c1758c01a268d494c8e9e62642fe Mon Sep 17 00:00:00 2001 From: Mark Slee Date: Tue, 20 Feb 2007 18:44:05 +0000 Subject: [PATCH] Generate Java code into proper source directory heirarchy Reviewed By: tbr-aditya git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665001 13f79535-47bb-0310-9956-ffa450edef68 --- compiler/cpp/src/generate/t_java_generator.cc | 23 +++++++++++++++---- compiler/cpp/src/generate/t_java_generator.h | 1 + compiler/cpp/src/generate/t_php_generator.cc | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/compiler/cpp/src/generate/t_java_generator.cc b/compiler/cpp/src/generate/t_java_generator.cc index 8894c99d6..3dc50ff4c 100644 --- a/compiler/cpp/src/generate/t_java_generator.cc +++ b/compiler/cpp/src/generate/t_java_generator.cc @@ -14,6 +14,21 @@ void t_java_generator::init_generator() { // Make output directory mkdir(T_JAVA_DIR, S_IREAD | S_IWRITE | S_IEXEC); package_name_ = program_->get_java_package(); + + string dir = package_name_; + string subdir = T_JAVA_DIR; + string::size_type loc; + while ((loc = dir.find(".")) != string::npos) { + subdir = subdir + "/" + dir.substr(0, loc); + mkdir(subdir.c_str(), S_IREAD | S_IWRITE | S_IEXEC); + dir = dir.substr(loc+1); + } + if (dir.size() > 0) { + subdir = subdir + "/" + dir; + mkdir(subdir.c_str(), S_IREAD | S_IWRITE | S_IEXEC); + } + + package_dir_ = subdir; } /** @@ -76,7 +91,7 @@ void t_java_generator::generate_typedef(t_typedef* ttypedef) {} */ void t_java_generator::generate_enum(t_enum* tenum) { // Make output file - string f_enum_name = string(T_JAVA_DIR)+"/"+(tenum->get_name())+".java"; + string f_enum_name = package_dir_+"/"+(tenum->get_name())+".java"; ofstream f_enum; f_enum.open(f_enum_name.c_str()); @@ -112,7 +127,7 @@ void t_java_generator::generate_enum(t_enum* tenum) { * Generates a class that holds all the constants. */ void t_java_generator::generate_consts(std::vector consts) { - string f_consts_name = string(T_JAVA_DIR)+"/Constants.java"; + string f_consts_name = package_dir_+"/Constants.java"; ofstream f_consts; f_consts.open(f_consts_name.c_str()); @@ -301,7 +316,7 @@ void t_java_generator::generate_xception(t_struct* txception) { void t_java_generator::generate_java_struct(t_struct* tstruct, bool is_exception) { // Make output file - string f_struct_name = string(T_JAVA_DIR)+"/"+(tstruct->get_name())+".java"; + string f_struct_name = package_dir_+"/"+(tstruct->get_name())+".java"; ofstream f_struct; f_struct.open(f_struct_name.c_str()); @@ -626,7 +641,7 @@ void t_java_generator::generate_java_struct_result_writer(ofstream& out, */ void t_java_generator::generate_service(t_service* tservice) { // Make output file - string f_service_name = string(T_JAVA_DIR)+"/"+service_name_+".java"; + string f_service_name = package_dir_+"/"+service_name_+".java"; f_service_.open(f_service_name.c_str()); f_service_ << diff --git a/compiler/cpp/src/generate/t_java_generator.h b/compiler/cpp/src/generate/t_java_generator.h index 3c7680e23..48533437c 100644 --- a/compiler/cpp/src/generate/t_java_generator.h +++ b/compiler/cpp/src/generate/t_java_generator.h @@ -150,6 +150,7 @@ class t_java_generator : public t_oop_generator { std::string package_name_; std::ofstream f_service_; + std::string package_dir_; }; #endif diff --git a/compiler/cpp/src/generate/t_php_generator.cc b/compiler/cpp/src/generate/t_php_generator.cc index cee406587..35f4de450 100644 --- a/compiler/cpp/src/generate/t_php_generator.cc +++ b/compiler/cpp/src/generate/t_php_generator.cc @@ -664,7 +664,7 @@ void t_php_generator::generate_process_function(t_service* tservice, t_function* tfunction) { // Open function indent(f_service_) << - "private function process_" << tfunction->get_name() << + "protected function process_" << tfunction->get_name() << "($seqid, $input, $output) {" << endl; indent_up();