Examples of BCField


Examples of serp.bytecode.BCField

        _pc.declareField(PRE + "FieldTypes", Class[].class).setStatic(true);
        _pc.declareField(PRE + "FieldFlags", byte[].class).setStatic(true);
        _pc.declareField(SUPER, Class.class).setStatic(true);
        if (_addVersionInitFlag && _meta.getVersionField() != null) {
            // protected transient boolean pcVersionInit;
            BCField field = _pc.declareField(VERSION_INIT_STR, boolean.class);
            field.makeProtected();
            field.setTransient(true);
        }
        if (_meta.getPCSuperclass() == null || getCreateSubclass()) {
            BCField field = _pc.declareField(SM, SMTYPE);
            field.makeProtected();
            field.setTransient(true);
        }
    }
View Full Code Here

Examples of serp.bytecode.BCField

        // if not already present, add a serialVersionUID field; if the instance
        // is detachable and uses detached state without a declared field,
        // can't add a serial version UID because we'll be adding extra fields
        // to the enhanced version
        BCField field = _pc.getDeclaredField("serialVersionUID");
        if (field == null) {
            Long uid = null;
            try {
                uid = ObjectStreamClass.lookup
                    (_meta.getDescribedType()).getSerialVersionUID();
            } catch (Throwable t) {
                // last-chance catch for bug #283 (which can happen
                // in a variety of ClassLoading environments)
                if (_log.isTraceEnabled())
                    _log.warn(_loc.get("enhance-uid-access", _meta), t);
                else
                    _log.warn(_loc.get("enhance-uid-access", _meta));
            }

            // if we couldn't access the serialVersionUID, we will have to
            // skip the override of that field and not be serialization
            // compatible with non-enhanced classes
            if (uid != null) {
                field = _pc.declareField("serialVersionUID", long.class);
                field.makePrivate();
                field.setStatic(true);
                field.setFinal(true);

                Code code = getOrCreateClassInitCode(false);
                code.beforeFirst();
                code.constant().setValue(uid.longValue());
                code.putstatic().setField(field);
View Full Code Here

Examples of serp.bytecode.BCField

        String name = null;
        String declarer = null;
        if (impl && detachField == null) {
            name = PRE + "DetachedState";
            declarer = _pc.getName();
            BCField field = _pc.declareField(name, Object.class);
            field.makePrivate();
            field.setTransient(true);
        } else if (impl) {
            name = detachField.getName();
            declarer = detachField.getDeclaringClass().getName();
        }
View Full Code Here

Examples of serp.bytecode.BCField

        // first, see if we can convert the attribute name to a field name
        String fieldName = toBackingFieldName(attrName);

        // next, find the field in the managed type hierarchy
        BCField field = null;
        outer: for (BCClass bc = _pc; bc != null; bc = bc.getSuperclassBC()) {
            BCField[] fields = AccessController
                .doPrivileged(J2DoPrivHelper.getBCClassFieldsAction(bc,
                    fieldName));
            for (int i = 0; i < fields.length; i++) {
                field = fields[i];
                // if we reach a field declared in this type, then this is the
                // most-masking field, and is the one that we want.
                if (fields[i].getDeclarer() == declarer) {
                    break outer;
                }
            }
        }

        if (getCreateSubclass() && code.getMethod().getDeclarer() == _pc
            && (field == null || !field.isPublic())) {
            // we're creating the subclass, not redefining the user type.

            // Reflection.getXXX(this, Reflection.findField(...));
            code.classconstant().setClass(declarer);
            code.constant().setValue(fieldName);
            code.constant().setValue(true);
            code.invokestatic().setMethod(Reflection.class,
                "findField", Field.class, new Class[] {
                Class.class, String.class, boolean.class });
            Class type = _meta.getField(attrName).getDeclaredType();
            try {
                code.invokestatic().setMethod(
                    getReflectionGetterMethod(type, Field.class));
            } catch (NoSuchMethodException e) {
                // should never happen
                throw new InternalException(e);
            }
            if (!type.isPrimitive() && type != Object.class)
                code.checkcast().setType(type);
        } else {
            code.getfield().setField(declarer.getName(), fieldName,
                field.getType().getName());
        }
    }
View Full Code Here

Examples of serp.bytecode.BCField

                getPCSuperclassMetaData()), PRE + "ReadUnmanaged", void.class,
                inargs);
        }

        // read declared unmanaged serializable fields
        BCField field;
        for (Iterator itr = unmgd.iterator(); itr.hasNext();) {
            field = (BCField) itr.next();
            readExternal(code, field.getName(), field.getType(), null);
        }
        code.vreturn();
        code.calculateMaxStack();
        code.calculateMaxLocals();
    }
View Full Code Here

