Java Code Examples for javassist.bytecode.ConstPool#CONST_Class

The following examples show how to use javassist.bytecode.ConstPool#CONST_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: ClassFileJavassist.java    From jbse with GNU General Public License v3.0 5 votes vote down vote up
@Override
public String getClassSignature(int classIndex) throws InvalidIndexException {
    if (classIndex < 1 || classIndex > this.cp.getSize()) {
        throw new InvalidIndexException(indexOutOfRangeMessage(classIndex));
    }
    if (this.cp.getTag(classIndex) != ConstPool.CONST_Class) {
        throw new InvalidIndexException(entryInvalidMessage(classIndex));
    }
    return internalClassName(this.cp.getClassInfo(classIndex));
}
 
Example 2
Source File: ClassFileJavassist.java    From jbse with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ConstantPoolValue getValueFromConstantPool(int index) throws InvalidIndexException {
    if (index < 1 || index > this.cp.getSize()) {
        throw new InvalidIndexException(indexOutOfRangeMessage(index));
    }
    final int tag = this.cp.getTag(index);
    switch (tag) {
    case ConstPool.CONST_Integer:
        return new ConstantPoolPrimitive(this.cp.getIntegerInfo(index));
    case ConstPool.CONST_Float:
        return new ConstantPoolPrimitive(this.cp.getFloatInfo(index));
    case ConstPool.CONST_Long:
        return new ConstantPoolPrimitive(this.cp.getLongInfo(index));
    case ConstPool.CONST_Double:
        return new ConstantPoolPrimitive(this.cp.getDoubleInfo(index));
    case ConstPool.CONST_String:
        if (this.cpPatches != null && index < this.cpPatches.length && this.cpPatches[index] != null) {
            return this.cpPatches[index];
        }
        return new ConstantPoolString(this.cp.getStringInfo(index));
    case ConstPool.CONST_Class:
        return new ConstantPoolClass(internalClassName(this.cp.getClassInfo(index)));
    case ConstPool.CONST_Utf8:
        return new ConstantPoolUtf8(this.cp.getUtf8Info(index));
    }
    throw new InvalidIndexException(entryInvalidMessage(index));
}
 
Example 3
Source File: ClassFileJavassist.java    From jbse with GNU General Public License v3.0 4 votes vote down vote up
private void checkCpPatches(javassist.bytecode.ConstPool cp, ConstantPoolValue[] cpPatches) 
throws InvalidInputException {
    if (cpPatches == null) {
        return;
    }
    for (int i = 1; i < Math.min(cp.getSize(), cpPatches.length); ++i) {
        if (cpPatches[i] == null) {
            continue;
        }
        final int tag = cp.getTag(i);
        if (tag == ConstPool.CONST_String) {
            continue; //any will fit
        }
        if (tag == ConstPool.CONST_Integer && 
            cpPatches[i] instanceof ConstantPoolPrimitive && 
            ((ConstantPoolPrimitive) cpPatches[i]).getValue() instanceof Integer) {
            continue;
        }
        if (tag == ConstPool.CONST_Long && 
            cpPatches[i] instanceof ConstantPoolPrimitive && 
            ((ConstantPoolPrimitive) cpPatches[i]).getValue() instanceof Long) {
            continue;
        }
        if (tag == ConstPool.CONST_Float && 
            cpPatches[i] instanceof ConstantPoolPrimitive && 
            ((ConstantPoolPrimitive) cpPatches[i]).getValue() instanceof Float) {
            continue;
        }
        if (tag == ConstPool.CONST_Double && 
            cpPatches[i] instanceof ConstantPoolPrimitive && 
            ((ConstantPoolPrimitive) cpPatches[i]).getValue() instanceof Double) {
            continue;
        }
        if (tag == ConstPool.CONST_Utf8 && cpPatches[i] instanceof ConstantPoolString) {
            continue;
        }
        if (tag == ConstPool.CONST_Class && cpPatches[i] instanceof ConstantPoolClass) {
            continue;
        }
        throw new InvalidInputException("ClassFile constructor for anonymous classfile invoked with cpPatches parameter not matching bytecode's constant pool.");
    }
}