Java Code Examples for com.sun.org.apache.bcel.internal.Constants#CONSTANT_Class

The following examples show how to use com.sun.org.apache.bcel.internal.Constants#CONSTANT_Class . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Constant.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
/**
 * Read one constant from the given file, the type depends on a tag byte.
 *
 * @param file Input stream
 * @return Constant object
 */
static final Constant readConstant(DataInputStream file)
  throws IOException, ClassFormatException
{
  byte b = file.readByte(); // Read tag byte

  switch(b) {
  case Constants.CONSTANT_Class:              return new ConstantClass(file);
  case Constants.CONSTANT_Fieldref:           return new ConstantFieldref(file);
  case Constants.CONSTANT_Methodref:          return new ConstantMethodref(file);
  case Constants.CONSTANT_InterfaceMethodref: return new
                                      ConstantInterfaceMethodref(file);
  case Constants.CONSTANT_String:             return new ConstantString(file);
  case Constants.CONSTANT_Integer:            return new ConstantInteger(file);
  case Constants.CONSTANT_Float:              return new ConstantFloat(file);
  case Constants.CONSTANT_Long:               return new ConstantLong(file);
  case Constants.CONSTANT_Double:             return new ConstantDouble(file);
  case Constants.CONSTANT_NameAndType:        return new ConstantNameAndType(file);
  case Constants.CONSTANT_Utf8:               return new ConstantUtf8(file);
  default:
    throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
  }
}
 
Example 2
Source File: Constant.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read one constant from the given file, the type depends on a tag byte.
 *
 * @param file Input stream
 * @return Constant object
 */
static final Constant readConstant(DataInputStream file)
  throws IOException, ClassFormatException
{
  byte b = file.readByte(); // Read tag byte

  switch(b) {
  case Constants.CONSTANT_Class:              return new ConstantClass(file);
  case Constants.CONSTANT_Fieldref:           return new ConstantFieldref(file);
  case Constants.CONSTANT_Methodref:          return new ConstantMethodref(file);
  case Constants.CONSTANT_InterfaceMethodref: return new
                                      ConstantInterfaceMethodref(file);
  case Constants.CONSTANT_String:             return new ConstantString(file);
  case Constants.CONSTANT_Integer:            return new ConstantInteger(file);
  case Constants.CONSTANT_Float:              return new ConstantFloat(file);
  case Constants.CONSTANT_Long:               return new ConstantLong(file);
  case Constants.CONSTANT_Double:             return new ConstantDouble(file);
  case Constants.CONSTANT_NameAndType:        return new ConstantNameAndType(file);
  case Constants.CONSTANT_Utf8:               return new ConstantUtf8(file);
  default:
    throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
  }
}
 
Example 3
Source File: Constant.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read one constant from the given file, the type depends on a tag byte.
 *
 * @param file Input stream
 * @return Constant object
 */
static final Constant readConstant(DataInputStream file)
  throws IOException, ClassFormatException
{
  byte b = file.readByte(); // Read tag byte

  switch(b) {
  case Constants.CONSTANT_Class:              return new ConstantClass(file);
  case Constants.CONSTANT_Fieldref:           return new ConstantFieldref(file);
  case Constants.CONSTANT_Methodref:          return new ConstantMethodref(file);
  case Constants.CONSTANT_InterfaceMethodref: return new
                                      ConstantInterfaceMethodref(file);
  case Constants.CONSTANT_String:             return new ConstantString(file);
  case Constants.CONSTANT_Integer:            return new ConstantInteger(file);
  case Constants.CONSTANT_Float:              return new ConstantFloat(file);
  case Constants.CONSTANT_Long:               return new ConstantLong(file);
  case Constants.CONSTANT_Double:             return new ConstantDouble(file);
  case Constants.CONSTANT_NameAndType:        return new ConstantNameAndType(file);
  case Constants.CONSTANT_Utf8:               return new ConstantUtf8(file);
  default:
    throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
  }
}
 
Example 4
Source File: Constant.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read one constant from the given file, the type depends on a tag byte.
 *
 * @param file Input stream
 * @return Constant object
 */
