當前位置: 首頁>>代碼示例>>Java>>正文


Java ConstPool.addMethodrefInfo方法代碼示例

本文整理匯總了Java中javassist.bytecode.ConstPool.addMethodrefInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java ConstPool.addMethodrefInfo方法的具體用法?Java ConstPool.addMethodrefInfo怎麽用?Java ConstPool.addMethodrefInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javassist.bytecode.ConstPool的用法示例。


在下文中一共展示了ConstPool.addMethodrefInfo方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: transformInvokevirtualsIntoGetfields

import javassist.bytecode.ConstPool; //導入方法依賴的package包/類
private int transformInvokevirtualsIntoGetfields(ClassFile classfile, CodeIterator iter, int pos) {
	final ConstPool constPool = classfile.getConstPool();
	final int c = iter.byteAt( pos );
	if ( c != Opcode.GETFIELD ) {
		return pos;
	}

	final int index = iter.u16bitAt( pos + 1 );
	final String fieldName = constPool.getFieldrefName( index );
	final String className = constPool.getFieldrefClassName( index );
	if ( !filter.handleReadAccess( className, fieldName ) ) {
		return pos;
	}

	final String fieldReaderMethodDescriptor = "()" + constPool.getFieldrefType( index );
	final int fieldReaderMethodIndex = constPool.addMethodrefInfo(
			constPool.getThisClassInfo(),
			EACH_READ_METHOD_PREFIX + fieldName,
			fieldReaderMethodDescriptor
	);
	iter.writeByte( Opcode.INVOKEVIRTUAL, pos );
	iter.write16bit( fieldReaderMethodIndex, pos + 1 );
	return pos;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:FieldTransformer.java

示例2: transformInvokevirtualsIntoPutfields

import javassist.bytecode.ConstPool; //導入方法依賴的package包/類
private int transformInvokevirtualsIntoPutfields(ClassFile classfile, CodeIterator iter, int pos) {
	final ConstPool constPool = classfile.getConstPool();
	final int c = iter.byteAt( pos );
	if ( c != Opcode.PUTFIELD ) {
		return pos;
	}

	final int index = iter.u16bitAt( pos + 1 );
	final String fieldName = constPool.getFieldrefName( index );
	final String className = constPool.getFieldrefClassName( index );
	if ( !filter.handleWriteAccess( className, fieldName ) ) {
		return pos;
	}

	final String fieldWriterMethodDescriptor = "(" + constPool.getFieldrefType( index ) + ")V";
	final int fieldWriterMethodIndex = constPool.addMethodrefInfo(
			constPool.getThisClassInfo(),
			EACH_WRITE_METHOD_PREFIX + fieldName,
			fieldWriterMethodDescriptor
	);
	iter.writeByte( Opcode.INVOKEVIRTUAL, pos );
	iter.write16bit( fieldWriterMethodIndex, pos + 1 );
	return pos;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:25,代碼來源:FieldTransformer.java

示例3: transformInvokevirtualsIntoGetfields

import javassist.bytecode.ConstPool; //導入方法依賴的package包/類
private int transformInvokevirtualsIntoGetfields(ClassFile classfile,
                                                 CodeIterator iter, int pos) {
	ConstPool cp = classfile.getConstPool();
	int c = iter.byteAt(pos);
	if (c != Opcode.GETFIELD) {
		return pos;
	}
	int index = iter.u16bitAt(pos + 1);
	String fieldName = cp.getFieldrefName(index);
	String className = cp.getFieldrefClassName(index);
	if ((!classfile.getName().equals(className))
	    || (!readableFields.containsKey(fieldName))) {
		return pos;
	}
	String desc = "()" + (String) readableFields.get(fieldName);
	int read_method_index = cp.addMethodrefInfo(cp.getThisClassInfo(),
	                                            EACH_READ_METHOD_PREFIX + fieldName, desc);
	iter.writeByte(Opcode.INVOKEVIRTUAL, pos);
	iter.write16bit(read_method_index, pos + 1);
	return pos;
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:22,代碼來源:FieldTransformer.java

示例4: transformInvokevirtualsIntoPutfields

import javassist.bytecode.ConstPool; //導入方法依賴的package包/類
private int transformInvokevirtualsIntoPutfields(ClassFile classfile,
                                                 CodeIterator iter, int pos) {
	ConstPool cp = classfile.getConstPool();
	int c = iter.byteAt(pos);
	if (c != Opcode.PUTFIELD) {
		return pos;
	}
	int index = iter.u16bitAt(pos + 1);
	String fieldName = cp.getFieldrefName(index);
	String className = cp.getFieldrefClassName(index);
	if ((!classfile.getName().equals(className))
	    || (!writableFields.containsKey(fieldName))) {
		return pos;
	}
	String desc = "(" + (String) writableFields.get(fieldName) + ")V";
	int write_method_index = cp.addMethodrefInfo(cp.getThisClassInfo(),
	                                             EACH_WRITE_METHOD_PREFIX + fieldName, desc);
	iter.writeByte(Opcode.INVOKEVIRTUAL, pos);
	iter.write16bit(write_method_index, pos + 1);
	return pos;
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:22,代碼來源:FieldTransformer.java

示例5: replace

import javassist.bytecode.ConstPool; //導入方法依賴的package包/類
private int replace(ConstPool cp, CodeIterator iterator, int pos,
        int opcode, String signature) throws BadBytecode {
    String castType = null;
    String methodName = getMethodName(opcode);
    if (methodName != null) {
        // See if the object must be cast
        if (opcode == AALOAD) {
            castType = getTopType(iterator.lookAhead());
            // Do not replace an AALOAD instruction that we do not have a type for
            // This happens when the state is guaranteed to be null (Type.UNINIT)
            // So we don't really care about this case.
            if (castType == null)
                return pos;
            if ("java/lang/Object".equals(castType))
                castType = null;
        }

        // The gap may include extra padding
        // Write a nop in case the padding pushes the instruction forward
        iterator.writeByte(NOP, pos);
        CodeIterator.Gap gap
            = iterator.insertGapAt(pos, castType != null ? 5 : 2, false);
        pos = gap.position;
        int mi = cp.addClassInfo(methodClassname);
        int methodref = cp.addMethodrefInfo(mi, methodName, signature);
        iterator.writeByte(INVOKESTATIC, pos);
        iterator.write16bit(methodref, pos + 1);

        if (castType != null) {
            int index = cp.addClassInfo(castType);
            iterator.writeByte(CHECKCAST, pos + 3);
            iterator.write16bit(index, pos + 4);
        }

        pos = updatePos(pos, gap.length);
    }

    return pos;
}
 
開發者ID:AndreJCL,項目名稱:JCL,代碼行數:40,代碼來源:TransformAccessArrayField.java


注:本文中的javassist.bytecode.ConstPool.addMethodrefInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。