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


Java CtField类代码示例

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


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

示例1: atFieldRead

import scouter.javassist.CtField; //导入依赖的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,项目名称:scouter,代码行数:21,代码来源:TypeChecker.java

示例2: atFieldAssignCore

import scouter.javassist.CtField; //导入依赖的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.CtField; //导入依赖的package包/类
protected void atFieldRead(ASTree expr) throws CompileError
{
    CtField f = fieldAccess(expr, true);
    if (f == null) {
        atArrayLength(expr);
        return;
    }

    boolean is_static = resultStatic;
    ASTree cexpr = TypeChecker.getConstantFieldValue(f);
    if (cexpr == null)
        atFieldRead(f, is_static);
    else {
        cexpr.accept(this);
        setFieldType(f.getFieldInfo2());
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:18,代码来源:MemberCodeGen.java

示例4: isAccessibleField

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

import scouter.javassist.CtField; //导入依赖的package包/类
protected void atFieldPlusPlus(int token, boolean isPost,
                               ASTree oprand, Expr expr, boolean doDup)
    throws CompileError
{
    CtField f = fieldAccess(oprand, false);
    boolean is_static = resultStatic;
    if (!is_static)
        bytecode.addOpcode(DUP);

    int fi = atFieldRead(f, is_static);
    int t = exprType;
    boolean is2w = is2word(t, arrayDim);

    int dup_code;
    if (is_static)
        dup_code = (is2w ? DUP2 : DUP);
    else
        dup_code = (is2w ? DUP2_X1 : DUP_X1);

    atPlusPlusCore(dup_code, doDup, token, isPost, expr);
    atFieldAssignCore(f, is_static, fi, is2w);
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:23,代码来源:MemberCodeGen.java

示例6: TransformFieldAccess

import scouter.javassist.CtField; //导入依赖的package包/类
public TransformFieldAccess(Transformer next, CtField field,
                            String newClassname, String newFieldname)
{
    super(next);
    this.fieldClass = field.getDeclaringClass();
    this.fieldname = field.getName();
    this.isPrivate = Modifier.isPrivate(field.getModifiers());
    this.newClassname = newClassname;
    this.newFieldname = newFieldname;
    this.constPool = null;
}
 
开发者ID:scouter-project,项目名称:bytescope,代码行数:12,代码来源:TransformFieldAccess.java

示例7: TransformReadField

import scouter.javassist.CtField; //导入依赖的package包/类
public TransformReadField(Transformer next, CtField field,
                          String methodClassname, String methodName)
{
    super(next);
    this.fieldClass = field.getDeclaringClass();
    this.fieldname = field.getName();
    this.methodClassname = methodClassname;
    this.methodName = methodName;
    this.isPrivate = Modifier.isPrivate(field.getModifiers());
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:11,代码来源:TransformReadField.java

示例8: isFieldInSuper

import scouter.javassist.CtField; //导入依赖的package包/类
static boolean isFieldInSuper(CtClass clazz, CtClass fclass, String fname) {
    if (!clazz.subclassOf(fclass))
        return false;

    try {
        CtField f = clazz.getField(fname);
        return f.getDeclaringClass() == fclass;
    }
    catch (NotFoundException e) {}
    return false;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:12,代码来源:TransformReadField.java

示例9: registerReflectiveClass

import scouter.javassist.CtField; //导入依赖的package包/类
/**
 * Registers a reflective class.  The field accesses to the instances
 * of this class are instrumented.
 */
private void registerReflectiveClass(CtClass clazz) {
    CtField[] fs = clazz.getDeclaredFields();
    for (int i = 0; i < fs.length; ++i) {
        CtField f = fs[i];
        int mod = f.getModifiers();
        if ((mod & Modifier.PUBLIC) != 0 && (mod & Modifier.FINAL) == 0) {
            String name = f.getName();
            converter.replaceFieldRead(f, clazz, readPrefix + name);
            converter.replaceFieldWrite(f, clazz, writePrefix + name);
        }
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:17,代码来源:Reflection.java

示例10: processFields

import scouter.javassist.CtField; //导入依赖的package包/类
private void processFields(CtClass clazz)
    throws CannotCompileException, NotFoundException
{
    CtField[] fs = clazz.getDeclaredFields();
    for (int i = 0; i < fs.length; ++i) {
        CtField f = fs[i];
        int mod = f.getModifiers();
        if ((mod & Modifier.PUBLIC) != 0 && (mod & Modifier.FINAL) == 0) {
            mod |= Modifier.STATIC;
            String name = f.getName();
            CtClass ftype = f.getType();
            CtMethod wmethod
                = CtNewMethod.wrapped(ftype, readPrefix + name,
                                      readParam, null, trapRead,
                                      CtMethod.ConstParameter.string(name),
                                      clazz);
            wmethod.setModifiers(mod);
            clazz.addMethod(wmethod);
            CtClass[] writeParam = new CtClass[2];
            writeParam[0] = classPool.get("java.lang.Object");
            writeParam[1] = ftype;
            wmethod = CtNewMethod.wrapped(CtClass.voidType,
                            writePrefix + name,
                            writeParam, null, trapWrite,
                            CtMethod.ConstParameter.string(name), clazz);
            wmethod.setModifiers(mod);
            clazz.addMethod(wmethod);
        }
    }
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:31,代码来源:Reflection.java

示例11: getField

import scouter.javassist.CtField; //导入依赖的package包/类
/**
 * Returns the field accessed by this expression.
 */
public CtField getField() throws NotFoundException {
    CtClass cc = getCtClass();
    int index = iterator.u16bitAt(currentPos + 1);
    ConstPool cp = getConstPool();
    return cc.getField(cp.getFieldrefName(index), cp.getFieldrefType(index));
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:10,代码来源:FieldAccess.java

示例12: lookupField

import scouter.javassist.CtField; //导入依赖的package包/类
/**
 * @param className      a qualified class name. e.g. java.lang.String
 */
public CtField lookupField(String className, Symbol fieldName)
    throws CompileError
{
    CtClass cc = lookupClass(className, false);
    try {
        return cc.getField(fieldName.get());
    }
    catch (NotFoundException e) {}
    throw new CompileError("no such field: " + fieldName.get());
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:14,代码来源:MemberResolver.java

示例13: atFieldAssign

import scouter.javassist.CtField; //导入依赖的package包/类
protected void atFieldAssign(Expr expr, int op, ASTree left, ASTree right)
    throws CompileError
{
    CtField f = fieldAccess(left);
    atFieldRead(f);
    int fType = exprType;
    int fDim = arrayDim;
    String cname = className;
    right.accept(this);
    exprType = fType;
    arrayDim = fDim;
    className = cname;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:14,代码来源:TypeChecker.java

示例14: fieldAccess2

import scouter.javassist.CtField; //导入依赖的package包/类
private CtField fieldAccess2(Expr e, String jvmClassName) throws CompileError {
    Member fname = (Member)e.oprand2();
    CtField f = resolver.lookupFieldByJvmName2(jvmClassName, fname, e);
    e.setOperator(MEMBER);
    e.setOprand1(new Symbol(MemberResolver.jvmToJavaName(jvmClassName)));
    fname.setField(f);
    return f;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:9,代码来源:TypeChecker.java

示例15: atFieldPlusPlus

import scouter.javassist.CtField; //导入依赖的package包/类
protected void atFieldPlusPlus(ASTree oprand) throws CompileError
{
    CtField f = fieldAccess(oprand);
    atFieldRead(f);
    int t = exprType;
    if (t == INT || t == BYTE || t == CHAR || t == SHORT)
        exprType = INT;
}
 
开发者ID:scouter-project,项目名称:scouter,代码行数:9,代码来源:TypeChecker.java


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