Search in sources :

Example 1 with Features

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

the class ModelFragmentsBuilderTest method testModelFeaturesBuilderWithFeatureEvents.

@Test
public void testModelFeaturesBuilderWithFeatureEvents() {
    ITemplateFactory<Model> modelsModel = new ModelsModelWithFeatureEvents();
    Features features = ModelsEntityFactory.instance.createFeatures(0);
    modelsModel.apply(new SpecificBuilderAdapterOperation(new ModelFeaturesBuilder(features)));
    int count = 0;
    Model model = modelsModel.create();
    AbstractPatternFilterIterator<Feature> i = IteratorFactory.<Feature>descendantOrSelfMatcherIterator().withPattern(ModelsEntityDescriptorEnum.Feature);
    i.reset(model);
    for (Feature feature : i) if (EntityUtils.isNotResolver(feature))
        count++;
    assertEquals(features.wSize(), count);
}
Also used : ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) Features(org.whole.lang.models.model.Features) ModelFeaturesBuilder(org.whole.lang.builders.builder.ModelFeaturesBuilder) Feature(org.whole.lang.models.model.Feature) Test(org.junit.Test)

Example 2 with Features

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

the class ModelFragmentsBuilderTest method testModelFeaturesBuilder.

@Test
public void testModelFeaturesBuilder() {
    ITemplateFactory<Model> modelsModel = new ModelsModel();
    final Features features = ModelsEntityFactory.instance.createFeatures(0);
    modelsModel.apply(new SpecificBuilderAdapterOperation(new ModelFeaturesBuilder(features)));
    int count = 0;
    Model model = modelsModel.create();
    AbstractPatternFilterIterator<Feature> i = IteratorFactory.<Feature>descendantOrSelfMatcherIterator().withPattern(ModelsEntityDescriptorEnum.Feature);
    i.reset(model);
    for (Feature feature : i) if (EntityUtils.isNotResolver(feature))
        count++;
    assertEquals(features.wSize(), count);
}
Also used : ModelsModel(org.whole.lang.models.codebase.ModelsModel) Model(org.whole.lang.models.model.Model) Features(org.whole.lang.models.model.Features) ModelsModel(org.whole.lang.models.codebase.ModelsModel) ModelFeaturesBuilder(org.whole.lang.builders.builder.ModelFeaturesBuilder) Feature(org.whole.lang.models.model.Feature) Test(org.junit.Test)

Example 3 with Features

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

the class ModelsJavaModelGeneratorVisitor method visit.

public void visit(SimpleEntity entity) {
    entityModifiers.clear();
    isConcrete = true;
    entity.getModifiers().accept(this);
    metaName = entity.getName().wStringValue();
    // was entity.getName().wStringValue();
    entityName = modelInfo.entityImplName(metaName);
    qEntityName = modelsGen.entityInterfaceQName(entityName);
    if (isConcrete)
        simpleEntityBuilder = modelsGen.simpleEntityBuilder(entityName);
    anyEntityBuilder = simpleEntityInterfaceBuilder = modelsGen.simpleEntityInterfaceBuilder(entityName);
    // before factoryBuilder
    if (!entityName.equals(modelsGen.entityVariableName())) {
        entityAdapterBuilder = modelsGen.entityAdapterBuilder(entityName);
        modelsGen.adapterRegistryBuilder().addFactoryProduct(entityName);
        if (isConcrete)
            modelsGen.implRegistryBuilder().addFactoryProduct(entityName);
    }
    Features features = entity.getFeatures();
    if (isConcrete)
        modelsGen.entityFactoryBuilder().addFactoryMethodWithBuild(entityName, features.wIsEmpty() ? 0 : features.wSize());
    modelsGen.entityDescriptorEnumBuilder().addSimpleEntity(entityName, metaName, qEntityName, entityModifiers, modelInfo.entityImplNames(modelInfo.allSubTypes(metaName)));
    // modelsGen.entityDescriptorEnumBuilder().addSupertypes(qEntityName, metaName, modelInfo.allSuperTypes(metaName));
    entity.getTypes().accept(this);
    features.accept(this);
    if (isConcrete) {
        simpleEntityBuilder.endBody();
        modelsGen.visitorsBuilder().addSimpleEntity(entityName);
        if (hasUI)
            modelsGen.partFactoryVisitorBuilder().addPartFactoryVisitMethod(entityName, features.wSize());
    }
}
Also used : Features(org.whole.lang.models.model.Features)

Example 4 with Features

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

use of org.whole.lang.models.model.Features 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)

Aggregations

Features (org.whole.lang.models.model.Features)8 Test (org.junit.Test)5 ModelsModel (org.whole.lang.models.codebase.ModelsModel)5 Model (org.whole.lang.models.model.Model)5 SimpleEntity (org.whole.lang.models.model.SimpleEntity)5 IEntity (org.whole.lang.model.IEntity)3 CompositeEntity (org.whole.lang.models.model.CompositeEntity)3 DataEntity (org.whole.lang.models.model.DataEntity)3 Feature (org.whole.lang.models.model.Feature)3 ModelDeclarations (org.whole.lang.models.model.ModelDeclarations)3 PathExpression (org.whole.lang.queries.model.PathExpression)3 ITemplateManager (org.whole.lang.templates.ITemplateManager)3 ModelFeaturesBuilder (org.whole.lang.builders.builder.ModelFeaturesBuilder)2 XmlModel (org.whole.lang.models.codebase.XmlModel)2 EnumEntity (org.whole.lang.models.model.EnumEntity)2 IBindingManager (org.whole.lang.bindings.IBindingManager)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