KickJava   Java API By Example, From Geeks To Geeks.

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


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 returns.
15  *
16  * @author Remi Douence
17  * @version 1.0
18  */

19 public class MethodReturn extends Event {
20
21     public Object JavaDoc receiver;
22     public Method method;
23     public Object JavaDoc[] args;
24     public Object JavaDoc returnValue;
25     public int stackLevel;
26
27     public MethodReturn(Thread JavaDoc thread, Object JavaDoc returnValue,
28          Object JavaDoc receiver, Method method, Object JavaDoc[] args) {
29     super(thread);
30     this.receiver = receiver;
31     this.method = method;
32     this.args = args;
33     this.returnValue = returnValue;
34     // remi: hack in order to get the stack level, aka number of lines in:
35
// new Exception().printStackTrace();
36
this.stackLevel = 0;
37     StringWriter stringWriter = new StringWriter();
38     PrintWriter printWriter = new PrintWriter(stringWriter, true);
39     new Exception JavaDoc().printStackTrace(printWriter);
40     String JavaDoc string = stringWriter.toString();
41     int pos = 0;
42     while ((pos = string.indexOf('\n', pos + 1)) > -1) {
43         this.stackLevel++;
44     }
45     }
46     public String JavaDoc toString() {
47     String JavaDoc result = "MethodReturn ";
48     result += returnValue;
49     result += this.toString2();
50     return result;
51     }
52     public String JavaDoc toString2() {
53     String JavaDoc result = receiver + "." + method.getName() + "(";
54     for (int i=0; i<args.length; i++) {
55         result += args[i] + ",";
56     }
57     result += ")";
58     result += super.toString();
59     return result;
60     }
61 }
62
Popular Tags