Bug 1210585 - Avoid fields with same name in class and superclass; r=snorp
authorJim Chen <nchen@mozilla.com>
Thu, 22 Oct 2015 17:45:45 -0400
changeset 269018 6502eda903ea9389cabea8d645e76e1c52be3b5c
parent 269017 406f9bce7d238e3d4d63fb83114723d8d7114d90
child 269019 f1d6e64f8ae7584ef5e8abc20ea6b2537eab03fb
push id67000
push usernchen@mozilla.com
push dateThu, 22 Oct 2015 21:47:22 +0000
treeherdermozilla-inbound@d9882266e0b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp
bugs1210585
milestone44.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1210585 - Avoid fields with same name in class and superclass; r=snorp Java allows a class field to have the same name as a superclass field, but when we generate bindings for them, they'll end up with the same C++ name and cause an error. This patch makes the SDK processor filter out any superclass fields that are hidden by a subclass field with the same name.
build/annotationProcessors/SDKProcessor.java
--- a/build/annotationProcessors/SDKProcessor.java
+++ b/build/annotationProcessors/SDKProcessor.java
@@ -157,16 +157,30 @@ public class SDKProcessor {
                 version = version2;
             }
             if (version > sMaxSdkVersion) {
                 System.out.println("Skipping " + m.getDeclaringClass().getName() + "." + m.getName() +
                     ", version " + version + " > " + sMaxSdkVersion);
                 continue;
             }
 
+            // Sometimes (e.g. KeyEvent) a field can appear in both a class and a superclass. In
+            // that case we want to filter out the version that appears in the superclass, or
+            // we'll have bindings with duplicate names.
+            try {
+                if (m instanceof Field && !m.equals(cls.getField(m.getName()))) {
+                    // m is a field in a superclass that has been hidden by
+                    // a field with the same name in a subclass.
+                    System.out.println("Skipping " + m.getName() +
+                                       " from " + m.getDeclaringClass());
+                    continue;
+                }
+            } catch (final NoSuchFieldException e) {
+            }
+
             list.add(m);
         }
 
         return list.toArray(new Member[list.size()]);
     }
 
     private static void generateClass(Class<?> clazz,
                                       StringBuilder implementationFile,