THRIFT-4086: Use true type when generating field meta data (#2765)

Client: java
diff --git a/lib/java/gradle/generateTestThrift.gradle b/lib/java/gradle/generateTestThrift.gradle
index 301812f..10bb16b 100644
--- a/lib/java/gradle/generateTestThrift.gradle
+++ b/lib/java/gradle/generateTestThrift.gradle
@@ -26,8 +26,8 @@
 ext.genFullCamelSrc = file("$buildDir/gen-fullcamel")
 ext.genOptionTypeJdk8Src = file("$buildDir/gen-option-type-jdk8")
 ext.genUnsafeSrc = file("$buildDir/gen-unsafe")
-ext.genStructOrderTestASrc = file("$buildDir/resources/test/struct-order-test/a")
-ext.genStructOrderTestBSrc = file("$buildDir/resources/test/struct-order-test/b")
+ext.genDefinitionOrderTestASrc = file("$buildDir/resources/test/definition-order-test/a")
+ext.genDefinitionOrderTestBSrc = file("$buildDir/resources/test/definition-order-test/b")
 
 // Add the generated code directories to the test source set
 sourceSets {
@@ -146,12 +146,12 @@
     thriftCompile(it, 'JavaAnnotationTest.thrift', 'java:annotations_as_metadata', genSrc)
 }
 
-task generateJavaStructOrderTestJava(group: 'Build') {
-    description = 'Generate structs defined in different order and add to build dir so we can compare them'
+task generateJavaDefinitionOrderTestJava(group: 'Build') {
+    description = 'Generate fields defined in different order and add to build dir so we can compare them'
     generate.dependsOn it
 
     ext.outputBuffer = new ByteArrayOutputStream()
 
-    thriftCompile(it, 'JavaStructOrderA.thrift', 'java', genStructOrderTestASrc)
-    thriftCompile(it, 'JavaStructOrderB.thrift', 'java', genStructOrderTestBSrc)
+    thriftCompile(it, 'JavaDefinitionOrderA.thrift', 'java', genDefinitionOrderTestASrc)
+    thriftCompile(it, 'JavaDefinitionOrderB.thrift', 'java', genDefinitionOrderTestBSrc)
 }
diff --git a/lib/java/src/test/java/org/apache/thrift/TestStructOrder.java b/lib/java/src/test/java/org/apache/thrift/TestDefinitionOrder.java
similarity index 78%
rename from lib/java/src/test/java/org/apache/thrift/TestStructOrder.java
rename to lib/java/src/test/java/org/apache/thrift/TestDefinitionOrder.java
index dd67d9b..51021b7 100644
--- a/lib/java/src/test/java/org/apache/thrift/TestStructOrder.java
+++ b/lib/java/src/test/java/org/apache/thrift/TestDefinitionOrder.java
@@ -26,20 +26,20 @@
 import java.util.List;
 import org.junit.jupiter.api.Test;
 
-// Tests that declaring structs in different order (esp. when they reference each other) generates
+// Tests that declaring fields in different order (esp. when they reference each other) generates
 // identical code
-public class TestStructOrder {
+public class TestDefinitionOrder {
 
   @Test
-  public void testStructOrder() throws Exception {
-    List<String> filenames = Arrays.asList("Parent.java", "Child.java");
+  public void testDefinitionOrder() throws Exception {
+    List<String> filenames = Arrays.asList("Parent.java", "Child.java", "MyEnum.java");
 
     for (String fn : filenames) {
-      String fnA = "struct-order-test/a/" + fn;
-      String fnB = "struct-order-test/b/" + fn;
+      String fnA = "definition-order-test/a/" + fn;
+      String fnB = "definition-order-test/b/" + fn;
 
-      try (InputStream isA = TestStructOrder.class.getClassLoader().getResourceAsStream(fnA);
-          InputStream isB = TestStructOrder.class.getClassLoader().getResourceAsStream(fnB)) {
+      try (InputStream isA = TestDefinitionOrder.class.getClassLoader().getResourceAsStream(fnA);
+          InputStream isB = TestDefinitionOrder.class.getClassLoader().getResourceAsStream(fnB)) {
 
         assertNotNull(isA, "Resource not found: " + fnA);
         assertNotNull(isB, "Resource not found: " + fnB);
diff --git a/lib/java/src/test/resources/JavaStructOrderA.thrift b/lib/java/src/test/resources/JavaDefinitionOrderA.thrift
similarity index 64%
rename from lib/java/src/test/resources/JavaStructOrderA.thrift
rename to lib/java/src/test/resources/JavaDefinitionOrderA.thrift
index f00a710..9b42964 100644
--- a/lib/java/src/test/resources/JavaStructOrderA.thrift
+++ b/lib/java/src/test/resources/JavaDefinitionOrderA.thrift
@@ -22,7 +22,29 @@
     1: required string Name
 }
 
+typedef Parent MyParent
+typedef list<Parent> Parents
+
+enum MyEnum {
+    FOO = 1
+    BAR = 2
+}
+
+typedef i8 Age
+typedef MyEnum MyEnumV2
+typedef set<MyEnum> MyEnums
+typedef map<MyEnumV2, Parent> MyMapping
+typedef binary MyBinary
+
 struct Child {
     1: required string Name
-    2: required Parent Parent
+    2: required Age Age
+    3: required Parent Parent1
+    4: required MyParent Parent2
+    5: required Parents GrandParents
+    6: required MyEnum MyEnum
+    7: required MyEnumV2 MyEnumV2
+    8: required MyEnums MyEnums
+    9: required MyMapping MyMapping
+    10: required MyBinary MyBinary
 }
diff --git a/lib/java/src/test/resources/JavaStructOrderB.thrift b/lib/java/src/test/resources/JavaDefinitionOrderB.thrift
similarity index 68%
rename from lib/java/src/test/resources/JavaStructOrderB.thrift
rename to lib/java/src/test/resources/JavaDefinitionOrderB.thrift
index 4682668..0cccd97 100644
--- a/lib/java/src/test/resources/JavaStructOrderB.thrift
+++ b/lib/java/src/test/resources/JavaDefinitionOrderB.thrift
@@ -21,9 +21,30 @@
 // fixing THRIFT-4086: Java compiler generates different meta data depending on order of structures in file
 struct Child {
     1: required string Name
-    2: required Parent Parent
+    2: required Age Age
+    3: required Parent Parent1
+    4: required MyParent Parent2
+    5: required Parents GrandParents
+    6: required MyEnum MyEnum
+    7: required MyEnumV2 MyEnumV2
+    8: required MyEnums MyEnums
+    9: required MyMapping MyMapping
+    10: required MyBinary MyBinary
 }
 
+typedef i8 Age
+typedef Parent MyParent
+typedef list<Parent> Parents
+typedef MyEnum MyEnumV2
+typedef set<MyEnum> MyEnums
+typedef map<MyEnumV2, Parent> MyMapping
+typedef binary MyBinary
+
 struct Parent {
     1: required string Name
 }
+
+enum MyEnum {
+    FOO = 1
+    BAR = 2
+}