Source code: com/chaoswg/xtc4y/classdesc/ExceptionInfo.java
1 //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/ExceptionInfo.java,v 1.2 2003/08/26 12:46:53 toggm Exp $
2 /******************************************************************************
3 * XTC4y - eXtreme Testing Collection 4 you *
4 * -------------------------------------------------------------------------- *
5 * URL: http://www.chaoswg.com/xtc4y *
6 * Author: Mike Toggweiler (2.dog@gmx.ch) *
7 * *
8 * Last Updated: $Date: 2003/08/26 12:46:53 $, by $Author: toggm $ *
9 * Version: $Revision: 1.2 $ *
10 * -------------------------------------------------------------------------- *
11 * COPYRIGHT: (c) 2003 by Mike Toggweiler *
12 * *
13 * This program is free software; you can redistribute it and/or modify *
14 * it under the terms of the GNU General Public License as published by *
15 * the Free Software Foundation; either version 2 of the License, or *
16 * (at your option) any later version. *
17 *****************************************************************************/
18 package com.chaoswg.xtc4y.classdesc;
19
20 import java.io.DataInputStream;
21 import java.io.DataOutputStream;
22 import java.io.IOException;
23
24 import com.chaoswg.xtc4y.classdesc.code.Code;
25 import com.chaoswg.xtc4y.classdesc.code.instructions.Instruction;
26
27 /**
28 * IS used to descibe an exception in a code attribute
29 * @author Mike Toggweiler
30 **/
31 public class ExceptionInfo {
32
33 //start of exception in respect to the code array
34 //private short startPc;
35 //end of exception in respect to the code array
36 //private short endPc;
37 //start of exception handler in respect to the code array
38 //private short handlerPc;
39 //catch type
40 private ClassCPEntry catchType;
41
42 private Instruction startInstr;
43 private Instruction endInstr;
44 private Instruction handlerInstr;
45
46 /**
47 * Creates a ExceptionInfo and initializes it from a DataInputStream
48 * @param dis the DataInputStream to read from
49 * @param cp the constant pool to resolve indices
50 * @param code the code to resolve indexes
51 **/
52 protected ExceptionInfo(DataInputStream dis, ConstantPool cp, Code code)
53 throws IOException {
54 short startPc = (short)dis.readUnsignedShort();
55 short endPc = (short)dis.readUnsignedShort();
56 short handlerPc = (short)dis.readUnsignedShort();
57 short catchIndex = (short)dis.readUnsignedShort();
58
59 startInstr = code.getInstructionAt(startPc);
60 endInstr = code.getInstructionAt(endPc);
61 handlerInstr = code.getInstructionAt(handlerPc);
62
63 if (catchIndex != 0) {
64 catchType = (ClassCPEntry)cp.getCPEntryAt(catchIndex);
65 }
66 else {
67 catchType = null;
68 }
69 }
70
71 /**
72 * Create a new exception
73 * @param startPc start of the exception in respect to the code array
74 * @param endPc end of the exception in respect to the code array
75 * @param handlerPc start of the exception handler in respect to the code
76 * array
77 * @param catchType a ClassCPEntry describing the catch type
78 **/
79 /*public ExceptionInfo(short startPc, short endPc, short handlerPc,
80 ClassCPEntry catchType) {
81 this.startPc = startPc;
82 this.endPc = endPc;
83 this.handlerPc = handlerPc;
84 this.catchType = catchType;
85 }*/
86
87 /**
88 * Write the exception information into a DataOutputStream
89 * @param dos the DataOutputStream to write on
90 * @param cp the constant pool to store variables
91 * @param code the code to resolve indexes
92 **/
93 protected final void write(DataOutputStream dos, ConstantPool cp,
94 Code code)
95 throws IOException {
96 dos.writeShort(code.getIndexOf(startInstr));
97 dos.writeShort(code.getIndexOf(endInstr));
98 dos.writeShort(code.getIndexOf(handlerInstr));
99 if (catchType != null) {
100 dos.writeShort(cp.addCPEntry(catchType));
101 }
102 else {
103 dos.writeShort((short)0);
104 }
105 }
106
107 /**
108 * @return the classCPEntry
109 **/
110 public ClassCPEntry getCatchType() {
111 return catchType;
112 }
113
114 /**
115 * @return the start instr
116 **/
117 public Instruction getStartInstruction() {
118 return startInstr;
119 }
120
121 /**
122 * @return the emd instruction
123 **/
124 public Instruction getEndInstruction() {
125 return endInstr;
126 }
127
128 /**
129 * @return the start instruction of the hanlder
130 **/
131 public Instruction getHandlerInstruction() {
132 return handlerInstr;
133 }
134
135 /**
136 * Set a new startInstr
137 * @param startInstr the new instr
138 **/
139 public void setStartInstruction(Instruction startInstr) {
140 this.startInstr = startInstr;
141 }
142
143 /**
144 * Set a new endInstruction
145 * @param endInstr the new instruction
146 **/
147 public void setEndInstruction(Instruction endInstr) {
148 this.endInstr = endInstr;
149 }
150
151 /**
152 * Set a new startInstr of the handler
153 * @param handlerInstr the new instruction
154 **/
155 public void setHandlerInstruction(Instruction handlerInstr) {
156 this.handlerInstr = handlerInstr;
157 }
158 }