Mercurial > hg > graal-compiler
comparison 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 |
comparison
equal
deleted
inserted
replaced
16974:841119d17b02 | 16975:ccb4e2bd894f |
---|---|
50 } | 50 } |
51 | 51 |
52 private static List<? extends Element> sortBySourceOrder(List<Element> elements) { | 52 private static List<? extends Element> sortBySourceOrder(List<Element> elements) { |
53 final Map<TypeElement, List<Object>> declarationOrders = new HashMap<>(); | 53 final Map<TypeElement, List<Object>> declarationOrders = new HashMap<>(); |
54 | 54 |
55 Collections.sort(elements, new Comparator<Element>() { | 55 Comparator<Element> comparator = new Comparator<Element>() { |
56 public int compare(Element o1, Element o2) { | 56 public int compare(Element o1, Element o2) { |
57 try { | 57 try { |
58 TypeMirror enclosing1 = o1.getEnclosingElement().asType(); | 58 TypeMirror enclosing1 = o1.getEnclosingElement().asType(); |
59 TypeMirror enclosing2 = o2.getEnclosingElement().asType(); | 59 TypeMirror enclosing2 = o2.getEnclosingElement().asType(); |
60 | 60 |
61 if (ElementUtils.typeEquals(enclosing1, enclosing2)) { | 61 if (ElementUtils.typeEquals(enclosing1, enclosing2)) { |
62 List<Object> declarationOrder = lookupDeclarationOrder(declarationOrders, (TypeElement) o1.getEnclosingElement()); | 62 List<Object> declarationOrder = lookupDeclarationOrder(declarationOrders, (TypeElement) o1.getEnclosingElement()); |
63 | |
63 if (declarationOrder == null) { | 64 if (declarationOrder == null) { |
64 return 0; | 65 return 0; |
65 } | 66 } |
66 Object o1Binding = field(o1, "_binding"); | 67 Object o1Binding = field(o1, "_binding"); |
67 Object o2Binding = field(o2, "_binding"); | 68 Object o2Binding = field(o2, "_binding"); |
68 | 69 |
69 int i1 = declarationOrder.indexOf(o1Binding); | 70 int i1 = declarationOrder.indexOf(o1Binding); |
70 int i2 = declarationOrder.indexOf(o2Binding); | 71 int i2 = declarationOrder.indexOf(o2Binding); |
72 | |
73 if (i1 == -1 || i2 == -1) { | |
74 return 0; | |
75 } | |
71 | 76 |
72 return i1 - i2; | 77 return i1 - i2; |
73 } else { | 78 } else { |
74 if (ElementUtils.isSubtype(enclosing1, enclosing2)) { | 79 if (ElementUtils.isSubtype(enclosing1, enclosing2)) { |
75 return 1; | 80 return 1; |
76 } else if (ElementUtils.isSubtype(enclosing2, enclosing1)) { | 81 } else { |
77 return -1; | 82 return -1; |
78 } else { | |
79 return 0; | |
80 } | 83 } |
81 } | 84 } |
82 } catch (Exception e) { | 85 } catch (Exception e) { |
83 throw new RuntimeException(e); | 86 throw new RuntimeException(e); |
84 } | 87 } |
85 } | 88 } |
86 }); | 89 }; |
90 | |
91 Collections.sort(elements, comparator); | |
87 return elements; | 92 return elements; |
88 } | 93 } |
89 | 94 |
90 private static List<Object> lookupDeclarationOrder(Map<TypeElement, List<Object>> declarationOrders, TypeElement type) throws Exception, ClassNotFoundException { | 95 private static List<Object> lookupDeclarationOrder(Map<TypeElement, List<Object>> declarationOrders, TypeElement type) throws Exception, ClassNotFoundException { |
91 if (declarationOrders.containsKey(type)) { | 96 if (declarationOrders.containsKey(type)) { |