Search in sources :

Example 1 with Feature

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

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

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

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

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

Aggregations

Feature (org.whole.lang.models.model.Feature)18 Test (org.junit.Test)13 IEntity (org.whole.lang.model.IEntity)9 PathExpression (org.whole.lang.queries.model.PathExpression)9 ITemplateManager (org.whole.lang.templates.ITemplateManager)9 Model (org.whole.lang.models.model.Model)8 XmlModel (org.whole.lang.models.codebase.XmlModel)6 FieldDeclaration (org.whole.lang.java.model.FieldDeclaration)5 SimpleEntity (org.whole.lang.models.model.SimpleEntity)5 IBindingManager (org.whole.lang.bindings.IBindingManager)4 ModelsModel (org.whole.lang.models.codebase.ModelsModel)4 Grammar (org.whole.lang.grammars.model.Grammar)3 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)3 Features (org.whole.lang.models.model.Features)3 ModelFeaturesBuilder (org.whole.lang.builders.builder.ModelFeaturesBuilder)2 Variable (org.whole.lang.commons.model.Variable)2 As (org.whole.lang.grammars.model.As)2 CompositeEntity (org.whole.lang.models.model.CompositeEntity)2 EnumEntity (org.whole.lang.models.model.EnumEntity)2 EnumValues (org.whole.lang.models.model.EnumValues)2