Search in sources :

Example 6 with ModelsEntityFactory

use of org.whole.lang.models.factories.ModelsEntityFactory in project whole by wholeplatform.

the class WorkflowsInterpreterVisitorTest method testCreateEntity.

@Test
public void testCreateEntity() {
    IEntity createEntityTest = WorkflowsTestTemplateManager.instance().create("createEntityTest");
    IBindingManager args = BindingManagerFactory.instance.createArguments();
    InterpreterOperation.interpret(createEntityTest, args);
    ModelsEntityFactory mef = ModelsEntityFactory.instance(RegistryConfigurations.RESOLVER);
    Assert.assertTrue(args.wIsSet("entity"));
    Assert.assertTrue(Matcher.match(mef.buildSimpleEntity().set(ModelsFeatureDescriptorEnum.modifiers, mef.createEntityModifiers(0)).set(ModelsFeatureDescriptorEnum.name, mef.createSimpleName("EntityName")).set(ModelsFeatureDescriptorEnum.types, mef.createTypes(mef.createSimpleName("Type"))).set(ModelsFeatureDescriptorEnum.features, mef.createFeatures(mef.buildFeature().set(ModelsFeatureDescriptorEnum.type, mef.createSimpleName("FType")).set(ModelsFeatureDescriptorEnum.name, mef.createSimpleName("fname")).getResult())).getResult(), args.wGet("entity")));
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) ModelsEntityFactory(org.whole.lang.models.factories.ModelsEntityFactory) Test(org.junit.Test)

Example 7 with ModelsEntityFactory

use of org.whole.lang.models.factories.ModelsEntityFactory in project whole by wholeplatform.

the class Grammars2ModelsVisitor method createFeature.

protected Feature createFeature(IEntityIterator<Rule> ruleIterator, String featureName) {
    ModelsEntityFactory mf = ModelsEntityFactory.instance;
    IEntityBuilder<Feature> fb = mf.buildFeature();
    fb.set(ModelsFeatureDescriptorEnum.name, featureName);
    while (ruleIterator.hasNext()) {
        Rule rule = ruleIterator.next();
        switch(rule.wGetEntityOrd()) {
            // break;
            case GrammarsEntityDescriptorEnum.When_ord:
                When when = (When) rule;
                ((AbstractPatternFilterIterator<Rule>) ruleIterator).skipTo(when.getRule());
                break;
            case GrammarsEntityDescriptorEnum.NonTerminal_ord:
                if (isLexicalNonTerminal((NonTerminal) rule) && EntityUtils.hasParent(rule) && Matcher.match(GrammarsEntityDescriptorEnum.Concatenate, rule.wGetParent()))
                    break;
                fb.set(ModelsFeatureDescriptorEnum.type, mf.createSimpleName(getMappedEntityName((NonTerminal) rule)));
                IEntity ancestor = null;
                IEntityIterator<IEntity> iterator = IteratorFactory.ancestorIterator();
                iterator.reset(Matcher.findAncestor(GrammarsEntityDescriptorEnum.As, rule));
                while (iterator.hasNext() && !Matcher.match(GrammarsEntityDescriptorEnum.Production, ancestor = iterator.next())) if (Matcher.match(GrammarsEntityDescriptorEnum.Optional, ancestor))
                    fb.set(ModelsFeatureDescriptorEnum.modifiers, mf.createFeatureModifiers(mf.createFeatureModifier(FeatureModifierEnum.optional)));
                return fb.getResult();
        }
    }
    throw new IllegalArgumentException("Missing NonTerminal");
}
Also used : When(org.whole.lang.grammars.model.When) AbstractPatternFilterIterator(org.whole.lang.iterators.AbstractPatternFilterIterator) IEntity(org.whole.lang.model.IEntity) ModelsEntityFactory(org.whole.lang.models.factories.ModelsEntityFactory) Rule(org.whole.lang.grammars.model.Rule) Feature(org.whole.lang.models.model.Feature)

Example 8 with ModelsEntityFactory

use of org.whole.lang.models.factories.ModelsEntityFactory in project whole by wholeplatform.

the class Grammars2ModelsVisitor method visit.

