Search in sources :

Example 6 with SimpleName

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

the class PathExpressionsQueriesTest method testChildStepByName.

@Test
public void testChildStepByName() {
    Model model = new XmlModel().create();
    SimpleName name = model.getName();
    QueriesEntityFactory ef = QueriesEntityFactory.instance;
    IEntity result = BehaviorUtils.evaluateFirstResult(ef.createFeatureStep("name"), model);
    Assert.assertSame(name, result);
}
Also used : IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) SimpleName(org.whole.lang.models.model.SimpleName) XmlModel(org.whole.lang.models.codebase.XmlModel) Model(org.whole.lang.models.model.Model) XmlModel(org.whole.lang.models.codebase.XmlModel) Test(org.junit.Test)

Example 7 with SimpleName

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

the class ModelInvariantsTest method testSetOrphanByIndexInSimpleEntity.

@Test
public void testSetOrphanByIndexInSimpleEntity() {
    SimpleName oldName = model.getName();
    SimpleName newName = ModelsEntityFactory.instance.createSimpleName("name");
    int index = model.wIndexOf(oldName);
    Assert.assertTrue(model.wContains(oldName));
    Assert.assertSame(model, oldName.wGetParent());
    Assert.assertTrue(EntityUtils.hasParent(oldName));
    Assert.assertSame(NullEntity.instance, newName.wGetParent());
    Assert.assertTrue(!EntityUtils.hasParent(newName));
    model.wSet(index, newName);
    Assert.assertFalse(model.wContains(oldName));
    Assert.assertSame(NullEntity.instance, oldName.wGetParent());
    Assert.assertTrue(!EntityUtils.hasParent(oldName));
    Assert.assertSame(model, newName.wGetParent());
    Assert.assertTrue(EntityUtils.hasParent(newName));
    model.wSet(index, oldName);
    Assert.assertSame(model, oldName.wGetParent());
    Assert.assertTrue(EntityUtils.hasParent(oldName));
    Assert.assertSame(NullEntity.instance, newName.wGetParent());
    Assert.assertTrue(!EntityUtils.hasParent(newName));
}
Also used : SimpleName(org.whole.lang.models.model.SimpleName) Test(org.junit.Test)

Example 8 with SimpleName

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

the class ModelInvariantsTest method testSetOrphanByName.

@Test
public void testSetOrphanByName() {
    SimpleName oldName = model.getName();
    SimpleName newName = ModelsEntityFactory.instance.createSimpleName("name");
    Assert.assertTrue(model.wContains(oldName));
    Assert.assertSame(model, oldName.wGetParent());
    Assert.assertTrue(EntityUtils.hasParent(oldName));
    Assert.assertSame(NullEntity.instance, newName.wGetParent());
    Assert.assertTrue(!EntityUtils.hasParent(newName));
    model.setName(newName);
    Assert.assertFalse(model.wContains(oldName));
    Assert.assertSame(NullEntity.instance, oldName.wGetParent());
    Assert.assertTrue(!EntityUtils.hasParent(oldName));
    Assert.assertSame(model, newName.wGetParent());
    Assert.assertTrue(EntityUtils.hasParent(newName));
    model.setName(oldName);
    Assert.assertSame(model, oldName.wGetParent());
    Assert.assertTrue(EntityUtils.hasParent(oldName));
    Assert.assertSame(NullEntity.instance, newName.wGetParent());
    Assert.assertTrue(!EntityUtils.hasParent(newName));
}
Also used : SimpleName(org.whole.lang.models.model.SimpleName) Test(org.junit.Test)

Example 9 with SimpleName

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

the class ModelInvariantsTest method testParentedFailures.

@Test
public void testParentedFailures() {
    SimpleName name = model.getName();
    SimpleEntity simpleEntity = ModelsEntityFactory.instance.createSimpleEntity();
    try {
        simpleEntity.setName(name);
        Assert.fail();
    } catch (IllegalArgumentException e) {
        simpleEntity.wUnset(name);
    }
    try {
        simpleEntity.getTypes().wAdd(name);
        Assert.fail();
    } catch (IllegalArgumentException e) {
        simpleEntity.getTypes().wRemove(name);
    }
    try {
        simpleEntity.getTypes().wSet(0, name);
        Assert.fail();
    } catch (IllegalArgumentException e) {
        simpleEntity.getTypes().wRemove(0);
    }
    try {
        simpleEntity.getTypes().wAdd(0, name);
        Assert.fail();
    } catch (IllegalArgumentException e) {
        simpleEntity.getTypes().wRemove(0);
    }
}
Also used : SimpleName(org.whole.lang.models.model.SimpleName) SimpleEntity(org.whole.lang.models.model.SimpleEntity) Test(org.junit.Test)

Example 10 with SimpleName

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

the class ModelsJavaModelGeneratorVisitor method visit.

public void visit(Feature feature) {
    String name = feature.getName().wStringValue();
    // was StringUtils.javaKeywordFilter(name);
    String fName = modelInfo.featureImplName(name);
    String type = feature.getType().wStringValue();
    String fType = modelInfo.entityImplName(type);
    String fQType = modelsGen.entityInterfaceQName(fType);
    String oName = null;
    String ofName = null;
    SimpleName oppositeName = feature.getOppositeName();
    if (DataTypeUtils.getDataKind(oppositeName).isString()) {
        oName = oppositeName.getValue();
        // was StringUtils.javaKeywordFilter(oName);
        ofName = modelInfo.featureImplName(oName);
    }
    FeatureModifiers mods = feature.getModifiers();
    featureModifiers.clear();
    mods.accept(this);
    boolean isByReference = mods.wContainsValue(FeatureModifierEnum.reference);
    if (isConcrete)
        simpleEntityBuilder.addField(fType, fName, name, mods.wContainsValue(FeatureModifierEnum.id), mods.wContainsValue(FeatureModifierEnum.optional), isByReference, mods.wContainsValue(FeatureModifierEnum.shared), mods.wContainsValue(FeatureModifierEnum.derived));
    if (modelInfo.isNotInherited(metaName, name))
        simpleEntityInterfaceBuilder.addField(fType, fName, name);
    modelsGen.modelContextBuilder().addFeature(fType, fName);
    modelsGen.visitorsBuilder().addFeature(entityName, fType, fName, name, isByReference);
    modelsGen.entityDescriptorEnumBuilder().addFeature(qEntityName, fType, fName, ofName, featureModifiers);
    modelsGen.featureDescriptorEnumBuilder().addFeature(fType, fName, name);
    if (oName != null)
        modelsGen.featureDescriptorEnumBuilder().addFeature(entityName, ofName, oName);
    if (isConcrete)
        modelsGen.entityFactoryBuilder().addFactoryMethodCase(fQType, fName);
    entityAdapterBuilder.addFeature(fType, fName, name);
}
Also used : FeatureModifiers(org.whole.lang.models.model.FeatureModifiers) SimpleName(org.whole.lang.models.model.SimpleName)

Aggregations

SimpleName (org.whole.lang.models.model.SimpleName)11 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)2 ForeignType (org.whole.lang.models.model.ForeignType)2 Model (org.whole.lang.models.model.Model)2 IBindingManager (org.whole.lang.bindings.IBindingManager)1 IBindingScope (org.whole.lang.bindings.IBindingScope)1 IEntity (org.whole.lang.model.IEntity)1 XmlModel (org.whole.lang.models.codebase.XmlModel)1 FeatureModifiers (org.whole.lang.models.model.FeatureModifiers)1 SimpleEntity (org.whole.lang.models.model.SimpleEntity)1 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)1 TestingModel (org.whole.lang.testentities.codebase.TestingModel)1