1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 package org.codehaus.groovy.classgen;
37
38 import groovy.lang.Reference;
39
40 import org.codehaus.groovy.runtime.InvokerHelper;
41
42 /***
43 * This is a scratch class used to experiment with ASM to see what kind of
44 * stuff is output for normal Java code
45 *
46 * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
47 * @version $Revision: 1.16 $
48 */
49 public class DumpClass4 {
50
51 public DumpClass4() {
52 }
53
54 public static void main(String[] args) {
55 Object foo = InvokerHelper.invokeConstructorOf(DumpClass4.class, null);
56 }
57
58 public void run() {
59 synchronized (this) {
60 InvokerHelper.invokeMethod(this, "foo", null);
61 }
62 InvokerHelper.invokeMethod(this, "bar", null);
63 }
64
65 public void throwException() {
66 throw (RuntimeException) InvokerHelper.invokeConstructorOf("java.lang.RuntimeException", "Hello");
67 }
68
69 public void switchTest(int i) {
70 String x = "foo";
71
72 switch (i) {
73 case 1 :
74 x = "1";
75 break;
76 case 2 :
77 x = "2";
78 case 3 :
79 x = "3";
80 break;
81 default :
82 x = "default";
83 }
84 System.out.println(x);
85 }
86
87 public Object createReferenceTest() {
88 Reference foo = new Reference();
89 foo.set(new Integer(12));
90 return foo.get();
91 }
92
93 public static void makeInstance() {
94 InvokerHelper.invokeConstructorOf(DumpClass4.class, null);
95 }
96
97 public void makeNestedArray() {
98 InvokerHelper.invokeMethod(
99 "outer",
100 "foo",
101 new Object[] { InvokerHelper.invokeMethod("inner", "plus", new Object[] { "1" })
102 });
103 }
104
105 public void makeNestedEmptyArray() {
106 InvokerHelper
107 .invokeMethod("outer", "foo", new Object[] { InvokerHelper.invokeMethod("inner", "plus", new Object[] {
108 })
109 });
110 }
111
112 public Object makeAnotherArray(Object a, Object b) {
113 return new Object[] { a, b };
114 }
115
116 public void tryFinally() {
117 try {
118 System.out.println("Try");
119 }
120 finally {
121 System.out.println("Finally");
122 }
123 }
124
125 public void tryCatchFinally() {
126 try {
127 System.out.println("Try");
128 }
129 catch (Exception e) {
130 System.out.println("Catch");
131 }
132 finally {
133 System.out.println("Finally");
134 }
135 }
136
137 public void emptyTryCatch() {
138 try {
139 }
140 catch (Throwable t) {
141 }
142 }
143
144 public void usePrimitiveType() {
145 System.out.println(int.class);
146 }
147
148 public String testSuperCall() {
149 return super.toString();
150 }
151
152 public Object createReference(Object foo) {
153 return new Reference(foo);
154 }
155 }