KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > emn > info > eaop > event > MethodCall


1 /* ----------------------------------------------------------------------------
2  * EAOP 1.0, 2002-12-19
3  * (c) 2002 Remi Douence, Mario Sudholt; OBASCO group; EMN/INRIA; France
4  * THIS SOFTWARE IS PROVIDED AS IS AND WITHOUT ANY WARRANTY
5   -------------------------------------------------------------------------- */

6
7 package fr.emn.info.eaop.event;
8
9 import java.util.*;
10 import java.lang.reflect.*;
11 import java.io.*;
12
13 /**
14  * This class/event gathers information when a method is called. An
15  * aspect is an event transfomer, it can change, for instance, the value
16  * of arguments.
17  *
18  * @author RD
19  * @version 1.0
20  */

21 public class MethodCall extends Event {
22
23     public Object JavaDoc receiver;
24     public Method method;
25     public Object JavaDoc[] args;
26
27     /**
28      * <code>skip</skip> is a boolean indicating that body execution should
29      * skipped.
30      */

31     public boolean skip = false;
32
33     /**
34      * Value to be returned when the body of the method is not
35      * executed (<code>skip == true</code>).
36      */

37     public Object JavaDoc returnValue;
38     public int stackLevel;
39
40     public MethodCall(Thread JavaDoc thread,
41               Object JavaDoc receiver,
42               Method method,
43               Object JavaDoc[] args) {
44     super(thread);
45     this.receiver = receiver;
46     this.method = method;
47     this.args = args;
48     // remi: hack in order to get the stack level, aka number of lines in:
49
// new Exception().printStackTrace();
50
this.stackLevel = 0;
51     StringWriter stringWriter = new StringWriter();
52     PrintWriter printWriter = new PrintWriter(stringWriter, true);
53     new Exception JavaDoc().printStackTrace(printWriter);
54     String JavaDoc string = stringWriter.toString();
55     int pos = 0;
56     while ((pos = string.indexOf('\n', pos + 1)) > -1) {
57         this.stackLevel++;
58     }
59     }
60     public String JavaDoc toString() {
61     String JavaDoc result = "MethodCall " + this.toString2();
62     return result;
63     }
64     public String JavaDoc toString2() {
65     String JavaDoc result = receiver + "." + method.getName() + "(";
66     for (int i=0; i<args.length; i++) {
67         result += args[i] + ",";
68     }
69     result += ")";
70     result += super.toString();
71     return result;
72     }
73 }
74
75
Popular Tags