Examples of serp.bytecode.BCField

                getPCSuperclassMetaData()), PRE + "WriteUnmanaged", void.class,
                outargs);
        }

        // write declared unmanaged serializable fields
        BCField field;
        for (Iterator itr = unmgd.iterator(); itr.hasNext();) {
            field = (BCField) itr.next();
            writeExternal(code, field.getName(), field.getType(), null);
        }
        code.vreturn();
        code.calculateMaxStack();
        code.calculateMaxLocals();
    }
View Full Code Here

Examples of serp.bytecode.BCField

     */
    private BCMethod createGetMethod(FieldMetaData fmd) {
        BCMethod getter;
        if (isFieldAccess(fmd)) {
            // static <fieldtype> pcGet<field> (XXX inst)
            BCField field = _pc.getDeclaredField(fmd.getName());
            getter = _pc.declareMethod(PRE + "Get" + fmd.getName(), fmd.
                getDeclaredType().getName(), new String[]{ _pc.getName() });
            getter.setAccessFlags(field.getAccessFlags()
                & ~Constants.ACCESS_TRANSIENT & ~Constants.ACCESS_VOLATILE);
            getter.setStatic(true);
            getter.setFinal(true);
            return getter;
        }
View Full Code Here

Examples of serp.bytecode.BCField

     */
    private BCMethod createSetMethod(FieldMetaData fmd) {
        BCMethod setter;
        if (isFieldAccess(fmd)) {
            // static void pcSet<field> (XXX inst, <fieldtype> value)
            BCField field = _pc.getDeclaredField(fmd.getName());
            setter = _pc.declareMethod(PRE + "Set" + fmd.getName(), void.class,
                new Class[]{ getType(_meta), fmd.getDeclaredType() });
            setter.setAccessFlags(field.getAccessFlags()
                & ~Constants.ACCESS_TRANSIENT & ~Constants.ACCESS_VOLATILE);
            setter.setStatic(true);
            setter.setFinal(true);
            return setter;
        }
View Full Code Here

Examples of serp.bytecode.BCField

     *
     * @param changeTracker whether to implement a null change tracker; if false
     * the change tracker method is left unimplemented
     */
    private void addProxyMethods(BCClass bc, boolean changeTracker) {
        BCField sm = bc.declareField("sm", OpenJPAStateManager.class);
        sm.setTransient(true);
        BCField field = bc.declareField("field", int.class);
        field.setTransient(true);

        BCMethod m = bc.declareMethod("setOwner", void.class, new Class[] {
            OpenJPAStateManager.class, int.class });
        m.makePublic();
        Code code = m.getCode(true);
View Full Code Here

Examples of serp.bytecode.BCField

    /**
     * Implement the methods in the {@link ProxyCollection} interface.
     */
    private void addProxyCollectionMethods(BCClass bc, Class type) {
        // change tracker
        BCField changeTracker = bc.declareField("changeTracker",
            CollectionChangeTracker.class);
        changeTracker.setTransient(true);
        BCMethod m = bc.declareMethod("getChangeTracker", ChangeTracker.class,
            null);
        m.makePublic();
        Code code = m.getCode(true);
        code.aload().setThis();
        code.getfield().setField(changeTracker);
        code.areturn();
        code.calculateMaxStack();
        code.calculateMaxLocals();

        // collection copy
        Constructor cons = findCopyConstructor(type);
        if (cons == null && SortedSet.class.isAssignableFrom(type))
            cons = findComparatorConstructor(type);
        Class[] params = (cons == null) ? new Class[0]
            : cons.getParameterTypes();

        m = bc.declareMethod("copy", Object.class, new Class[] {Object.class});
        m.makePublic();
        code = m.getCode(true);

        code.anew().setType(type);
        code.dup();
        if (params.length == 1) {
            code.aload().setParam(0);
            if (params[0] == Comparator.class) {
                code.checkcast().setType(SortedSet.class);
                code.invokeinterface().setMethod(SortedSet.class, "comparator",
                    Comparator.class, null);
            } else
                code.checkcast().setType(params[0]);
        }
        code.invokespecial().setMethod(type, "<init>", void.class, params);
        if (params.length == 0 || params[0] == Comparator.class) {
            code.dup();
            code.aload().setParam(0);
            code.checkcast().setType(Collection.class);
            code.invokevirtual().setMethod(type, "addAll", boolean.class,
                new Class[] { Collection.class });
            code.pop();
        }
        code.areturn();
        code.calculateMaxStack();
        code.calculateMaxLocals();

        // element type
        BCField elementType = bc.declareField("elementType", Class.class);
        elementType.setTransient(true);
        m = bc.declareMethod("getElementType", Class.class, null);
        m.makePublic();
        code = m.getCode(true);
        code.aload().setThis();
        code.getfield().setField(elementType);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.