Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/compiler/JDTCompiler.java @ 22123:329fe954f6f2
Can compile Truffle API with following javac lints: -Xlint:all,-auxiliaryclass,-try,-processing
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Wed, 02 Sep 2015 13:15:51 +0200 |
parents | 9c8c0937da41 |
children | dc83cc1f94f2 |
rev | line source |
---|---|
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
1 /* |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
4 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
8 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
13 * accompanied this code). |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
14 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
18 * |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
21 * questions. |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
22 */ |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16753
diff
changeset
|
23 package com.oracle.truffle.dsl.processor.java.compiler; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
24 |
11188
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
25 import java.util.*; |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
26 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
27 import javax.annotation.processing.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
28 import javax.lang.model.element.*; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
29 |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16753
diff
changeset
|
30 import com.oracle.truffle.dsl.processor.java.*; |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
31 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
32 public class JDTCompiler extends AbstractCompiler { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
33 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
34 public static boolean isValidElement(Element currentElement) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
35 try { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
36 Class<?> elementClass = Class.forName("org.eclipse.jdt.internal.compiler.apt.model.ElementImpl"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
37 return elementClass.isAssignableFrom(currentElement.getClass()); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
38 } catch (ClassNotFoundException e) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
39 return false; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
40 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
41 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
42 |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
43 public List<? extends Element> getAllMembersInDeclarationOrder(ProcessingEnvironment environment, TypeElement type) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
44 return sortBySourceOrder(new ArrayList<>(environment.getElementUtils().getAllMembers(type))); |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
45 |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
46 } |
11188
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
47 |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
48 public List<? extends Element> getEnclosedElementsInDeclarationOrder(TypeElement type) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
49 return sortBySourceOrder(new ArrayList<>(type.getEnclosedElements())); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
50 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
51 |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
52 private static List<? extends Element> sortBySourceOrder(List<Element> elements) { |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
53 Map<TypeElement, List<Element>> groupedByEnclosing = new HashMap<>(); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
54 for (Element element : elements) { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
55 Element enclosing = element.getEnclosingElement(); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
56 List<Element> grouped = groupedByEnclosing.get(enclosing); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
57 if (grouped == null) { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
58 grouped = new ArrayList<>(); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
59 groupedByEnclosing.put((TypeElement) enclosing, grouped); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
60 } |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
61 grouped.add(element); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
62 } |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
63 |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
64 for (TypeElement enclosing : groupedByEnclosing.keySet()) { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
65 Collections.sort(groupedByEnclosing.get(enclosing), createSourceOrderComparator(enclosing)); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
66 } |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
67 |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
68 if (groupedByEnclosing.size() == 1) { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
69 return groupedByEnclosing.get(groupedByEnclosing.keySet().iterator().next()); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
70 } else { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
71 List<TypeElement> enclosingTypes = new ArrayList<>(groupedByEnclosing.keySet()); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
72 |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
73 Collections.sort(enclosingTypes, new Comparator<TypeElement>() { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
74 public int compare(TypeElement o1, TypeElement o2) { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
75 if (ElementUtils.isSubtype(o1.asType(), o2.asType())) { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
76 return 1; |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
77 } else { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
78 return -1; |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
79 } |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
80 } |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
81 }); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
82 |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
83 List<Element> sourceOrderElements = new ArrayList<>(); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
84 for (TypeElement typeElement : enclosingTypes) { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
85 sourceOrderElements.addAll(groupedByEnclosing.get(typeElement)); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
86 } |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
87 return sourceOrderElements; |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
88 } |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
89 |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
90 } |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
91 |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
92 private static Comparator<Element> createSourceOrderComparator(final TypeElement enclosing) { |
11188
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
93 |
16975
ccb4e2bd894f
Truffle-DSL: fixed JDT element comparator violated transitivity.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
94 Comparator<Element> comparator = new Comparator<Element>() { |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
95 |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
96 final List<Object> declarationOrder = lookupDeclarationOrder(enclosing); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
97 |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
98 public int compare(Element o1, Element o2) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
99 try { |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
100 Element enclosing1Element = o1.getEnclosingElement(); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
101 Element enclosing2Element = o2.getEnclosingElement(); |
16975
ccb4e2bd894f
Truffle-DSL: fixed JDT element comparator violated transitivity.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
102 |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
103 if (!ElementUtils.typeEquals(enclosing1Element.asType(), enclosing2Element.asType())) { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
104 throw new AssertionError(); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
105 } |
11188
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
106 |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
107 Object o1Binding = field(o1, "_binding"); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
108 Object o2Binding = field(o2, "_binding"); |
11188
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
109 |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
110 int i1 = declarationOrder.indexOf(o1Binding); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
111 int i2 = declarationOrder.indexOf(o2Binding); |
16975
ccb4e2bd894f
Truffle-DSL: fixed JDT element comparator violated transitivity.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
112 |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
113 if (i1 == -1 || i2 == -1) { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
114 return 0; |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
115 } |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
116 |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
117 return i1 - i2; |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
118 } catch (Exception e) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
119 throw new RuntimeException(e); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
120 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
121 } |
16975
ccb4e2bd894f
Truffle-DSL: fixed JDT element comparator violated transitivity.
Christian Humer <christian.humer@gmail.com>
parents:
16759
diff
changeset
|
122 }; |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
123 return comparator; |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
124 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
125 |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
126 private static List<Object> lookupDeclarationOrder(TypeElement type) { |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
127 |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
128 List<Object> declarationOrder; |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
129 try { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
130 Object binding = field(type, "_binding"); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
131 Class<?> sourceTypeBinding = Class.forName("org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding"); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
132 Class<?> binaryTypeBinding = Class.forName("org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding"); |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
133 |
18494
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
134 declarationOrder = null; |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
135 if (sourceTypeBinding.isAssignableFrom(binding.getClass())) { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
136 declarationOrder = findSourceTypeOrder(binding); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
137 } else if (binaryTypeBinding.isAssignableFrom(binding.getClass())) { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
138 declarationOrder = findBinaryTypeOrder(binding); |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
139 } |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
140 } catch (Exception e) { |
9e944c7eaded
Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents:
16975
diff
changeset
|
141 throw new RuntimeException(e); |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
142 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
143 |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
144 return declarationOrder; |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
145 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
146 |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
147 private static List<Object> findBinaryTypeOrder(Object binding) throws Exception { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
148 Object binaryType = lookupBinaryType(binding); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
149 final Object[] sortedMethods = (Object[]) method(binaryType, "getMethods"); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
150 |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
151 List<Object> sortedElements = new ArrayList<>(); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
152 if (sortedMethods != null) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
153 sortedElements.addAll(Arrays.asList(sortedMethods)); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
154 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
155 final Object[] sortedFields = (Object[]) method(binaryType, "getFields"); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
156 if (sortedFields != null) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
157 sortedElements.addAll(Arrays.asList(sortedFields)); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
158 } |
22123
329fe954f6f2
Can compile Truffle API with following javac lints: -Xlint:all,-auxiliaryclass,-try,-processing
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
159 final Object[] sortedTypes = (Object[]) method(binaryType, "getMemberTypes", new Class<?>[0]); |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
160 if (sortedTypes != null) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
161 sortedElements.addAll(Arrays.asList(sortedTypes)); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
162 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
163 |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
164 Collections.sort(sortedElements, new Comparator<Object>() { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
165 public int compare(Object o1, Object o2) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
166 try { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
167 int structOffset1 = (int) field(o1, "structOffset"); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
168 int structOffset2 = (int) field(o2, "structOffset"); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
169 return structOffset1 - structOffset2; |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
170 } catch (Exception e) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
171 throw new RuntimeException(e); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
172 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
173 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
174 }); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
175 |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
176 Class<?> binaryMethod = Class.forName("org.eclipse.jdt.internal.compiler.env.IBinaryMethod"); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
177 Class<?> binaryField = Class.forName("org.eclipse.jdt.internal.compiler.env.IBinaryField"); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
178 Class<?> nestedType = Class.forName("org.eclipse.jdt.internal.compiler.env.IBinaryNestedType"); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
179 |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
180 List<Object> bindings = new ArrayList<>(); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
181 for (Object sortedElement : sortedElements) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
182 Class<?> elementClass = sortedElement.getClass(); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
183 if (binaryMethod.isAssignableFrom(elementClass)) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
184 char[] selector = (char[]) method(sortedElement, "getSelector"); |
22123
329fe954f6f2
Can compile Truffle API with following javac lints: -Xlint:all,-auxiliaryclass,-try,-processing
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
185 Object[] foundBindings = (Object[]) method(binding, "getMethods", new Class<?>[]{char[].class}, selector); |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
186 if (foundBindings == null || foundBindings.length == 0) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
187 continue; |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
188 } else if (foundBindings.length == 1) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
189 bindings.add(foundBindings[0]); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
190 } else { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
191 char[] idescriptor = (char[]) method(sortedElement, "getMethodDescriptor"); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
192 for (Object foundBinding : foundBindings) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
193 char[] descriptor = (char[]) method(foundBinding, "signature"); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
194 if (descriptor == null && idescriptor == null || Arrays.equals(descriptor, idescriptor)) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
195 bindings.add(foundBinding); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
196 break; |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
197 } |
11188
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
198 } |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
199 } |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
200 } else if (binaryField.isAssignableFrom(elementClass)) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
201 char[] selector = (char[]) method(sortedElement, "getName"); |
22123
329fe954f6f2
Can compile Truffle API with following javac lints: -Xlint:all,-auxiliaryclass,-try,-processing
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
202 Object foundField = method(binding, "getField", new Class<?>[]{char[].class, boolean.class}, selector, true); |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
203 if (foundField != null) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
204 bindings.add(foundField); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
205 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
206 } else if (nestedType.isAssignableFrom(elementClass)) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
207 char[] selector = (char[]) method(sortedElement, "getSourceName"); |
22123
329fe954f6f2
Can compile Truffle API with following javac lints: -Xlint:all,-auxiliaryclass,-try,-processing
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
208 Object foundType = method(binding, "getMemberType", new Class<?>[]{char[].class}, selector); |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
209 if (foundType != null) { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
210 bindings.add(foundType); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
211 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
212 } else { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
213 throw new AssertionError("Unexpected encountered type " + elementClass); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
214 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
215 } |
11188
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
216 |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
217 return bindings; |
11188
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
218 } |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
219 |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
220 private static Object lookupBinaryType(Object binding) throws Exception { |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
221 Object lookupEnvironment = field(binding, "environment"); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
222 Object compoundClassName = field(binding, "compoundName"); |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
223 Object nameEnvironment = field(lookupEnvironment, "nameEnvironment"); |
22123
329fe954f6f2
Can compile Truffle API with following javac lints: -Xlint:all,-auxiliaryclass,-try,-processing
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
224 Object nameEnvironmentAnswer = method(nameEnvironment, "findType", new Class<?>[]{char[][].class}, compoundClassName); |
329fe954f6f2
Can compile Truffle API with following javac lints: -Xlint:all,-auxiliaryclass,-try,-processing
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
225 Object binaryType = method(nameEnvironmentAnswer, "getBinaryType", new Class<?>[0]); |
16753
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
226 return binaryType; |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
227 } |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
228 |
f78eafd5ba9e
Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents:
11188
diff
changeset
|
229 private static List<Object> findSourceTypeOrder(Object binding) throws Exception { |
11188
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
230 Object referenceContext = field(field(binding, "scope"), "referenceContext"); |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
231 |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
232 TreeMap<Integer, Object> orderedBindings = new TreeMap<>(); |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
233 |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
234 collectSourceOrder(orderedBindings, referenceContext, "methods"); |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
235 collectSourceOrder(orderedBindings, referenceContext, "fields"); |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
236 collectSourceOrder(orderedBindings, referenceContext, "memberTypes"); |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
237 |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
238 return new ArrayList<>(orderedBindings.values()); |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
239 } |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
240 |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
241 private static void collectSourceOrder(TreeMap<Integer, Object> orderedBindings, Object referenceContext, String fieldName) throws Exception { |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
242 Object[] declarations = (Object[]) field(referenceContext, fieldName); |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
243 if (declarations != null) { |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
244 for (int i = 0; i < declarations.length; i++) { |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
245 Integer declarationSourceStart = (Integer) field(declarations[i], "declarationSourceStart"); |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
246 orderedBindings.put(declarationSourceStart, field(declarations[i], "binding")); |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
247 } |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
248 } |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
249 } |
ae6b8ec920e2
Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents:
10597
diff
changeset
|
250 |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
251 @Override |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
252 public String getMethodBody(ProcessingEnvironment env, ExecutableElement method) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
253 try { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
254 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
255 char[] source = getSource(method); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
256 if (source == null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
257 return null; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
258 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
259 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
260 /* |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
261 * AbstractMethodDeclaration decl = |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
262 * ((MethodBinding)(((ElementImpl)method)._binding)).sourceMethod(); int bodyStart = |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
263 * decl.bodyStart; int bodyEnd = decl.bodyEnd; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
264 */ |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
265 Object decl = method(field(method, "_binding"), "sourceMethod"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
266 int bodyStart = (int) field(decl, "bodyStart"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
267 int bodyEnd = (int) field(decl, "bodyEnd"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
268 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
269 int length = bodyEnd - bodyStart; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
270 char[] target = new char[length]; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
271 System.arraycopy(source, bodyStart, target, 0, length); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
272 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
273 return new String(target); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
274 } catch (Exception e) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16753
diff
changeset
|
275 return ElementUtils.printException(e); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
276 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
277 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
278 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
279 private static char[] getSource(Element element) throws Exception { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
280 /* |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
281 * Binding binding = ((ElementImpl)element)._binding; char[] source = null; if (binding |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
282 * instanceof MethodBinding) { source = ((MethodBinding) |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
283 * binding).sourceMethod().compilationResult.getCompilationUnit().getContents(); } else if |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
284 * (binding instanceof SourceTypeBinding) { source = |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
285 * ((SourceTypeBinding)binding).scope.referenceContext |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
286 * .compilationResult.compilationUnit.getContents(); } return source; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
287 */ |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
288 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
289 Object binding = field(element, "_binding"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
290 Class<?> methodBindingClass = Class.forName("org.eclipse.jdt.internal.compiler.lookup.MethodBinding"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
291 Class<?> referenceBindingClass = Class.forName("org.eclipse.jdt.internal.compiler.lookup.SourceTypeBinding"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
292 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
293 char[] source = null; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
294 if (methodBindingClass.isAssignableFrom(binding.getClass())) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
295 Object sourceMethod = method(binding, "sourceMethod"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
296 if (sourceMethod == null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
297 return null; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
298 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
299 source = (char[]) method(method(field(sourceMethod, "compilationResult"), "getCompilationUnit"), "getContents"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
300 } else if (referenceBindingClass.isAssignableFrom(binding.getClass())) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
301 source = (char[]) method(field(field(field(field(binding, "scope"), "referenceContext"), "compilationResult"), "compilationUnit"), "getContents"); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
302 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
303 return source; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
304 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
305 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
306 @Override |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
307 public String getHeaderComment(ProcessingEnvironment env, Element type) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
308 try { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
309 char[] source = getSource(type); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
310 if (source == null) { |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
311 return null; |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
312 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
313 return parseHeader(new String(source)); |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
314 } catch (Exception e) { |
16759
23415229349b
Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents:
16753
diff
changeset
|
315 return ElementUtils.printException(e); |
10597
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
316 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
317 } |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
318 |
79041ab43660
Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff
changeset
|
319 } |