aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/javanano/javanano_message.cc
diff options
context:
space:
mode:
authorGravatar Max Cai <maxtroy@google.com>2013-07-29 17:20:50 +0100
committerGravatar Max Cai <maxtroy@google.com>2013-08-05 21:54:58 +0100
commit06eed37ec6a0bc912c0f342ee92449069846cea1 (patch)
treeaf741f5657862c073731290fddc23be1860e8f2e /src/google/protobuf/compiler/javanano/javanano_message.cc
parent064b60c65938dbdb45b1377975cee8a104e6d62b (diff)
Fix outer classname for javamicro/javanano.
- File class name is defined as the java_outer_classname option value or the file name ToCamelCase; never the single message's ClassName. - File-scope enums are translated to constants in the file class, regardless of java_multiple_files. - If java_multiple_files=true, and file's class name equals a message's class name, no error. This is done by detecting that the outer class is not needed and skipping the outer class codegen and clash checks. Note: there is a disparity between java[lite] and the previous java{micr|nan}o: when generating code for a single-message proto, the outer class is omitted by java{micr|nan}o if the file does not have java_outer_classname. This change makes java{micr|nan}o align with java[lite] codegen and create the outer class, but will print some info to warn of potential change of code. - Also fixed the "is_own_file" detection and made all parseX() methods static. Previously, all messages in a java_multiple_files=true file are (incorrectly) considered to be in their own files, including nested messages, causing them to become inner classes (instance- bound) and forcing the parseX() methods to lose the static modifier. - This change supersedes c/60164 and c/60086, which causes javanano to put enum values into enum shell classes if java_multiple_files=true. We now always use the parent class to host the enum values. A future change will add a command line option to provide more flexibility. - Elaborated in java/README.txt. Change-Id: I684932f90e0a028ef37c662b221def5ffa202439
Diffstat (limited to 'src/google/protobuf/compiler/javanano/javanano_message.cc')
-rw-r--r--src/google/protobuf/compiler/javanano/javanano_message.cc20
1 files changed, 4 insertions, 16 deletions
diff --git a/src/google/protobuf/compiler/javanano/javanano_message.cc b/src/google/protobuf/compiler/javanano/javanano_message.cc
index de569441..851c4434 100644
--- a/src/google/protobuf/compiler/javanano/javanano_message.cc
+++ b/src/google/protobuf/compiler/javanano/javanano_message.cc
@@ -114,7 +114,7 @@ void MessageGenerator::GenerateStaticVariableInitializers(
io::Printer* printer) {
// Generate static member initializers for all nested types.
for (int i = 0; i < descriptor_->nested_type_count(); i++) {
- // TODO(kenton): Reuse MessageGenerator objects?
+ // TODO(kenton): Reuse MessageGenerator objects?
MessageGenerator(descriptor_->nested_type(i), params_)
.GenerateStaticVariableInitializers(printer);
}
@@ -124,15 +124,7 @@ void MessageGenerator::Generate(io::Printer* printer) {
const string& file_name = descriptor_->file()->name();
bool is_own_file =
params_.java_multiple_files(file_name)
- || ((descriptor_->containing_type() == NULL)
- && !params_.has_java_outer_classname(file_name));
-
-#if 0
- GOOGLE_LOG(INFO) << "is_own_file=" << is_own_file;
- GOOGLE_LOG(INFO) << "containing_type()=" << ((descriptor_->containing_type() == NULL) ? "NULL" : "not null");
- GOOGLE_LOG(INFO) << "java_multiple_files()=" << params_.java_multiple_files();
- GOOGLE_LOG(INFO) << "has_java_outer_classname()=" << params_.has_java_outer_classname(file_->name());
-#endif
+ && descriptor_->containing_type() == NULL;
if (!params_.store_unknown_fields() &&
(descriptor_->extension_count() != 0 || descriptor_->extension_range_count() != 0)) {
@@ -355,25 +347,21 @@ void MessageGenerator::GenerateMergeFromMethods(io::Printer* printer) {
void MessageGenerator::
GenerateParseFromMethods(io::Printer* printer) {
- bool is_own_file =
- descriptor_->containing_type() == NULL;
-
// Note: These are separate from GenerateMessageSerializationMethods()
// because they need to be generated even for messages that are optimized
// for code size.
printer->Print(
- "public $static$ $classname$ parseFrom(byte[] data)\n"
+ "public static $classname$ parseFrom(byte[] data)\n"
" throws com.google.protobuf.nano.InvalidProtocolBufferNanoException {\n"
" return com.google.protobuf.nano.MessageNano.mergeFrom(new $classname$(), data);\n"
"}\n"
"\n"
- "public $static$ $classname$ parseFrom(\n"
+ "public static $classname$ parseFrom(\n"
" com.google.protobuf.nano.CodedInputByteBufferNano input)\n"
" throws java.io.IOException {\n"
" return new $classname$().mergeFrom(input);\n"
"}\n"
"\n",
- "static", (is_own_file ? "static" : ""),
"classname", descriptor_->name());
}