Java Code Examples for org.apache.bcel.classfile.ConstantUtf8#getBytes()

The following examples show how to use org.apache.bcel.classfile.ConstantUtf8#getBytes() . These examples are extracted from open source projects. 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
private static ClassSymbol makeSymbol(
    ConstantClass constantClass, ConstantPool constantPool, JavaClass sourceClass) {
  int nameIndex = constantClass.getNameIndex();
  Constant classNameConstant = constantPool.getConstant(nameIndex);
  if (!(classNameConstant instanceof ConstantUtf8)) {
    // This constant_pool entry must be a CONSTANT_Utf8_info
    // as specified https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.4.1
    throw new ClassFormatException(
        "Failed to lookup ConstantUtf8 constant indexed at "
            + nameIndex
            + ". However, the content is not ConstantUtf8. It is "
            + classNameConstant);
  }
  ConstantUtf8 classNameConstantUtf8 = (ConstantUtf8) classNameConstant;
  // classNameConstantUtf8 has internal form of class names that uses '.' to separate identifiers
  String targetClassNameInternalForm = classNameConstantUtf8.getBytes();
  // Adjust the internal form to comply with binary names defined in JLS 13.1
  String targetClassName = targetClassNameInternalForm.replace('/', '.');
  String superClassName = sourceClass.getSuperclassName();

  // Relationships between superclass and subclass need special validation for 'final' keyword
  boolean referenceIsForInheritance = superClassName.equals(targetClassName);
  if (referenceIsForInheritance) {
    return new SuperClassSymbol(targetClassName);
  }
  return new ClassSymbol(targetClassName);
}
 
Example 2
@Override
public void visitClassContext(ClassContext classContext) {
    JavaClass jclass = classContext.getJavaClass();

    // We can ignore classes that were compiled for anything
    // less than JDK 1.5. This should avoid lots of unnecessary work
    // when analyzing code for older VM targets.
    if (BCELUtil.preTiger(jclass)) {
        return;
    }

    boolean sawUtilConcurrentLocks = false;
    for (Constant c : jclass.getConstantPool().getConstantPool()) {
        if (c instanceof ConstantMethodref) {
            ConstantMethodref m = (ConstantMethodref) c;
            ConstantClass cl = (ConstantClass) jclass.getConstantPool().getConstant(m.getClassIndex());
            ConstantUtf8 name = (ConstantUtf8) jclass.getConstantPool().getConstant(cl.getNameIndex());
            String nameAsString = name.getBytes();
            if (nameAsString.startsWith("java/util/concurrent/locks")) {
                sawUtilConcurrentLocks = true;
            }

        }
    }
    if (sawUtilConcurrentLocks) {
        super.visitClassContext(classContext);
    }
}
 
Example 3
public String getClassString()
{
    final ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(idx);
    return cu8.getBytes();
    // ConstantClass c = (ConstantClass)getConstantPool().getConstant(idx);
    // ConstantUtf8 utf8 =
    // (ConstantUtf8)getConstantPool().getConstant(c.getNameIndex());
    // return utf8.getBytes();
}
 
Example 4
public String getValueString()
{
    if (super.getElementValueType() != STRING) {
        throw new IllegalStateException(
                "Dont call getValueString() on a non STRING ElementValue");
    }
    final ConstantUtf8 c = (ConstantUtf8) getConstantPool().getConstant(idx);
    return c.getBytes();
}
 
Example 5
@Override
public String stringifyValue()
{
    switch (super.getElementValueType())
    {
    case PRIMITIVE_INT:
        final ConstantInteger c = (ConstantInteger) getConstantPool().getConstant(idx);
        return Integer.toString(c.getBytes());
    case PRIMITIVE_LONG:
        final ConstantLong j = (ConstantLong) getConstantPool().getConstant(idx);
        return Long.toString(j.getBytes());
    case PRIMITIVE_DOUBLE:
        final ConstantDouble d = (ConstantDouble) getConstantPool().getConstant(idx);
        return Double.toString(d.getBytes());
    case PRIMITIVE_FLOAT:
        final ConstantFloat f = (ConstantFloat) getConstantPool().getConstant(idx);
        return Float.toString(f.getBytes());
    case PRIMITIVE_SHORT:
        final ConstantInteger s = (ConstantInteger) getConstantPool().getConstant(idx);
        return Integer.toString(s.getBytes());
    case PRIMITIVE_BYTE:
        final ConstantInteger b = (ConstantInteger) getConstantPool().getConstant(idx);
        return Integer.toString(b.getBytes());
    case PRIMITIVE_CHAR:
        final ConstantInteger ch = (ConstantInteger) getConstantPool().getConstant(idx);
        return Integer.toString(ch.getBytes());
    case PRIMITIVE_BOOLEAN:
        final ConstantInteger bo = (ConstantInteger) getConstantPool().getConstant(idx);
        if (bo.getBytes() == 0) {
            return "false";
        }
        return "true";
    case STRING:
        final ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(idx);
        return cu8.getBytes();
    default:
        throw new IllegalStateException(
            "SimpleElementValueGen class does not know how to stringify type " + super.getElementValueType());
    }
}
 
Example 6
@Override
public String stringifyValue()
{
    final ConstantUtf8 cu8 = (ConstantUtf8) getConstantPool().getConstant(valueIdx);
    return cu8.getBytes();
    // ConstantString cu8 =
    // (ConstantString)getConstantPool().getConstant(valueIdx);
    // return
    // ((ConstantUtf8)getConstantPool().getConstant(cu8.getStringIndex())).getBytes();
}
 
Example 7
protected String getStringFromIndex(int i) {
    ConstantUtf8 name = (ConstantUtf8) constantPool.getConstant(i);
    return name.getBytes();
}
 
Example 8
private String getStringFromIndex(DismantleBytecode dbc, int i) {
    ConstantUtf8 name = (ConstantUtf8) dbc.getConstantPool().getConstant(i);
    return name.getBytes();
}
 
Example 9
Source Project: commons-bcel   File: AnnotationEntryGen.java    License: Apache License 2.0 4 votes vote down vote up
public final String getTypeSignature() {
    // ConstantClass c = (ConstantClass)cpool.getConstant(typeIndex);
    final ConstantUtf8 utf8 = (ConstantUtf8) cpool
            .getConstant(typeIndex/* c.getNameIndex() */);
    return utf8.getBytes();
}