Package org.aspectj.apache.bcel.classfile

Examples of org.aspectj.apache.bcel.classfile.Constant


    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
     //getfield, putfield, getstatic, putstatic
     public void visitFieldInstruction(FieldInstruction o){
      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

    }

    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
    public void visitNEW(NEW 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+"'.");
      }
      else{
        ConstantUtf8 cutf8 = (ConstantUtf8) (cpg.getConstant( ((ConstantClass) c).getNameIndex() ));
View Full Code Here

    }

    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
    public void visitMULTIANEWARRAY(MULTIANEWARRAY 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+"'.");
      }
      int dimensions2create = o.getDimensions();
      if (dimensions2create < 1){
View Full Code Here

    }

    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
    public void visitANEWARRAY(ANEWARRAY 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+"'.");
      }
      Type t = o.getType(cpg);
      if (t instanceof ArrayType){
View Full Code Here

  /**
   * @return mnemonic for instruction with symbolic references resolved
   */
  public String toString(ConstantPool cp) {
    Constant        c   = cp.getConstant(index);
    StringTokenizer tok = new StringTokenizer(cp.constantToString(c));

    return Constants.OPCODE_NAMES[opcode] + " " +
      tok.nextToken().replace('.', '/') + tok.nextToken();
  }
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('.', '/');

View Full Code Here

   public void visitFieldInstruction(FieldInstruction o){
     // visitLoadClass(o) has been called before: Every FieldOrMethod
     // implements LoadClass.
     // visitCPInstruction(o) has been called before.
    // A FieldInstruction may be: GETFIELD, GETSTATIC, PUTFIELD, PUTSTATIC
      Constant c = cpg.getConstant(o.getIndex());
      if (!(c instanceof ConstantFieldref)){
        constraintViolated(o, "Index '"+o.getIndex()+"' should refer to a CONSTANT_Fieldref_info structure, but refers to '"+c+"'.");
      }
      // the o.getClassType(cpg) type has passed pass 2; see visitLoadClass(o).
      Type t = o.getType(cpg);
View Full Code Here

TOP

Related Classes of org.aspectj.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.