本文整理汇总了Java中scouter.javassist.bytecode.ConstPool.isConstructor方法的典型用法代码示例。如果您正苦于以下问题:Java ConstPool.isConstructor方法的具体用法?Java ConstPool.isConstructor怎么用?Java ConstPool.isConstructor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scouter.javassist.bytecode.ConstPool
的用法示例。
在下文中一共展示了ConstPool.isConstructor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isEmpty
import scouter.javassist.bytecode.ConstPool; //导入方法依赖的package包/类
/**
* Returns true if the constructor (or static initializer)
* is the default one. This method returns true if the constructor
* takes some arguments but it does not perform anything except
* calling <code>super()</code> (the no-argument constructor of
* the super class).
*/
public boolean isEmpty() {
CodeAttribute ca = getMethodInfo2().getCodeAttribute();
if (ca == null)
return false; // native or abstract??
// they are not allowed, though.
ConstPool cp = ca.getConstPool();
CodeIterator it = ca.iterator();
try {
int pos, desc;
int op0 = it.byteAt(it.next());
return op0 == Opcode.RETURN // empty static initializer
|| (op0 == Opcode.ALOAD_0
&& it.byteAt(pos = it.next()) == Opcode.INVOKESPECIAL
&& (desc = cp.isConstructor(getSuperclassName(),
it.u16bitAt(pos + 1))) != 0
&& "()V".equals(cp.getUtf8Info(desc))
&& it.byteAt(it.next()) == Opcode.RETURN
&& !it.hasNext());
}
catch (BadBytecode e) {}
return false;
}
示例2: transform
import scouter.javassist.bytecode.ConstPool; //导入方法依赖的package包/类
/**
* Modifies a sequence of
* NEW classname
* DUP
* ...
* INVOKESPECIAL classname:method
*/
public int transform(CtClass clazz, int pos, CodeIterator iterator,
ConstPool cp) throws CannotCompileException
{
int index;
int c = iterator.byteAt(pos);
if (c == NEW) {
index = iterator.u16bitAt(pos + 1);
if (cp.getClassInfo(index).equals(classname)) {
if (iterator.byteAt(pos + 3) != DUP)
throw new CannotCompileException(
"NEW followed by no DUP was found");
if (newClassIndex == 0)
newClassIndex = cp.addClassInfo(newClassName);
iterator.write16bit(newClassIndex, pos + 1);
++nested;
}
}
else if (c == INVOKESPECIAL) {
index = iterator.u16bitAt(pos + 1);
int typedesc = cp.isConstructor(classname, index);
if (typedesc != 0 && nested > 0) {
int nt = cp.getMethodrefNameAndType(index);
if (newMethodNTIndex != nt) {
newMethodNTIndex = nt;
newMethodIndex = cp.addMethodrefInfo(newClassIndex, nt);
}
iterator.write16bit(newMethodIndex, pos + 1);
--nested;
}
}
return pos;
}
示例3: transform
import scouter.javassist.bytecode.ConstPool; //导入方法依赖的package包/类
/**
* Replace a sequence of
* NEW classname
* DUP
* ...
* INVOKESPECIAL
* with
* NOP
* NOP
* ...
* INVOKESTATIC trapMethod in trapClass
*/
public int transform(CtClass clazz, int pos, CodeIterator iterator,
ConstPool cp) throws CannotCompileException
{
int index;
int c = iterator.byteAt(pos);
if (c == NEW) {
index = iterator.u16bitAt(pos + 1);
if (cp.getClassInfo(index).equals(classname)) {
if (iterator.byteAt(pos + 3) != DUP)
throw new CannotCompileException(
"NEW followed by no DUP was found");
iterator.writeByte(NOP, pos);
iterator.writeByte(NOP, pos + 1);
iterator.writeByte(NOP, pos + 2);
iterator.writeByte(NOP, pos + 3);
++nested;
StackMapTable smt
= (StackMapTable)iterator.get().getAttribute(StackMapTable.tag);
if (smt != null)
smt.removeNew(pos);
StackMap sm
= (StackMap)iterator.get().getAttribute(StackMap.tag);
if (sm != null)
sm.removeNew(pos);
}
}
else if (c == INVOKESPECIAL) {
index = iterator.u16bitAt(pos + 1);
int typedesc = cp.isConstructor(classname, index);
if (typedesc != 0 && nested > 0) {
int methodref = computeMethodref(typedesc, cp);
iterator.writeByte(INVOKESTATIC, pos);
iterator.write16bit(methodref, pos + 1);
--nested;
}
}
return pos;
}