git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@1188 379699f6-c40d-0410-875b-85095c16579ebranch_1_1
parent
b06f5a9c12
commit
f7fced3615
@ -0,0 +1,124 @@ |
||||
/* MethodScopedClass Copyright (C) 1999 Jochen Hoenicke. |
||||
* |
||||
* This program is free software; you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation; either version 2, or (at your option) |
||||
* any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program; see the file COPYING. If not, write to |
||||
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
||||
* |
||||
* $Id$ |
||||
*/ |
||||
|
||||
import java.util.Vector; |
||||
|
||||
public class MethodScopedClass { |
||||
int var = 3; |
||||
|
||||
public void test1() { |
||||
final long longVar = 5; |
||||
final int intVar = var; |
||||
final double dblVar = 3; |
||||
|
||||
final float fooFloat = 5; |
||||
final float barFloat = 7; |
||||
|
||||
class Hello { |
||||
int var = (int) longVar; |
||||
|
||||
{ |
||||
System.err.println("all constructors"); |
||||
} |
||||
|
||||
Hello(float f, String info) { |
||||
System.err.println("construct: "+info+" "+f); |
||||
} |
||||
|
||||
Hello(float f) { |
||||
this(f, "default"); |
||||
} |
||||
|
||||
public void hello() { |
||||
System.err.println("HelloWorld: "+dblVar+" "+intVar); |
||||
} |
||||
}; |
||||
|
||||
/* This test checks if the variables longVar, intVar and dblVar |
||||
* can be detected correctly as inner values. The first parameter |
||||
* of the Hello constructor can't be an outer value, because bar |
||||
* uses a different value for this. |
||||
*/ |
||||
class foo { |
||||
foo() { |
||||
new Hello(fooFloat); |
||||
} |
||||
} |
||||
|
||||
class bar { |
||||
bar() { |
||||
new Hello(barFloat, "bar"); |
||||
} |
||||
} |
||||
|
||||
new foo(); |
||||
new bar(); |
||||
} |
||||
|
||||
// public void test2() {
|
||||
// final long longVar = 5;
|
||||
// final int intVar = var;
|
||||
// final double dblVar = 3;
|
||||
|
||||
// final float barFloat = 7;
|
||||
|
||||
// class Hello {
|
||||
// int var = (int) longVar;
|
||||
|
||||
// {
|
||||
// System.err.println("all constructors");
|
||||
// }
|
||||
|
||||
// Hello(int i, String info) {
|
||||
// System.err.println("construct: "+info);
|
||||
// }
|
||||
|
||||
// Hello(int i) {
|
||||
// this(i, "This can only be compiled correctly"
|
||||
// +" by a recent jikes");
|
||||
// }
|
||||
|
||||
// public void hello() {
|
||||
// System.err.println("HelloWorld: "+dblVar+" "+intVar);
|
||||
// }
|
||||
// };
|
||||
|
||||
// /* Similar to the test above. But this time foo is given barFloat
|
||||
// * as parameter.
|
||||
// */
|
||||
// class foo {
|
||||
// foo(int param) {
|
||||
// new Hello(param);
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// class bar {
|
||||
// bar() {
|
||||
// new Hello(barFloat, "bar");
|
||||
// }
|
||||
// test() {
|
||||
// new foo(fooFloat);
|
||||
// }
|
||||
// }
|
||||
|
||||
// new foo(barFloat);
|
||||
// new bar();
|
||||
// }
|
||||
} |
@ -0,0 +1,89 @@ |
||||
|
||||
/** |
||||
* This class tests accesses to private methods and fields, that can be |
||||
* accessed via a cast. |
||||
* |
||||
* The test class has some problems, that no compiler will produce |
||||
* correct code. When all constructors are declared as private all |
||||
* compilers won't even compile it. |
||||
* |
||||
* I wish there would be a clear document saying what constructs are |
||||
* allowed and a compiler that would compile them all... |
||||
*/ |
||||
public class PrivateHideTest { |
||||
|
||||
public static class Test { |
||||
private String id; |
||||
|
||||
Test(int val) { |
||||
id = "Test"+val; |
||||
} |
||||
|
||||
private void a(String descr) { |
||||
System.err.println(descr+" = "+id); |
||||
} |
||||
|
||||
class Mid extends Test { |
||||
private String id; |
||||
|
||||
Mid(int val) { |
||||
super(val); |
||||
id = "Mid"+val; |
||||
} |
||||
|
||||
private void a(String descr) { |
||||
System.err.println(descr+" = "+id); |
||||
} |
||||
|
||||
private Test getTestThis() { |
||||
return Test.this; |
||||
} |
||||
|
||||
class Inner extends Mid { |
||||
private String id; |
||||
|
||||
Inner(int val, Test midOuter) { |
||||
midOuter.super(val); |
||||
id = "Inner"+val; |
||||
} |
||||
|
||||
private void a(String descr) { |
||||
System.err.println(descr+" = "+id); |
||||
} |
||||
|
||||
private void methodTest() { |
||||
this.a("this"); |
||||
super.a("super"); |
||||
((Mid) this).a("(Mid) this"); |
||||
((Test) this).a("(Test) this"); |
||||
Mid.this.a("Mid.this"); |
||||
((Test) Mid.this).a("(Test) Mid.this"); |
||||
Test.this.a("Test.this"); |
||||
((Mid) this).getTestThis().a("((Mid) this).getTestThis()"); |
||||
Mid.this.getTestThis().a("Mid.this.getTestThis()"); |
||||
} |
||||
|
||||
|
||||
private void fieldTest() { |
||||
System.err.println("this = "+this.id); |
||||
System.err.println("(Mid) this = " + ((Mid) this).id); |
||||
System.err.println("(Test) this = " + ((Test) this).id); |
||||
System.err.println("Mid.this = " + Mid.this.id); |
||||
System.err.println("(Test) Mid.this = " + ((Test) Mid.this).id); |
||||
System.err.println("Test.this = " + Test.this.id); |
||||
System.err.println("((Mid) this).getTestThis() = " + ((Mid)this).getTestThis().id); |
||||
System.err.println("Mid.this.getTestThis() = " + Mid.this.getTestThis().id); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static void main(String[] argv) { |
||||
Test.Mid.Inner inner = |
||||
new Test(1).new Mid(2).new Inner(3, new Test(4).new Mid(5)); |
||||
inner.methodTest(); |
||||
System.err.println("--"); |
||||
inner.fieldTest(); |
||||
((Test.Mid)inner).a("(Test.Mid) inner"); |
||||
} |
||||
} |
Loading…
Reference in new issue