@Override
public void visit(Grammar entity) {
    entity = normalize(entity);
    IEntityIterator<Production> lexiconIiterator = IteratorFactory.<Production>childIterator();
    lexiconIiterator.reset(entity.getLexicalStructure());
    for (Production p : lexiconIiterator) lexiconMap.put(p.getName().getValue(), p);
    LanguageDescriptor ld = (LanguageDescriptor) entity.getTargetLanguage();
    ModelsEntityFactory mf = ModelsEntityFactory.instance;
    Model model = mf.createModel(mf.createSimpleName(ld.getName().getValue()), mf.createTypeRelations(), modelDeclarations = mf.createModelDeclarations(), mf.createNamespace(ld.getNamespace().getValue()), EntityUtils.isResolver(ld.getVersion()) ? CommonsEntityAdapterFactory.createResolver(ModelsEntityDescriptorEnum.Version) : mf.createVersion(ld.getVersion().getValue()), mf.createURI(ld.getUri().getValue()));
    entity.getPhraseStructure().accept(this);
    setResult(model);
}
Also used : Production(org.whole.lang.grammars.model.Production) Model(org.whole.lang.models.model.Model) LanguageDescriptor(org.whole.lang.grammars.model.LanguageDescriptor) ModelsEntityFactory(org.whole.lang.models.factories.ModelsEntityFactory)

Example 9 with ModelsEntityFactory

use of org.whole.lang.models.factories.ModelsEntityFactory in project whole by wholeplatform.

the class ControlQueriesTest method testQueryDecl8.

@Test
public void testQueryDecl8() {
    ModelsEntityFactory mef = ModelsEntityFactory.instance;
    FeatureModifiers modifiers = mef.createFeatureModifiers(mef.createFeatureModifier(FeatureModifierEnum.optional), mef.createFeatureModifier(FeatureModifierEnum.derived), mef.createFeatureModifier(FeatureModifierEnum.id));
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("queryDecl8");
    int count = 0;
    for (IEntity p : BehaviorUtils.compileAndLazyEvaluate(query, modifiers)) {
        IEntity modifier = modifiers.wGet(count++);
        assertTrue(Matcher.match(modifier, p));
    }
    assertEquals(modifiers.wSize(), count);
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) FeatureModifiers(org.whole.lang.models.model.FeatureModifiers) ModelsEntityFactory(org.whole.lang.models.factories.ModelsEntityFactory) ITemplateManager(org.whole.lang.templates.ITemplateManager) Test(org.junit.Test)

Example 10 with ModelsEntityFactory

use of org.whole.lang.models.factories.ModelsEntityFactory in project whole by wholeplatform.

the class ByChildAPITest method testAbstractListEntity.

@Test
public void testAbstractListEntity() {
    ModelsEntityFactory mf = ModelsEntityFactory.instance;
    ComponentModifier o = mf.createComponentModifier(ComponentModifierEnum.ordered);
    ComponentModifier r1 = mf.createComponentModifier(ComponentModifierEnum.reference);
    ComponentModifier r2 = mf.createComponentModifier(ComponentModifierEnum.reference);
    ComponentModifier s = mf.createComponentModifier(ComponentModifierEnum.derived);
    ComponentModifier[] modifiersArray = new ComponentModifier[] { o, r1, r2, s };
    int[] businessEquivalence = new int[] { 0, 1, 1, 3 };
    ComponentModifiers modifiers = mf.createComponentModifiers(modifiersArray);
    orderedCompositeOperationsEntityTest(modifiersArray, businessEquivalence, modifiers);
    commonOperationsEntityTest(modifiersArray, modifiersArray, modifiers);
    propertyChangeEntityTest(modifiersArray, modifiers, mf.createComponentModifier(ComponentModifierEnum.reference));
}
Also used : ComponentModifiers(org.whole.lang.models.model.ComponentModifiers) ComponentModifier(org.whole.lang.models.model.ComponentModifier) ModelsEntityFactory(org.whole.lang.models.factories.ModelsEntityFactory) Test(org.junit.Test)

Aggregations

ModelsEntityFactory (org.whole.lang.models.factories.ModelsEntityFactory)10 Test (org.junit.Test)5 IEntity (org.whole.lang.model.IEntity)4 IBindingManager (org.whole.lang.bindings.IBindingManager)2 Production (org.whole.lang.grammars.model.Production)2 Rule (org.whole.lang.grammars.model.Rule)2 AbstractPatternFilterIterator (org.whole.lang.iterators.AbstractPatternFilterIterator)2 ComponentModifier (org.whole.lang.models.model.ComponentModifier)2 ComponentModifiers (org.whole.lang.models.model.ComponentModifiers)2 SimpleEntity (org.whole.lang.models.model.SimpleEntity)2 As (org.whole.lang.grammars.model.As)1 LanguageDescriptor (org.whole.lang.grammars.model.LanguageDescriptor)1 NonTerminal (org.whole.lang.grammars.model.NonTerminal)1 Repeat (org.whole.lang.grammars.model.Repeat)1 Template (org.whole.lang.grammars.model.Template)1 When (org.whole.lang.grammars.model.When)1 CompositeEntity (org.whole.lang.models.model.CompositeEntity)1 DataEntity (org.whole.lang.models.model.DataEntity)1 EnumEntity (org.whole.lang.models.model.EnumEntity)1 EnumValues (org.whole.lang.models.model.EnumValues)1