Mercurial > hg > truffle
comparison jvmci/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveMethodTest.java @ 21798:395ac43a8578
moved JVMCI sources from graal/ to jvmci/ directory
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Tue, 09 Jun 2015 00:22:49 +0200 |
parents | graal/com.oracle.jvmci.runtime.test/src/com/oracle/jvmci/runtime/test/ResolvedJavaTypeResolveMethodTest.java@381ab4105afe |
children |
comparison
equal
deleted
inserted
replaced
21797:42452d2dfbec | 21798:395ac43a8578 |
---|---|
1 /* | |
2 * Copyright (c) 2014, 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.jvmci.runtime.test; | |
24 | |
25 import static org.junit.Assert.*; | |
26 | |
27 import org.junit.*; | |
28 | |
29 import com.oracle.jvmci.meta.*; | |
30 import com.oracle.jvmci.runtime.*; | |
31 | |
32 public class ResolvedJavaTypeResolveMethodTest { | |
33 public final MetaAccessProvider metaAccess; | |
34 | |
35 public ResolvedJavaTypeResolveMethodTest() { | |
36 metaAccess = JVMCI.getRuntime().getHostJVMCIBackend().getMetaAccess(); | |
37 } | |
38 | |
39 protected abstract static class A { | |
40 @SuppressWarnings("unused") | |
41 private void priv() { | |
42 } | |
43 | |
44 public void v1() { | |
45 } | |
46 | |
47 public void v2() { | |
48 } | |
49 | |
50 public abstract void abs(); | |
51 } | |
52 | |
53 protected static class B extends A implements I { | |
54 public void i() { | |
55 } | |
56 | |
57 @Override | |
58 public void v2() { | |
59 } | |
60 | |
61 @Override | |
62 public void abs() { | |
63 | |
64 } | |
65 } | |
66 | |
67 protected static class C extends B { | |
68 public void d() { | |
69 } | |
70 } | |
71 | |
72 protected abstract static class D extends A { | |
73 | |
74 } | |
75 | |
76 protected static class E extends D { | |
77 @Override | |
78 public void abs() { | |
79 } | |
80 } | |
81 | |
82 protected interface I { | |
83 void i(); | |
84 | |
85 default void d() { | |
86 } | |
87 } | |
88 | |
89 @Test | |
90 public void testDefaultMethod() { | |
91 ResolvedJavaType i = getType(I.class); | |
92 ResolvedJavaType b = getType(B.class); | |
93 ResolvedJavaType c = getType(C.class); | |
94 ResolvedJavaMethod di = getMethod(i, "d"); | |
95 ResolvedJavaMethod dc = getMethod(c, "d"); | |
96 | |
97 assertEquals(di, i.resolveMethod(di, c, true)); | |
98 assertEquals(di, b.resolveMethod(di, c, true)); | |
99 assertEquals(dc, c.resolveMethod(di, c, true)); | |
100 } | |
101 | |
102 @Test | |
103 public void testPrivateMethod() { | |
104 ResolvedJavaType a = getType(A.class); | |
105 ResolvedJavaType b = getType(B.class); | |
106 ResolvedJavaType c = getType(C.class); | |
107 ResolvedJavaMethod priv = getMethod(a, "priv"); | |
108 | |
109 assertNull(a.resolveMethod(priv, c, true)); | |
110 assertNull(b.resolveMethod(priv, c, true)); | |
111 } | |
112 | |
113 @Test | |
114 public void testAbstractMethod() { | |
115 ResolvedJavaType a = getType(A.class); | |
116 ResolvedJavaType b = getType(B.class); | |
117 ResolvedJavaType c = getType(C.class); | |
118 ResolvedJavaType d = getType(D.class); | |
119 ResolvedJavaType e = getType(E.class); | |
120 ResolvedJavaMethod absa = getMethod(a, "abs"); | |
121 ResolvedJavaMethod absb = getMethod(b, "abs"); | |
122 ResolvedJavaMethod abse = getMethod(e, "abs"); | |
123 | |
124 assertEquals(absa, a.resolveMethod(absa, c, true)); | |
125 assertEquals(absa, d.resolveMethod(absa, c, true)); | |
126 | |
127 assertEquals(absb, b.resolveMethod(absa, c, true)); | |
128 assertEquals(absb, b.resolveMethod(absb, c, true)); | |
129 assertEquals(absb, c.resolveMethod(absa, c, true)); | |
130 assertEquals(absb, c.resolveMethod(absb, c, true)); | |
131 assertEquals(abse, e.resolveMethod(absa, c, true)); | |
132 assertNull(e.resolveMethod(absb, c, true)); | |
133 assertEquals(abse, e.resolveMethod(abse, c, true)); | |
134 } | |
135 | |
136 @Test | |
137 public void testVirtualMethod() { | |
138 ResolvedJavaType a = getType(A.class); | |
139 ResolvedJavaType b = getType(B.class); | |
140 ResolvedJavaType c = getType(C.class); | |
141 ResolvedJavaMethod v1a = getMethod(a, "v1"); | |
142 ResolvedJavaMethod v2a = getMethod(a, "v2"); | |
143 ResolvedJavaMethod v2b = getMethod(b, "v2"); | |
144 | |
145 assertEquals(v1a, a.resolveMethod(v1a, c, true)); | |
146 assertEquals(v1a, b.resolveMethod(v1a, c, true)); | |
147 assertEquals(v1a, c.resolveMethod(v1a, c, true)); | |
148 assertEquals(v2a, a.resolveMethod(v2a, c, true)); | |
149 assertEquals(v2b, b.resolveMethod(v2a, c, true)); | |
150 assertEquals(v2b, b.resolveMethod(v2b, c, true)); | |
151 assertEquals(v2b, c.resolveMethod(v2a, c, true)); | |
152 assertEquals(v2b, c.resolveMethod(v2b, c, true)); | |
153 | |
154 } | |
155 | |
156 static ResolvedJavaMethod getMethod(ResolvedJavaType type, String methodName) { | |
157 for (ResolvedJavaMethod method : type.getDeclaredMethods()) { | |
158 if (method.getName().equals(methodName)) { | |
159 return method; | |
160 } | |
161 } | |
162 throw new IllegalArgumentException(); | |
163 } | |
164 | |
165 protected ResolvedJavaType getType(Class<?> clazz) { | |
166 ResolvedJavaType type = metaAccess.lookupJavaType(clazz); | |
167 type.initialize(); | |
168 return type; | |
169 } | |
170 } |