1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 package org.apache.bcel.generic; 19 20 /** 21 * LDC2_W - Push long or double from constant pool 22 * 23 * <PRE>Stack: ... -> ..., item.word1, item.word2</PRE> 24 * 25 * @version $Id$ 26 */ 27 public class LDC2_W extends CPInstruction implements PushInstruction { 28 29 /** 30 * Empty constructor needed for Instruction.readInstruction. 31 * Not to be used otherwise. 32 */ LDC2_W()33 LDC2_W() { 34 } 35 36 LDC2_W(final int index)37 public LDC2_W(final int index) { 38 super(org.apache.bcel.Const.LDC2_W, index); 39 } 40 41 42 @Override getType( final ConstantPoolGen cpg )43 public Type getType( final ConstantPoolGen cpg ) { 44 switch (cpg.getConstantPool().getConstant(super.getIndex()).getTag()) { 45 case org.apache.bcel.Const.CONSTANT_Long: 46 return Type.LONG; 47 case org.apache.bcel.Const.CONSTANT_Double: 48 return Type.DOUBLE; 49 default: // Never reached 50 throw new RuntimeException("Unknown constant type " + super.getOpcode()); 51 } 52 } 53 54 getValue( final ConstantPoolGen cpg )55 public Number getValue( final ConstantPoolGen cpg ) { 56 final org.apache.bcel.classfile.Constant c = cpg.getConstantPool().getConstant(super.getIndex()); 57 switch (c.getTag()) { 58 case org.apache.bcel.Const.CONSTANT_Long: 59 return Long.valueOf(((org.apache.bcel.classfile.ConstantLong) c).getBytes()); 60 case org.apache.bcel.Const.CONSTANT_Double: 61 return new Double(((org.apache.bcel.classfile.ConstantDouble) c).getBytes()); 62 default: // Never reached 63 throw new RuntimeException("Unknown or invalid constant type at " + super.getIndex()); 64 } 65 } 66 67 68 /** 69 * Call corresponding visitor method(s). The order is: 70 * Call visitor methods of implemented interfaces first, then 71 * call methods according to the class hierarchy in descending order, 72 * i.e., the most specific visitXXX() call comes last. 73 * 74 * @param v Visitor object 75 */ 76 @Override accept( final Visitor v )77 public void accept( final Visitor v ) { 78 v.visitStackProducer(this); 79 v.visitPushInstruction(this); 80 v.visitTypedInstruction(this); 81 v.visitCPInstruction(this); 82 v.visitLDC2_W(this); 83 } 84 } 85