Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.Constant


    }


    private void setValue( int index ) {
        ConstantPool cp = this.cp.getConstantPool();
        Constant c = cp.getConstant(index);
        value = ((ConstantObject) c).getConstantValue(cp);
    }
View Full Code Here


    public void visit(ConstantValue s) {
        if (!visitingField()) {
            return;
        }
        int i = s.getConstantValueIndex();
        Constant c = getConstantPool().getConstant(i);
        if (c instanceof ConstantString) {
            String value = ((ConstantString) c).getBytes(getConstantPool());
            if (value.length() < SIZE_OF_HUGE_CONSTANT) {
                return;
            }
View Full Code Here

            if ((seen == DCONST_0) || (seen == DCONST_1)) {
                constValue = seen - DCONST_0;
                state = SEEN_DCONST;
            } else if ((seen == LDC2_W) || (seen == LDC_W)) {
                state = SEEN_DCONST;
                Constant c = this.getConstantRefOperand();
                if (c instanceof ConstantDouble) {
                    constValue = ((ConstantDouble) c).getBytes();
                } else if (c instanceof ConstantFloat) {
                    constValue = ((ConstantFloat) c).getBytes();
                } else if (c instanceof ConstantLong) {
View Full Code Here

    }

    @Override
    public void sawOpcode(int seen) {
        if (seen == LDC || seen == LDC_W || seen == LDC2_W) {
            Constant c = getConstantRefOperand();
            if (c instanceof ConstantFloat) {
                checkConst(((ConstantFloat) c).getBytes());
            } else if (c instanceof ConstantDouble) {
                checkConst(((ConstantDouble) c).getBytes());
            }
View Full Code Here

   
    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
    // LDC and LDC_W (LDC_W is a subclass of LDC in BCEL's model)
    public void visitLDC(LDC o){
      indexValid(o, o.getIndex());
      Constant c = cpg.getConstant(o.getIndex());
      if (c instanceof ConstantClass){
        addMessage("Operand of LDC or LDC_W is CONSTANT_Class '"+c+"' - this is only supported in JDK 1.5 and higher.");
      }
      else{
        if (! ( (c instanceof ConstantInteger||
View Full Code Here

    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
    // LDC2_W
    public void visitLDC2_W(LDC2_W o){
      indexValid(o, o.getIndex());
      Constant c = cpg.getConstant(o.getIndex());
      if (! ( (c instanceof ConstantLong||
              (c instanceof ConstantDouble) ) ){
        constraintViolated(o, "Operand of LDC2_W must be CONSTANT_Long or CONSTANT_Double, but is '"+c+"'.");
      }
      try{
View Full Code Here

    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
     //getfield, putfield, getstatic, putstatic
     public void visitFieldInstruction(FieldInstruction o){
       try {
      indexValid(o, o.getIndex());
      Constant c = cpg.getConstant(o.getIndex());
      if (! (c instanceof ConstantFieldref)){
        constraintViolated(o, "Indexing a constant that's not a CONSTANT_Fieldref but a '"+c+"'.");
      }
     
      String field_name = o.getFieldName(cpg);
View Full Code Here

    public void visitInvokeInstruction(InvokeInstruction o){
      indexValid(o, o.getIndex());
      if (  (o instanceof INVOKEVIRTUAL||
            (o instanceof INVOKESPECIAL||
            (o instanceof INVOKESTATIC)  ){
        Constant c = cpg.getConstant(o.getIndex());
        if (! (c instanceof ConstantMethodref)){
          constraintViolated(o, "Indexing a constant that's not a CONSTANT_Methodref but a '"+c+"'.");
        }
        else{
          // Constants are okay due to pass2.
          ConstantNameAndType cnat = (ConstantNameAndType) (cpg.getConstant(((ConstantMethodref) c).getNameAndTypeIndex()));
          ConstantUtf8 cutf8 = (ConstantUtf8) (cpg.getConstant(cnat.getNameIndex()));
          if (cutf8.getBytes().equals(Constants.CONSTRUCTOR_NAME) && (!(o instanceof INVOKESPECIAL)) ){
            constraintViolated(o, "Only INVOKESPECIAL is allowed to invoke instance initialization methods.");
          }
          if ( (! (cutf8.getBytes().equals(Constants.CONSTRUCTOR_NAME)) ) && (cutf8.getBytes().startsWith("<")) ){
            constraintViolated(o, "No method with a name beginning with '<' other than the instance initialization methods may be called by the method invocation instructions.");
          }
        }
      }
      else{ //if (o instanceof INVOKEINTERFACE){
        Constant c = cpg.getConstant(o.getIndex());
        if (! (c instanceof ConstantInterfaceMethodref)){
          constraintViolated(o, "Indexing a constant that's not a CONSTANT_InterfaceMethodref but a '"+c+"'.");
        }
        // TODO: From time to time check if BCEL allows to detect if the
        // 'count' operand is consistent with the information in the
View Full Code Here

    }
   
    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
    public void visitINSTANCEOF(INSTANCEOF o){
      indexValid(o, o.getIndex());
      Constant c = cpg.getConstant(o.getIndex());
      if ((c instanceof ConstantClass)){
        constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'.");
      }
    }
View Full Code Here

    }

    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
    public void visitCHECKCAST(CHECKCAST o){
      indexValid(o, o.getIndex());
      Constant c = cpg.getConstant(o.getIndex());
      if ((c instanceof ConstantClass)){
        constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'.");
      }
    }
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.