Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/techtrader/modules/tools/bytecode/MultiANewArrayInstruction.java


1   package com.techtrader.modules.tools.bytecode;
2   
3   
4   import java.io.IOException;
5   import java.io.DataInput;
6   import java.io.DataOutput;
7   
8   import com.techtrader.modules.tools.bytecode.visitor.BCVisitor;
9   
10  
11  /**
12   *  Represents the MULTIANEWARRAY opcode instruction, which creates a new
13   *  multi-dimensional array.
14   *
15   *  @author    Abe White
16   */
17  public class MultiANewArrayInstruction
18    extends ClassInstruction
19  {
20    private int _dims = 0;
21  
22  
23    protected MultiANewArrayInstruction (Code owner)
24    {
25      super (owner, MULTIANEWARRAY);
26    }
27  
28  
29    /**
30     *  Set the dimensions of the array.
31     *  
32     *  @return    this Instruction, for method chaining
33     */
34    public MultiANewArrayInstruction setDimensions (int dims)
35    {
36      _dims = dims;
37      return this;
38    }  
39  
40  
41    /**
42      *  Get the dimensions of the array.
43     */
44    public int getDimensions ()
45    {
46      return _dims;
47    }  
48  
49  
50    /**
51     *  Two MULTIANEWARRAY instructions are equal if they have the same
52     *  type and dimensions, or if the type and dimensions of either
53     *  is unset.
54     */
55    public boolean equals (Object other)
56    {
57      if (other == this)
58        return true;
59      if (!(other instanceof MultiANewArrayInstruction))
60        return false;
61      if (!super.equals (other))
62        return false;
63  
64      MultiANewArrayInstruction ins = (MultiANewArrayInstruction) other;
65      return _dims == 0 || ins._dims == 0 || _dims == ins._dims;
66    }
67  
68  
69    public int getLength ()
70    {
71      return super.getLength () + 1;
72    }
73  
74    
75    public int getStackChange ()
76    {
77      return -(getDimensions ()) + 1;
78    }
79  
80  
81    protected void copy (Instruction orig)
82    {
83      super.copy (orig);
84      setDimensions (((MultiANewArrayInstruction) orig).getDimensions ());
85    }
86  
87    
88    protected void readData (DataInput in)
89      throws IOException
90    {
91      super.readData (in);
92      setDimensions (in.readUnsignedByte ());
93    }
94  
95  
96    protected void writeData (DataOutput out)
97      throws IOException
98    {
99      super.writeData (out);
100     out.writeByte (getDimensions ());
101   }
102 
103 
104   public void acceptVisit (BCVisitor visit)
105   {
106     visit.enterMultiANewArrayInstruction (this);
107     visit.exitMultiANewArrayInstruction (this);
108   }
109 }