com.sun.org.apache.bcel.internal.classfile.ConstantCP Java Examples

The following examples show how to use com.sun.org.apache.bcel.internal.classfile.ConstantCP. 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: FieldOrMethod.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/** @return signature of referenced method/field.
 */
public String getSignature( final ConstantPoolGen cpg ) {
    final ConstantPool cp = cpg.getConstantPool();
    final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex());
    final ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
    return ((ConstantUtf8) cp.getConstant(cnat.getSignatureIndex())).getBytes();
}
 
Example #2
Source File: FieldOrMethod.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/** @return name of referenced method/field.
 */
public String getName( final ConstantPoolGen cpg ) {
    final ConstantPool cp = cpg.getConstantPool();
    final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex());
    final ConstantNameAndType cnat = (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
    return ((ConstantUtf8) cp.getConstant(cnat.getNameIndex())).getBytes();
}
 
Example #3
Source File: FieldOrMethod.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * @return name of the referenced class/interface
 * @deprecated If the instruction references an array class,
 *    this method will return "java.lang.Object".
 *    For code generated by Java 1.5, this answer is
 *    sometimes wrong (e.g., if the "clone()" method is
 *    called on an array).  A better idea is to use
 *    the {@link #getReferenceType(ConstantPoolGen)} method, which correctly distinguishes
 *    between class types and array types.
 *
 */
@Deprecated
public String getClassName( final ConstantPoolGen cpg ) {
    final ConstantPool cp = cpg.getConstantPool();
    final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex());
    final String className = cp.getConstantString(cmr.getClassIndex(), Const.CONSTANT_Class);
    if (className.startsWith("[")) {
        // Turn array classes into java.lang.Object.
        return "java.lang.Object";
    }
    return className.replace('/', '.');
}
 
Example #4
Source File: FieldOrMethod.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Return the reference type representing the class, interface,
 * or array class referenced by the instruction.
 * @param cpg the ConstantPoolGen used to create the instruction
 * @return an ObjectType (if the referenced class type is a class
 *   or interface), or an ArrayType (if the referenced class
 *   type is an array class)
 */
public ReferenceType getReferenceType( final ConstantPoolGen cpg ) {
    final ConstantPool cp = cpg.getConstantPool();
    final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex());
    String className = cp.getConstantString(cmr.getClassIndex(), Const.CONSTANT_Class);
    if (className.startsWith("[")) {
        return (ArrayType) Type.getType(className);
    }
    className = className.replace('/', '.');
    return ObjectType.getInstance(className);
}
 
Example #5
Source File: NameSignatureInstruction.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
public ConstantNameAndType getNameAndType(final ConstantPoolGen cpg) {
    final ConstantPool cp = cpg.getConstantPool();
    final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex());
    return  (ConstantNameAndType) cp.getConstant(cmr.getNameAndTypeIndex());
}
 
Example #6
Source File: InvokeInstruction.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * This overrides the deprecated version as we know here that the referenced class
 * may legally be an array.
 *
 * @deprecated in FieldOrMethod
 *
 * @return name of the referenced class/interface
 * @throws IllegalArgumentException if the referenced class is an array (this should not happen)
 */
@Override
@Deprecated
public String getClassName( final ConstantPoolGen cpg ) {
    final ConstantPool cp = cpg.getConstantPool();
    final ConstantCP cmr = (ConstantCP) cp.getConstant(super.getIndex());
    final String className = cp.getConstantString(cmr.getClassIndex(), Const.CONSTANT_Class);
    return className.replace('/', '.');
}