当前位置: 首页>>代码示例>>Java>>正文


Java ConstPool.isConstructor方法代码示例

本文整理汇总了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;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:31,代码来源:CtConstructor.java

示例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;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:44,代码来源:TransformNewClass.java

示例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;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:55,代码来源:TransformNew.java


注:本文中的scouter.javassist.bytecode.ConstPool.isConstructor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。