Mercurial > hg > graal-compiler
changeset 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 | 841119d17b02 |
children | 87fc600ec586 6e05e73c942c |
files | graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/compiler/JDTCompiler.java |
diffstat | 1 files changed, 10 insertions(+), 5 deletions(-) [+] |
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; }