Package org.apache.bcel.classfile

Examples of org.apache.bcel.classfile.ConstantUtf8


        }
        // Adapt the class name to the passed value
        ConstantPool cp = clazz.getConstantPool();
        ConstantClass cl = (ConstantClass) cp.getConstant(clazz.getClassNameIndex(),
                Constants.CONSTANT_Class);
        ConstantUtf8 name = (ConstantUtf8) cp.getConstant(cl.getNameIndex(),
                Constants.CONSTANT_Utf8);
        name.setBytes(class_name.replace('.', '/'));
        return clazz;
    }
View Full Code Here


   */
  public static final Attribute readAttribute(DataInputStream file,
      ConstantPool constant_pool) throws IOException,
      ClassFormatException
  {
    ConstantUtf8 c;
    String name;
    int name_index;
    int length;
    byte tag = Constants.ATTR_UNKNOWN; // Unknown attribute
    // Get class name from constant pool via `name_index' indirection
    name_index = file.readUnsignedShort();
    c = (ConstantUtf8) constant_pool.getConstant(name_index,
        Constants.CONSTANT_Utf8);
    name = c.getBytes();
    // Length of data in bytes
    length = file.readInt();
    // Compare strings to find known attribute
    // System.out.println(name);
    for (byte i = 0; i < Constants.KNOWN_ATTRIBUTES; i++)
View Full Code Here

  /**
   * @return Name of attribute
   */
  public String getName()
  {
    ConstantUtf8 c = (ConstantUtf8) constant_pool.getConstant(name_index,
        Constants.CONSTANT_Utf8);
    return c.getBytes();
  }
View Full Code Here

          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){
View Full Code Here

      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() ));
        Type t = Type.getType("L"+cutf8.getBytes()+";");
        if (t instanceof ArrayType){
          constraintViolated(o, "NEW must not be used to create an array.");
        }
      }
     
View Full Code Here

TOP

Related Classes of org.apache.bcel.classfile.ConstantUtf8

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.