Package org.aspectj.apache.bcel.classfile

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


              // it should be runtime visible, so put it on the Field
              Annotation a = decaF.getAnnotationX().getBcelAnnotation();
              AnnotationGen ag = new AnnotationGen(a,clazz.getConstantPoolGen(),true);
              FieldGen myGen = new FieldGen(fields[fieldCounter],clazz.getConstantPoolGen());
              myGen.addAnnotation(ag);
              Field newField = myGen.getField();
             
              aBcelField.addAnnotation(decaF.getAnnotationX());
              clazz.replaceField(fields[fieldCounter],newField);
              fields[fieldCounter]=newField;
             
View Full Code Here


  }
 
  // TAG: WeavingMessage
  private void reportFieldAnnotationWeavingMessage(LazyClassGen clazz, Field[] fields, int fieldCounter, DeclareAnnotation decaF) {
    if (!getWorld().getMessageHandler().isIgnoring(IMessage.WEAVEINFO)){
      Field theField = fields[fieldCounter];
      world.getMessageHandler().handleMessage(
              WeaveMessage.constructWeavingMessage(WeaveMessage.WEAVEMESSAGE_ANNOTATES,
                  new String[]{
              theField.toString() + "' of type '" + clazz.getName(),
              clazz.getFileName(),
              decaF.getAnnotationString(),
              "field",
              decaF.getAspect().toString(),
              Utility.beautifyLocation(decaF.getSourceLocation())}));
View Full Code Here

        throw new ClassConstraintException("The ConstantValue attribute '"+tostring(obj)+"' is not correctly named 'ConstantValue' but '"+name+"'.");
      }

      Object pred = carrier.predecessor();
      if (pred instanceof Field){ //ConstantValue attributes are quite senseless if the predecessor is not a field.
        Field f = (Field) pred;
        // Field constraints have been checked before -- so we are safe using their type information.
        Type field_type = Type.getType(((ConstantUtf8) (cp.getConstant(f.getSignatureIndex()))).getBytes());

        int index = obj.getConstantValueIndex();
        if ((index < 0) || (index >= cplen)){
          throw new ClassConstraintException("Invalid index '"+index+"' used by '"+tostring(obj)+"'.");
        }
View Full Code Here

     
      String field_name = o.getFieldName(cpg);
      JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
      Field[] fields = jc.getFields();
      Field f = null;
      for (int i=0; i<fields.length; i++){
        if (fields[i].getName().equals(field_name)){
          f = fields[i];
          break;
        }
      }
      if (f == null){
        /* TODO: also look up if the field is inherited! */
        constraintViolated(o, "Referenced field '"+field_name+"' does not exist in class '"+jc.getClassName()+"'.");
      }
      else{
        /* TODO: Check if assignment compatibility is sufficient.
           What does Sun do? */
        Type f_type = Type.getType(f.getSignature());
        Type o_type = o.getType(cpg);
       
        /* TODO: Is there a way to make BCEL tell us if a field
        has a void method's signature, i.e. "()I" instead of "I"? */
       
 
View Full Code Here

    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
    public void visitPUTSTATIC(PUTSTATIC o){
      String field_name = o.getFieldName(cpg);
      JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
      Field[] fields = jc.getFields();
      Field f = null;
      for (int i=0; i<fields.length; i++){
        if (fields[i].getName().equals(field_name)){
          f = fields[i];
          break;
        }
      }
      if (f == null){
        throw new AssertionViolatedException("Field not found?!?");
      }

      if (f.isFinal()){
        if (!(myOwner.getClassName().equals(o.getClassType(cpg).getClassName()))){
          constraintViolated(o, "Referenced field '"+f+"' is final and must therefore be declared in the current class '"+myOwner.getClassName()+"' which is not the case: it is declared in '"+o.getClassType(cpg).getClassName()+"'.");
        }
      }

      if (! (f.isStatic())){
        constraintViolated(o, "Referenced field '"+f+"' is not static which it should be.");
      }

      String meth_name = Repository.lookupClass(myOwner.getClassName()).getMethods()[method_no].getName();

View Full Code Here

    /** Checks if the constraints of operands of the said instruction(s) are satisfied. */
    public void visitGETSTATIC(GETSTATIC o){
      String field_name = o.getFieldName(cpg);
      JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
      Field[] fields = jc.getFields();
      Field f = null;
      for (int i=0; i<fields.length; i++){
        if (fields[i].getName().equals(field_name)){
          f = fields[i];
          break;
        }
      }
      if (f == null){
        throw new AssertionViolatedException("Field not found?!?");
      }

      if (! (f.isStatic())){
        constraintViolated(o, "Referenced field '"+f+"' is not static which it should be.");
      }
    }
View Full Code Here

  public boolean munge(BcelClassWeaver weaver) {
    LazyClassGen gen = weaver.getLazyClassGen();
    if (!gen.getType().equals(cflowStackField.getDeclaringType())) return false;

    Field f = new FieldGen(cflowStackField.getModifiers(),
        BcelWorld.makeBcelType(cflowStackField.getReturnType()),
        cflowStackField.getName(),
        gen.getConstantPoolGen()).getField();
      gen.addField(f,getSourceLocation());
View Full Code Here

   
    String field_name = o.getFieldName(cpg);
   
    JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
    Field[] fields = jc.getFields();
    Field f = null;
    for (int i=0; i<fields.length; i++){
      if (fields[i].getName().equals(field_name)){
        f = fields[i];
        break;
      }
    }
    if (f == null){
      throw new AssertionViolatedException("Field not found?!?");
    }

    if (f.isProtected()){
      ObjectType classtype = o.getClassType(cpg);
      ObjectType curr = new ObjectType(mg.getClassName());

      if classtype.equals(curr) ||
            curr.subclassOf(classtype)  ){
        Type t = stack().peek();
        if (t == Type.NULL){
          return;
        }
        if (! (t instanceof ObjectType) ){
          constraintViolated(o, "The 'objectref' must refer to an object that's not an array. Found instead: '"+t+"'.");
        }
        ObjectType objreftype = (ObjectType) t;
        if (! ( objreftype.equals(curr) ||
                objreftype.subclassOf(curr) ) ){
          //TODO: One day move to Staerk-et-al's "Set of object types" instead of "wider" object types
          //      created during the verification.
          //      "Wider" object types don't allow us to check for things like that below.
          //constraintViolated(o, "The referenced field has the ACC_PROTECTED modifier, and it's a member of the current class or a superclass of the current class. However, the referenced object type '"+stack().peek()+"' is not the current class or a subclass of the current class.");
        }
      }
    }
   
    // TODO: Could go into Pass 3a.
    if (f.isStatic()){
      constraintViolated(o, "Referenced field '"+f+"' is static which it shouldn't be.");
    }
  }
View Full Code Here

   
    String field_name = o.getFieldName(cpg);
   
    JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
    Field[] fields = jc.getFields();
    Field f = null;
    for (int i=0; i<fields.length; i++){
      if (fields[i].getName().equals(field_name)){
        f = fields[i];
        break;
      }
    }
    if (f == null){
      throw new AssertionViolatedException("Field not found?!?");
    }

    Type value = stack().peek();
    Type t = Type.getType(f.getSignature());
    Type shouldbe = t;
    if (shouldbe == Type.BOOLEAN ||
        shouldbe == Type.BYTE ||
        shouldbe == Type.CHAR ||
        shouldbe == Type.SHORT){
      shouldbe = Type.INT;
    }
    if (t instanceof ReferenceType){
      ReferenceType rvalue = null;
      if (value instanceof ReferenceType){
        rvalue = (ReferenceType) value;
        referenceTypeIsInitialized(o, rvalue);
      }
      else{
        constraintViolated(o, "The stack top type '"+value+"' is not of a reference type as expected.");
      }
      // TODO: This can possibly only be checked using Staerk-et-al's "set-of-object types", not
      // using "wider cast object types" created during verification.
      // Comment it out if you encounter problems. See also the analogon at visitPUTSTATIC.
      if (!(rvalue.isAssignmentCompatibleWith(shouldbe))){
        constraintViolated(o, "The stack top type '"+value+"' is not assignment compatible with '"+shouldbe+"'.");
      }
    }
    else{
      if (shouldbe != value){
        constraintViolated(o, "The stack top type '"+value+"' is not of type '"+shouldbe+"' as expected.");
      }
    }
   
    if (f.isProtected()){
      ObjectType classtype = o.getClassType(cpg);
      ObjectType curr = new ObjectType(mg.getClassName());

      if classtype.equals(curr) ||
            curr.subclassOf(classtype)  ){
        Type tp = stack().peek(1);
        if (tp == Type.NULL){
          return;
        }
        if (! (tp instanceof ObjectType) ){
          constraintViolated(o, "The 'objectref' must refer to an object that's not an array. Found instead: '"+tp+"'.");
        }
        ObjectType objreftype = (ObjectType) tp;
        if (! ( objreftype.equals(curr) ||
                objreftype.subclassOf(curr) ) ){
          constraintViolated(o, "The referenced field has the ACC_PROTECTED modifier, and it's a member of the current class or a superclass of the current class. However, the referenced object type '"+stack().peek()+"' is not the current class or a subclass of the current class.");
        }
      }
    }

    // TODO: Could go into Pass 3a.
    if (f.isStatic()){
      constraintViolated(o, "Referenced field '"+f+"' is static which it shouldn't be.");
    }
  }
View Full Code Here

   */
  public void visitPUTSTATIC(PUTSTATIC o){
    String field_name = o.getFieldName(cpg);
    JavaClass jc = Repository.lookupClass(o.getClassType(cpg).getClassName());
    Field[] fields = jc.getFields();
    Field f = null;
    for (int i=0; i<fields.length; i++){
      if (fields[i].getName().equals(field_name)){
        f = fields[i];
        break;
      }
    }
    if (f == null){
      throw new AssertionViolatedException("Field not found?!?");
    }
    Type value = stack().peek();
    Type t = Type.getType(f.getSignature());
    Type shouldbe = t;
    if (shouldbe == Type.BOOLEAN ||
        shouldbe == Type.BYTE ||
        shouldbe == Type.CHAR ||
        shouldbe == Type.SHORT){
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.classfile.Field

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.