Search in sources :

Example 1 with SimpleEntity

use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.

the class ModelInfo method addInheritedFeatures.

protected void addInheritedFeatures(SimpleEntity entity, Types types, Set<String> entityTypes, Map<String, Set<String>> entityFeatures) {
    ScannerIterator<IEntity> i = IteratorFactory.childReverseScannerIterator();
    i.reset(types);
    for (IEntity type : i) {
        String typeName = type.wStringValue();
        entityTypes.remove(typeName);
        SimpleEntity declaration = (SimpleEntity) nameEntityMap.get(typeName);
        if (declaration != null) {
            ScannerIterator<Feature> i2 = IteratorFactory.<Feature>childReverseScannerIterator();
            i2.reset(declaration.getFeatures());
            for (Feature feature : i2) {
                if (entityFeatures.get(entity.getName().wStringValue()).add(feature.getName().wStringValue()))
                    entity.getFeatures().wAdd(0, EntityUtils.clone(feature));
            }
            addInheritedFeatures(entity, declaration.getTypes(), entityTypes, entityFeatures);
        }
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) SimpleEntity(org.whole.lang.models.model.SimpleEntity) Feature(org.whole.lang.models.model.Feature)

Example 2 with SimpleEntity

use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.

the class ModelInfo method sortFeatures.

public void sortFeatures(Model model) {
    for (String entityName : simpleEntityTypes) {
        SimpleEntity e = (SimpleEntity) nameEntityMap.get(entityName);
        Features features = e.getFeatures();
        Collections.sort(features, new Comparator<Feature>() {

            public int compare(Feature f1, Feature f2) {
                boolean f1IsReference = f1.getModifiers().wContainsValue(FeatureModifierEnum.reference);
                boolean f2IsReference = f2.getModifiers().wContainsValue(FeatureModifierEnum.reference);
                if (f2IsReference)
                    return f1IsReference ? 0 : -1;
                else
                    return !f1IsReference ? 0 : +1;
            }
        });
    }
}
Also used : SimpleEntity(org.whole.lang.models.model.SimpleEntity) Features(org.whole.lang.models.model.Features) Feature(org.whole.lang.models.model.Feature)

Example 3 with SimpleEntity

use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.

the class ModelInfo method addInheritedFeatures.

public void addInheritedFeatures(Model model) {
    for (String entityName : simpleEntityTypes) {
        SimpleEntity e = (SimpleEntity) nameEntityMap.get(entityName);
        addInheritedFeatures(e, e.getTypes(), new HashSet<String>(simpleEntityTypes), simpleEntityFeatures);
    }
}
Also used : SimpleEntity(org.whole.lang.models.model.SimpleEntity)

Example 4 with SimpleEntity

use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.

the class ControlQueriesTest method testChoose4.

@Test
public void testChoose4() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("choose4");
    int i = 0;
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model, bm);
    while (iterator.hasNext()) {
        IEntity result = iterator.next();
        assertSame(result, bm.wGet("type"));
        assertTrue(result instanceof ClassDeclaration);
        ClassDeclaration classDecl = (ClassDeclaration) result;
        IEntity decl = decls.wGet(i++);
        String name = "", superClassName = "";
        switch(decl.wGetEntityOrd()) {
            case ModelsEntityDescriptorEnum.SimpleEntity_ord:
                SimpleEntity simpleEntity = (SimpleEntity) decl;
                name = simpleEntity.getName().wStringValue();
                superClassName = "AbstractSimpleEntity";
                break;
            case ModelsEntityDescriptorEnum.CompositeEntity_ord:
                CompositeEntity compositeEntity = (CompositeEntity) decl;
                name = compositeEntity.getName().wStringValue();
                superClassName = "AbstractCompositeEntity";
                break;
            case ModelsEntityDescriptorEnum.DataEntity_ord:
                DataEntity dataEntity = (DataEntity) decl;
                name = dataEntity.getName().wStringValue();
                superClassName = "AbstractDataEntity";
                break;
            case ModelsEntityDescriptorEnum.EnumEntity_ord:
                EnumEntity enumEntity = (EnumEntity) decl;
                name = enumEntity.getName().wStringValue();
                superClassName = "AbstractEnumEntity";
                break;
        }
        assertEquals(name, classDecl.getName().wStringValue());
        assertEquals(superClassName, classDecl.getSuperclassType().wStringValue());
    }
}
Also used : EnumEntity(org.whole.lang.models.model.EnumEntity) IEntity(org.whole.lang.model.IEntity) SimpleEntity(org.whole.lang.models.model.SimpleEntity) ITemplateManager(org.whole.lang.templates.ITemplateManager) ClassDeclaration(org.whole.lang.java.model.ClassDeclaration) ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) PathExpression(org.whole.lang.queries.model.PathExpression) XmlModel(org.whole.lang.models.codebase.XmlModel) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) IBindingManager(org.whole.lang.bindings.IBindingManager) CompositeEntity(org.whole.lang.models.model.CompositeEntity) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 5 with SimpleEntity

use of org.whole.lang.models.model.SimpleEntity in project whole by wholeplatform.

the class ControlQueriesTest method testFor1.

@Test
public void testFor1() {
    Model model = new XmlModel().create();
    ModelDeclarations decls = model.getDeclarations();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("for1");
    int i = 0;
    for (IEntity name : BehaviorUtils.compileAndLazyEvaluate(query, model)) {
        while (!Matcher.match(ModelsEntityDescriptorEnum.SimpleEntity, decls.wGet(i))) i++;
        assertEquals(((SimpleEntity) decls.wGet(i++)).getName().wStringValue(), name.wStringValue());
    }
    assertTrue(i > 0);
}
Also used : ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) SimpleEntity(org.whole.lang.models.model.SimpleEntity) XmlModel(org.whole.lang.models.codebase.XmlModel) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) XmlModel(org.whole.lang.models.codebase.XmlModel) ITemplateManager(org.whole.lang.templates.ITemplateManager) Test(org.junit.Test)

Aggregations

SimpleEntity (org.whole.lang.models.model.SimpleEntity)29 Test (org.junit.Test)22 IEntity (org.whole.lang.model.IEntity)14 Model (org.whole.lang.models.model.Model)13 PathExpression (org.whole.lang.queries.model.PathExpression)13 ITemplateManager (org.whole.lang.templates.ITemplateManager)13 XmlModel (org.whole.lang.models.codebase.XmlModel)12 IBindingManager (org.whole.lang.bindings.IBindingManager)9 ModelsModel (org.whole.lang.models.codebase.ModelsModel)7 ModelDeclarations (org.whole.lang.models.model.ModelDeclarations)7 CompositeEntity (org.whole.lang.models.model.CompositeEntity)6 DataEntity (org.whole.lang.models.model.DataEntity)5 EnumEntity (org.whole.lang.models.model.EnumEntity)5 Feature (org.whole.lang.models.model.Feature)5 Features (org.whole.lang.models.model.Features)5 EnumValues (org.whole.lang.models.model.EnumValues)3 Document (org.whole.lang.text.model.Document)3 ClassDeclaration (org.whole.lang.java.model.ClassDeclaration)2 ModelsEntityFactory (org.whole.lang.models.factories.ModelsEntityFactory)2 ArrayList (java.util.ArrayList)1