Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.Field


    il.append(_type.STORE(_local.getIndex()));
      }
  }
  else {
      if (classGen.containsField(name) == null) {
    classGen.addField(new Field(ACC_PUBLIC, cpg.addUtf8(name),
              cpg.addUtf8(signature),
              null, cpg.getConstantPool()));
    il.append(classGen.loadTranslet());
    il.append(DUP);
    il.append(new PUSH(cpg, name));
View Full Code Here


            Util.getJCRefType(NODE_ITERATOR_SIG),
            il.getEnd(), null);

  // Add a new private field if this is the main class
  if (!classGen.isExternal()) {
      final Field iterator =
    new Field(ACC_PRIVATE,
        cpg.addUtf8(iteratorName),
        cpg.addUtf8(NODE_ITERATOR_SIG),
        null, cpg.getConstantPool());
      classGen.addField(iterator);
      iteratorIndex = cpg.addFieldref(classGen.getClassName(),
View Full Code Here

  // Add a new instance variable for each var in closure
  for (int i = 0; i < length; i++) {
      VariableBase var = ((VariableRefBase) _closureVars.get(i)).getVariable();

      filterGen.addField(new Field(ACC_PUBLIC,
          cpg.addUtf8(var.getVariable()),
          cpg.addUtf8(var.getType().toSignature()),
          null, cpg.getConstantPool()));
  }
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 only be checked using Staerk-et-al's "set-of-object types", not
      // using "wider cast object types" created during verification.
      //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

    // Discard duplicate variable references
    if (dups.contains(varRef)) continue;

    final VariableBase var = varRef.getVariable();
    sortRecordFactory.addField(new Field(ACC_PUBLIC,
             cpg.addUtf8(var.getEscapedName()),
             cpg.addUtf8(var.getType().toSignature()),
             null, cpg.getConstantPool()));
    dups.add(varRef);
      }
View Full Code Here

    // Discard duplicate variable references
    if (dups.contains(varRef)) continue;

    final VariableBase var = varRef.getVariable();
    sortRecord.addField(new Field(ACC_PUBLIC,
            cpg.addUtf8(var.getEscapedName()),
            cpg.addUtf8(var.getType().toSignature()),
            null, cpg.getConstantPool()));
    dups.add(varRef);
      }
View Full Code Here

  InstructionList il = methodGen.getInstructionList();

  int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();

  if (fieldIndexes[_level] == -1) {
      Field defaultNode = new Field(ACC_PRIVATE,
            cpg.addUtf8(FieldNames[_level]),
            cpg.addUtf8(NODE_COUNTER_SIG),
            null,
            cpg.getConstantPool());
View Full Code Here

  for (int i = 0; i < closureLen; i++) {
      VariableBase var =
    ((VariableRefBase) _closureVars.get(i)).getVariable();

      nodeCounterGen.addField(new Field(ACC_PUBLIC,
          cpg.addUtf8(var.getEscapedName()),
          cpg.addUtf8(var.getType().toSignature()),
          null, cpg.getConstantPool()));
  }
View Full Code Here

TOP

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