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


Java FieldInfo类代码示例

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


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

示例1: atFieldRead

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
private void atFieldRead(CtField f) throws CompileError {
    FieldInfo finfo = f.getFieldInfo2();
    String type = finfo.getDescriptor();

    int i = 0;
    int dim = 0;
    char c = type.charAt(i);
    while (c == '[') {
        ++dim;
        c = type.charAt(++i);
    }

    arrayDim = dim;
    exprType = MemberResolver.descToType(c);

    if (c == 'L')
        className = type.substring(i + 1, type.indexOf(';', i + 1));
    else
        className = null;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:21,代码来源:TypeChecker.java

示例2: atFieldAssignCore

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
private void atFieldAssignCore(CtField f, boolean is_static, int fi,
                               boolean is2byte) throws CompileError {
    if (fi != 0) {
        if (is_static) {
           bytecode.add(PUTSTATIC);
           bytecode.growStack(is2byte ? -2 : -1);
        }
        else {
            bytecode.add(PUTFIELD);
            bytecode.growStack(is2byte ? -3 : -2);
        }
    
        bytecode.addIndex(fi);
    }
    else {
        CtClass declClass = f.getDeclaringClass();
        AccessorMaker maker = declClass.getAccessorMaker();
        // make should be non null.
        FieldInfo finfo = f.getFieldInfo2();
        MethodInfo minfo = maker.getFieldSetter(finfo, is_static);
        bytecode.addInvokestatic(declClass, minfo.getName(),
                                 minfo.getDescriptor());
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:25,代码来源:MemberCodeGen.java

示例3: atFieldRead

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
/**
 * Generates bytecode for reading a field value.
 * It returns a fieldref_info index or zero if the field is a private
 * one declared in an enclosing class. 
 */
private int atFieldRead(CtField f, boolean isStatic) throws CompileError {
    FieldInfo finfo = f.getFieldInfo2();
    boolean is2byte = setFieldType(finfo);
    AccessorMaker maker = isAccessibleField(f, finfo);
    if (maker != null) {
        MethodInfo minfo = maker.getFieldGetter(finfo, isStatic);
        bytecode.addInvokestatic(f.getDeclaringClass(), minfo.getName(),
                                 minfo.getDescriptor());
        return 0;
    }
    else {
        int fi = addFieldrefInfo(f, finfo);
        if (isStatic) {
            bytecode.add(GETSTATIC);
            bytecode.growStack(is2byte ? 2 : 1);
        }
        else {
            bytecode.add(GETFIELD);
            bytecode.growStack(is2byte ? 1 : 0);
        }

        bytecode.addIndex(fi);
        return fi;
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:31,代码来源:MemberCodeGen.java

示例4: isAccessibleField

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
/**
 * Returns null if the field is accessible.  Otherwise, it throws
 * an exception or it returns AccessorMaker if the field is a private
 * one declared in an enclosing class.
 */
private AccessorMaker isAccessibleField(CtField f, FieldInfo finfo)
    throws CompileError
{
    if (AccessFlag.isPrivate(finfo.getAccessFlags())
        && f.getDeclaringClass() != thisClass) {
        CtClass declClass = f.getDeclaringClass(); 
        if (isEnclosing(declClass, thisClass)) {
            AccessorMaker maker = declClass.getAccessorMaker();
            if (maker != null)
                return maker;
            else
                throw new CompileError("fatal error.  bug?");
        }
        else
            throw new CompileError("Field " + f.getName() + " in "
                                   + declClass.getName() + " is private.");
    }

    return null;    // accessible field
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:26,代码来源:MemberCodeGen.java

示例5: setFieldType

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
/**
 * Sets exprType, arrayDim, and className.
 *
 * @return true if the field type is long or double. 
 */
private boolean setFieldType(FieldInfo finfo) throws CompileError {
    String type = finfo.getDescriptor();

    int i = 0;
    int dim = 0;
    char c = type.charAt(i);
    while (c == '[') {
        ++dim;
        c = type.charAt(++i);
    }

    arrayDim = dim;
    exprType = MemberResolver.descToType(c);

    if (c == 'L')
        className = type.substring(i + 1, type.indexOf(';', i + 1));
    else
        className = null;

    boolean is2byte = dim == 0 && (c == 'J' || c == 'D');
    return is2byte;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:28,代码来源:MemberCodeGen.java

示例6: 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

示例7: 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

示例8: CtField

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
private CtField(String typeDesc, String name, CtClass clazz)
    throws CannotCompileException
{
    super(clazz);
    ClassFile cf = clazz.getClassFile2();
    if (cf == null)
        throw new CannotCompileException("bad declaring class: "
                                         + clazz.getName());

    fieldInfo = new FieldInfo(cf.getConstPool(), name, typeDesc);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:12,代码来源:CtField.java

示例9: hasAnnotation

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
/**
 * Returns true if the class has the specified annotation type.
 *
 * @param typeName      the name of annotation type.
 * @return <code>true</code> if the annotation is found, otherwise <code>false</code>.
 * @since 3.21
 */
public boolean hasAnnotation(String typeName) {
    FieldInfo fi = getFieldInfo2();
    AnnotationsAttribute ainfo = (AnnotationsAttribute)
                fi.getAttribute(AnnotationsAttribute.invisibleTag);  
    AnnotationsAttribute ainfo2 = (AnnotationsAttribute)
                fi.getAttribute(AnnotationsAttribute.visibleTag);  
    return CtClassType.hasAnnotationType(typeName, getDeclaringClass().getClassPool(),
                                         ainfo, ainfo2);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:17,代码来源:CtField.java

示例10: getAnnotations

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
private Object[] getAnnotations(boolean ignoreNotFound) throws ClassNotFoundException {
    FieldInfo fi = getFieldInfo2();
    AnnotationsAttribute ainfo = (AnnotationsAttribute)
                fi.getAttribute(AnnotationsAttribute.invisibleTag);  
    AnnotationsAttribute ainfo2 = (AnnotationsAttribute)
                fi.getAttribute(AnnotationsAttribute.visibleTag);  
    return CtClassType.toAnnotationType(ignoreNotFound, getDeclaringClass().getClassPool(),
                                        ainfo, ainfo2);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:10,代码来源:CtField.java

示例11: makeFieldCache

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
private void makeFieldCache(CtMember.Cache cache) {
    List list = getClassFile3(false).getFields();
    int n = list.size();
    for (int i = 0; i < n; ++i) {
        FieldInfo finfo = (FieldInfo)list.get(i);
        CtField newField = new CtField(finfo, this);
        cache.addField(newField);
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:10,代码来源:CtClassType.java

示例12: removeField

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
public void removeField(CtField f) throws NotFoundException {
    checkModify();
    FieldInfo fi = f.getFieldInfo2();
    ClassFile cf = getClassFile2();
    if (cf.getFields().remove(fi)) {
        getMembers().remove(f);
        gcConstPool = true;
    }
    else
        throw new NotFoundException(f.toString());
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:12,代码来源:CtClassType.java

示例13: addFieldrefInfo

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
private int addFieldrefInfo(CtField f, FieldInfo finfo) {
    ConstPool cp = bytecode.getConstPool();
    String cname = f.getDeclaringClass().getName();
    int ci = cp.addClassInfo(cname);
    String name = finfo.getName();
    String type = finfo.getDescriptor();
    return cp.addFieldrefInfo(ci, name, type);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:9,代码来源:MemberCodeGen.java

示例14: getFieldInfo

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
/**
 * Returns the FieldInfo representing the field in the class file.
 */
public FieldInfo getFieldInfo() {
    declaringClass.checkModify();
    return fieldInfo;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:8,代码来源:CtField.java

示例15: make

import scouter.javassist.bytecode.FieldInfo; //导入依赖的package包/类
private ClassFile make() throws CannotCompileException {
    ClassFile cf = new ClassFile(false, classname, superName);
    cf.setAccessFlags(AccessFlag.PUBLIC);
    setInterfaces(cf, interfaces, hasGetHandler ? Proxy.class : ProxyObject.class);
    ConstPool pool = cf.getConstPool();

    // legacy: we only add the static field for the default interceptor if caching is disabled
    if  (!factoryUseCache) {
        FieldInfo finfo = new FieldInfo(pool, DEFAULT_INTERCEPTOR, HANDLER_TYPE);
        finfo.setAccessFlags(AccessFlag.PUBLIC | AccessFlag.STATIC);
        cf.addField(finfo);
    }

    // handler is per instance
    FieldInfo finfo2 = new FieldInfo(pool, HANDLER, HANDLER_TYPE);
    finfo2.setAccessFlags(AccessFlag.PRIVATE);
    cf.addField(finfo2);

    // filter signature is per class
    FieldInfo finfo3 = new FieldInfo(pool, FILTER_SIGNATURE_FIELD, FILTER_SIGNATURE_TYPE);
    finfo3.setAccessFlags(AccessFlag.PUBLIC | AccessFlag.STATIC);
    cf.addField(finfo3);

    // the proxy class serial uid must always be a fixed value
    FieldInfo finfo4 = new FieldInfo(pool, SERIAL_VERSION_UID_FIELD, SERIAL_VERSION_UID_TYPE);
    finfo4.setAccessFlags(AccessFlag.PUBLIC | AccessFlag.STATIC| AccessFlag.FINAL);
    cf.addField(finfo4);
    
    // HashMap allMethods = getMethods(superClass, interfaces);
    // int size = allMethods.size();
    makeConstructors(classname, cf, pool, classname);

    ArrayList forwarders = new ArrayList();
    int s = overrideMethods(cf, pool, classname, forwarders);
    addClassInitializer(cf, pool, classname, s, forwarders);
    addSetter(classname, cf, pool);
    if (!hasGetHandler)
        addGetter(classname, cf, pool);

    if (factoryWriteReplace) {
        try {
            cf.addMethod(makeWriteReplace(pool));
        }
        catch (DuplicateMemberException e) {
            // writeReplace() is already declared in the super class/interfaces.
        }
    }

    thisClass = null;
    return cf;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:52,代码来源:ProxyFactory.java


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