aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorMax Cai <maxtroy@google.com>2013-07-24 14:16:38 +0100
committerMax Cai <maxtroy@google.com>2013-07-25 19:49:23 +0100
commit8170787391efcb6cc6a8babc1cce35d5b1aff420 (patch)
tree161feb4e9f57c056a743590a090748217d5c0b22 /java
parent3099f911382d143d9b702d36e5e52d2f37d8edd9 (diff)
downloadexternal_protobuf-8170787391efcb6cc6a8babc1cce35d5b1aff420.zip
external_protobuf-8170787391efcb6cc6a8babc1cce35d5b1aff420.tar.gz
external_protobuf-8170787391efcb6cc6a8babc1cce35d5b1aff420.tar.bz2
Per-file java_multiple_files flag.
Imported source files may have different values for the 'java_multiple_files' option to the main source file's. Whether the fully qualified Java name of an entity should include the outer class name depends on the flag value in the file defining the referenced entity, not the main file. This CL loads the flag values from the main and all transitively imported files into the params, and generates the fully qualified Java names accordingly. If the generator option 'java_multiple_files' is set, its value overrides any in-file values in all source/imported files. This is because this generator option is typically used on either none or all source files. Change-Id: Id6a4a42426d68961dc669487d38f35530deb7d8e
Diffstat (limited to 'java')
-rw-r--r--java/pom.xml2
-rw-r--r--java/src/test/java/com/google/protobuf/MicroTest.java21
-rw-r--r--java/src/test/java/com/google/protobuf/NanoTest.java16
3 files changed, 37 insertions, 2 deletions
diff --git a/java/pom.xml b/java/pom.xml
index 0b9f6e4..399540f 100644
--- a/java/pom.xml
+++ b/java/pom.xml
@@ -126,6 +126,7 @@
<arg value="../src/google/protobuf/unittest_stringutf8_micro.proto" />
<arg value="../src/google/protobuf/unittest_recursive_micro.proto" />
<arg value="../src/google/protobuf/unittest_import_micro.proto" />
+ <arg value="../src/google/protobuf/unittest_multiple_micro.proto" />
</exec>
<exec executable="../src/protoc">
<arg value="--javanano_out=java_package=google/protobuf/unittest_import_nano.proto|com.google.protobuf.nano,java_outer_classname=google/protobuf/unittest_import_nano.proto|UnittestImportNano:target/generated-test-sources" />
@@ -137,6 +138,7 @@
<arg value="../src/google/protobuf/unittest_recursive_nano.proto" />
<arg value="../src/google/protobuf/unittest_import_nano.proto" />
<arg value="../src/google/protobuf/unittest_enum_multiplejava_nano.proto" />
+ <arg value="../src/google/protobuf/unittest_multiple_nano.proto" />
</exec>
<exec executable="../src/protoc">
<arg value="--javanano_out=store_unknown_fields=true:target/generated-test-sources" />
diff --git a/java/src/test/java/com/google/protobuf/MicroTest.java b/java/src/test/java/com/google/protobuf/MicroTest.java
index 9e18feb..03005a7 100644
--- a/java/src/test/java/com/google/protobuf/MicroTest.java
+++ b/java/src/test/java/com/google/protobuf/MicroTest.java
@@ -30,14 +30,16 @@
package com.google.protobuf;
+import com.google.protobuf.micro.ByteStringMicro;
+import com.google.protobuf.micro.CodedInputStreamMicro;
import com.google.protobuf.micro.MicroOuterClass;
import com.google.protobuf.micro.MicroOuterClass.TestAllTypesMicro;
+import com.google.protobuf.micro.MultipleImportingNonMultipleMicro1;
+import com.google.protobuf.micro.MultipleImportingNonMultipleMicro2;
import com.google.protobuf.micro.RecursiveMessageMicro;
import com.google.protobuf.micro.SimpleMessageMicro;
import com.google.protobuf.micro.StringUtf8;
import com.google.protobuf.micro.UnittestImportMicro;
-import com.google.protobuf.micro.ByteStringMicro;
-import com.google.protobuf.micro.CodedInputStreamMicro;
import junit.framework.TestCase;
@@ -2101,6 +2103,21 @@ public class MicroTest extends TestCase {
assertEquals("world", newMsg.getRepeatedCord(1));
}
+ /**
+ * Tests that code generation with mixed values of the java_multiple_files
+ * options between the main source file and the imported source files would
+ * generate correct references. Any error would cause this method to fail
+ * compilation.
+ */
+ public void testMicroMultipleImportingNonMultiple() throws Exception {
+ UnittestImportMicro.ImportMessageMicro importMsg =
+ new UnittestImportMicro.ImportMessageMicro();
+ MultipleImportingNonMultipleMicro1 micro1 = new MultipleImportingNonMultipleMicro1();
+ micro1.setField(importMsg);
+ MultipleImportingNonMultipleMicro2 micro2 = new MultipleImportingNonMultipleMicro2();
+ micro2.setMicro1(micro1);
+ }
+
public void testMicroDefaults() throws Exception {
TestAllTypesMicro msg = new TestAllTypesMicro();
assertFalse(msg.hasDefaultInt32());
diff --git a/java/src/test/java/com/google/protobuf/NanoTest.java b/java/src/test/java/com/google/protobuf/NanoTest.java
index 92ddda6..0ea80d4 100644
--- a/java/src/test/java/com/google/protobuf/NanoTest.java
+++ b/java/src/test/java/com/google/protobuf/NanoTest.java
@@ -35,6 +35,8 @@ import com.google.protobuf.nano.Extensions;
import com.google.protobuf.nano.Extensions.AnotherMessage;
import com.google.protobuf.nano.InternalNano;
import com.google.protobuf.nano.MessageNano;
+import com.google.protobuf.nano.MultipleImportingNonMultipleNano1;
+import com.google.protobuf.nano.MultipleImportingNonMultipleNano2;
import com.google.protobuf.nano.NanoOuterClass;
import com.google.protobuf.nano.NanoOuterClass.TestAllTypesNano;
import com.google.protobuf.nano.RecursiveMessageNano;
@@ -2039,6 +2041,20 @@ public class NanoTest extends TestCase {
assertEquals(nestedMsg2.bb, newMsg.repeatedNestedMessage[2].bb);
}
+ /**
+ * Tests that code generation with mixed values of the java_multiple_files
+ * options between the main source file and the imported source files would
+ * generate correct references. Any error would cause this method to fail
+ * compilation.
+ */
+ public void testNanoMultipleImportingNonMultiple() throws Exception {
+ UnittestImportNano.ImportMessageNano importMsg = new UnittestImportNano.ImportMessageNano();
+ MultipleImportingNonMultipleNano1 nano1 = new MultipleImportingNonMultipleNano1();
+ nano1.field = importMsg;
+ MultipleImportingNonMultipleNano2 nano2 = new MultipleImportingNonMultipleNano2();
+ nano2.nano1 = nano1;
+ }
+
public void testNanoDefaults() throws Exception {
TestAllTypesNano msg = new TestAllTypesNano();
for (int i = 0; i < 2; i++) {