aboutsummaryrefslogtreecommitdiff
path: root/src/google/protobuf/compiler/java/java_file.cc
diff options
context:
space:
mode:
authorkenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-07-29 01:13:20 +0000
committerkenton@google.com <kenton@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2009-07-29 01:13:20 +0000
commit80b1d62bfcea65c59e2160da71dad84b1bd19cef (patch)
tree5423b830c53174fec83a7ea01ff0877e11c1ddb6 /src/google/protobuf/compiler/java/java_file.cc
parentd2fd0638c309113ccae3731a58e30419f522269a (diff)
downloadprotobuf-80b1d62bfcea65c59e2160da71dad84b1bd19cef.tar.gz
protobuf-80b1d62bfcea65c59e2160da71dad84b1bd19cef.tar.bz2
protobuf-80b1d62bfcea65c59e2160da71dad84b1bd19cef.zip
Submit recent changes from internal branch, including "lite mode" for
C++ and Java. See CHANGES.txt for more details.
Diffstat (limited to 'src/google/protobuf/compiler/java/java_file.cc')
-rw-r--r--src/google/protobuf/compiler/java/java_file.cc43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/google/protobuf/compiler/java/java_file.cc b/src/google/protobuf/compiler/java/java_file.cc
index 31d75be6..0e170b38 100644
--- a/src/google/protobuf/compiler/java/java_file.cc
+++ b/src/google/protobuf/compiler/java/java_file.cc
@@ -151,7 +151,9 @@ void FileGenerator::Generate(io::Printer* printer) {
printer->Print(
"public static void registerAllExtensions(\n"
- " com.google.protobuf.ExtensionRegistry registry) {\n");
+ " com.google.protobuf.ExtensionRegistry$lite$ registry) {\n",
+ "lite", HasDescriptorMethods(file_) ? "" : "Lite");
+
printer->Indent();
for (int i = 0; i < file_->extension_count(); i++) {
@@ -195,8 +197,42 @@ void FileGenerator::Generate(io::Printer* printer) {
printer->Print("\n");
- // -----------------------------------------------------------------
+ if (HasDescriptorMethods(file_)) {
+ GenerateEmbeddedDescriptor(printer);
+ } else {
+ printer->Print(
+ "static {\n");
+ printer->Indent();
+ for (int i = 0; i < file_->message_type_count(); i++) {
+ // TODO(kenton): Reuse MessageGenerator objects?
+ MessageGenerator(file_->message_type(i))
+ .GenerateStaticVariableInitializers(printer);
+ }
+
+ for (int i = 0; i < file_->extension_count(); i++) {
+ // TODO(kenton): Reuse ExtensionGenerator objects?
+ ExtensionGenerator(file_->extension(i))
+ .GenerateInitializationCode(printer);
+ }
+
+ printer->Outdent();
+ printer->Print(
+ "}\n");
+ }
+
+ // Dummy function we can use to force the static initialization block to
+ // run. Needed by inner classes. Cannot be private due to
+ // java_multiple_files option.
+ printer->Print(
+ "\n"
+ "public static void internalForceInit() {}\n");
+
+ printer->Outdent();
+ printer->Print("}\n");
+}
+
+void FileGenerator::GenerateEmbeddedDescriptor(io::Printer* printer) {
// Embed the descriptor. We simply serialize the entire FileDescriptorProto
// and embed it as a string literal, which is parsed and built into real
// descriptors at initialization time. We unfortunately have to put it in
@@ -310,9 +346,6 @@ void FileGenerator::Generate(io::Printer* printer) {
printer->Outdent();
printer->Print(
"}\n");
-
- printer->Outdent();
- printer->Print("}\n");
}
template<typename GeneratorClass, typename DescriptorClass>