Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.Constant


   * Ensures the specific preconditions of the said instruction.
   */
  public void visitLDC2_W(LDC2_W o){
    // visitCPInstruction is called first.
   
    Constant c = cpg.getConstant(o.getIndex());
    if   ((  ( c instanceof ConstantLong) ||
              ( c instanceof ConstantDouble )  )  ){
      constraintViolated(o, "Referenced constant should be a CONSTANT_Integer, a CONSTANT_Float or a CONSTANT_String, but is '"+c+"'.");
    }
  }
View Full Code Here


    public void replaceConstantPool( ConstantPoolGen old_cp, ConstantPoolGen new_cp ) {
        for (InstructionHandle ih = start; ih != null; ih = ih.next) {
            Instruction i = ih.instruction;
            if (i instanceof CPInstruction) {
                CPInstruction ci = (CPInstruction) i;
                Constant c = old_cp.getConstant(ci.getIndex());
                ci.setIndex(new_cp.addConstant(c, old_cp));
            }
        }
    }
View Full Code Here

    public boolean innerClassReferenced(){
      return hasInnerClass;
    }
    /** This method casually visits ConstantClass references. */
    public void visitConstantClass(ConstantClass obj){
      Constant c = cp.getConstant(obj.getNameIndex());
      if (c instanceof ConstantUtf8){ //Ignore the case where it's not a ConstantUtf8 here, we'll find out later.
        String classname = ((ConstantUtf8) c).getBytes();
        if (classname.startsWith(jc.getClassName().replace('.','/')+"$")){
          hasInnerClass = true;
        }
View Full Code Here

    /**
     * @return mnemonic for instruction with symbolic references resolved
     */
    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 void checkIndex(Node referrer, int index, Class shouldbe){
      if ((index < 0) || (index >= cplen)){
        throw new ClassConstraintException("Invalid index '"+index+"' used by '"+tostring(referrer)+"'.");
      }
      Constant c = cp.getConstant(index);
      if (! shouldbe.isInstance(c)){
        /* String isnot = shouldbe.toString().substring(shouldbe.toString().lastIndexOf(".")+1); //Cut all before last "." */
        throw new ClassCastException("Illegal constant '"+tostring(c)+"' at index '"+index+"'. '"+tostring(referrer)+"' expects a '"+shouldbe+"'.");
      }
    }
View Full Code Here

        int index = obj.getConstantValueIndex();
        if ((index < 0) || (index >= cplen)){
          throw new ClassConstraintException("Invalid index '"+index+"' used by '"+tostring(obj)+"'.");
        }
        Constant c = cp.getConstant(index);

        if (CONST_Long.isInstance(c) && field_type.equals(Type.LONG)){
          return;
        }
        if (CONST_Float.isInstance(c) && field_type.equals(Type.FLOAT)){
View Full Code Here

  public void visitLCONST(LCONST o){
    stack().push(Type.LONG);
  }
  /** Symbolically executes the corresponding Java Virtual Machine instruction. */
  public void visitLDC(LDC o){
    Constant c = cpg.getConstant(o.getIndex());
    if (c instanceof ConstantInteger){
      stack().push(Type.INT);
    }
    if (c instanceof ConstantFloat){
      stack().push(Type.FLOAT);
View Full Code Here

      stack().push(Type.STRING);
    }
  }
  /** Symbolically executes the corresponding Java Virtual Machine instruction. */
  public void visitLDC_W(LDC_W o){
    Constant c = cpg.getConstant(o.getIndex());
    if (c instanceof ConstantInteger){
      stack().push(Type.INT);
    }
    if (c instanceof ConstantFloat){
      stack().push(Type.FLOAT);
View Full Code Here

      stack().push(Type.STRING);
    }
  }
  /** Symbolically executes the corresponding Java Virtual Machine instruction. */
  public void visitLDC2_W(LDC2_W o){
    Constant c = cpg.getConstant(o.getIndex());
    if (c instanceof ConstantLong){
      stack().push(Type.LONG);
    }
    if (c instanceof ConstantDouble){
      stack().push(Type.DOUBLE);
View Full Code Here

    private void init(JavaClass jclass) {
        ConstantPool cp = jclass.getConstantPool();
        int numConstants = cp.getLength();
        for (int i = 0; i < numConstants; ++i) {
            try {
                Constant c = cp.getConstant(i);
                if (c instanceof ConstantMethodref) {
                    ConstantMethodref cmr = (ConstantMethodref) c;
                    ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex(),
                            CONSTANT_NameAndType);
                    String methodName = ((ConstantUtf8) cp.getConstant(cnat.getNameIndex(), CONSTANT_Utf8)).getBytes();
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.