Source code: com/chaoswg/xtc4y/classdesc/code/instructions/MultiANewArray.java
1 //$Header: /cvsroot/xtc4y/xtc4y/src/com/chaoswg/xtc4y/classdesc/code/instructions/MultiANewArray.java,v 1.1 2003/08/26 12:35:25 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:35:25 $, by $Author: toggm $ *
9 * Version: $Revision: 1.1 $ *
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.code.instructions;
19
20 import java.io.DataInputStream;
21 import java.io.DataOutputStream;
22 import java.io.IOException;
23
24 import com.chaoswg.xtc4y.classdesc.ConstantPool;
25 import com.chaoswg.xtc4y.classdesc.ClassCPEntry;
26
27 /**
28 * Creates a multidimensional array
29 * @author Mike Toggweiler
30 **/
31 public class MultiANewArray extends Instruction {
32 private byte dimension;
33 private ClassCPEntry cpEntry;
34
35 /**
36 * Opcode of the multianewarray instruction
37 **/
38 public static final byte MULTIANEWARRAY = (byte)197;
39
40 /**
41 * Creates an MultiANewArray and initializes it from a
42 * DataInputStream
43 * @param dis the DataInputStream to read from
44 * @param cp the constant pool to resolve indices
45 **/
46 protected MultiANewArray(DataInputStream dis,
47 ConstantPool cp) throws IOException {
48 super(MULTIANEWARRAY);
49 short cpIndex = (short)dis.readUnsignedShort();
50 cpEntry = (ClassCPEntry)cp.getCPEntryAt(cpIndex);
51 dimension = (byte)dis.readUnsignedByte();
52 }
53
54 /**
55 * Construct a new multi dimensional array with the given classcpentry
56 * and the dimension
57 * @param cpEntry the classCPEntry of the array type
58 * @param dimension the dimension of the array
59 **/
60 public MultiANewArray(ClassCPEntry cpEntry, byte dimension) {
61 super(MULTIANEWARRAY);
62 this.cpEntry = cpEntry;
63 this.dimension = dimension;
64 }
65
66 /**
67 * Write the instruction onto the DataOutputStream, using the
68 * constant pool to register variables. .
69 * @param dos the DataOutputStream to write on
70 * @param cp The constant pool to register variables
71 **/
72 public final void write(DataOutputStream dos, ConstantPool cp)
73 throws IOException {
74 super.write(dos, cp);
75 dos.writeShort(cp.addCPEntry(cpEntry));
76 dos.writeByte(dimension);
77 }
78
79 /**
80 * @return the number of bytes used in this command
81 **/
82 public int getNumberOfUsedBytes() {
83 return 4;
84 }
85 }