Package org.drools.core.util.asm

Examples of org.drools.core.util.asm.ClassFieldInspector$GetterOverloadWarning


        ByteArrayClassLoader byteArrayClassLoader = cache.getByteArrayClassLoader();
        Map<Class< ? >, ClassFieldInspector> inspectors = cache.getInspectors();
       
        try {
            // otherwise, bytecode generate a specific extractor
            ClassFieldInspector inspector = inspectors.get( clazz );
            if ( inspector == null ) {
                inspector = new ClassFieldInspector( clazz );
                inspectors.put( clazz,
                                inspector );
            }
            final Method setterMethod = (Method) inspector.getSetterMethods().get( fieldName );
            if ( setterMethod != null ) {
                final Class< ? > fieldType = setterMethod.getParameterTypes()[0];
                final String className = ClassFieldAccessorFactory.BASE_PACKAGE + "/" + Type.getInternalName( clazz ) + Math.abs( System.identityHashCode( clazz ) ) + "$" + setterMethod.getName();

                // generating byte array to create target class
                final byte[] bytes = dumpWriter( clazz,
                                                 className,
                                                 setterMethod,
                                                 fieldType,
                                                 clazz.isInterface() );
                // use bytes to get a class

                final Class< ? > newClass = byteArrayClassLoader.defineClass( className.replace( '/',
                                                                                                 '.' ),
                                                                              bytes,
                                                                              PROTECTION_DOMAIN );
                // instantiating target class
                final Integer index = (Integer) inspector.getFieldNames().get( fieldName );
                final ValueType valueType = ValueType.determineValueType( fieldType );
                final Object[] params = {index, fieldType, valueType};
                return (BaseClassFieldWriter) newClass.getConstructors()[0].newInstance( params );
            } else {
                throw new RuntimeDroolsException( "Field/method '" + fieldName + "' not found for class '" + clazz.getName() + "'" );
View Full Code Here


     * @param fieldName
     */
    public BaseClassFieldReader(final Class< ? > clazz,
                                final String fieldName) {
        try {
            final ClassFieldInspector inspector = new ClassFieldInspector( clazz );
            this.index = ((Integer) inspector.getFieldNames().get( fieldName )).intValue();
            this.fieldType = (Class< ? >) inspector.getFieldTypes().get( fieldName );
            this.valueType = ValueType.determineValueType( this.fieldType );
        } catch ( final Exception e ) {
            throw new RuntimeDroolsException( e );
        }
    }
View Full Code Here

        }

        // look for the class externally
        if ( !isSuperClassDeclared || isSuperClassTagged ) {
            try {
                ClassFieldInspector inspector = new ClassFieldInspector( registry.getTypeResolver().resolveType( fullSuper ) );
                for ( String name : inspector.getGetterMethods().keySet() ) {
                    if ( !inspector.isNonGetter( name ) && !"class".equals( name ) ) {
                        TypeFieldDescr inheritedFlDescr = new TypeFieldDescr( name,
                                                                              new PatternDescr( inspector.getFieldTypes().get( name ).getSimpleName() ) );
                        inheritedFlDescr.setInherited( true );
                        inheritedFlDescr.setIndex( inspector.getFieldNames().size() + inspector.getFieldNames().get( name ) );

                        if ( !fieldMap.containsKey( inheritedFlDescr.getFieldName() ) ) fieldMap.put( inheritedFlDescr.getFieldName(),
                                                                                                      inheritedFlDescr );
                    }
                }
View Full Code Here

                                                                    "this['']",
                                                                    6 );
                                    p.setImage( METHOD_ICON );
                                    list.add( p );
                                }
                                ClassFieldInspector inspector = new ClassFieldInspector( clazz );
                                Map types = inspector.getFieldTypes();
                                Iterator iterator2 = inspector.getFieldNames().keySet().iterator();
                                while ( iterator2.hasNext() ) {
                                    String name = (String) iterator2.next();
                                    p = new RuleCompletionProposal( documentOffset - prefix.length(),
                                                                    prefix.length(),
                                                                    name,
View Full Code Here

        ClassTypeResolver resolver = new ClassTypeResolver( getUniqueImports(),
                                                            ProjectClassLoader.getProjectClassLoader( getEditor() ) );
        try {
            Class clazz = resolver.resolveType( className );
            if ( clazz != null ) {
                Class clazzz = (Class) new ClassFieldInspector( clazz ).getFieldTypes().get( propertyName );
                if ( clazzz != null ) {
                    return clazzz.getName();
                }
            }
        } catch ( IOException exc ) {
View Full Code Here

                    superKlass = registry.getTypeResolver().resolveType(fullSuper);
                } else {
                    // if the supertype has not been declared, and we have got so far, it means that this class is not novel
                    superKlass = resolver.resolveType( fullSuper );
                }
                ClassFieldInspector inspector = new ClassFieldInspector(superKlass);
                for (String name : inspector.getGetterMethods().keySet()) {
                    // classFieldAccessor requires both getter and setter
                    if (inspector.getSetterMethods().containsKey(name)) {
                        if (!inspector.isNonGetter(name) && !"class".equals(name)) {
                            TypeFieldDescr inheritedFlDescr = new TypeFieldDescr(
                                    name,
                                    new PatternDescr(
                                            inspector.getFieldTypes().get(name).getName()));
                            inheritedFlDescr.setInherited(!Modifier.isAbstract(inspector.getGetterMethods().get(name).getModifiers()));

                            if (!fieldMap.containsKey(inheritedFlDescr.getFieldName()))
                                fieldMap.put(inheritedFlDescr.getFieldName(),
                                             inheritedFlDescr);
                        }
View Full Code Here

            if ( inferFields ) {
                // not novel, but only an empty declaration was provided.
                // after inheriting the fields from supertypes, now we fill in the locally declared fields
                try {
                Class existingClass = getExistingDeclarationClass( typeDescr );
                ClassFieldInspector inspector = new ClassFieldInspector( existingClass );
                    for (String name : inspector.getGetterMethods().keySet()) {
                        // classFieldAccessor requires both getter and setter
                        if (inspector.getSetterMethods().containsKey(name)) {
                            if (!inspector.isNonGetter(name) && !"class".equals(name)) {
                                TypeFieldDescr inheritedFlDescr = new TypeFieldDescr(
                                        name,
                                        new PatternDescr(
                                                inspector.getFieldTypes().get(name).getName()));
                                inheritedFlDescr.setInherited(!Modifier.isAbstract(inspector.getGetterMethods().get(name).getModifiers()));

                                if (!tDescr.getFields().containsKey(inheritedFlDescr.getFieldName()))
                                    tDescr.getFields().put(inheritedFlDescr.getFieldName(),
                                                 inheritedFlDescr);
                            }
View Full Code Here

                         !GeneratedFact.class.isAssignableFrom(existingDeclarationClass) &&
                         !type.getTypeClassDef().getFields().isEmpty()
                    ) {
                        try {
                            Class existingClass = pkgRegistry.getPackage().getTypeResolver().resolveType( typeDescr.getType().getFullName() );
                            ClassFieldInspector cfi = new ClassFieldInspector( existingClass );

                            int fieldCount = 0;
                            for ( String existingFieldName : cfi.getFieldTypesField().keySet() ) {
                                if ( ! cfi.isNonGetter( existingFieldName ) && ! "class".equals( existingFieldName ) && cfi.getSetterMethods().containsKey( existingFieldName ) ) {
                                    if ( ! typeDescr.getFields().containsKey( existingFieldName ) ) {
                                        type.setValid(false);
                                        kbuilder.addBuilderResult(new TypeDeclarationError(typeDescr, "New declaration of "+typeDescr.getType().getFullName() +
                                                                                                    " does not include field " + existingFieldName ) );
                                    } else {
                                        String fldType = cfi.getFieldTypes().get( existingFieldName ).getName();
                                        TypeFieldDescr declaredField = typeDescr.getFields().get( existingFieldName );
                                        if ( ! fldType.equals( type.getTypeClassDef().getField( existingFieldName ).getTypeName() ) ) {
                                            type.setValid(false);
                                            kbuilder.addBuilderResult(new TypeDeclarationError(typeDescr, "New declaration of "+typeDescr.getType().getFullName() +
                                                                                                         " redeclared field " + existingFieldName + " : \n" +
                                                                                                         "existing : " + fldType + " vs declared : " + declaredField.getPattern().getObjectType() ) );
                                        } else {
                                            fieldCount++;
                                        }

                                    }
                                }
                            }

                            if ( fieldCount != typeDescr.getFields().size() ) {
                                kbuilder.addBuilderResult(new TypeDeclarationError(typeDescr, "New declaration of "+typeDescr.getType().getFullName()
                                                                                             +" can't declaredeclares a different set of fields \n" +
                                                                                             "existing : " + cfi.getFieldTypesField() + "\n" +
                                                                                             "declared : " + typeDescr.getFields() ));

                            }
                        } catch ( IOException e ) {
                            e.printStackTrace();
View Full Code Here

    private void updateTraitDefinition(TypeDeclaration type,
                                       Class concrete) {
        try {

            ClassFieldInspector inspector = new ClassFieldInspector(concrete);
            Map<String, Method> methods = inspector.getGetterMethods();
            Map<String, Method> setters = inspector.getSetterMethods();
            int j = 0;
            for (String fieldName : methods.keySet()) {
                if ("core".equals(fieldName) || "fields".equals(fieldName)) {
                    continue;
                }
                if (!inspector.isNonGetter(fieldName) && setters.keySet().contains(fieldName)) {

                    Class ret = methods.get(fieldName).getReturnType();
                    FieldDefinition field = new FieldDefinition();
                    field.setName(fieldName);
                    field.setTypeName(ret.getName());
View Full Code Here

                return true;
            }
            if ( ! sup.getName().equals( typeDescr.getSupertTypeFullName() ) ) {
                return false;
            }
            ClassFieldInspector cfi = new ClassFieldInspector( typeClass, false );
            if ( cfi.getGetterMethods().size() != typeDescr.getFields().size() ) {
                return false;
            }
            for ( String fieldName : cfi.getFieldTypes().keySet() ) {
                if ( ! typeDescr.getFields().containsKey( fieldName ) ) {
                    return false;
                }
                String fieldTypeName = typeDescr.getFields().get( fieldName ).getPattern().getObjectType();
                Class fieldType = cfi.getFieldTypes().get( fieldName );
                if ( ! fieldTypeName.equals( fieldType.getName() ) || ! fieldTypeName.equals( fieldType.getSimpleName() ) ) {
                    return false;
                }
            }
View Full Code Here

TOP

Related Classes of org.drools.core.util.asm.ClassFieldInspector$GetterOverloadWarning

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.