annotate truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/compiler/JDTCompiler.java @ 22548:6b76a24fffbd default tip

Use all variables: a, b, u,v and x, y
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 14 Jan 2016 14:20:57 +0100
parents 4a43dc00a654
children
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 */
22327
4a43dc00a654 added workaround based on JDK-8075793 to allow compilation with JDK9 javac (2nd attempt)
Doug Simon <doug.simon@oracle.com>
parents: 22326
diff changeset
55 @SuppressWarnings("unused")
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
56 private static List<Element> newElementList(List<? extends Element> src) {
22327
4a43dc00a654 added workaround based on JDK-8075793 to allow compilation with JDK9 javac (2nd attempt)
Doug Simon <doug.simon@oracle.com>
parents: 22326
diff changeset
57 List<Element> workaround = new ArrayList<Element>(src);
22326
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
58 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
59 }
6cec0097107f added workaround based on JDK-8075793 to allow compilation with JDK9 javac
Doug Simon <doug.simon@oracle.com>
parents: 22157
diff changeset
60
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
61 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
62 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
63 }
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
64
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
65 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
66 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
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
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
69 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
70 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
71 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
72 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
73 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
74 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
75 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
76 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
77 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
78 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
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 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
82 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
83 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
84
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
85 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
86 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
87 } else {
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
88 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
89
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
90 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
91 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
92 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
93 return 1;
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
94 } else {
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
95 return -1;
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
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
100 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
101 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
102 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
103 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
104 return sourceOrderElements;
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
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
109 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
110
16975
ccb4e2bd894f Truffle-DSL: fixed JDT element comparator violated transitivity.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
111 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
112
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
113 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
114
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 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
116 try {
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
117 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
118 Element enclosing2Element = o2.getEnclosingElement();
16975
ccb4e2bd894f Truffle-DSL: fixed JDT element comparator violated transitivity.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
119
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
120 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
121 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
122 }
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
123
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
124 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
125 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
126
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
127 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
128 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
129
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
130 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
131 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
132 }
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
133
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
134 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
135 } 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
136 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
137 }
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
138 }
16975
ccb4e2bd894f Truffle-DSL: fixed JDT element comparator violated transitivity.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
139 };
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
140 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
141 }
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
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
143 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
144
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
145 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
146 try {
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
147 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
148 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
149 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
150
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
151 declarationOrder = null;
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
152 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
153 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
154 } 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
155 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
156 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
157 } 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
158 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
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
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 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
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 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
165 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
166 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
167
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 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
169 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
170 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
171 }
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 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
173 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
174 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
175 }
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
176 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
177 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
178 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
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
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 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
182 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
183 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
184 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
185 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
186 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
187 } 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
188 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
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
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<?> 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
194 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
195 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
196
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 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
198 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
199 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
200 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
201 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
202 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
203 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
204 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
205 } 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
206 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
207 } 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
208 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
209 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
210 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
211 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
212 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
213 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
214 }
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
215 }
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 } 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
218 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
219 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
220 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
221 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
222 }
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 } 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
224 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
225 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
226 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
227 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
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 } 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
230 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
231 }
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
232 }
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
233
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
234 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
235 }
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
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
237 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
238 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
239 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
240 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
241 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
242 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
243 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
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
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
246 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
247 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
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 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
250
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, "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
252 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
253 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
254
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 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
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
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 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
259 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
260 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
261 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
262 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
263 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
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 }
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
267
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
268 @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
269 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
270 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
271
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 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
273 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
274 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
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 /*
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 * 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
279 * ((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
280 * 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
281 */
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 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
283 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
284 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
285
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 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
287 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
288 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
289
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 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
291 } catch (Exception e) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16753
diff changeset
292 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
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
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 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
297 /*
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 * 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
299 * 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
300 * 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
301 * (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
302 * ((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
303 * .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
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 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
307 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
308 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
309
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 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
311 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
312 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
313 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
314 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
315 }
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 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
317 } 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
318 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
319 }
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 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
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
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 @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
324 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
325 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
326 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
327 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
328 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
329 }
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 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
331 } catch (Exception e) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16753
diff changeset
332 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
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
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
336 }