annotate truffle/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/java/compiler/JDTCompiler.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents 329fe954f6f2
children 6cec0097107f
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;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
26 import java.util.ArrayList;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
27 import java.util.Arrays;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
28 import java.util.Collections;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
29 import java.util.Comparator;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
30 import java.util.HashMap;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
31 import java.util.List;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
32 import java.util.Map;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
33 import java.util.TreeMap;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
34 import javax.annotation.processing.ProcessingEnvironment;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
35 import javax.lang.model.element.Element;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
36 import javax.lang.model.element.ExecutableElement;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
37 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
38
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39 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
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 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
42 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
43 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
44 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
45 } 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
46 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
47 }
79041ab43660 Truffle-DSL: 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 }
79041ab43660 Truffle-DSL: 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
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
50 public List<? extends Element> getAllMembersInDeclarationOrder(ProcessingEnvironment environment, TypeElement type) {
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents: 11188
diff changeset
51 return sortBySourceOrder(new ArrayList<>(environment.getElementUtils().getAllMembers(type)));
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
52
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
53 }
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
54
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
55 public List<? extends Element> getEnclosedElementsInDeclarationOrder(TypeElement type) {
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents: 11188
diff changeset
56 return sortBySourceOrder(new ArrayList<>(type.getEnclosedElements()));
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents: 11188
diff changeset
57 }
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents: 11188
diff changeset
58
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents: 11188
diff changeset
59 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
60 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
61 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
62 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
63 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
64 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
65 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
66 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
67 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
68 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
69 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
70
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
71 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
72 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
73 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
74
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
75 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
76 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
77 } else {
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
78 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
79
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
80 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
81 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
82 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
83 return 1;
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
84 } else {
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
85 return -1;
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
86 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
87 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
88 });
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
89
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
90 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
91 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
92 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
93 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
94 return sourceOrderElements;
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 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
100
16975
ccb4e2bd894f Truffle-DSL: fixed JDT element comparator violated transitivity.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
101 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
102
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
103 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
104
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
105 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
106 try {
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
107 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
108 Element enclosing2Element = o2.getEnclosingElement();
16975
ccb4e2bd894f Truffle-DSL: fixed JDT element comparator violated transitivity.
Christian Humer <christian.humer@gmail.com>
parents: 16759
diff changeset
109
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
110 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
111 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
112 }
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
113
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
114 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
115 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
116
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
117 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
118 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
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 (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
121 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
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
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
124 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
125 } 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
126 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
127 }
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents: 11188
diff changeset
128 }
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 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
131 }
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration 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 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
134
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
135 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
136 try {
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
137 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
138 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
139 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
140
18494
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
141 declarationOrder = null;
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
142 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
143 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
144 } 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
145 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
146 }
9e944c7eaded Truffle-DSL: fixed bug in source ordering when compiling with JDT.
Christian Humer <christian.humer@gmail.com>
parents: 16975
diff changeset
147 } 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
148 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
149 }
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents: 11188
diff changeset
150
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents: 11188
diff changeset
151 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
152 }
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents: 11188
diff changeset
153
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents: 11188
diff changeset
154 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
155 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
156 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
157
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration 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 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
159 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
160 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
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 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
163 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
164 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
165 }
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
166 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
167 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
168 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
169 }
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration 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 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
172 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
173 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
174 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
175 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
176 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
177 } 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
178 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
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 });
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration 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
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration 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 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
184 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
185 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
186
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration 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 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
188 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
189 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
190 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
191 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
192 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
193 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
194 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
195 } 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
196 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
197 } 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
198 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
199 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
200 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
201 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
202 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
203 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
204 }
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
205 }
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
206 }
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
207 } 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
208 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
209 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
210 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
211 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
212 }
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration 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 } 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
214 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
215 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
216 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
217 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
218 }
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration 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 } 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
220 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
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 }
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
223
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
224 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
225 }
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
226
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
227 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
228 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
229 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
230 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
231 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
232 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
233 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
234 }
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration oder for enclosed elements of types for JDT which is not conforming to specification.
Christian Humer <christian.humer@gmail.com>
parents: 11188
diff changeset
235
f78eafd5ba9e Truffle-DSL: the processor compiler abstraction now supports declaration 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 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
237 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
238
ae6b8ec920e2 Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
239 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
240
ae6b8ec920e2 Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
241 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
242 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
243 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
244
ae6b8ec920e2 Truffle-DSL: Added a hack to get around eclipse bug 300408. (https://bugs.eclipse.org/bugs/show_bug.cgi?id=300408)
Christian Humer <christian.humer@gmail.com>
parents: 10597
diff changeset
245 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
246 }
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 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
249 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
250 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
251 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
252 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
253 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
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 }
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
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
258 @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
259 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
260 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
261
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
262 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
263 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
264 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
265 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
266
79041ab43660 Truffle-DSL: 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 /*
79041ab43660 Truffle-DSL: 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 * 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
269 * ((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
270 * 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
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 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
273 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
274 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
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 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
277 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
278 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
279
79041ab43660 Truffle-DSL: 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 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
281 } catch (Exception e) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16753
diff changeset
282 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
283 }
79041ab43660 Truffle-DSL: 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
79041ab43660 Truffle-DSL: 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 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
287 /*
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
288 * 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
289 * 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
290 * 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
291 * (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
292 * ((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
293 * .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
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 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
297 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
298 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
299
79041ab43660 Truffle-DSL: 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 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
301 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
302 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
303 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
304 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
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 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
307 } 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
308 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
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 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
311 }
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
312
79041ab43660 Truffle-DSL: API-change: Renamed truffle.api.codegen to truffle.api.dsl for all projects and packages.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
313 @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
314 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
315 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
316 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
317 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
318 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
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 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
321 } catch (Exception e) {
16759
23415229349b Truffle-DSL: new package structure.
Christian Humer <christian.humer@gmail.com>
parents: 16753
diff changeset
322 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
323 }
79041ab43660 Truffle-DSL: 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 }
79041ab43660 Truffle-DSL: 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
79041ab43660 Truffle-DSL: 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 }