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


Java CodeAttribute.getAttribute方法代码示例

本文整理汇总了Java中scouter.javassist.bytecode.CodeAttribute.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java CodeAttribute.getAttribute方法的具体用法?Java CodeAttribute.getAttribute怎么用?Java CodeAttribute.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scouter.javassist.bytecode.CodeAttribute的用法示例。


在下文中一共展示了CodeAttribute.getAttribute方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addLocalVariable

import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
/**
 * Declares a new local variable.  The scope of this variable is the
 * whole method body.  The initial value of that variable is not set.
 * The declared variable can be accessed in the code snippet inserted
 * by <code>insertBefore()</code>, <code>insertAfter()</code>, etc.
 *
 * <p>If the second parameter <code>asFinally</code> to
 * <code>insertAfter()</code> is true, the declared local variable
 * is not visible from the code inserted by <code>insertAfter()</code>.
 *
 * @param name      the name of the variable
 * @param type      the type of the variable
 * @see #insertBefore(String)
 * @see #insertAfter(String)
 */
public void addLocalVariable(String name, CtClass type)
    throws CannotCompileException
{
    declaringClass.checkModify();
    ConstPool cp = methodInfo.getConstPool();
    CodeAttribute ca = methodInfo.getCodeAttribute();
    if (ca == null)
        throw new CannotCompileException("no method body");

    LocalVariableAttribute va = (LocalVariableAttribute)ca.getAttribute(
                                            LocalVariableAttribute.tag);
    if (va == null) {
        va = new LocalVariableAttribute(cp);
        ca.getAttributes().add(va);
    }

    int maxLocals = ca.getMaxLocals();
    String desc = Descriptor.of(type);
    va.addEntry(0, ca.getCodeLength(),
                cp.addUtf8Info(name), cp.addUtf8Info(desc), maxLocals);
    ca.setMaxLocals(maxLocals + Descriptor.dataSize(desc));
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:38,代码来源:CtBehavior.java

示例2: recordLocalVariables

import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
/**
 * Records local variables available at the specified program counter.
 * If the LocalVariableAttribute is not available, this method does not
 * record any local variable.  It only returns false.
 *
 * @param pc    program counter (&gt;= 0)
 * @return false if the CodeAttribute does not include a
 *              LocalVariableAttribute.
 */
public boolean recordLocalVariables(CodeAttribute ca, int pc)
    throws CompileError
{
    LocalVariableAttribute va
        = (LocalVariableAttribute)
          ca.getAttribute(LocalVariableAttribute.tag);
    if (va == null)
        return false;

    int n = va.tableLength();
    for (int i = 0; i < n; ++i) {
        int start = va.startPc(i);
        int len = va.codeLength(i);
        if (start <= pc && pc < start + len)
            gen.recordVariable(va.descriptor(i), va.variableName(i),
                               va.index(i), stable);
    }

    return true;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:30,代码来源:Javac.java

示例3: recordParamNames

import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
/**
 * Records parameter names if the LocalVariableAttribute is available.
 * It returns false unless the LocalVariableAttribute is available.
 *
 * @param numOfLocalVars    the number of local variables used
 *                          for storing the parameters.
 * @return false if the CodeAttribute does not include a
 *              LocalVariableAttribute.
 */
public boolean recordParamNames(CodeAttribute ca, int numOfLocalVars)
    throws CompileError
{
    LocalVariableAttribute va
        = (LocalVariableAttribute)
          ca.getAttribute(LocalVariableAttribute.tag);
    if (va == null)
        return false;

    int n = va.tableLength();
    for (int i = 0; i < n; ++i) {
        int index = va.index(i);
        if (index < numOfLocalVars)
            gen.recordVariable(va.descriptor(i), va.variableName(i),
                               index, stable);
    }

    return true;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:29,代码来源:Javac.java

示例4: addParameter2

import scouter.javassist.bytecode.CodeAttribute; //导入方法依赖的package包/类
private void addParameter2(int where, CtClass type, String desc)
    throws BadBytecode
{
    CodeAttribute ca = methodInfo.getCodeAttribute();
    if (ca != null) {
        int size = 1;
        char typeDesc = 'L';
        int classInfo = 0;
        if (type.isPrimitive()) {
            CtPrimitiveType cpt = (CtPrimitiveType)type;
            size = cpt.getDataSize();
            typeDesc = cpt.getDescriptor();
        }
        else
            classInfo = methodInfo.getConstPool().addClassInfo(type);

        ca.insertLocalVar(where, size);
        LocalVariableAttribute va
            = (LocalVariableAttribute)ca.getAttribute(LocalVariableAttribute.tag);
        if (va != null)
            va.shiftIndex(where, size);

        LocalVariableTypeAttribute lvta
            = (LocalVariableTypeAttribute)ca.getAttribute(LocalVariableTypeAttribute.tag);
        if (lvta != null)
            lvta.shiftIndex(where, size);

        StackMapTable smt = (StackMapTable)ca.getAttribute(StackMapTable.tag);
        if (smt != null)
            smt.insertLocal(where, StackMapTable.typeTagOf(typeDesc), classInfo);

        StackMap sm = (StackMap)ca.getAttribute(StackMap.tag);
        if (sm != null)
            sm.insertLocal(where, StackMapTable.typeTagOf(typeDesc), classInfo);
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:37,代码来源:CtBehavior.java


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