static final Constant readConstant(DataInputStream file)
  throws IOException, ClassFormatException
{
  byte b = file.readByte(); // Read tag byte

  switch(b) {
  case Constants.CONSTANT_Class:              return new ConstantClass(file);
  case Constants.CONSTANT_Fieldref:           return new ConstantFieldref(file);
  case Constants.CONSTANT_Methodref:          return new ConstantMethodref(file);
  case Constants.CONSTANT_InterfaceMethodref: return new
                                      ConstantInterfaceMethodref(file);
  case Constants.CONSTANT_String:             return new ConstantString(file);
  case Constants.CONSTANT_Integer:            return new ConstantInteger(file);
  case Constants.CONSTANT_Float:              return new ConstantFloat(file);
  case Constants.CONSTANT_Long:               return new ConstantLong(file);
  case Constants.CONSTANT_Double:             return new ConstantDouble(file);
  case Constants.CONSTANT_NameAndType:        return new ConstantNameAndType(file);
  case Constants.CONSTANT_Utf8:               return new ConstantUtf8(file);
  default:
    throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
  }
}
 
Example 5
Source File: Constant.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read one constant from the given file, the type depends on a tag byte.
 *
 * @param file Input stream
 * @return Constant object
 */
static final Constant readConstant(DataInputStream file)
  throws IOException, ClassFormatException
{
  byte b = file.readByte(); // Read tag byte

  switch(b) {
  case Constants.CONSTANT_Class:              return new ConstantClass(file);
  case Constants.CONSTANT_Fieldref:           return new ConstantFieldref(file);
  case Constants.CONSTANT_Methodref:          return new ConstantMethodref(file);
  case Constants.CONSTANT_InterfaceMethodref: return new
                                      ConstantInterfaceMethodref(file);
  case Constants.CONSTANT_String:             return new ConstantString(file);
  case Constants.CONSTANT_Integer:            return new ConstantInteger(file);
  case Constants.CONSTANT_Float:              return new ConstantFloat(file);
  case Constants.CONSTANT_Long:               return new ConstantLong(file);
  case Constants.CONSTANT_Double:             return new ConstantDouble(file);
  case Constants.CONSTANT_NameAndType:        return new ConstantNameAndType(file);
  case Constants.CONSTANT_Utf8:               return new ConstantUtf8(file);
  default:
    throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
  }
}
 
Example 6
Source File: Constant.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read one constant from the given file, the type depends on a tag byte.
 *
 * @param file Input stream
 * @return Constant object
 */
static final Constant readConstant(DataInputStream file)
  throws IOException, ClassFormatException
{
  byte b = file.readByte(); // Read tag byte

  switch(b) {
  case Constants.CONSTANT_Class:              return new ConstantClass(file);
  case Constants.CONSTANT_Fieldref:           return new ConstantFieldref(file);
  case Constants.CONSTANT_Methodref:          return new ConstantMethodref(file);
  case Constants.CONSTANT_InterfaceMethodref: return new
                                      ConstantInterfaceMethodref(file);
  case Constants.CONSTANT_String:             return new ConstantString(file);
  case Constants.CONSTANT_Integer:            return new ConstantInteger(file);
  case Constants.CONSTANT_Float:              return new ConstantFloat(file);
  case Constants.CONSTANT_Long:               return new ConstantLong(file);
  case Constants.CONSTANT_Double:             return new ConstantDouble(file);
  case Constants.CONSTANT_NameAndType:        return new ConstantNameAndType(file);
  case Constants.CONSTANT_Utf8:               return new ConstantUtf8(file);
  default:
    throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
  }
}
 
Example 7
Source File: Constant.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Read one constant from the given file, the type depends on a tag byte.
 *
 * @param file Input stream
 * @return Constant object
 */
static final Constant readConstant(DataInputStream file)
  throws IOException, ClassFormatException
{
  byte b = file.readByte(); // Read tag byte

  switch(b) {
  case Constants.CONSTANT_Class:              return new ConstantClass(file);
  case Constants.CONSTANT_Fieldref:           return new ConstantFieldref(file);
  case Constants.CONSTANT_Methodref:          return new ConstantMethodref(file);
  case Constants.CONSTANT_InterfaceMethodref: return new
                                      ConstantInterfaceMethodref(file);
  case Constants.CONSTANT_String:             return new ConstantString(file);
  case Constants.CONSTANT_Integer:            return new ConstantInteger(file);
  case Constants.CONSTANT_Float:              return new ConstantFloat(file);
  case Constants.CONSTANT_Long:               return new ConstantLong(file);
  case Constants.CONSTANT_Double:             return new ConstantDouble(file);
  case Constants.CONSTANT_NameAndType:        return new ConstantNameAndType(file);
  case Constants.CONSTANT_Utf8:               return new ConstantUtf8(file);
  default:
    throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
  }
}
 
