Package org.drools.lang.descr

Examples of org.drools.lang.descr.TypeDeclarationDescr


public class DeclareDescrBuilderImpl extends BaseDescrBuilderImpl<TypeDeclarationDescr>
    implements
    DeclareDescrBuilder {

    protected DeclareDescrBuilderImpl() {
        super( new TypeDeclarationDescr() );
    }
View Full Code Here


        /** now we do the dynamic facts - the declared types */
        Set<String> declaredTypes = new HashSet<String>();

        for ( final Iterator<TypeDeclarationDescr> it = pkgDescr.getTypeDeclarations().iterator(); it.hasNext(); ) {
            TypeDeclarationDescr td = it.next();
            declaredTypes.add( td.getTypeName() );
        }

        for ( final Iterator<TypeDeclarationDescr> it = pkgDescr.getTypeDeclarations().iterator(); it.hasNext(); ) {
            TypeDeclarationDescr td = it.next();

            if ( td.getFields().size() > 0 ) {
                //add the type to the map
                String declaredType = td.getTypeName();

                this.builder.addFactType( declaredType,
                                          FIELD_CLASS_TYPE.TYPE_DECLARATION_CLASS);
                List<String> fieldNames = new ArrayList<String>();
                for ( Map.Entry<String, TypeFieldDescr> f : td.getFields().entrySet() ) {
                    String fieldName = f.getKey();
                    fieldNames.add( fieldName );
                    String fieldClass = f.getValue().getPattern().getObjectType();

                    if ( declaredTypes.contains( fieldClass ) ) {
View Full Code Here

        /** now we do the dynamic facts - the declared types */
        Set<String> declaredTypes = new HashSet<String>();

        for ( final Iterator<TypeDeclarationDescr> it = pkgDescr.getTypeDeclarations().iterator(); it.hasNext(); ) {
            TypeDeclarationDescr td = it.next();
            declaredTypes.add( td.getTypeName() );
        }

        for ( final Iterator<TypeDeclarationDescr> it = pkgDescr.getTypeDeclarations().iterator(); it.hasNext(); ) {
            TypeDeclarationDescr td = it.next();

            if ( td.getFields().size() > 0 ) {
                //add the type to the map
                String declaredType = td.getTypeName();

                this.builder.addFactType( declaredType,
                                          FIELD_CLASS_TYPE.TYPE_DECLARATION_CLASS);
                List<String> fieldNames = new ArrayList<String>();
                for ( Map.Entry<String, TypeFieldDescr> f : td.getFields().entrySet() ) {
                    String fieldName = f.getKey();
                    fieldNames.add( fieldName );
                    String fieldClass = f.getValue().getPattern().getObjectType();

                    if ( declaredTypes.contains( fieldClass ) ) {
View Full Code Here

                    if (!Thing.class.isAssignableFrom( resolvedType )) {
                        updateTraitDefinition( type,
                                               resolvedType );

                        String target = typeDescr.getTypeName() + TraitFactory.SUFFIX;
                        TypeDeclarationDescr tempDescr = new TypeDeclarationDescr();
                        tempDescr.setNamespace( typeDescr.getNamespace() );
                        tempDescr.setFields( typeDescr.getFields() );
                        tempDescr.setType( target,
                                           typeDescr.getNamespace() );
                        tempDescr.addSuperType( typeDescr.getType() );
                        TypeDeclaration tempDeclr = new TypeDeclaration( target );
                        tempDeclr.setFormat( TypeDeclaration.Format.TRAIT );
                        tempDeclr.setTypesafe( type.isTypesafe() );
                        tempDeclr.setNovel( true );
                        tempDeclr.setTypeClassName( tempDescr.getType().getFullName() );
                        tempDeclr.setResource( type.getResource() );

                        ClassDefinition tempDef = new ClassDefinition( target );
                        tempDef.setClassName( tempDescr.getType().getFullName() );
                        tempDef.setTraitable( false );
                        for (FieldDefinition fld : def.getFieldsDefinitions()) {
                            tempDef.addField( fld );
                        }
                        tempDef.setInterfaces( def.getInterfaces() );
View Full Code Here

    private List<TypeDeclarationDescr> getDeclaredTypeHierachy(TypeDeclarationDescr td,
                                                               List< ? > jars) {
        List<TypeDeclarationDescr> th = new ArrayList<TypeDeclarationDescr>();
        th.add( td );
        TypeDeclarationDescr std;
        while ( (std = getDeclaredSuperType( td )) != null ) {
            th.add( std );
            td = std;
        }

        //If the super-most class has been imported attempt to make a pseudo TypeDeclaration for the imported class
        if ( this.pkgDescr.getImports().size() > 0 ) {
            for ( ImportDescr imp : this.pkgDescr.getImports() ) {
                if ( imp.getTarget().endsWith( "." + td.getTypeName() ) ) {
                    TypeDeclarationDescr pseudoTypeDeclr = makePseudoTypeDeclarationDescrFromSuperClassType( imp.getTarget(),
                                                                                                             jars );
                    if ( pseudoTypeDeclr != null ) {
                        th.add( pseudoTypeDeclr );
                    }
                }
View Full Code Here

            Method[] methods = clazz.getMethods();
            Map<String, MethodSignature> methodSignatures = getMethodSignatures( className,
                                                                                 methods );

            TypeDeclarationDescr td = new TypeDeclarationDescr();
            td.setTypeName( className );

            for ( Map.Entry<String, MethodSignature> e : methodSignatures.entrySet() ) {
                if ( e.getValue().accessorAndMutator == FieldAccessorsAndMutators.BOTH ) {
                    String fieldShortName = getShortNameOfClass( e.getKey() );
                    TypeFieldDescr fieldDescr = new TypeFieldDescr( fieldShortName );
                    PatternDescr patternDescr = new PatternDescr( e.getValue().returnType.getName() );
                    fieldDescr.setPattern( patternDescr );
                    td.addField( fieldDescr );
                }
            }
            return td;

        }
View Full Code Here

    }

    @Test
    public void testTypeDeclaration() throws Exception {
        PackageDescr pkgDescr = new PackageDescr( "org.drools" );
        TypeDeclarationDescr typeDescr = new TypeDeclarationDescr( "StockTick" );
        typeDescr.addAnnotation( TypeDeclaration.Role.ID,
                                    "event" );
        typeDescr.addAnnotation( TypeDeclaration.ATTR_CLASS,
                                    "org.drools.StockTick" );
        pkgDescr.addTypeDeclaration( typeDescr );

        PackageBuilder builder = new PackageBuilder();
        builder.addPackage( pkgDescr );
View Full Code Here

    }

    @Test
    public void testTypeDeclarationNewBean() throws Exception {
        PackageDescr pkgDescr = new PackageDescr( "org.test" );
        TypeDeclarationDescr typeDescr = new TypeDeclarationDescr( "NewBean" );

        TypeFieldDescr f1 = new TypeFieldDescr( "name",
                                                new PatternDescr( "String" ) );
        TypeFieldDescr f2 = new TypeFieldDescr( "age",
                                                new PatternDescr( "int" ) );

        typeDescr.addField( f1 );
        typeDescr.addField( f2 );

        pkgDescr.addTypeDeclaration( typeDescr );

        PackageBuilder builder = new PackageBuilder();
        builder.addPackage( pkgDescr );
View Full Code Here

    @Test
    public void testTimeWindowBehavior() throws Exception {
        final PackageBuilder builder = new PackageBuilder();

        final PackageDescr packageDescr = new PackageDescr( "p1" );
        final TypeDeclarationDescr typeDeclDescr = new TypeDeclarationDescr( StockTick.class.getName() );
        typeDeclDescr.addAnnotation( "role",
                                     "event" );
        packageDescr.addTypeDeclaration( typeDeclDescr );
        final RuleDescr ruleDescr = new RuleDescr( "rule-1" );
        packageDescr.addRule( ruleDescr );
View Full Code Here

                     + "cheese : String \n"
                     + "end";

        DrlParser parser = new DrlParser();
        PackageDescr pkgDescr = parser.parse( drl );
        TypeDeclarationDescr bean1Type = pkgDescr.getTypeDeclarations().get( 0 );
        assertNull( bean1Type.getSuperTypeName() );

        TypeDeclarationDescr bean2Type = pkgDescr.getTypeDeclarations().get( 1 );
        assertEquals( "Bean1",
                      bean2Type.getSuperTypeName() );
    }
View Full Code Here

TOP

Related Classes of org.drools.lang.descr.TypeDeclarationDescr

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.