01: /*
02: * Copyright 2007 Google Inc.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License. You may obtain a copy of
06: * the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13: * License for the specific language governing permissions and limitations under
14: * the License.
15: */
16: package com.google.gwt.dev.jjs.test;
17:
18: import com.google.gwt.junit.client.GWTTestCase;
19:
20: /**
21: * Tests that field and method shadowing works correctly in hosted and web
22: * modes.
23: *
24: * NOTE: Also tests that the {@link CompilingClassLoader} can resolve binary and
25: * source level class names inside of JSNI Java member references. Where should
26: * this really go?
27: */
28: public class MemberShadowingTest extends GWTTestCase {
29: /**
30: * TODO: document me.
31: */
32: public class Subclass extends Superclass {
33: public int getSubclassA() {
34: return a;
35: }
36:
37: public void setSubclassA(int a) {
38: this .a = a;
39: }
40:
41: private void foo() {
42: fail("MemberShadowingTest.Subclass.foo() called instead of MemberShadowingTest.Superclass.foo()");
43: }
44:
45: public native void callShadowedMethod() /*-{
46: this.@com.google.gwt.dev.jjs.test.MemberShadowingTest$Superclass::foo()();
47: }-*/;
48:
49: public int a;
50: }
51:
52: /**
53: * TODO: document me.
54: */
55: public class Superclass {
56: public native int getSuperclassA() /*-{
57: return this.@com.google.gwt.dev.jjs.test.MemberShadowingTest.Superclass::a;
58: }-*/;
59:
60: public void setSuperclassA(int a) {
61: this .a = a;
62: }
63:
64: private void foo() {
65: /*
66: * if the method that this one shadows is called the test will fail
67: * otherwise if we get here we are good
68: */
69: }
70:
71: public int a;
72: }
73:
74: /**
75: * TODO: document me.
76: */
77: public static interface Foo {
78: void f();
79: }
80:
81: public String getModuleName() {
82: return "com.google.gwt.dev.jjs.CompilerSuite";
83: }
84:
85: public void testFieldShadowing() {
86: Subclass s1 = new Subclass();
87:
88: s1.setSuperclassA(1);
89: s1.setSubclassA(2);
90:
91: assertEquals(s1.getSuperclassA(), 1);
92: }
93:
94: public void testMethodShadowing() {
95: Subclass s1 = new Subclass();
96:
97: s1.callShadowedMethod();
98: }
99: }
|