KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > try_catch_clinit > FieldAssignTest


1 package test.try_catch_clinit;
2
3 import java.lang.reflect.Modifier JavaDoc;
4
5 import alt.jiapi.*;
6 import alt.jiapi.reflect.*;
7 import alt.jiapi.instrumentor.*;
8
9 import test.InstrumentorTest;
10
11 // Usage: java -Dn=5 test.try_catch_clinit.FieldAssignTest
12
public class FieldAssignTest extends InstrumentorTest {
13     static {
14         System.setProperty("class", "test.try_catch_clinit.Main");
15         System.setProperty("include", "test.try_catch_clinit.*");
16     }
17
18     public static void main(String JavaDoc [] args) throws Exception JavaDoc {
19         FieldAssignTest ft = new FieldAssignTest();
20         ft.run(args);
21     }
22
23     public FieldAssignTest() throws JiapiException {
24         InstrumentationDescriptor id = new InstrumentationDescriptor();
25
26         InstrumentorChain chain1 = new InstrumentorChain();
27         Instrumentor createField =
28             new CreateFieldInstrumentor(Modifier.PRIVATE, "java.lang.Object",
29                                         "jeejee");
30         chain1.add(createField);
31         id.addChain(chain1);
32
33         InstrumentorChain chain2 = new InstrumentorChain();
34
35         // The Logger class has an exception table:
36
// from to target type
37
// 0 12 15 <Class java.lang.Exception>
38
//
39
// 0 is an instruction whose index is 0
40
// 12 is an instruction whose index is 6
41
// The instrumentation fails for
42
// java.lang.IncompatibleClassChangeError when assign is done
43
// in between these indexes: 0 - 6.
44
// index >= 6 works
45
int index = Integer.parseInt(System.getProperty("n", "2"));
46         Instrumentor head = new HeadInstrumentor(index);
47         Instrumentor assign = new FieldAssignInstrumentor("jeejee",
48                                                           new Object JavaDoc());
49         
50         chain2.add(head);
51         chain2.add(assign);
52
53         id.addChain(chain2);
54
55         addInclusionRules(id, getInclusionRules());
56         addExclusionRules(id, getExclusionRules());
57
58         ctx.addInstrumentationDescriptor(id);
59     }
60 }
61
Popular Tags