Bug 1428989 - Generate Android bindings more deterministically. r=nalexander
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 09 Jan 2018 16:44:27 +0900
changeset 450230 5faa091699916d85b7afb4fc3a5e2b5fd52d92d3
parent 450229 ac7f70f6635ab948e746b41d2c812a500858a191
child 450231 c535f544f4bc541242071ee11c268ebc74dc4113
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs1428989
milestone59.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 1428989 - Generate Android bindings more deterministically. r=nalexander There are multiple methods with the same name and that differ in their arguments. They end up being ordered in the source file randomly, despite there being some sorting done, because the sorting was only done on the method name. Now, when the method name matches, also compare the arguments.
build/annotationProcessors/SDKProcessor.java
--- a/build/annotationProcessors/SDKProcessor.java
+++ b/build/annotationProcessors/SDKProcessor.java
@@ -328,17 +328,29 @@ public class SDKProcessor {
             throw new IllegalArgumentException("expected member to be Method, Constructor, or Field");
         }
     }
 
     private static Member[] sortAndFilterMembers(Class<?> cls, Member[] members) {
         Arrays.sort(members, new Comparator<Member>() {
             @Override
             public int compare(Member a, Member b) {
-                return a.getName().compareTo(b.getName());
+                int result = a.getName().compareTo(b.getName());
+                if (result == 0) {
+                    if (a instanceof Constructor && b instanceof Constructor) {
+                        String sa = Arrays.toString(((Constructor) a).getParameterTypes());
+                        String sb = Arrays.toString(((Constructor) b).getParameterTypes());
+                        result = sa.compareTo(sb);
+                    } else if (a instanceof Method && b instanceof Method) {
+                        String sa = Arrays.toString(((Method) a).getParameterTypes());
+                        String sb = Arrays.toString(((Method) b).getParameterTypes());
+                        result = sa.compareTo(sb);
+                    }
+                }
+                return result;
             }
         });
 
         ArrayList<Member> list = new ArrayList<>();
         for (final Member m : members) {
             if (m.getDeclaringClass() == Object.class) {
                 // Skip methods from Object.
                 continue;