Search in sources :

Example 1 with DataEntity

use of org.whole.lang.models.model.DataEntity 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 2 with DataEntity

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

the class ControlQueriesTest method testChoose3.

@Test
public void testChoose3() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("choose3");
    int i = 0;
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model);
    while (iterator.hasNext()) {
        IEntity result = iterator.next();
        IEntity decl = decls.wGet(i++);
        switch(decl.wGetEntityOrd()) {
            case ModelsEntityDescriptorEnum.SimpleEntity_ord:
                Features features = ((SimpleEntity) decl).getFeatures();
                if (!features.isEmpty())
                    assertEquals(features.get(0).getName().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.CompositeEntity_ord:
                CompositeEntity compositeEntity = (CompositeEntity) decl;
                assertEquals(compositeEntity.getComponentType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.DataEntity_ord:
                DataEntity dataEntity = (DataEntity) decl;
                assertEquals(dataEntity.getDataType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.EnumEntity_ord:
                EnumEntity enumEntity = (EnumEntity) decl;
                assertEquals(enumEntity.getValues().wGet(0).wStringValue(), result.wStringValue());
                break;
        }
    }
}
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) 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) CompositeEntity(org.whole.lang.models.model.CompositeEntity) Features(org.whole.lang.models.model.Features) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 3 with DataEntity

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

the class ControlQueriesTest method testQueryDecl5.

@Test
public void testQueryDecl5() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("queryDecl5");
    int count = 0;
    int index = 0;
    for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        IEntity decl = decls.wGet(index++);
        switch(decl.wGetEntityOrd()) {
            case ModelsEntityDescriptorEnum.SimpleEntity_ord:
                Features features = ((SimpleEntity) decl).getFeatures();
                if (!features.isEmpty())
                    assertEquals(features.get(0).getName().wStringValue(), p.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.CompositeEntity_ord:
                assertEquals(((CompositeEntity) decl).getComponentType().wStringValue(), p.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.DataEntity_ord:
                assertEquals(((DataEntity) decl).getName().wStringValue(), p.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.EnumEntity_ord:
                assertTrue(Matcher.matchImpl(ModelsEntityDescriptorEnum.EnumEntity, p));
                break;
        }
        count++;
    }
    assertEquals(33, count);
}
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) IBindingManager(org.whole.lang.bindings.IBindingManager) CompositeEntity(org.whole.lang.models.model.CompositeEntity) ITemplateManager(org.whole.lang.templates.ITemplateManager) Features(org.whole.lang.models.model.Features) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Example 4 with DataEntity

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

the class ControlQueriesTest method testChoose2.

@Test
public void testChoose2() {
    Model model = new ModelsModel().create();
    ModelDeclarations decls = model.getDeclarations();
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("choose2");
    int i = 0;
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model);
    while (iterator.hasNext()) {
        IEntity result;
        IEntity decl = decls.wGet(i++);
        switch(decl.wGetEntityOrd()) {
            case ModelsEntityDescriptorEnum.SimpleEntity_ord:
                IEntity features = ((SimpleEntity) decl).getFeatures();
                for (int j = 0; j < features.wSize(); j++) {
                    result = iterator.next();
                    assertEquals(((Feature) features.wGet(j)).getName().wStringValue(), result.wStringValue());
                }
                break;
            case ModelsEntityDescriptorEnum.CompositeEntity_ord:
                result = iterator.next();
                CompositeEntity compositeEntity = (CompositeEntity) decl;
                assertEquals(compositeEntity.getComponentType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.DataEntity_ord:
                result = iterator.next();
                DataEntity dataEntity = (DataEntity) decl;
                assertEquals(dataEntity.getDataType().wStringValue(), result.wStringValue());
                break;
            case ModelsEntityDescriptorEnum.EnumEntity_ord:
                EnumValues enumValues = ((EnumEntity) decl).getValues();
                if (enumValues.wIsEmpty())
                    iterator.next();
                else
                    for (int j = 0; j < enumValues.wSize(); j++) {
                        result = iterator.next();
                        assertEquals(enumValues.wGet(j).wStringValue(), result.wStringValue());
                    }
                break;
        }
    }
}
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) Feature(org.whole.lang.models.model.Feature) EnumValues(org.whole.lang.models.model.EnumValues) 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) 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 DataEntity

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

the class RewriteQueriesTest method testUpdate9.

@Test
public void testUpdate9() {
    Model model = new ModelsModel().create();
    ModelDeclarations declarations = model.getDeclarations();
    ITemplateManager tm = RewriteQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("update9");
    for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.DataEntity, entity));
    for (int i = 0; i < declarations.wSize(); i++) {
        IEntity decl = declarations.wGet(i);
        if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
            assertEquals("Object", ((DataEntity) decl).getDataType().getValue());
            assertTrue(((DataEntity) decl).getName().getValue().startsWith("My"));
        }
    }
}
Also used : ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) ITemplateManager(org.whole.lang.templates.ITemplateManager) DataEntity(org.whole.lang.models.model.DataEntity) ModelsModel(org.whole.lang.models.codebase.ModelsModel) Test(org.junit.Test)

Aggregations

DataEntity (org.whole.lang.models.model.DataEntity)13 Test (org.junit.Test)10 IEntity (org.whole.lang.model.IEntity)10 ModelsModel (org.whole.lang.models.codebase.ModelsModel)10 Model (org.whole.lang.models.model.Model)10 PathExpression (org.whole.lang.queries.model.PathExpression)10 ITemplateManager (org.whole.lang.templates.ITemplateManager)10 ModelDeclarations (org.whole.lang.models.model.ModelDeclarations)9 CompositeEntity (org.whole.lang.models.model.CompositeEntity)5 SimpleEntity (org.whole.lang.models.model.SimpleEntity)5 XmlModel (org.whole.lang.models.codebase.XmlModel)4 EnumEntity (org.whole.lang.models.model.EnumEntity)4 Features (org.whole.lang.models.model.Features)3 IBindingManager (org.whole.lang.bindings.IBindingManager)2 EnumValues (org.whole.lang.models.model.EnumValues)2 ArrayList (java.util.ArrayList)1 As (org.whole.lang.grammars.model.As)1 NonTerminal (org.whole.lang.grammars.model.NonTerminal)1 Repeat (org.whole.lang.grammars.model.Repeat)1 Rule (org.whole.lang.grammars.model.Rule)1