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


Java Bytecode.addPutfield方法代码示例

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


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

示例1: compile

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
/**
 * Produces codes in which a new object is created and assigned to
 * the field as the initial value.
 */
int compile(CtClass type, String name, Bytecode code,
            CtClass[] parameters, Javac drv)
    throws CannotCompileException
{
    int stacksize;

    code.addAload(0);
    code.addNew(objectType);
    code.add(Bytecode.DUP);
    code.addAload(0);

    if (stringParams == null)
        stacksize = 4;
    else
        stacksize = compileStringParameter(code) + 4;

    if (withConstructorParams)
        stacksize += CtNewWrappedMethod.compileParameterList(code,
                                                    parameters, 1);

    code.addInvokespecial(objectType, "<init>", getDescriptor());
    code.addPutfield(Bytecode.THIS, name, Descriptor.of(type));
    return stacksize;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:29,代码来源:CtField.java

示例2: setter

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
/**
 * Creates a public setter method.  The setter method assigns the
 * value of the first parameter to the specified field
 * in the class to which this method is added.
 * The created method is not static even if the field is
 * static.  You may not change it to be static
 * by <code>setModifiers()</code> in <code>CtBehavior</code>.
 *
 * @param methodName        the name of the setter
 * @param field             the field accessed.
 */
public static CtMethod setter(String methodName, CtField field)
    throws CannotCompileException
{
    FieldInfo finfo = field.getFieldInfo2();
    String fieldType = finfo.getDescriptor();
    String desc = "(" + fieldType + ")V";
    ConstPool cp = finfo.getConstPool();
    MethodInfo minfo = new MethodInfo(cp, methodName, desc);
    minfo.setAccessFlags(AccessFlag.PUBLIC);

    Bytecode code = new Bytecode(cp, 3, 3);
    try {
        String fieldName = finfo.getName();
        if ((finfo.getAccessFlags() & AccessFlag.STATIC) == 0) {
            code.addAload(0);
            code.addLoad(1, field.getType());
            code.addPutfield(Bytecode.THIS, fieldName, fieldType);
        }
        else {
            code.addLoad(1, field.getType());
            code.addPutstatic(Bytecode.THIS, fieldName, fieldType);
        }

        code.addReturn(null);
    }
    catch (NotFoundException e) {
        throw new CannotCompileException(e);
    }

    minfo.setCodeAttribute(code.toCodeAttribute());
    CtClass cc = field.getDeclaringClass();
    // a stack map is not needed.
    return new CtMethod(minfo, cc);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:46,代码来源:CtNewMethod.java

示例3: addSetter

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static void addSetter(String classname, ClassFile cf, ConstPool cp)
    throws CannotCompileException
{
    MethodInfo minfo = new MethodInfo(cp, HANDLER_SETTER,
                                      HANDLER_SETTER_TYPE);
    minfo.setAccessFlags(AccessFlag.PUBLIC);
    Bytecode code = new Bytecode(cp, 2, 2);
    code.addAload(0);
    code.addAload(1);
    code.addPutfield(classname, HANDLER, HANDLER_TYPE);
    code.addOpcode(Bytecode.RETURN);
    minfo.setCodeAttribute(code.toCodeAttribute());
    cf.addMethod(minfo);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:15,代码来源:ProxyFactory.java

示例4: makeConstructor

import scouter.javassist.bytecode.Bytecode; //导入方法依赖的package包/类
private static MethodInfo makeConstructor(String thisClassName, Constructor cons,
                                          ConstPool cp, Class superClass, boolean doHandlerInit) {
    String desc = RuntimeSupport.makeDescriptor(cons.getParameterTypes(),
                                                Void.TYPE);
    MethodInfo minfo = new MethodInfo(cp, "<init>", desc);
    minfo.setAccessFlags(Modifier.PUBLIC);      // cons.getModifiers() & ~Modifier.NATIVE
    setThrows(minfo, cp, cons.getExceptionTypes());
    Bytecode code = new Bytecode(cp, 0, 0);

    // legacy: if we are not using caching then we initialise the instance's handler
    // from the class's static default interceptor and skip the next few instructions if
    // it is non-null
    if (doHandlerInit) {
        code.addAload(0);
        code.addGetstatic(thisClassName, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
        code.addPutfield(thisClassName, HANDLER, HANDLER_TYPE);
        code.addGetstatic(thisClassName, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
        code.addOpcode(Opcode.IFNONNULL);
        code.addIndex(10);
    }
    // if caching is enabled then we don't have a handler to initialise so this else branch will install
    // the handler located in the static field of class RuntimeSupport.
    code.addAload(0);
    code.addGetstatic(NULL_INTERCEPTOR_HOLDER, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
    code.addPutfield(thisClassName, HANDLER, HANDLER_TYPE);
    int pc = code.currentPc();

    code.addAload(0);
    int s = addLoadParameters(code, cons.getParameterTypes(), 1);
    code.addInvokespecial(superClass.getName(), "<init>", desc);
    code.addOpcode(Opcode.RETURN);
    code.setMaxLocals(s + 1);
    CodeAttribute ca = code.toCodeAttribute();
    minfo.setCodeAttribute(ca);

    StackMapTable.Writer writer = new StackMapTable.Writer(32);
    writer.sameFrame(pc);
    ca.setAttribute(writer.toStackMapTable(cp));
    return minfo;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:41,代码来源:ProxyFactory.java


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