comparison truffle/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ImportGuardsTest.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ImportGuardsTest.java@259a416388d7
children dc83cc1f94f2
comparison
equal deleted inserted replaced
21950:2a5011c7e641 21951:9c8c0937da41
1 /*
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package com.oracle.truffle.api.dsl.test;
24
25 import static com.oracle.truffle.api.dsl.test.TestHelper.*;
26
27 import org.junit.*;
28
29 import com.oracle.truffle.api.dsl.*;
30 import com.oracle.truffle.api.dsl.test.ImportGuardsTestFactory.ImportGuards6Factory;
31 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
32
33 public class ImportGuardsTest {
34
35 @ImportStatic(Imports0.class)
36 @NodeChild("a")
37 static class ImportGuards0 extends ValueNode {
38
39 @Specialization(guards = "staticGuard(a)")
40 int f0(int a) {
41 return a;
42 }
43 }
44
45 @NodeChild("a")
46 @ImportStatic(Imports0.class)
47 static class ImportGuards1 extends ValueNode {
48
49 @ExpectError("Error parsing expression 'nonStaticGuard(a)': The method nonStaticGuard is undefined for the enclosing scope.")
50 @Specialization(guards = "nonStaticGuard(a)")
51 int f1(int a) {
52 return a;
53 }
54
55 @ExpectError("Error parsing expression 'protectedGuard(a)': The method protectedGuard is undefined for the enclosing scope.")
56 @Specialization(guards = "protectedGuard(a)")
57 int f2(int a) {
58 return a;
59 }
60
61 @ExpectError("Error parsing expression 'packageGuard(a)': The method packageGuard is undefined for the enclosing scope.")
62 @Specialization(guards = "packageGuard(a)")
63 int f3(int a) {
64 return a;
65 }
66
67 @ExpectError("Error parsing expression 'privateGuard(a)': The method privateGuard is undefined for the enclosing scope.")
68 @Specialization(guards = "privateGuard(a)")
69 int f4(int a) {
70 return a;
71 }
72 }
73
74 public static class Imports0 {
75 public static boolean staticGuard(int a) {
76 return a == 0;
77 }
78
79 public boolean nonStaticGuard(int a) {
80 return a == 0;
81 }
82
83 protected static boolean protectedGuard(int a) {
84 return a == 0;
85 }
86
87 static boolean packageGuard(int a) {
88 return a == 0;
89 }
90
91 @SuppressWarnings("unused")
92 private static boolean privateGuard(int a) {
93 return a == 0;
94 }
95
96 }
97
98 @ExpectError("The specified import guard class 'com.oracle.truffle.api.dsl.test.ImportGuardsTest.Imports1' must be public.")
99 @NodeChild("a")
100 @ImportStatic(Imports1.class)
101 static class ImportGuards2 extends ValueNode {
102
103 int do1(int a) {
104 return a;
105 }
106 }
107
108 static class Imports1 {
109
110 }
111
112 @ExpectError("The specified import guard class 'com.oracle.truffle.api.dsl.test.ImportGuardsTest.Imports2' must be public.")
113 @NodeChild("a")
114 @ImportStatic(Imports2.class)
115 static class ImportGuards3 extends ValueNode {
116
117 int do1(int a) {
118 return a;
119 }
120 }
121
122 @ExpectError("The specified import guard class 'boolean' is not a declared type.")
123 @NodeChild("a")
124 @ImportStatic(boolean.class)
125 static class ImportGuards4 extends ValueNode {
126
127 int do1(int a) {
128 return a;
129 }
130 }
131
132 private static class Imports2 {
133
134 }
135
136 @ExpectError("At least import guard classes must be specified.")
137 @NodeChild("a")
138 @ImportStatic({})
139 static class ImportGuards5 extends ValueNode {
140
141 int do1(int a) {
142 return a;
143 }
144 }
145
146 @Test
147 public void testImportGuards6() {
148 // should use the guar declared in the node instead of the imported one.
149 assertRuns(ImportGuards6Factory.getInstance(), //
150 array(1, 1), //
151 array(1, 1));
152 }
153
154 @ImportStatic(Imports0.class)
155 @NodeChild("a")
156 static class ImportGuards6 extends ValueNode {
157
158 static boolean staticGuard(int a) {
159 return a == 1;
160 }
161
162 @Specialization(guards = "staticGuard(a)")
163 int f0(int a) {
164 return a;
165 }
166 }
167
168 }