# HG changeset patch # User Christian Humer # Date 1409147640 -7200 # Node ID ccb4e2bd894f9e5ea07289ac5feca77921d53c35 # Parent 841119d17b02fbe72a1e865a49e162a80a5ddaca Truffle-DSL: fixed JDT element comparator violated transitivity. diff -r 841119d17b02 -r ccb4e2bd894f graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/compiler/JDTCompiler.java --- 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 sortBySourceOrder(List elements) { final Map> declarationOrders = new HashMap<>(); - Collections.sort(elements, new Comparator() { + Comparator comparator = new Comparator() { public int compare(Element o1, Element o2) { try { TypeMirror enclosing1 = o1.getEnclosingElement().asType(); @@ -60,6 +60,7 @@ if (ElementUtils.typeEquals(enclosing1, enclosing2)) { List 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; }