Package org.ow2.asm

Examples of org.ow2.asm.FieldVisitor


     * @param cw
     * @param fieldDef
     */
    private void buildField(ClassWriter cw,
                            FieldDefinition fieldDef) {
        FieldVisitor fv;
        fv = cw.visitField( Opcodes.ACC_PRIVATE,
                            fieldDef.getName(),
                            getTypeDescriptor( fieldDef.getTypeName() ),
                            null,
                            null );
        fv.visitEnd();
    }
View Full Code Here


        Class coreKlazz = core.getDefinedClass();
        String coreName = coreKlazz.getName();
        String wrapperName = coreName + "Wrapper";

        ClassWriter cw = new ClassWriter( ClassWriter.COMPUTE_MAXS );
        FieldVisitor fv;
        MethodVisitor mv;

        cw.visit( ClassGenerator.JAVA_VERSION, ACC_PUBLIC + ACC_SUPER,
                BuildUtils.getInternalType( wrapperName ),
                BuildUtils.getTypeDescriptor( coreName ) +
                        "Lorg/drools/factmodel/traits/CoreWrapper<" + BuildUtils.getTypeDescriptor( coreName ) + ">;",
                BuildUtils.getInternalType( coreName ),
                new String[] { Type.getInternalName( CoreWrapper.class ), Type.getInternalName( Externalizable.class ) } );

        {
            AnnotationVisitor av0 = cw.visitAnnotation( Type.getDescriptor( Traitable.class ), true );
            av0.visit( "logical", core.isFullTraiting() );
        }

        {
            fv = cw.visitField( ACC_PRIVATE, "core", BuildUtils.getTypeDescriptor( coreName ), null, null);
            fv.visitEnd();
        }
        {
            fv = cw.visitField( ACC_PRIVATE, TraitableBean.MAP_FIELD_NAME, Type.getDescriptor( Map.class ), "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;", null );
            fv.visitEnd();
        }
        {
            fv = cw.visitField( ACC_PRIVATE, TraitableBean.TRAITSET_FIELD_NAME, Type.getDescriptor( Map.class ), "Ljava/util/Map<Ljava/lang/String;Lorg/drools/factmodel/traits/Thing;>;", null );
            fv.visitEnd();
        }
        {
            fv = cw.visitField( ACC_PRIVATE, TraitableBean.FIELDTMS_FIELD_NAME, Type.getDescriptor( TraitFieldTMS.class ), null, null );
            fv.visitEnd();
        }

        {
            mv = cw.visitMethod( ACC_PUBLIC, "<init>", "()V", null, null );
            mv.visitCode();
View Full Code Here

            InvocationTargetException,
            InstantiationException,
            NoSuchFieldException {

        ClassWriter cw = new ClassWriter( 0 );
        FieldVisitor fv;
        MethodVisitor mv;

        // get the method bitmask
        long mask = TraitRegistry.getInstance().getFieldMask( getTrait().getName(),
                                                              core.getDefinedClass().getName() );

        String name = TraitFactory.getPropertyWrapperName( getTrait(),
                                                           core );
        String masterName = TraitFactory.getProxyName( getTrait(),
                                                       core );

        String internalWrapper = BuildUtils.getInternalType( name );
        String internalProxy = BuildUtils.getInternalType( masterName );
        String descrWrapper = BuildUtils.getTypeDescriptor( name );
        String descrProxy = BuildUtils.getTypeDescriptor( masterName );

        String internalCore = BuildUtils.getInternalType( core.getClassName() );
        String descrCore = BuildUtils.getTypeDescriptor( core.getClassName() );
        String internalTrait = BuildUtils.getInternalType( getTrait().getClassName() );
        String descrTrait = BuildUtils.getTypeDescriptor( getTrait().getClassName() );

        Class mixinClass = null;
        String mixin = null;
        Set<Method> mixinMethods = new HashSet<Method>();
        Map<String, Method> mixinGetSet = new HashMap<String, Method>();
        try {
            if (getTrait().getDefinedClass() != null) {
                Trait annTrait = getAnnotation( getTrait().getDefinedClass(),
                                                Trait.class );
                if (annTrait != null && !annTrait.impl().equals( Trait.NullMixin.class )) {
                    mixinClass = annTrait.impl();
                    mixin = mixinClass.getSimpleName().substring( 0,
                                                                  1 ).toLowerCase() + mixinClass.getSimpleName().substring( 1 );
                    ClassFieldInspector cfi = new ClassFieldInspector( mixinClass );

                    for (Method m : mixinClass.getMethods()) {
                        try {
                            getTrait().getDefinedClass().getMethod( m.getName(),
                                                                    m.getParameterTypes() );
                            if (cfi.getGetterMethods().containsValue( m )
                                || cfi.getSetterMethods().containsValue( m )) {
                                mixinGetSet.put( m.getName(),
                                                 m );
                            } else {
                                mixinMethods.add( m );
                            }
                        } catch (NoSuchMethodException e) {

                        }
                    }

                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        cw.visit( V1_5,
                  ACC_PUBLIC + ACC_SUPER,
                  internalProxy,
                  null,
                  "org/drools/factmodel/traits/TraitProxy",
                  new String[] { internalTrait, "java/io/Externalizable" } );

        {
            fv = cw.visitField(ACC_PUBLIC + ACC_FINAL + ACC_TRANSIENT, "object", descrCore, null, null);
            fv.visitEnd();
        }
        {
            fv = cw.visitField(ACC_PRIVATE + ACC_TRANSIENT, "store", "Lorg/drools/core/util/TripleStore;", null, null);
            fv.visitEnd();
        }
        {
            fv = cw.visitField(ACC_PRIVATE, "storeId", "Ljava/lang/String;", null, null);
            fv.visitEnd();
        }
        if (mixinClass != null) {
            {
                fv = cw.visitField( ACC_PRIVATE,
                                    mixin,
                                    BuildUtils.getTypeDescriptor( mixinClass.getName() ),
                                    null,
                                    null );
                fv.visitEnd();
            }
        }
        {
            mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
            mv.visitCode();
View Full Code Here

        }

    }

    protected void buildProxyAccessor( long mask, ClassWriter cw, String masterName, ClassDefinition core, Map<String, Method> mixinGetSet, FieldDefinition field, boolean isSoftField ) {
        FieldVisitor fv;

        if (isSoftField) {
            if (!mixinGetSet.containsKey( BuildUtils.getterName( field.getName(),
                                                                 field.getTypeName() ) )) {
                buildSoftGetter( cw,
                                 field,
                                 masterName );
                buildSoftSetter( cw,
                                 field,
                                 masterName );
            } else {
                //
            }

        } else {
            {
                fv = cw.visitField( ACC_PUBLIC + ACC_STATIC,
                                    field.getName() + "_reader",
                                    "Lorg/drools/spi/InternalReadAccessor;",
                                    null,
                                    null );
                fv.visitEnd();
            }
            {
                fv = cw.visitField( ACC_PUBLIC + ACC_STATIC,
                                    field.getName() + "_writer",
                                    "Lorg/drools/spi/WriteAccessor;",
                                    null,
                                    null );
                fv.visitEnd();
            }

            buildHardGetter( cw,
                             field,
                             masterName,
View Full Code Here

                BuildUtils.getInternalTypes( classDef.getInterfaces() ) );

    }

    protected void buildLiterals(ClassWriter cw, EnumClassDefinition classDef) {
        FieldVisitor fv;
        for ( EnumLiteralDefinition lit : classDef.getEnumLiterals() ) {
            fv = cw.visitField( ACC_PUBLIC + ACC_FINAL + ACC_STATIC + ACC_ENUM,
                    lit.getName(),
                    BuildUtils.getTypeDescriptor( classDef.getClassName() ),
                    null,
                    null);
            fv.visitEnd();
        }

        {
            fv = cw.visitField( ACC_PRIVATE + ACC_FINAL + ACC_STATIC + ACC_SYNTHETIC,
                    "$VALUES",
                    "[" + BuildUtils.getTypeDescriptor( classDef.getClassName() ),
                    null,
                    null);
            fv.visitEnd();
        }
    }
View Full Code Here

        }
    }


    protected void buildFields(ClassWriter cw, EnumClassDefinition classDef) {
        FieldVisitor fv;
        for ( FieldDefinition fld : classDef.getFieldsDefinitions() ) {
            fv = cw.visitField( ACC_PRIVATE + ACC_FINAL,
                    fld.getName(),
                    BuildUtils.getTypeDescriptor( fld.getTypeName() ),
                    null,
                    null);
            fv.visitEnd();
        }

        {
            fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "$context", "Lorg/mvel2/ParserContext;", null, null);
            fv.visitEnd();
        }
    }
View Full Code Here

        Class coreKlazz = core.getDefinedClass();
        String coreName = coreKlazz.getName();
        String wrapperName = coreName + "Wrapper";

        ClassWriter cw = new ClassWriter(0);
        FieldVisitor fv;
        MethodVisitor mv;

        cw.visit(V1_5, ACC_PUBLIC + ACC_SUPER,
                BuildUtils.getInternalType(wrapperName),
                BuildUtils.getTypeDescriptor( coreName) +
                        "Lorg/drools/factmodel/traits/CoreWrapper<" + BuildUtils.getTypeDescriptor( coreName ) + ">;",
                BuildUtils.getInternalType( coreName ),
                new String[]{"org/drools/factmodel/traits/CoreWrapper", "java/io/Externalizable" });

        {
            fv = cw.visitField(ACC_PRIVATE, "core", BuildUtils.getTypeDescriptor( coreName ), null, null);
            fv.visitEnd();
        }
        {
            fv = cw.visitField(ACC_PRIVATE, TraitableBean.MAP_FIELD_NAME, "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;", null);
            fv.visitEnd();
        }
        {
            fv = cw.visitField(ACC_PRIVATE, TraitableBean.TRAITSET_FIELD_NAME, "Ljava/util/Map;", "Ljava/util/Map<Ljava/lang/String;Lorg/drools/factmodel/traits/Thing;>;", null);
            fv.visitEnd();
        }

        {
            mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
            mv.visitCode();
View Full Code Here

            InvocationTargetException,
            InstantiationException,
            NoSuchFieldException {


        FieldVisitor fv;
        MethodVisitor mv;

        // get the method bitmask
        BitSet mask = traitRegistry.getFieldMask( getTrait().getName(), core.getDefinedClass().getName() );

        String name = TraitFactory.getPropertyWrapperName( getTrait(), core );
        String masterName = TraitFactory.getProxyName( getTrait(), core );


        String internalWrapper  = BuildUtils.getInternalType( name );
        String internalProxy    = BuildUtils.getInternalType( masterName );

        String descrCore        = Type.getDescriptor( core.getDefinedClass() );
        String internalCore     = Type.getInternalName( core.getDefinedClass() );
        String internalTrait    = Type.getInternalName( getTrait().getDefinedClass() );


        Class mixinClass = null;
        String mixin = null;
        Set<Method> mixinMethods = new HashSet<Method>();
        Map<String,Method> mixinGetSet = new HashMap<String,Method>();
        try {
            if ( getTrait().getDefinedClass() != null ) {
                Trait annTrait = getAnnotation( getTrait().getDefinedClass(), Trait.class );
                if ( hasImpl( annTrait ) ) {
                    mixinClass = annTrait.impl();
                    mixin = mixinClass.getSimpleName().substring(0,1).toLowerCase() + mixinClass.getSimpleName().substring(1);
                    ClassFieldInspector cfi = new ClassFieldInspector( mixinClass );

                    for ( Method m : mixinClass.getMethods() ) {
                        try {
                            getTrait().getDefinedClass().getMethod(m.getName(), m.getParameterTypes() );
                            if ( cfi.getGetterMethods().containsValue( m )
                                    || cfi.getSetterMethods().containsValue( m )) {
                                mixinGetSet.put( m.getName(), m );
                            } else {
                                mixinMethods.add( m );
                            }
                        } catch (NoSuchMethodException e) {

                        }
                    }

                }
            }
        } catch ( Exception e ) {
            e.printStackTrace();
        }



        ClassWriter cw = createClassWriter( classLoader,
                                            ACC_PUBLIC + ACC_SUPER,
                                            internalProxy,
                                            null,
                                            Type.getInternalName( proxyBaseClass ),
                                            new String[]{ internalTrait, Type.getInternalName( Serializable.class ) } );

        {
            fv = cw.visitField( ACC_PRIVATE + ACC_FINAL + ACC_STATIC,
                    TraitType.traitNameField, Type.getDescriptor( String.class ),
                    null, null );
            fv.visitEnd();
        }

        {
            fv = cw.visitField( ACC_PUBLIC + ACC_FINAL, "object", descrCore, null, null );
            fv.visitEnd();
        }
        {
            fv = cw.visitField( ACC_PUBLIC + ACC_FINAL, "map", Type.getDescriptor( Map.class ), "Ljava/util/Map<Ljava/lang/String;Ljava/lang/Object;>;", null );
            fv.visitEnd();
        }

        if ( mixinClass != null ) {
            {
                fv = cw.visitField( ACC_PRIVATE,
                        mixin,
                        BuildUtils.getTypeDescriptor( mixinClass.getName() ),
                        null, null );
                fv.visitEnd();
            }
        }

        {
            mv = cw.visitMethod( ACC_STATIC, "<clinit>", "()V", null, null );
View Full Code Here

            InvocationTargetException,
            InstantiationException,
            NoSuchFieldException {


        FieldVisitor fv;
        MethodVisitor mv;

        // get the method bitmask
        BitSet mask = traitRegistry.getFieldMask( getTrait().getName(), core.getDefinedClass().getName() );

        String name = TraitFactory.getPropertyWrapperName( getTrait(), core );
        String masterName = TraitFactory.getProxyName( getTrait(), core );


        String internalWrapper  = BuildUtils.getInternalType(name);
        String internalProxy    = BuildUtils.getInternalType(masterName);

        String internalCore     = Type.getInternalName(core.getDefinedClass());
        String descrCore        = Type.getDescriptor(core.getDefinedClass());
        String internalTrait    = Type.getInternalName(getTrait().getDefinedClass());


        Class mixinClass = null;
        String mixin = null;
        Set<Method> mixinMethods = new HashSet<Method>();
        Map<String,Method> mixinGetSet = new HashMap<String,Method>();
        try {
            if ( getTrait().getDefinedClass() != null ) {
                Trait annTrait = getAnnotation( getTrait().getDefinedClass(), Trait.class );
                if ( hasImpl( annTrait ) ) {
                    mixinClass = annTrait.impl();
                    mixin = mixinClass.getSimpleName().substring(0,1).toLowerCase() + mixinClass.getSimpleName().substring(1);
                    ClassFieldInspector cfi = new ClassFieldInspector( mixinClass );

                    for ( Method m : mixinClass.getMethods() ) {
                        try {
                            getTrait().getDefinedClass().getMethod(m.getName(), m.getParameterTypes() );
                            if ( cfi.getGetterMethods().containsValue( m )
                                    || cfi.getSetterMethods().containsValue( m )) {
                                mixinGetSet.put( m.getName(), m );
                            } else {
                                mixinMethods.add( m );
                            }
                        } catch ( NoSuchMethodException e ) {

                        }
                    }

                }
            }
        } catch ( Exception e ) {
            e.printStackTrace();
        }


        ClassWriter cw = createClassWriter( classLoader,
                                            ACC_PUBLIC + ACC_SUPER,
                                            internalProxy,
                                            null,
                                            Type.getInternalName( proxyBaseClass ),
                                            new String[] { internalTrait, Type.getInternalName( Externalizable.class ) } );

        {
            fv = cw.visitField( ACC_PRIVATE + ACC_FINAL + ACC_STATIC,
                    TraitType.traitNameField, Type.getDescriptor( String.class ),
                    null, null );
            fv.visitEnd();
        }
        {
            fv = cw.visitField( ACC_PUBLIC, "object", descrCore, null, null );
            fv.visitEnd();
        }
        {
            fv = cw.visitField( ACC_PRIVATE, "store", Type.getDescriptor( TripleStore.class ), null, null );
            fv.visitEnd();
        }
        {
            fv = cw.visitField( ACC_PRIVATE, "storeId", Type.getDescriptor( String.class ), null, null);
            fv.visitEnd();
        }
        if ( mixinClass != null ) {
            {
                fv = cw.visitField( ACC_PRIVATE,
                        mixin,
                        Type.getDescriptor( mixinClass ),
                        null, null);
                fv.visitEnd();
            }
        }

        {
            mv = cw.visitMethod( ACC_STATIC, "<clinit>", "()V", null, null );
View Full Code Here

    }


    protected void buildProxyAccessor( BitSet mask, ClassWriter cw, String masterName, ClassDefinition core, Map<String,Method> mixinGetSet, FieldDefinition field, boolean isSoftField ) {
        FieldVisitor fv;

        if ( core.isFullTraiting() ) {
            buildLogicalGetter( cw, field, masterName, trait, core );
            if ( ! isSoftField ) {
                buildHardSetter( cw, field, masterName, trait, core );
View Full Code Here

TOP

Related Classes of org.ow2.asm.FieldVisitor

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.