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


Java FieldInfo.getConstPool方法代码示例

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


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

示例1: getter

import scouter.javassist.bytecode.FieldInfo; //导入方法依赖的package包/类
/**
 * Creates a public getter method.  The getter method returns the value
 * of the specified field in the class to which this method is added.
 * The created method is initially not static even if the field is
 * static.  Change the modifiers if the method should be static.
 *
 * @param methodName        the name of the getter
 * @param field             the field accessed.
 */
public static CtMethod getter(String methodName, CtField field)
    throws CannotCompileException
{
    FieldInfo finfo = field.getFieldInfo2();
    String fieldType = finfo.getDescriptor();
    String desc = "()" + fieldType;
    ConstPool cp = finfo.getConstPool();
    MethodInfo minfo = new MethodInfo(cp, methodName, desc);
    minfo.setAccessFlags(AccessFlag.PUBLIC);

    Bytecode code = new Bytecode(cp, 2, 1);
    try {
        String fieldName = finfo.getName();
        if ((finfo.getAccessFlags() & AccessFlag.STATIC) == 0) {
            code.addAload(0);
            code.addGetfield(Bytecode.THIS, fieldName, fieldType);
        }
        else
            code.addGetstatic(Bytecode.THIS, fieldName, fieldType);

        code.addReturn(field.getType());
    }
    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,代码行数:41,代码来源:CtNewMethod.java

示例2: setter

import scouter.javassist.bytecode.FieldInfo; //导入方法依赖的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: CtField

import scouter.javassist.bytecode.FieldInfo; //导入方法依赖的package包/类
/**
 * Creates a copy of the given field.
 * The created field must be added to a class
 * with <code>CtClass.addField()</code>.
 * An initial value of the field is specified
 * by a <code>CtField.Initializer</code> object.
 *
 * <p>If getter and setter methods are needed,
 * call <code>CtNewMethod.getter()</code> and 
 * <code>CtNewMethod.setter()</code>.
 *
 * @param src               the original field
 * @param declaring         the class to which the field will be added.
 * @see CtNewMethod#getter(String,CtField)
 * @see CtNewMethod#setter(String,CtField)
 * @see CtField.Initializer
 */
public CtField(CtField src, CtClass declaring)
    throws CannotCompileException
{
    this(src.fieldInfo.getDescriptor(), src.fieldInfo.getName(),
         declaring);
    java.util.ListIterator iterator
        = src.fieldInfo.getAttributes().listIterator();
    FieldInfo fi = fieldInfo;
    fi.setAccessFlags(src.fieldInfo.getAccessFlags());
    ConstPool cp = fi.getConstPool();
    while (iterator.hasNext()) {
        AttributeInfo ainfo = (AttributeInfo)iterator.next();
        fi.addAttribute(ainfo.copy(cp, null));
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:33,代码来源:CtField.java


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