Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.ConstantClass


                        + class_index + "\">Class(" + class_index + ")</A><BR>\n"
                        + "<LI><A HREF=\"#cp" + name_index + "\">NameAndType(" + name_index
                        + ")</A></UL>");
                break;
            case CONSTANT_Class:
                ConstantClass c4 = (ConstantClass) constant_pool.getConstant(index, CONSTANT_Class);
                name_index = c4.getNameIndex();
                String class_name2 = constant_pool.constantToString(index, tag); // / -> .
                String short_class_name = Utility.compactClassName(class_name2); // I.e., remove java.lang.
                short_class_name = Utility.compactClassName(short_class_name, class_package + ".",
                        true); // Remove class package prefix
                ref = "<A HREF=\"" + class_name2 + ".html\" TARGET=_top>" + short_class_name
View Full Code Here


   
    ConstantCP methodConst =
      (ConstantCP)constPoolGen.getConstant(
          methodCall.getIndex() );
   
    ConstantClass classConst =
      (ConstantClass)constPoolGen.getConstant(
        methodConst.getClassIndex() );

    ConstantNameAndType ntConst =
      (ConstantNameAndType)constPoolGen.getConstant(
        methodConst.getNameAndTypeIndex() );
   
      return new CallInfo(
      ((ConstantUtf8)constPoolGen.getConstant(
        classConst.getNameIndex() )).getBytes(),
      ntConst.getName( constPoolGen.getConstantPool() ),
      ntConst.getSignature( constPoolGen.getConstantPool() ) );
  }
View Full Code Here

    {
        Constant c = cp.getConstant(((CPInstruction) ih.getInstruction()).getIndex());
        if (c instanceof ConstantFieldref)
        {
            ConstantFieldref fieldRef = (ConstantFieldref) c;
            ConstantClass cclass = (ConstantClass) cp.getConstant(fieldRef.getClassIndex());
            ConstantUtf8 className = (ConstantUtf8) cp.getConstant(cclass.getNameIndex());
            return StringUtils.replaceAll(className.getBytes().toString(), "/", ".");
        }
        return null;
    }