Example 8
Source File: Constant.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Read one constant from the given file, the type depends on a tag byte.
 *
 * @param file Input stream
 * @return Constant object
 */
static final Constant readConstant(DataInputStream file)
  throws IOException, ClassFormatException
{
  byte b = file.readByte(); // Read tag byte

  switch(b) {
  case Constants.CONSTANT_Class:              return new ConstantClass(file);
  case Constants.CONSTANT_Fieldref:           return new ConstantFieldref(file);
  case Constants.CONSTANT_Methodref:          return new ConstantMethodref(file);
  case Constants.CONSTANT_InterfaceMethodref: return new
                                      ConstantInterfaceMethodref(file);
  case Constants.CONSTANT_String:             return new ConstantString(file);
  case Constants.CONSTANT_Integer:            return new ConstantInteger(file);
  case Constants.CONSTANT_Float:              return new ConstantFloat(file);
  case Constants.CONSTANT_Long:               return new ConstantLong(file);
  case Constants.CONSTANT_Double:             return new ConstantDouble(file);
  case Constants.CONSTANT_NameAndType:        return new ConstantNameAndType(file);
  case Constants.CONSTANT_Utf8:               return new ConstantUtf8(file);
  default:
    throw new ClassFormatException("Invalid byte tag in constant pool: " + b);
  }
}
 
