annotate truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/compiler/JDTCompiler.java @ 22326:6cec0097107f

added workaround based on JDK-8075793 to allow compilation with JDK9 javac
author Doug Simon <doug.simon@oracle.com>
date Mon, 26 Oct 2015 13:28:19 +0100
parents dc83cc1f94f2
children 4a43dc00a654
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
25 import com.oracle.truffle.dsl.processor.java.ElementUtils;
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
26
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
27 import java.util.ArrayList;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
28 import java.util.Arrays;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
29 import java.util.Collections;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
30 import java.util.Comparator;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
31 import java.util.HashMap;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
32 import java.util.List;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
33 import java.util.Map;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
34 import java.util.TreeMap;
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
35
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
36 import javax.annotation.processing.ProcessingEnvironment;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
37 import javax.lang.model.element.Element;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
38 import javax.lang.model.element.ExecutableElement;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
39 import javax.lang.model.element.TypeElement;
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
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 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
42
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
43 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
44 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
45 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
46 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
47 } 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
48 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
49 }
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
50 }
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
51
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
52 /**
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
53 * @see "https://bugs.openjdk.java.net/browse/JDK-8039214"
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
54 */
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
55 private static List<Element> newElementList(List<? extends Element> src) {
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
56 List<Element> workaround = new ArrayList<>(src);
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
57 return workaround;
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
58 }
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
59
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
60 public List<? extends Element> getAllMembersInDeclarationOrder(ProcessingEnvironment environment, TypeElement type) {
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
61 return sortBySourceOrder(newElementList(environment.getElementUtils().getAllMembers(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
62 }
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
63
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
64 public List<? extends Element> getEnclosedElementsInDeclarationOrder(TypeElement type) {
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
65 return sortBySourceOrder(newElementList(type.getEnclosedElements()));
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
66 }
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
67
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
68 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
69 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
70 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
71 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
72 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
73 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
74 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
75 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
76 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
77 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
78 }
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 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
81 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
82 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
83
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
84 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
85 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
86 } else {
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
87 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
88
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
89 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
90 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
91 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
92 return 1;
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
93 } else {
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
94 return -1;
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 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
97 });
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
98
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
99 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
100 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
101 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
102 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
103 return sourceOrderElements;
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
104 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
105
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
106 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
107
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
108 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
109
16975
ccb4e2bd894f Truffle-DSL: fixed JDT element comparator violated transitivity.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
110 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
111
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
112 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
113
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
114 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
115 try {
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
116 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
117 Element enclosing2Element = o2.getEnclosingElement();
16975
ccb4e2bd894f Truffle-DSL: fixed JDT element comparator violated transitivity.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
118
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
119 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
120 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
121 }
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
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 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
124 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
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 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
127 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
128
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
129 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
130 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
131 }
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
132
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
133 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
134 } 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
135 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
136 }
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
137 }
16975
ccb4e2bd894f Truffle-DSL: fixed JDT element comparator violated transitivity.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
138 };
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
139 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
140 }
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
141
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
142 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
143
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
144 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
145 try {
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
146 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
147 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
148 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
149
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
150 declarationOrder = null;
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
151 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
152 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
153 } 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
154 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
155 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
156 } 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
157 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
158 }
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
159
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 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
161 }
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 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
164 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
165 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
166
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 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
168 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
169 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
170 }
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 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
172 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
173 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
174 }
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
175 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
176 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
177 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
178 }
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 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
181 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
182 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
183 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
184 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
185 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
186 } 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
187 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
188 }
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 }
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 });
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
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 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
193 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
194 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
195
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 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
197 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
198 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
199 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
200 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
201 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
202 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
203 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
204 } 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
205 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
206 } 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
207 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
208 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
209 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
210 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
211 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
212 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
213 }
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
214 }
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
215 }
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
216 } 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
217 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
218 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
219 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
220 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
221 }
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 } 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
223 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
224 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
225 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
226 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
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 } 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
229 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
230 }
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
231 }
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
232
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
233 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
234 }
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
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
236 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
237 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
238 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
239 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
240 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
241 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
242 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
243 }
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
244
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
245 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
246 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
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 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
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 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
251 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
252 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
253
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
254 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
255 }
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
256
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
257 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
258 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
259 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
260 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
261 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
262 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
263 }
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
264 }
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
265 }
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
266
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
267 @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
268 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
269 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
270
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 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
272 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
273 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
274 }
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
275
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 * 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
278 * ((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
279 * 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
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 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
282 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
283 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
284
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 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
286 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
287 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
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 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
290 } catch (Exception e) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16753
diff changeset
291 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
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 }
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
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 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
296 /*
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 * 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
298 * 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
299 * 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
300 * (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
301 * ((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
302 * .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
303 */
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 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
306 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
307 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
308
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 = 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
310 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
311 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
312 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
313 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
314 }
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
315 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
316 } 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
317 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
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 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
320 }
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
321
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
322 @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
323 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
324 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
325 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
326 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
327 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
328 }
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
329 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
330 } catch (Exception e) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16753
diff changeset
331 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
332 }
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
333 }
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
334
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
335 }