Package javassist

Examples of javassist.CtField$CodeInitializer


    protected CtField fieldAccess(ASTree expr) throws CompileError {
        if (expr instanceof Member) {
            Member mem = (Member)expr;
            String name = mem.get();
            try {
                CtField f = thisClass.getField(name);
                if (Modifier.isStatic(f.getModifiers()))
                    mem.setField(f);

                return f;
            }
            catch (NotFoundException e) {
                // EXPR might be part of a static member access?
                throw new NoFieldException(name, expr);
            }
        }
        else if (expr instanceof Expr) {
            Expr e = (Expr)expr;
            int op = e.getOperator();
            if (op == MEMBER) {
                Member mem = (Member)e.oprand2();
                CtField f
                    = resolver.lookupField(((Symbol)e.oprand1()).get(), mem);
                mem.setField(f);
                return f;
            }
            else if (op == '.') {
View Full Code Here


        throw new CompileError("bad filed access");
    }

    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;
    }
View Full Code Here

        }
    }

    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;
    }
View Full Code Here

            CtField[] fields = m_class.getDeclaredFields();

            for (int i = 0; i < fields.length; i++) {

                CtField field = fields[i];

                m_fields.put(JavassistFieldInfo.calculateHash(field), new JavassistFieldInfo(

                    field,
View Full Code Here

            + TransformationUtil.DELIMITER
            + ctMethod.getDeclaringClass().getName().replace('.', '_');
        boolean hasField = false;
        CtField[] fields = ctClass.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            CtField field = fields[i];
            if (field.getName().equals(fieldName)) {
                hasField = true;
                break;
            }
        }
        if (!hasField) {
            CtField field = new CtField(ctClass.getClassPool().get("java.lang.Class"), fieldName, ctClass);
            field.setModifiers(Modifier.STATIC | Modifier.PRIVATE | Modifier.FINAL);
            ctClass.addField(field, "java.lang.Class#forName(\""
                + ctMethod.getDeclaringClass().getName().replace('/', '.')
                + "\")");
        }
        return fieldName;
View Full Code Here

            + TransformationUtil.DELIMITER
            + ctField.getDeclaringClass().getName().replace('.', '_');
        boolean hasField = false;
        CtField[] fields = ctClass.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            CtField field = fields[i];
            if (field.getName().equals(fieldName)) {
                hasField = true;
                break;
            }
        }
        if (!hasField) {
            CtField field = new CtField(ctClass.getClassPool().get("java.lang.Class"), fieldName, ctClass);
            field.setModifiers(Modifier.STATIC | Modifier.PRIVATE | Modifier.FINAL);
            ctClass.addField(field, "java.lang.Class#forName(\""
                + ctField.getDeclaringClass().getName().replace('/', '.')
                + "\")");
        }
        return fieldName;
View Full Code Here

                    loader,
                    m_attributeExtractor));
            }
            CtField[] fields = m_class.getDeclaredFields();
            for (int i = 0; i < fields.length; i++) {
                CtField field = fields[i];
                m_fields.put(JavassistFieldInfo.calculateHash(field), new JavassistFieldInfo(
                    field,
                    this,
                    loader,
                    m_attributeExtractor));
View Full Code Here

        }
        List attributes = new ArrayList();
        CtField[] fields = m_ctClass.getDeclaredFields();
        for (int i = 0; i < fields.length; i++) {
            if (fields[i].getName().equals(fieldName)) {
                CtField field = fields[i];
                for (Iterator it = field.getFieldInfo().getAttributes().iterator(); it.hasNext();) {
                    retrieveCustomAttributes((AttributeInfo) it.next(), attributes);
                }
            }
        }
        return attributes.toArray(new Object[attributes.size()]);
View Full Code Here

        CtClass javassistClass = ClassPool.getDefault().get(this.getClass().getName());
        // build a class with synthetic method, field, ctor
        javassistClass.setName(this.getClass().getName()+"Generated");
        int syntheticModifier = Constants.ACC_SYNTHETIC | Modifier.PUBLIC;
        javassistClass.addMethod(CtNewMethod.make(syntheticModifier, CtClass.intType, "syntheticDo", new CtClass[]{}, new CtClass[]{}, "{return 0;}", javassistClass));
        CtField field = new CtField(CtClass.intType, "syntheticField", javassistClass);
        field.setModifiers(syntheticModifier);
        javassistClass.addField(field);
        CtConstructor ctor = new CtConstructor(new CtClass[]{CtClass.intType}, javassistClass);
        ctor.setModifiers(syntheticModifier);
        ctor.setBody("{super();}");
        javassistClass.addConstructor(ctor);
View Full Code Here

    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;
    }
View Full Code Here

TOP

Related Classes of javassist.CtField$CodeInitializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.