KickJava   Java API By Example, From Geeks To Geeks.

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


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 constructor is called.
15  *
16  * @author MS
17  * @version 1.0
18  */

19 public class ConstructorCall extends Event {
20
21     public Object JavaDoc receiver;
22     public Constructor constructor;
23     public Object JavaDoc[] args;
24
25     /**
26      * value to be returned when the body of the method is not
27      * executed (skip == true).
28      */

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