Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.Constant


    /**
     * @return mnemonic for instruction with symbolic references resolved
     */
    @Override
    public String toString( ConstantPool cp ) {
        Constant c = cp.getConstant(index);
        String str = cp.constantToString(c);
        if (c instanceof ConstantClass) {
            str = str.replace('.', '/');
        }
        return org.apache.bcel.Constants.OPCODE_NAMES[opcode] + " " + str;
View Full Code Here


  private Set<String> getUsedClassesFromConstantClassesCP(
      JavaClass theJavaClass) {
    Set<String> ret = new HashSet<String>();
    int nConstants = theJavaClass.getConstantPool().getLength();
    for (int i = 0; i < nConstants; i++) {
      Constant constant = theJavaClass.getConstantPool().getConstant(i);
      if (constant != null && constant instanceof ConstantClass) {
        final String usedClassName = ((String) ((ConstantClass) constant)
            .getConstantValue(theJavaClass.getConstantPool()))
            .replace('/', '.');
        // If usedClassName is the name of an array class, we
View Full Code Here

  private Set<String> getUsedClassesFromConstantClassesCP(
      JavaClass theJavaClass) {
    Set<String> ret = new HashSet<String>();
    int nConstants = theJavaClass.getConstantPool().getLength();
    for (int i = 0; i < nConstants; i++) {
      Constant constant = theJavaClass.getConstantPool().getConstant(i);
      if (constant != null && constant instanceof ConstantClass) {
        final String usedClassName = ((String) ((ConstantClass) constant)
            .getConstantValue(theJavaClass.getConstantPool()))
            .replace('/', '.');
        // If usedClassName is the name of an array class, we
View Full Code Here

      for (int j= 0; j < attCount; j++)
      {
        Map<String, String> map= new LinkedHashMap<String, String>();
        annotations[j]= map;
        int nameIndex= file.readUnsignedShort();
        Constant constant= constantPool.getConstant(nameIndex);
        Signature signature= Project.getSingleton().getSignature(((ConstantUtf8) constant).getBytes());
        map.put("$signature", signature.toString());
        int fieldCount= file.readUnsignedShort();
        for (int i= 0; i < fieldCount; i++)
        {
View Full Code Here

    for (CodeException ce : code.getExceptionTable())
    {
      String exceptionType;
      if (ce.getCatchType() > 0)
      {
        Constant constant= constantPool.getConstant(ce.getCatchType());
        exceptionType= Pass1.constantToString(constant, constantPool);
      }
      else
      {
        exceptionType= "Default";
View Full Code Here

        }
        else
        {
          index= bytes.readUnsignedShort();
        }
        Constant constant= constantPool.getConstant(index);

        if (opcode == Const.LDC2_W && (constant.getTag() != Constants.CONSTANT_Double && constant.getTag() != Constants.CONSTANT_Long))
          throw new RuntimeException("LDC2_W must load long or double");

        if (constant.getTag() == Constants.CONSTANT_Integer)
        {
          instruction= NumberLiteral.create(new Integer(((ConstantInteger) constant).getBytes()));
        }
        else if (constant.getTag() == Constants.CONSTANT_Float)
        {
          instruction= NumberLiteral.create(new Float(((ConstantFloat) constant).getBytes()));
        }
        else if (constant.getTag() == Constants.CONSTANT_Long)
        {
          instruction= NumberLiteral.create(new Long(((ConstantLong) constant).getBytes()));
        }
        else if (constant.getTag() == Constants.CONSTANT_Double)
        {
          instruction= NumberLiteral.create(new Double(((ConstantDouble) constant).getBytes()));
        }
        else if (constant.getTag() == Constants.CONSTANT_Utf8)
        {
          instruction= new StringLiteral(((ConstantUtf8) constant).getBytes());
        }
        else if (constant.getTag() == Constants.CONSTANT_String)
        {
          int k= ((ConstantString) constant).getStringIndex();
          constant= constantPool.getConstant(k, Constants.CONSTANT_Utf8);
          instruction= new StringLiteral(((ConstantUtf8) constant).getBytes());
        }
        else if (constant.getTag() == Constants.CONSTANT_Class)
        {
          Signature signature= Project.getSingleton().getSignature(((ConstantClass) constant).getBytes(constantPool));
          instruction= new ClassLiteral(signature);
        }
        else
        {
          throw new RuntimeException("Cannot handle constant tag: " + constant.getTag());
        }
        break;
      }

      case Const.RET:
View Full Code Here

      // iName);
      ConstantPool pPool = iCF.getConstantPool();
      Constant[] constants = pPool.getConstantPool();
      for (int i = 0; i < constants.length; i++)
      {
         Constant pEntry = constants[i];
         if (pEntry instanceof ConstantClass)
         {
            String pClassName = ((ConstantClass) pEntry).getBytes(pPool);
            if (aClasses.get(pClassName) == null)
            {
View Full Code Here

      ConstantPool pPool = iCF.getConstantPool();
      Constant[] constants = pPool.getConstantPool();
      for (int i = 0; i < constants.length; i++)
      {
         Constant pEntry = constants[i];
         if (pEntry instanceof ConstantString
            || pEntry instanceof ConstantDouble
            || pEntry instanceof ConstantFloat
            || pEntry instanceof ConstantInteger
            || pEntry instanceof ConstantLong
View Full Code Here

      return ret;
   }

   ClassRecord getClassRecord(int aPoolIndex) throws TinyVMException
   {
      Constant pEntry = iCF.getConstantPool().getConstant(aPoolIndex); // TODO catch all (runtime) exceptions
      if (!(pEntry instanceof ConstantClass))
      {
         throw new TinyVMException("Classfile error: Instruction requiring "
            + "CONSTANT_Class entry got "
            + (pEntry == null? "null" : pEntry.getClass().getName()));
      }
      ConstantClass pClassEntry = (ConstantClass) pEntry;
      return getClassRecord(pClassEntry.getBytes(iCF.getConstantPool()));
   }
View Full Code Here

    * @return The constant table index
    * @throws js.tinyvm.TinyVMException
    */
   public int processConstantIndex (int aPoolIndex) throws TinyVMException
   {
      Constant pEntry = iCF.getConstantPool().getConstant(aPoolIndex);
      if (!(pEntry instanceof ConstantInteger)
         && !(pEntry instanceof ConstantFloat)
         && !(pEntry instanceof ConstantString)
         && !(pEntry instanceof ConstantDouble)
         && !(pEntry instanceof ConstantLong)
View Full Code Here

TOP

Related Classes of org.apache.bcel.classfile.Constant

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.