From 144143c2970a1e874d74cdbd0f8c622d4282a3c3 Mon Sep 17 00:00:00 2001 From: wisberg Date: Mon, 16 Dec 2002 18:51:06 +0000 Subject: initial version --- tests/errors/protectedAccess/Main.java | 62 +++++++++++++++++++++++++++++++++ tests/errors/protectedAccess/p1/C1.java | 17 +++++++++ 2 files changed, 79 insertions(+) create mode 100644 tests/errors/protectedAccess/Main.java create mode 100644 tests/errors/protectedAccess/p1/C1.java (limited to 'tests/errors/protectedAccess') diff --git a/tests/errors/protectedAccess/Main.java b/tests/errors/protectedAccess/Main.java new file mode 100644 index 000000000..39ba8307c --- /dev/null +++ b/tests/errors/protectedAccess/Main.java @@ -0,0 +1,62 @@ +package protectedAccess; + +import org.aspectj.testing.Tester; +import protectedAccess.p1.C1; + +public class Main { + public static void main(String[] args) { + SubC1 subc1 = new SubC1(); + subc1.m(subc1, subc1); + } +} + +class SubC1 extends C1 { + public void m(SubC1 subc1, C1 c1) { + Tester.checkEqual(this.s, "protected"); + Tester.checkEqual(this.m(), "protected"); + + Tester.checkEqual(s, "protected"); + Tester.checkEqual(m(), "protected"); + + Tester.checkEqual(subc1.s, "protected"); + Tester.checkEqual(subc1.m(), "protected"); + + C1 c1a = new C1() { }; + + C1 c1b = new C1(); //ERROR: illegal protected access + + Tester.checkEqual(c1.s, "protected"); //ERROR: illegal protected access + Tester.checkEqual(c1.m(), "protected"); //ERROR: illegal protected access + + Tester.checkEqual(c1.m(), "protected"); //ERROR: illegal protected access + } + + class SubI1 extends I1 { + public void m(SubC1 subc1, C1 c1, I1 i1) { + Tester.checkEqual(s, "protected"); + Tester.checkEqual(m(), "protected"); //ERROR: method not found + + Tester.checkEqual(SubC1.this.s, "protected"); + Tester.checkEqual(SubC1.this.m(), "protected"); + + Tester.checkEqual(subc1.s, "protected"); + Tester.checkEqual(subc1.m(), "protected"); + + Tester.checkEqual(c1.s, "protected"); //ERROR: illegal protected access + Tester.checkEqual(c1.m(), "protected"); //ERROR: illegal protected access + + Tester.checkEqual(si, "ip"); + Tester.checkEqual(mi(), "ip"); + + Tester.checkEqual(this.si, "ip"); + Tester.checkEqual(this.mi(), "ip"); + + Tester.checkEqual(i1.si, "ip"); //ERROR: illegal protected access + Tester.checkEqual(i1.mi(), "ip"); //ERROR: illegal protected access + } + } + + protected String mString(Object o) { + return o.toString(); + } +} diff --git a/tests/errors/protectedAccess/p1/C1.java b/tests/errors/protectedAccess/p1/C1.java new file mode 100644 index 000000000..976c8e7c6 --- /dev/null +++ b/tests/errors/protectedAccess/p1/C1.java @@ -0,0 +1,17 @@ +package protectedAccess.p1; + + +public class C1 { + protected C1() { } + + protected String s = "protected"; + + protected String m() { return "protected"; } + + protected String mString(String s) { return s; } + + protected static class I1 { + protected String si = "ip"; + protected String mi() { return "ip"; } + } +} -- cgit v1.2.3