本文整理汇总了Java中javassist.bytecode.CodeIterator.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java CodeIterator.hasNext方法的具体用法?Java CodeIterator.hasNext怎么用?Java CodeIterator.hasNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.bytecode.CodeIterator
的用法示例。
在下文中一共展示了CodeIterator.hasNext方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transformInvokevirtualsIntoPutAndGetfields
import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private void transformInvokevirtualsIntoPutAndGetfields(ClassFile classfile) throws CannotCompileException, BadBytecode {
for ( Object o : classfile.getMethods() ) {
final MethodInfo methodInfo = (MethodInfo) o;
final String methodName = methodInfo.getName();
if ( methodName.startsWith( EACH_READ_METHOD_PREFIX )
|| methodName.startsWith( EACH_WRITE_METHOD_PREFIX )
|| methodName.equals( GETFIELDHANDLER_METHOD_NAME )
|| methodName.equals( SETFIELDHANDLER_METHOD_NAME ) ) {
continue;
}
final CodeAttribute codeAttr = methodInfo.getCodeAttribute();
if ( codeAttr == null ) {
continue;
}
final CodeIterator iter = codeAttr.iterator();
while ( iter.hasNext() ) {
int pos = iter.next();
pos = transformInvokevirtualsIntoGetfields( classfile, iter, pos );
transformInvokevirtualsIntoPutfields( classfile, iter, pos );
}
final StackMapTable smt = MapMaker.make( classPool, methodInfo );
codeAttr.setAttribute( smt );
}
}
示例2: scan
import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private void scan(int pos, CodeIterator iter, Subroutine sub) throws BadBytecode {
// Skip already processed blocks
if (done.contains(Integer.valueOf(pos)))
return;
done.add(Integer.valueOf(pos));
int old = iter.lookAhead();
iter.move(pos);
boolean next;
do {
pos = iter.next();
next = scanOp(pos, iter, sub) && iter.hasNext();
} while (next);
iter.move(old);
}
示例3: getBehaviourBytecode
import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
/**
* This is basically the InstructionPrinter.getMethodBytecode but with a
* CtBehaviour parameter instead of a CtMethod
*
* @param behavior
* @return
*/
public static String getBehaviourBytecode(CtBehavior behavior) {
MethodInfo info = behavior.getMethodInfo2();
CodeAttribute code = info.getCodeAttribute();
if (code == null) {
return "";
}
ConstPool pool = info.getConstPool();
StringBuilder sb = new StringBuilder(1024);
CodeIterator iterator = code.iterator();
while (iterator.hasNext()) {
int pos;
try {
pos = iterator.next();
} catch (BadBytecode e) {
throw new JVoidIntrumentationException("BadBytecoode", e);
}
sb.append(pos + ": " + InstructionPrinter.instructionString(iterator, pos, pool) + "\n");
}
return sb.toString();
}
示例4: scan
import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private void scan(int pos, CodeIterator iter, Subroutine sub) throws BadBytecode {
// Skip already processed blocks
if (done.contains(new Integer(pos)))
return;
done.add(new Integer(pos));
int old = iter.lookAhead();
iter.move(pos);
boolean next;
do {
pos = iter.next();
next = scanOp(pos, iter, sub) && iter.hasNext();
} while (next);
iter.move(old);
}
示例5: initialize
import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
public void initialize(ConstPool cp, CtClass clazz, MethodInfo minfo) throws CannotCompileException {
/*
* This transformer must be isolated from other transformers, since some
* of them affect the local variable and stack maximums without updating
* the code attribute to reflect the changes. This screws up the
* data-flow analyzer, since it relies on consistent code state. Even
* if the attribute values were updated correctly, we would have to
* detect it, and redo analysis, which is not cheap. Instead, we are
* better off doing all changes in initialize() before everyone else has
* a chance to muck things up.
*/
CodeIterator iterator = minfo.getCodeAttribute().iterator();
while (iterator.hasNext()) {
try {
int pos = iterator.next();
int c = iterator.byteAt(pos);
if (c == AALOAD)
initFrames(clazz, minfo);
if (c == AALOAD || c == BALOAD || c == CALOAD || c == DALOAD
|| c == FALOAD || c == IALOAD || c == LALOAD
|| c == SALOAD) {
pos = replace(cp, iterator, pos, c, getLoadReplacementSignature(c));
} else if (c == AASTORE || c == BASTORE || c == CASTORE
|| c == DASTORE || c == FASTORE || c == IASTORE
|| c == LASTORE || c == SASTORE) {
pos = replace(cp, iterator, pos, c, getStoreReplacementSignature(c));
}
} catch (Exception e) {
throw new CannotCompileException(e);
}
}
}
示例6: transformInvokevirtualsIntoPutAndGetfields
import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private void transformInvokevirtualsIntoPutAndGetfields(ClassFile classfile)
throws CannotCompileException {
List methods = classfile.getMethods();
for (Iterator method_iter = methods.iterator(); method_iter.hasNext();) {
MethodInfo minfo = (MethodInfo) method_iter.next();
String methodName = minfo.getName();
if (methodName.startsWith(EACH_READ_METHOD_PREFIX)
|| methodName.startsWith(EACH_WRITE_METHOD_PREFIX)
|| methodName.equals(GETFIELDHANDLER_METHOD_NAME)
|| methodName.equals(SETFIELDHANDLER_METHOD_NAME)) {
continue;
}
CodeAttribute codeAttr = minfo.getCodeAttribute();
if (codeAttr == null) {
return;
}
CodeIterator iter = codeAttr.iterator();
while (iter.hasNext()) {
try {
int pos = iter.next();
pos = transformInvokevirtualsIntoGetfields(classfile, iter,
pos);
pos = transformInvokevirtualsIntoPutfields(classfile, iter,
pos);
} catch (BadBytecode e) {
throw new CannotCompileException(e);
}
}
}
}
示例7: equals
import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
public boolean equals(String methodName) throws NotFoundException, BadBytecode {
CtMethod mth1 = class1.getDeclaredMethod(methodName);
CtMethod mth2 = class2.getDeclaredMethod(methodName);
CodeIterator i1 = mth1.getMethodInfo().getCodeAttribute().iterator();
CodeIterator i2 = mth2.getMethodInfo().getCodeAttribute().iterator();
while (i1.hasNext() && i2.hasNext()) {
if(i1.byteAt(i1.next()) != i2.byteAt(i2.next())) {
return false;
}
}
return i1.hasNext() == i2.hasNext();
}
示例8: opCodeIndexList
import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
protected List<Integer> opCodeIndexList(CodeAttribute ca) throws BadBytecode {
List<Integer> list = new ArrayList<Integer>();
CodeIterator i = ca.iterator();
while (i.hasNext()) {
list.add(i.next());
}
return list;
}
示例9: lookAhead
import javassist.bytecode.CodeIterator; //导入方法依赖的package包/类
private int lookAhead(CodeIterator iter, int pos) throws BadBytecode {
if (! iter.hasNext())
throw new BadBytecode("Execution falls off end! [pos = " + pos + "]");
return iter.lookAhead();
}