< prev index next >

src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/LDC.java

Print this page




  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.bcel.internal.generic;
  22 
  23 import java.io.DataOutputStream;
  24 import java.io.IOException;
  25 
  26 import com.sun.org.apache.bcel.internal.ExceptionConst;
  27 import com.sun.org.apache.bcel.internal.util.ByteSequence;
  28 
  29 /**
  30  * LDC - Push item from constant pool.
  31  *
  32  * <PRE>Stack: ... -&gt; ..., item</PRE>
  33  *
  34  * @version $Id: LDC.java 1749603 2016-06-21 20:50:19Z ggregory $

  35  */
  36 public class LDC extends CPInstruction implements PushInstruction, ExceptionThrower {
  37 
  38     /**
  39      * Empty constructor needed for the Class.newInstance() statement in
  40      * Instruction.readInstruction(). Not to be used otherwise.
  41      */
  42     LDC() {
  43     }
  44 
  45 
  46     public LDC(final int index) {
  47         super(com.sun.org.apache.bcel.internal.Const.LDC_W, index);
  48         setSize();
  49     }
  50 
  51 
  52     // Adjust to proper size
  53     protected final void setSize() {
  54         if (super.getIndex() <= com.sun.org.apache.bcel.internal.Const.MAX_BYTE) { // Fits in one byte?


  87 
  88 
  89     /**
  90      * Read needed data (e.g. index) from file.
  91      */
  92     @Override
  93     protected void initFromFile( final ByteSequence bytes, final boolean wide ) throws IOException {
  94         super.setLength(2);
  95         super.setIndex(bytes.readUnsignedByte());
  96     }
  97 
  98 
  99     public Object getValue( final ConstantPoolGen cpg ) {
 100         com.sun.org.apache.bcel.internal.classfile.Constant c = cpg.getConstantPool().getConstant(super.getIndex());
 101         switch (c.getTag()) {
 102             case com.sun.org.apache.bcel.internal.Const.CONSTANT_String:
 103                 final int i = ((com.sun.org.apache.bcel.internal.classfile.ConstantString) c).getStringIndex();
 104                 c = cpg.getConstantPool().getConstant(i);
 105                 return ((com.sun.org.apache.bcel.internal.classfile.ConstantUtf8) c).getBytes();
 106             case com.sun.org.apache.bcel.internal.Const.CONSTANT_Float:
 107                 return new Float(((com.sun.org.apache.bcel.internal.classfile.ConstantFloat) c).getBytes());
 108             case com.sun.org.apache.bcel.internal.Const.CONSTANT_Integer:
 109                 return Integer.valueOf(((com.sun.org.apache.bcel.internal.classfile.ConstantInteger) c).getBytes());
 110             case com.sun.org.apache.bcel.internal.Const.CONSTANT_Class:
 111                 final int nameIndex = ((com.sun.org.apache.bcel.internal.classfile.ConstantClass) c).getNameIndex();
 112                 c = cpg.getConstantPool().getConstant(nameIndex);
 113                 return new ObjectType(((com.sun.org.apache.bcel.internal.classfile.ConstantUtf8) c).getBytes());
 114             default: // Never reached
 115                 throw new RuntimeException("Unknown or invalid constant type at " + super.getIndex());
 116         }
 117     }
 118 
 119 
 120     @Override
 121     public Type getType( final ConstantPoolGen cpg ) {
 122         switch (cpg.getConstantPool().getConstant(super.getIndex()).getTag()) {
 123             case com.sun.org.apache.bcel.internal.Const.CONSTANT_String:
 124                 return Type.STRING;
 125             case com.sun.org.apache.bcel.internal.Const.CONSTANT_Float:
 126                 return Type.FLOAT;
 127             case com.sun.org.apache.bcel.internal.Const.CONSTANT_Integer:
 128                 return Type.INT;
 129             case com.sun.org.apache.bcel.internal.Const.CONSTANT_Class:




  15  * distributed under the License is distributed on an "AS IS" BASIS,
  16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17  * See the License for the specific language governing permissions and
  18  * limitations under the License.
  19  */
  20 
  21 package com.sun.org.apache.bcel.internal.generic;
  22 
  23 import java.io.DataOutputStream;
  24 import java.io.IOException;
  25 
  26 import com.sun.org.apache.bcel.internal.ExceptionConst;
  27 import com.sun.org.apache.bcel.internal.util.ByteSequence;
  28 
  29 /**
  30  * LDC - Push item from constant pool.
  31  *
  32  * <PRE>Stack: ... -&gt; ..., item</PRE>
  33  *
  34  * @version $Id: LDC.java 1749603 2016-06-21 20:50:19Z ggregory $
  35  * @LastModified: Nov 2017
  36  */
  37 public class LDC extends CPInstruction implements PushInstruction, ExceptionThrower {
  38 
  39     /**
  40      * Empty constructor needed for the Class.newInstance() statement in
  41      * Instruction.readInstruction(). Not to be used otherwise.
  42      */
  43     LDC() {
  44     }
  45 
  46 
  47     public LDC(final int index) {
  48         super(com.sun.org.apache.bcel.internal.Const.LDC_W, index);
  49         setSize();
  50     }
  51 
  52 
  53     // Adjust to proper size
  54     protected final void setSize() {
  55         if (super.getIndex() <= com.sun.org.apache.bcel.internal.Const.MAX_BYTE) { // Fits in one byte?


  88 
  89 
  90     /**
  91      * Read needed data (e.g. index) from file.
  92      */
  93     @Override
  94     protected void initFromFile( final ByteSequence bytes, final boolean wide ) throws IOException {
  95         super.setLength(2);
  96         super.setIndex(bytes.readUnsignedByte());
  97     }
  98 
  99 
 100     public Object getValue( final ConstantPoolGen cpg ) {
 101         com.sun.org.apache.bcel.internal.classfile.Constant c = cpg.getConstantPool().getConstant(super.getIndex());
 102         switch (c.getTag()) {
 103             case com.sun.org.apache.bcel.internal.Const.CONSTANT_String:
 104                 final int i = ((com.sun.org.apache.bcel.internal.classfile.ConstantString) c).getStringIndex();
 105                 c = cpg.getConstantPool().getConstant(i);
 106                 return ((com.sun.org.apache.bcel.internal.classfile.ConstantUtf8) c).getBytes();
 107             case com.sun.org.apache.bcel.internal.Const.CONSTANT_Float:
 108                 return ((com.sun.org.apache.bcel.internal.classfile.ConstantFloat) c).getBytes();
 109             case com.sun.org.apache.bcel.internal.Const.CONSTANT_Integer:
 110                 return ((com.sun.org.apache.bcel.internal.classfile.ConstantInteger) c).getBytes();
 111             case com.sun.org.apache.bcel.internal.Const.CONSTANT_Class:
 112                 final int nameIndex = ((com.sun.org.apache.bcel.internal.classfile.ConstantClass) c).getNameIndex();
 113                 c = cpg.getConstantPool().getConstant(nameIndex);
 114                 return new ObjectType(((com.sun.org.apache.bcel.internal.classfile.ConstantUtf8) c).getBytes());
 115             default: // Never reached
 116                 throw new RuntimeException("Unknown or invalid constant type at " + super.getIndex());
 117         }
 118     }
 119 
 120 
 121     @Override
 122     public Type getType( final ConstantPoolGen cpg ) {
 123         switch (cpg.getConstantPool().getConstant(super.getIndex()).getTag()) {
 124             case com.sun.org.apache.bcel.internal.Const.CONSTANT_String:
 125                 return Type.STRING;
 126             case com.sun.org.apache.bcel.internal.Const.CONSTANT_Float:
 127                 return Type.FLOAT;
 128             case com.sun.org.apache.bcel.internal.Const.CONSTANT_Integer:
 129                 return Type.INT;
 130             case com.sun.org.apache.bcel.internal.Const.CONSTANT_Class:


< prev index next >