Example 9
Source File: ConstantPool.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get string from constant pool and bypass the indirection of
 * `ConstantClass' and `ConstantString' objects. I.e. these classes have
 * an index field that points to another entry of the constant pool of
 * type `ConstantUtf8' which contains the real data.
 *
 * @param  index Index in constant pool
 * @param  tag Tag of expected constant, either ConstantClass or ConstantString
 * @return Contents of string reference
 * @see    ConstantClass
 * @see    ConstantString
 * @throws  ClassFormatException
 */
public String getConstantString(int index, byte tag)
     throws ClassFormatException
{
  Constant c;
  int    i;

  c = getConstant(index, tag);

  /* This switch() is not that elegant, since the two classes have the
   * same contents, they just differ in the name of the index
   * field variable.
   * But we want to stick to the JVM naming conventions closely though
   * we could have solved these more elegantly by using the same
   * variable name or by subclassing.
   */
  switch(tag) {
  case Constants.CONSTANT_Class:  i = ((ConstantClass)c).getNameIndex();    break;
  case Constants.CONSTANT_String: i = ((ConstantString)c).getStringIndex(); break;
  default:
    throw new RuntimeException("getConstantString called with illegal tag " + tag);
  }

  // Finally get the string from the constant pool
  c = getConstant(i, Constants.CONSTANT_Utf8);
  return ((ConstantUtf8)c).getBytes();
}
 
Example 10
Source File: ConstantPool.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get string from constant pool and bypass the indirection of
 * `ConstantClass' and `ConstantString' objects. I.e. these classes have
 * an index field that points to another entry of the constant pool of
 * type `ConstantUtf8' which contains the real data.
 *
 * @param  index Index in constant pool
 * @param  tag Tag of expected constant, either ConstantClass or ConstantString
 * @return Contents of string reference
 * @see    ConstantClass
 * @see    ConstantString
 * @throws  ClassFormatException
 */
public String getConstantString(int index, byte tag)
     throws ClassFormatException
{
  Constant c;
  int    i;

  c = getConstant(index, tag);

  /* This switch() is not that elegant, since the two classes have the
   * same contents, they just differ in the name of the index
   * field variable.
   * But we want to stick to the JVM naming conventions closely though
   * we could have solved these more elegantly by using the same
   * variable name or by subclassing.
   */
  switch(tag) {
  case Constants.CONSTANT_Class:  i = ((ConstantClass)c).getNameIndex();    break;
  case Constants.CONSTANT_String: i = ((ConstantString)c).getStringIndex(); break;
  default:
    throw new RuntimeException("getConstantString called with illegal tag " + tag);
  }

  // Finally get the string from the constant pool
  c = getConstant(i, Constants.CONSTANT_Utf8);
  return ((ConstantUtf8)c).getBytes();
}
 
Example 11
Source File: ConstantPool.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get string from constant pool and bypass the indirection of
 * `ConstantClass' and `ConstantString' objects. I.e. these classes have
 * an index field that points to another entry of the constant pool of
 * type `ConstantUtf8' which contains the real data.
 *
 * @param  index Index in constant pool
 * @param  tag Tag of expected constant, either ConstantClass or ConstantString
 * @return Contents of string reference
 * @see    ConstantClass
 * @see    ConstantString
 * @throws  ClassFormatException
 */
public String getConstantString(int index, byte tag)
     throws ClassFormatException
{
  Constant c;
  int    i;

  c = getConstant(index, tag);

  /* This switch() is not that elegant, since the two classes have the
   * same contents, they just differ in the name of the index
   * field variable.
   * But we want to stick to the JVM naming conventions closely though
   * we could have solved these more elegantly by using the same
   * variable name or by subclassing.
   */
  switch(tag) {
  case Constants.CONSTANT_Class:  i = ((ConstantClass)c).getNameIndex();    break;
  case Constants.CONSTANT_String: i = ((ConstantString)c).getStringIndex(); break;
  default:
    throw new RuntimeException("getConstantString called with illegal tag " + tag);
  }

  // Finally get the string from the constant pool
  c = getConstant(i, Constants.CONSTANT_Utf8);
  return ((ConstantUtf8)c).getBytes();
}
 
Example 12
Source File: ConstantPool.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Get string from constant pool and bypass the indirection of
 * `ConstantClass' and `ConstantString' objects. I.e. these classes have
 * an index field that points to another entry of the constant pool of
 * type `ConstantUtf8' which contains the real data.
 *
 * @param  index Index in constant pool
 * @param  tag Tag of expected constant, either ConstantClass or ConstantString
 * @return Contents of string reference
 * @see    ConstantClass
 * @see    ConstantString
 * @throws  ClassFormatException
 */
public String getConstantString(int index, byte tag)
     throws ClassFormatException
{
  Constant c;
  int    i;

  c = getConstant(index, tag);

  /* This switch() is not that elegant, since the two classes have the
   * same contents, they just differ in the name of the index
   * field variable.
   * But we want to stick to the JVM naming conventions closely though
   * we could have solved these more elegantly by using the same
   * variable name or by subclassing.
   */
  switch(tag) {
  case Constants.CONSTANT_Class:  i = ((ConstantClass)c).getNameIndex();    break;
  case Constants.CONSTANT_String: i = ((ConstantString)c).getStringIndex(); break;
  default:
    throw new RuntimeException("getConstantString called with illegal tag " + tag);
  }

  // Finally get the string from the constant pool
  c = getConstant(i, Constants.CONSTANT_Utf8);
  return ((ConstantUtf8)c).getBytes();
}
 
Example 13
Source File: ConstantPool.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Get string from constant pool and bypass the indirection of
 * `ConstantClass' and `ConstantString' objects. I.e. these classes have
 * an index field that points to another entry of the constant pool of
 * type `ConstantUtf8' which contains the real data.
 *
 * @param  index Index in constant pool
 * @param  tag Tag of expected constant, either ConstantClass or ConstantString
 * @return Contents of string reference
 * @see    ConstantClass
 * @see    ConstantString
 * @throws  ClassFormatException
 */
public String getConstantString(int index, byte tag)
     throws ClassFormatException
{
  Constant c;
  int    i;

  c = getConstant(index, tag);

  /* This switch() is not that elegant, since the two classes have the
   * same contents, they just differ in the name of the index
   * field variable.
   * But we want to stick to the JVM naming conventions closely though
   * we could have solved these more elegantly by using the same
   * variable name or by subclassing.
   */
  switch(tag) {
  case Constants.CONSTANT_Class:  i = ((ConstantClass)c).getNameIndex();    break;
  case Constants.CONSTANT_String: i = ((ConstantString)c).getStringIndex(); break;
  default:
    throw new RuntimeException("getConstantString called with illegal tag " + tag);
  }

  // Finally get the string from the constant pool
  c = getConstant(i, Constants.CONSTANT_Utf8);
  return ((ConstantUtf8)c).getBytes();
}
 
Example 14
Source File: ConstantClass.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param name_index Name index in constant pool.  Should refer to a
 * ConstantUtf8.
 */
public ConstantClass(int name_index) {
  super(Constants.CONSTANT_Class);
  this.name_index = name_index;
}
 
Example 15
Source File: ConstantPool.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolve constant to a string representation.
 *
 * @param  constant Constant to be printed
 * @return String representation
 */
public String constantToString(Constant c)
     throws ClassFormatException
{
  String   str;
  int      i;
  byte     tag = c.getTag();

  switch(tag) {
  case Constants.CONSTANT_Class:
    i   = ((ConstantClass)c).getNameIndex();
    c   = getConstant(i, Constants.CONSTANT_Utf8);
    str = Utility.compactClassName(((ConstantUtf8)c).getBytes(), false);
    break;

  case Constants.CONSTANT_String:
    i   = ((ConstantString)c).getStringIndex();
    c   = getConstant(i, Constants.CONSTANT_Utf8);
    str = "\"" + escape(((ConstantUtf8)c).getBytes()) + "\"";
    break;

  case Constants.CONSTANT_Utf8:    str = ((ConstantUtf8)c).getBytes();         break;
  case Constants.CONSTANT_Double:  str = "" + ((ConstantDouble)c).getBytes();  break;
  case Constants.CONSTANT_Float:   str = "" + ((ConstantFloat)c).getBytes();   break;
  case Constants.CONSTANT_Long:    str = "" + ((ConstantLong)c).getBytes();    break;
  case Constants.CONSTANT_Integer: str = "" + ((ConstantInteger)c).getBytes(); break;

  case Constants.CONSTANT_NameAndType:
    str = (constantToString(((ConstantNameAndType)c).getNameIndex(),
                            Constants.CONSTANT_Utf8) + " " +
           constantToString(((ConstantNameAndType)c).getSignatureIndex(),
                            Constants.CONSTANT_Utf8));
    break;

  case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref:
  case Constants.CONSTANT_Fieldref:
    str = (constantToString(((ConstantCP)c).getClassIndex(),
                            Constants.CONSTANT_Class) + "." +
           constantToString(((ConstantCP)c).getNameAndTypeIndex(),
                            Constants.CONSTANT_NameAndType));
    break;

  default: // Never reached
    throw new RuntimeException("Unknown constant type " + tag);
  }

  return str;
}
 
Example 16
Source File: ConstantPool.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolve constant to a string representation.
 *
 * @param  constant Constant to be printed
 * @return String representation
 */
public String constantToString(Constant c)
     throws ClassFormatException
{
  String   str;
  int      i;
  byte     tag = c.getTag();

  switch(tag) {
  case Constants.CONSTANT_Class:
    i   = ((ConstantClass)c).getNameIndex();
    c   = getConstant(i, Constants.CONSTANT_Utf8);
    str = Utility.compactClassName(((ConstantUtf8)c).getBytes(), false);
    break;

  case Constants.CONSTANT_String:
    i   = ((ConstantString)c).getStringIndex();
    c   = getConstant(i, Constants.CONSTANT_Utf8);
    str = "\"" + escape(((ConstantUtf8)c).getBytes()) + "\"";
    break;

  case Constants.CONSTANT_Utf8:    str = ((ConstantUtf8)c).getBytes();         break;
  case Constants.CONSTANT_Double:  str = "" + ((ConstantDouble)c).getBytes();  break;
  case Constants.CONSTANT_Float:   str = "" + ((ConstantFloat)c).getBytes();   break;
  case Constants.CONSTANT_Long:    str = "" + ((ConstantLong)c).getBytes();    break;
  case Constants.CONSTANT_Integer: str = "" + ((ConstantInteger)c).getBytes(); break;

  case Constants.CONSTANT_NameAndType:
    str = (constantToString(((ConstantNameAndType)c).getNameIndex(),
                            Constants.CONSTANT_Utf8) + " " +
           constantToString(((ConstantNameAndType)c).getSignatureIndex(),
                            Constants.CONSTANT_Utf8));
    break;

  case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref:
  case Constants.CONSTANT_Fieldref:
    str = (constantToString(((ConstantCP)c).getClassIndex(),
                            Constants.CONSTANT_Class) + "." +
           constantToString(((ConstantCP)c).getNameAndTypeIndex(),
                            Constants.CONSTANT_NameAndType));
    break;

  default: // Never reached
    throw new RuntimeException("Unknown constant type " + tag);
  }

  return str;
}
 
Example 17
Source File: ConstantClass.java    From JDKSourceCode1.8 with MIT License 4 votes vote down vote up
/**
 * @param name_index Name index in constant pool.  Should refer to a
 * ConstantUtf8.
 */
public ConstantClass(int name_index) {
  super(Constants.CONSTANT_Class);
  this.name_index = name_index;
}
 
Example 18
Source File: ConstantPool.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolve constant to a string representation.
 *
 * @param  constant Constant to be printed
 * @return String representation
 */
public String constantToString(Constant c)
     throws ClassFormatException
{
  String   str;
  int      i;
  byte     tag = c.getTag();

  switch(tag) {
  case Constants.CONSTANT_Class:
    i   = ((ConstantClass)c).getNameIndex();
    c   = getConstant(i, Constants.CONSTANT_Utf8);
    str = Utility.compactClassName(((ConstantUtf8)c).getBytes(), false);
    break;

  case Constants.CONSTANT_String:
    i   = ((ConstantString)c).getStringIndex();
    c   = getConstant(i, Constants.CONSTANT_Utf8);
    str = "\"" + escape(((ConstantUtf8)c).getBytes()) + "\"";
    break;

  case Constants.CONSTANT_Utf8:    str = ((ConstantUtf8)c).getBytes();         break;
  case Constants.CONSTANT_Double:  str = "" + ((ConstantDouble)c).getBytes();  break;
  case Constants.CONSTANT_Float:   str = "" + ((ConstantFloat)c).getBytes();   break;
  case Constants.CONSTANT_Long:    str = "" + ((ConstantLong)c).getBytes();    break;
  case Constants.CONSTANT_Integer: str = "" + ((ConstantInteger)c).getBytes(); break;

  case Constants.CONSTANT_NameAndType:
    str = (constantToString(((ConstantNameAndType)c).getNameIndex(),
                            Constants.CONSTANT_Utf8) + " " +
           constantToString(((ConstantNameAndType)c).getSignatureIndex(),
                            Constants.CONSTANT_Utf8));
    break;

  case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref:
  case Constants.CONSTANT_Fieldref:
    str = (constantToString(((ConstantCP)c).getClassIndex(),
                            Constants.CONSTANT_Class) + "." +
           constantToString(((ConstantCP)c).getNameAndTypeIndex(),
                            Constants.CONSTANT_NameAndType));
    break;

  default: // Never reached
    throw new RuntimeException("Unknown constant type " + tag);
  }

  return str;
}
 
Example 19
Source File: ConstantPool.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Resolve constant to a string representation.
 *
 * @param  constant Constant to be printed
 * @return String representation
 */
public String constantToString(Constant c)
     throws ClassFormatException
{
  String   str;
  int      i;
  byte     tag = c.getTag();

  switch(tag) {
  case Constants.CONSTANT_Class:
    i   = ((ConstantClass)c).getNameIndex();
    c   = getConstant(i, Constants.CONSTANT_Utf8);
    str = Utility.compactClassName(((ConstantUtf8)c).getBytes(), false);
    break;

  case Constants.CONSTANT_String:
    i   = ((ConstantString)c).getStringIndex();
    c   = getConstant(i, Constants.CONSTANT_Utf8);
    str = "\"" + escape(((ConstantUtf8)c).getBytes()) + "\"";
    break;

  case Constants.CONSTANT_Utf8:    str = ((ConstantUtf8)c).getBytes();         break;
  case Constants.CONSTANT_Double:  str = "" + ((ConstantDouble)c).getBytes();  break;
  case Constants.CONSTANT_Float:   str = "" + ((ConstantFloat)c).getBytes();   break;
  case Constants.CONSTANT_Long:    str = "" + ((ConstantLong)c).getBytes();    break;
  case Constants.CONSTANT_Integer: str = "" + ((ConstantInteger)c).getBytes(); break;

  case Constants.CONSTANT_NameAndType:
    str = (constantToString(((ConstantNameAndType)c).getNameIndex(),
                            Constants.CONSTANT_Utf8) + " " +
           constantToString(((ConstantNameAndType)c).getSignatureIndex(),
                            Constants.CONSTANT_Utf8));
    break;

  case Constants.CONSTANT_InterfaceMethodref: case Constants.CONSTANT_Methodref:
  case Constants.CONSTANT_Fieldref:
    str = (constantToString(((ConstantCP)c).getClassIndex(),
                            Constants.CONSTANT_Class) + "." +
           constantToString(((ConstantCP)c).getNameAndTypeIndex(),
                            Constants.CONSTANT_NameAndType));
    break;

  default: // Never reached
    throw new RuntimeException("Unknown constant type " + tag);
  }

  return str;
}
 
Example 20
Source File: ConstantClass.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param name_index Name index in constant pool.  Should refer to a
 * ConstantUtf8.
 */
public ConstantClass(int name_index) {
  super(Constants.CONSTANT_Class);
  this.name_index = name_index;
}