diff graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/compiler/JDTCompiler.java @ 16975:ccb4e2bd894f

Truffle-DSL: fixed JDT element comparator violated transitivity.
author Christian Humer <christian.humer@gmail.com>
date Wed, 27 Aug 2014 15:54:00 +0200
parents 23415229349b
children 9e944c7eaded
line wrap: on
line diff
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/compiler/JDTCompiler.java	Wed Aug 27 14:14:18 2014 +0200
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/compiler/JDTCompiler.java	Wed Aug 27 15:54:00 2014 +0200
@@ -52,7 +52,7 @@
     private static List<? extends Element> sortBySourceOrder(List<Element> elements) {
         final Map<TypeElement, List<Object>> declarationOrders = new HashMap<>();
 
-        Collections.sort(elements, new Comparator<Element>() {
+        Comparator<Element> comparator = new Comparator<Element>() {
             public int compare(Element o1, Element o2) {
                 try {
                     TypeMirror enclosing1 = o1.getEnclosingElement().asType();
@@ -60,6 +60,7 @@
 
                     if (ElementUtils.typeEquals(enclosing1, enclosing2)) {
                         List<Object> declarationOrder = lookupDeclarationOrder(declarationOrders, (TypeElement) o1.getEnclosingElement());
+
                         if (declarationOrder == null) {
                             return 0;
                         }
@@ -69,21 +70,25 @@
                         int i1 = declarationOrder.indexOf(o1Binding);
                         int i2 = declarationOrder.indexOf(o2Binding);
 
+                        if (i1 == -1 || i2 == -1) {
+                            return 0;
+                        }
+
                         return i1 - i2;
                     } else {
                         if (ElementUtils.isSubtype(enclosing1, enclosing2)) {
                             return 1;
-                        } else if (ElementUtils.isSubtype(enclosing2, enclosing1)) {
+                        } else {
                             return -1;
-                        } else {
-                            return 0;
                         }
                     }
                 } catch (Exception e) {
                     throw new RuntimeException(e);
                 }
             }
-        });
+        };
+
+        Collections.sort(elements, comparator);
         return elements;
     }