View Javadoc

1   /*
2    * Copyright  2000-2004 The Apache Software Foundation
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License"); 
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License. 
15   *
16   */
17  package org.apache.bcel.generic;
18  
19  import java.io.DataOutputStream;
20  import java.io.IOException;
21  import org.apache.bcel.util.ByteSequence;
22  
23  /***
24   * SIPUSH - Push short
25   *
26   * <PRE>Stack: ... -&gt; ..., value</PRE>
27   *
28   * @version $Id: SIPUSH.java 386056 2006-03-15 11:31:56Z tcurdt $
29   * @author  <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
30   */
31  public class SIPUSH extends Instruction implements ConstantPushInstruction {
32  
33      private short b;
34  
35  
36      /***
37       * Empty constructor needed for the Class.newInstance() statement in
38       * Instruction.readInstruction(). Not to be used otherwise.
39       */
40      SIPUSH() {
41      }
42  
43  
44      public SIPUSH(short b) {
45          super(org.apache.bcel.Constants.SIPUSH, (short) 3);
46          this.b = b;
47      }
48  
49  
50      /***
51       * Dump instruction as short code to stream out.
52       */
53      public void dump( DataOutputStream out ) throws IOException {
54          super.dump(out);
55          out.writeShort(b);
56      }
57  
58  
59      /***
60       * @return mnemonic for instruction
61       */
62      public String toString( boolean verbose ) {
63          return super.toString(verbose) + " " + b;
64      }
65  
66  
67      /***
68       * Read needed data (e.g. index) from file.
69       */
70      protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException {
71          length = 3;
72          b = bytes.readShort();
73      }
74  
75  
76      public Number getValue() {
77          return new Integer(b);
78      }
79  
80  
81      /*** @return Type.SHORT
82       */
83      public Type getType( ConstantPoolGen cp ) {
84          return Type.SHORT;
85      }
86  
87  
88      /***
89       * Call corresponding visitor method(s). The order is:
90       * Call visitor methods of implemented interfaces first, then
91       * call methods according to the class hierarchy in descending order,
92       * i.e., the most specific visitXXX() call comes last.
93       *
94       * @param v Visitor object
95       */
96      public void accept( Visitor v ) {
97          v.visitPushInstruction(this);
98          v.visitStackProducer(this);
99          v.visitTypedInstruction(this);
100         v.visitConstantPushInstruction(this);
101         v.visitSIPUSH(this);
102     }
103 }