View Full Code Here

                Field f;
                FieldInstruction field = (FieldInstruction) i;
                Constant c = m.getConstantPool().getConstant(field.getIndex());
                ConstantFieldref fieldRef = (ConstantFieldref) c;

                ConstantClass cclass = (ConstantClass) m.getConstantPool().getConstant(fieldRef.getClassIndex());
                ConstantUtf8 utfClassName = (ConstantUtf8) m.getConstantPool().getConstant(cclass.getNameIndex());
                String utfClassNameString = StringUtils.replaceAll(utfClassName.getBytes().toString(), "/", ".");
                JavaClass fieldJavaClass = null;
                try
                {
                    fieldJavaClass = Repository.lookupClass(utfClassNameString);
View Full Code Here

        int length = constantPool.getLength();
        for (int i = 0; i < length; i++) {
            Constant constant = constantPool.getConstant(i);
            if (constant instanceof ConstantClass) {
                ConstantClass cc = (ConstantClass) constant;
                ConstantUtf8 constant2 = (ConstantUtf8) constantPool.getConstant(cc.getNameIndex());

                // In case a subclass fails, skip, but print warning.
                try {
                    String toLoad = constant2.getBytes().replace('/', '.');
                    if (toLoad.contains("[")) continue;
View Full Code Here

                    ConstantLong c = (ConstantLong) constant;
                    result.append("long\t");
                    result.append(constPool.constantToString(c));
                    result.append(';');
                } else if (constant instanceof ConstantClass) {
                    ConstantClass c = (ConstantClass) constant;
                    result.append("class\t#");
                    result.append(c.getNameIndex());
                    result.append(";\t//  ");
                    result.append(constPool.constantToString(c));
                } else if (constant instanceof ConstantString) {
                    ConstantString c = (ConstantString) constant;
                    result.append("String\t#");
                    result.append(c.getStringIndex());
                    result.append(";\t//  ");
                    result.append(constPool.constantToString(c));
                }

                result.append(n);
View Full Code Here

            case 193: // instanceof
                bcCodes.add(new Integer(bytecode));
                b1 = bytecodes[++i];
                b2 = bytecodes[++i];
                index = b1 << 8 | b2;
                ConstantClass constantClass = (ConstantClass) cp.getConstant(index);
                bcClassRef.add(cpBands.getCPClass(constantClass.getBytes(cp)));
                break;
            case 188: // newarray
                bcCodes.add(new Integer(bytecode));
                bcByte.add(new Integer(0xff & bytecodes[++i]));
                break;
            case 196: // wide
                bcCodes.add(new Integer(196));
                wide = true;
            case 197: // multianewarray
                bcCodes.add(new Integer(bytecode));
                b1 = bytecodes[++i];
                b2 = bytecodes[++i];
                index = b1 << 8 | b2;
                constantClass = (ConstantClass) cp.getConstant(index);
                bcClassRef.add(cpBands.getCPClass(constantClass.getBytes(cp)));
                byte dimensions = bytecodes[++i];
                bcByte.add(new Integer(0xff & dimensions));
                break;
            case 200: // goto_w
            case 201: // jsr_w
View Full Code Here

                    ConstantLong c = (ConstantLong) constant;
                    result.append("long\t");
                    result.append(constPool.constantToString(c));
                    result.append(';');
                } else if (constant instanceof ConstantClass) {
                    ConstantClass c = (ConstantClass) constant;
                    result.append("class\t#");
                    result.append(c.getNameIndex());
                    result.append(";\t//  ");
                    result.append(constPool.constantToString(c));
                } else if (constant instanceof ConstantString) {
                    ConstantString c = (ConstantString) constant;
                    result.append("String\t#");
                    result.append(c.getStringIndex());
                    result.append(";\t//  ");
                    result.append(constPool.constantToString(c));
                }

                result.append(n);
View Full Code Here

      case Const.CHECKCAST:
      {

        CastExpression cast= new CastExpression();
        int index= bytes.readUnsignedShort();
        ConstantClass c= (ConstantClass) constantPool.getConstant(index);
        ObjectType type= new ObjectType(c.getBytes(constantPool).replace('/', '.'));
        cast.setTypeBinding(type);
        cast.setExpression(stack.pop());
        instruction= cast;
        break;
      }

      case Const.INSTANCEOF:
      {

        int index= bytes.readUnsignedShort();
        InstanceofExpression ex= new InstanceofExpression();
        Expression objectref= stack.pop();
        ex.setLeftOperand(objectref);
        ConstantClass c= (ConstantClass) constantPool.getConstant(index);
        ObjectType type= new ObjectType(c.getBytes(constantPool).replace('/', '.'));
        ex.setRightOperand(type);
        ex.widen(objectref);
        instruction= ex;
        break;
      }

      case Const.ACONST_NULL:

        instruction= new NullLiteral();
        break;

      case Const.JSR:
      {

        instruction= new JumpSubRoutine(currentIndex + bytes.readShort());
        opStackDelta= 0;
        break;
      }

      case Const.JSR_W:
      {

        instruction= new JumpSubRoutine(currentIndex + bytes.readInt());
        break;
      }

      case Const.IFEQ:

        instruction= createConditional(currentIndex, InfixExpression.Operator.EQUALS, NumberLiteral.create(0));
        break;
      case Const.IFNE:

        instruction= createConditional(currentIndex, InfixExpression.Operator.NOT_EQUALS, NumberLiteral.create(0));
        break;
      case Const.IFGE:

        instruction= createConditional(currentIndex, InfixExpression.Operator.GREATER_EQUALS, NumberLiteral.create(0));
        break;
      case Const.IFGT:

        instruction= createConditional(currentIndex, InfixExpression.Operator.GREATER, NumberLiteral.create(0));
        break;
      case Const.IFLE:

        instruction= createConditional(currentIndex, InfixExpression.Operator.LESS_EQUALS, NumberLiteral.create(0));
        break;
      case Const.IFLT:

        instruction= createConditional(currentIndex, InfixExpression.Operator.LESS, NumberLiteral.create(0));
        break;
      case Const.IFNONNULL:

        instruction= createConditional(currentIndex, InfixExpression.Operator.NOT_EQUALS, new NullLiteral());
        break;
      case Const.IFNULL:

        instruction= createConditional(currentIndex, InfixExpression.Operator.EQUALS, new NullLiteral());
        break;

      case Const.IF_ACMPEQ:

      case Const.IF_ICMPEQ:

        instruction= createConditional(currentIndex, InfixExpression.Operator.EQUALS);
        break;
      case Const.IF_ACMPNE:

      case Const.IF_ICMPNE:

        instruction= createConditional(currentIndex, InfixExpression.Operator.NOT_EQUALS);
        break;
      case Const.IF_ICMPGE:

        instruction= createConditional(currentIndex, InfixExpression.Operator.GREATER_EQUALS);
        break;
      case Const.IF_ICMPGT:

        instruction= createConditional(currentIndex, InfixExpression.Operator.GREATER);
        break;
      case Const.IF_ICMPLE:

        instruction= createConditional(currentIndex, InfixExpression.Operator.LESS_EQUALS);
        break;
      case Const.IF_ICMPLT:

        instruction= createConditional(currentIndex, InfixExpression.Operator.LESS);
        break;

      case Const.LCMP:

      case Const.FCMPL:

      case Const.FCMPG:

      case Const.DCMPL:

      case Const.DCMPG:
      {

        MethodBinding binding= MethodBinding.lookup("javascript.Utils", "cmp", "(DDI)I");
        MethodInvocation mi= new MethodInvocation(methodDecl, binding);

        Expression value2= stack.pop();
        mi.addArgument(stack.pop());
        mi.addArgument(value2);

        int gORl= 0;
        if (instructionType.getName().endsWith("g"))
          gORl= 1;
        else if (instructionType.getName().endsWith("l"))
          gORl= -1;
        mi.addArgument(NumberLiteral.create(gORl));

        instruction= mi;

        break;
      }

      case Const.GOTO:
      {

        instruction= new Jump(currentIndex + bytes.readShort());
        break;
      }

      case Const.GOTO_W:
      {

        instruction= new Jump(currentIndex + bytes.readInt());
        break;
      }

      case Const.NEW:
      {

        ConstantClass c= (ConstantClass) constantPool.getConstant(bytes.readUnsignedShort());
        ObjectType type= new ObjectType(c.getBytes(constantPool).replace('/', '.'));

        instruction= new ClassInstanceCreation(type);
      }
        break;

      case Const.NEWARRAY:
      {

        String componentSignature= BasicType.getType(bytes.readByte()).getSignature();

        List<ASTNode> dimensions= new ArrayList<ASTNode>();
        dimensions.add(stack.pop());
        ArrayCreation ac= new ArrayCreation(methodDecl, new ObjectType("[" + componentSignature), dimensions);
        instruction= ac;
        break;
      }

      case Const.ANEWARRAY:
      {

        ConstantClass c= (ConstantClass) constantPool.getConstant(bytes.readUnsignedShort());
        String componentSignature= c.getBytes(constantPool).replace('/', '.');
        Type arrayType;
        if (componentSignature.startsWith("["))
        {
          arrayType= new ObjectType("[" + componentSignature);
        }
        else
        {
          arrayType= new ObjectType("[L" + componentSignature + ";");
        }

        List<ASTNode> dimensions= new ArrayList<ASTNode>();
        dimensions.add(stack.pop());
        ArrayCreation ac= new ArrayCreation(methodDecl, arrayType, dimensions);
        instruction= ac;
        break;
      }

      case Const.MULTIANEWARRAY:
      {

        ConstantClass c= (ConstantClass) constantPool.getConstant(bytes.readUnsignedShort());
        ObjectType arrayType= new ObjectType(c.getBytes(constantPool).replace('/', '.'));

        int dimCount= bytes.readUnsignedByte();
        opStackDelta= 1 - dimCount;
        List<ASTNode> dimensions= new ArrayList<ASTNode>();
        for (int i= 0; i < dimCount; i++)
View Full Code Here

        final int[] interfaces = cg.getInterfaces();
        final String interfaceName = TransformationUtil.IDENTIFIABLE_INTERFACE;

        boolean addInterface = true;
        for (int i = 0; i < interfaces.length; i++) {
            final ConstantClass cc = (ConstantClass)cpg.getConstant(interfaces[i]);
            final ConstantUtf8 cu = (ConstantUtf8)cpg.getConstant(cc.getNameIndex());

            if (implementsInterface(cu, interfaceName)) {
                addInterface = false;
                break;
            }
View Full Code Here

TOP

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

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.