KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > bcel > generic > LDC2_W


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 /**
20  * LDC2_W - Push long or double from constant pool
21  *
22  * <PRE>Stack: ... -&gt; ..., item.word1, item.word2</PRE>
23  *
24  * @version $Id: LDC2_W.java 386056 2006-03-15 11:31:56Z tcurdt $
25  * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
26  */

27 public class LDC2_W extends CPInstruction implements PushInstruction, TypedInstruction {
28
29     /**
30      * Empty constructor needed for the Class.newInstance() statement in
31      * Instruction.readInstruction(). Not to be used otherwise.
32      */

33     LDC2_W() {
34     }
35
36
37     public LDC2_W(int index) {
38         super(org.apache.bcel.Constants.LDC2_W, index);
39     }
40
41
42     public Type getType( ConstantPoolGen cpg ) {
43         switch (cpg.getConstantPool().getConstant(index).getTag()) {
44             case org.apache.bcel.Constants.CONSTANT_Long:
45                 return Type.LONG;
46             case org.apache.bcel.Constants.CONSTANT_Double:
47                 return Type.DOUBLE;
48             default: // Never reached
49
throw new RuntimeException JavaDoc("Unknown constant type " + opcode);
50         }
51     }
52
53
54     public Number JavaDoc getValue( ConstantPoolGen cpg ) {
55         org.apache.bcel.classfile.Constant c = cpg.getConstantPool().getConstant(index);
56         switch (c.getTag()) {
57             case org.apache.bcel.Constants.CONSTANT_Long:
58                 return new Long JavaDoc(((org.apache.bcel.classfile.ConstantLong) c).getBytes());
59             case org.apache.bcel.Constants.CONSTANT_Double:
60                 return new Double JavaDoc(((org.apache.bcel.classfile.ConstantDouble) c).getBytes());
61             default: // Never reached
62
throw new RuntimeException JavaDoc("Unknown or invalid constant type at " + index);
63         }
64     }
65
66
67     /**
68      * Call corresponding visitor method(s). The order is:
69      * Call visitor methods of implemented interfaces first, then
70      * call methods according to the class hierarchy in descending order,
71      * i.e., the most specific visitXXX() call comes last.
72      *
73      * @param v Visitor object
74      */

75     public void accept( Visitor v ) {
76         v.visitStackProducer(this);
77         v.visitPushInstruction(this);
78         v.visitTypedInstruction(this);
79         v.visitCPInstruction(this);
80         v.visitLDC2_W(this);
81     }
82 }
83
Popular Tags