From aaf2d4ab6b9b36a959b9f06db89e532cbb5ec6d7 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 3 May 1999 11:00:09 +0000 Subject: [PATCH] Initial revision git-svn-id: https://svn.code.sf.net/p/jode/code/trunk@753 379699f6-c40d-0410-875b-85095c16579e --- jode/jode/expr/ThisOperator.java | 66 ++++++++++++++++++++++++++++++++ jode/test/AnonymousClass.java | 55 ++++++++++++++++++++++++++ jode/test/Conflicts.java | 50 ++++++++++++++++++++++++ jode/test/InnerCompat.java | 35 +++++++++++++++++ 4 files changed, 206 insertions(+) create mode 100644 jode/jode/expr/ThisOperator.java create mode 100644 jode/test/AnonymousClass.java create mode 100644 jode/test/Conflicts.java create mode 100644 jode/test/InnerCompat.java diff --git a/jode/jode/expr/ThisOperator.java b/jode/jode/expr/ThisOperator.java new file mode 100644 index 0000000..c41625e --- /dev/null +++ b/jode/jode/expr/ThisOperator.java @@ -0,0 +1,66 @@ +/* ThisOperator Copyright (C) 1998-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$ + */ + +package jode.expr; +import jode.type.Type; +import jode.bytecode.ClassInfo; +import jode.decompiler.TabbedPrintWriter; + +public class ThisOperator extends NoArgOperator { + boolean isInnerMost; + ClassInfo classInfo; + + public ThisOperator(ClassInfo classInfo, boolean isInnerMost) { + super(Type.tClass(classInfo)); + this.classInfo = classInfo; + this.isInnerMost = isInnerMost; + } + + public ThisOperator(ClassInfo classInfo) { + this(classInfo, false); + } + + public ClassInfo getClassInfo() { + return classInfo; + } + + public int getPriority() { + return 1000; + } + + public String toString() { + return classInfo+".this"; + } + + public boolean equals(Object o) { + return (o instanceof ThisOperator && + ((ThisOperator) o).classInfo.equals(classInfo)); + } + + public void dumpExpression(TabbedPrintWriter writer, + Expression[] operands) + throws java.io.IOException { + if (!isInnerMost) { + writer.print(writer.getClassString(classInfo)); + writer.print("."); + } + writer.print("this"); + } +} + diff --git a/jode/test/AnonymousClass.java b/jode/test/AnonymousClass.java new file mode 100644 index 0000000..e974db9 --- /dev/null +++ b/jode/test/AnonymousClass.java @@ -0,0 +1,55 @@ +/* AnonymousClass 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$ + */ + +package jode.test; + +public class AnonymousClass { + class Inner { + public void test() { + class Hello { + Hello() { + System.err.println("construct"); + } + Hello(String info) { + System.err.println("construct: "+info); + } + + void hello() { + this.hashCode(); + Inner.this.hashCode(); + AnonymousClass.this.hashCode(); + System.err.println("HelloWorld"); + } + }; + final Hello hi = new Hello(); + final Hello ho = new Hello("ho"); + final Object o = new Object() { + public String toString() { + hi.hello(); + return Integer.toHexString(AnonymousClass.this.hashCode()); + } + }; + Object p = new Object() { + public String toString() { + return o.toString(); + } + }; + } + } +} diff --git a/jode/test/Conflicts.java b/jode/test/Conflicts.java new file mode 100644 index 0000000..8b92239 --- /dev/null +++ b/jode/test/Conflicts.java @@ -0,0 +1,50 @@ +package jode.test; + +/** + * This class tests name conflicts and their resolvation. + */ +public class Conflicts { + int Conflicts; + + class Inner { + int Conflicts; + + void Conflicts() { + int Conflicts = 4; + Conflicts(); + new Object() { + void Inner() { + jode.test.Conflicts.this.Inner(); + } + }; + this.Conflicts = Conflicts; + Inner(); + jode.test.Conflicts.this.Conflicts = this.Conflicts; + } + + jode.test.Conflicts Conflicts(Inner Conflicts) { + return jode.test.Conflicts.this; + } + } + + public void Inner() { + } + + class Second { + class Inner { + } + void create() { + new Inner(); + jode.test.Conflicts.this.new Inner(); + } + } + + + public Conflicts() { + int Conflicts = this.Conflicts; + Inner Inner = new Inner(); + Inner.Conflicts = 5; + new Inner().Conflicts(Inner).Inner(); + } +} + diff --git a/jode/test/InnerCompat.java b/jode/test/InnerCompat.java new file mode 100644 index 0000000..18fc491 --- /dev/null +++ b/jode/test/InnerCompat.java @@ -0,0 +1,35 @@ +package jode.test; + +public class InnerCompat { + int x; + + private class privateNeedThis { + void a() { x = 5; } + } + protected class protectedNeedThis { + void a() { x = 5; } + } + class packageNeedThis { + void a() { x = 5; } + } + public class publicNeedThis { + void a() { x = 5; } + } + private class privateNeedNotThis { + int x; + void a() { x = 5; } + } + protected class protectedNeedNotThis { + int x; + void a() { x = 5; } + } + class packageNeedNotThis { + int x; + void a() { x = 5; } + } + public class publicNeedNotThis { + int x; + void a() { x = 5; } + } + +}