Search in sources :

Example 1 with ModelsEntityFactory

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

the class ModelInfo method addUndeclaredTypes.

public void addUndeclaredTypes(Model model) {
    ModelDeclarations decls = model.getDeclarations();
    ModelsEntityFactory lf = ModelsEntityFactory.instance;
    for (String name : undefinedTypes) {
        decls.wAdd(lf.createSimpleEntity(lf.createEntityModifiers(lf.createEntityModifier(EntityModifierEnum._abstract)), lf.createSimpleName(name), lf.createTypes(), lf.createFeatures()));
    }
    markerTypes.addAll(undefinedTypes);
    abstractTypes.addAll(undefinedTypes);
    undefinedTypes.clear();
}
Also used : ModelDeclarations(org.whole.lang.models.model.ModelDeclarations) ModelsEntityFactory(org.whole.lang.models.factories.ModelsEntityFactory)

Example 2 with ModelsEntityFactory

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

the class ByChildAPITest method testAbstractSetCompositeEntity.

@Test
public void testAbstractSetCompositeEntity() {
    ModelsEntityFactory mf = ModelsEntityFactory.instance(RegistryConfigurations.STRICT);
    ComponentModifier o = mf.createComponentModifier(ComponentModifierEnum.ordered);
    ComponentModifier r = mf.createComponentModifier(ComponentModifierEnum.reference);
    ComponentModifier s = mf.createComponentModifier(ComponentModifierEnum.derived);
    ComponentModifier[] modifiersArray = new ComponentModifier[] { o, r, s };
    ComponentModifiers modifiers = mf.createComponentModifiers(modifiersArray);
    unorderedCompositeOperationsEntityTest(modifiersArray, modifiers);
    commonOperationsEntityTest(modifiersArray, modifiersArray, modifiers);
    uniqueOperationsEntityTest(modifiersArray, modifiers);
    propertyChangeEntityTest(modifiersArray, modifiers, mf.createComponentModifier(ComponentModifierEnum.unique));
}
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)

Example 3 with ModelsEntityFactory

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

the class Grammars2ModelsVisitor method visit.

@Override
public void visit(Productions entity) {
    ModelsEntityFactory mf = ModelsEntityFactory.instance;
    ScannerIterator<Production> i = IteratorFactory.<Production>childScannerIterator();
    i.reset(entity);
    for (Production p : i) {
        String eName = getMappedEntityName(p);
        ModelDeclaration mDecl = CommonsEntityAdapterFactory.createResolver(ModelsEntityDescriptorEnum.ModelDeclaration);
        productionMap.put(p.getName().getValue(), p);
        declarationMap.put(eName, mDecl);
        modelDeclarations.wAdd(mDecl);
        mDecl.setModifiers(mf.createEntityModifiers());
        mDecl.setName(mf.createSimpleName(eName));
        mDecl.setTypes(mf.createTypes());
    }
    super.visit(entity);
}
Also used : Production(org.whole.lang.grammars.model.Production) ModelsEntityFactory(org.whole.lang.models.factories.ModelsEntityFactory) ModelDeclaration(org.whole.lang.models.model.ModelDeclaration)

Example 4 with ModelsEntityFactory

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

the class Grammars2ModelsVisitor method visit.

@Override
public void visit(Production entity) {
    ModelsEntityFactory mf = ModelsEntityFactory.instance;
    String eName = getMappedEntityName(entity);
    Rule rule = entity.getRule();
    AbstractPatternFilterIterator<Rule> ruleIterator = IteratorFactory.<Rule>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Rule);
    ruleIterator.reset(rule);
    while (ruleIterator.hasNext()) {
        rule = ruleIterator.next();
        switch(rule.wGetEntityOrd()) {
            // map productions with a single lexical non-terminal as data entities
            case GrammarsEntityDescriptorEnum.NonTerminal_ord:
                if (!isLexicalNonTerminal((NonTerminal) rule) || !EntityUtils.hasParent(rule) || !Matcher.match(GrammarsEntityDescriptorEnum.Production, rule.wGetParent()) || !Matcher.match(GrammarsEntityDescriptorEnum.DataTerminal, lexiconMap.get(((NonTerminal) rule).getValue()).getRule()))
                    break;
            case GrammarsEntityDescriptorEnum.DataTerminal_ord:
                DataEntity de = getModelDeclaration(eName, ModelsEntityDescriptorEnum.DataEntity);
                Template template = entity.getTemplate();
                if (Matcher.matchImpl(GrammarsEntityDescriptorEnum.DataType, template))
                    de.getDataType().wSetValue(GrammarsUtils.getDataType((DataType) template));
                else if (Matcher.matchImpl(GrammarsEntityDescriptorEnum.CustomDataType, template))
                    de.getDataType().wSetValue(template.wStringValue());
                return;
            case GrammarsEntityDescriptorEnum.Choose_ord:
                boolean isPolymorphic = false;
                AbstractPatternFilterIterator<NonTerminal> ruleIterator2 = IteratorFactory.<NonTerminal>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.NonTerminal);
                ruleIterator2.reset(rule);
                for (NonTerminal nt2 : ruleIterator2) if (!isLexicalNonTerminal(nt2)) {
                    ensureType(getModelDeclaration(getMappedEntityName(nt2)).getTypes(), eName);
                    isPolymorphic = true;
                }
                if (isPolymorphic) {
                    SimpleEntity se = getModelDeclaration(eName, ModelsEntityDescriptorEnum.SimpleEntity);
                    se.getModifiers().wAdd(mf.createEntityModifier(EntityModifierEnum._abstract));
                    return;
                } else if (!rule.wIsEmpty() && Matcher.match(GrammarsEntityDescriptorEnum.As, rule.wGet(0))) {
                    EnumEntity ee = getModelDeclaration(eName, ModelsEntityDescriptorEnum.EnumEntity);
                    EnumValues enumValues = ModelsEntityFactory.instance.createEnumValues(0);
                    AbstractPatternFilterIterator<As> ruleIterator3 = IteratorFactory.<As>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.As);
                    ruleIterator3.reset(rule);
                    for (As as : ruleIterator3) enumValues.wAdd(ModelsEntityFactory.instance.createEnumValue(as.getName().getValue()));
                    ee.setValues(enumValues);
                    return;
                }
                // }
                break;
            case GrammarsEntityDescriptorEnum.Repeat_ord:
                if (ruleIterator.skipTo(GrammarsEntityDescriptorEnum.NonTerminal)) {
                    // FIXME wrongly assumes that the separator, if present, is a lexical token
                    if (!EntityUtils.isResolver(((Repeat) rule).getSeparator())) {
                        // if (Matcher.matchImpl(GrammarsEntityDescriptorEnum.NonTerminal, ((Repeat) rule).getSeparator())) {
                        ruleIterator.next();
                        ruleIterator.skipTo(GrammarsEntityDescriptorEnum.NonTerminal);
                    }
                    NonTerminal nt = null;
                    AbstractPatternFilterIterator<NonTerminal> ruleIterator4 = IteratorFactory.<NonTerminal>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.NonTerminal);
                    ruleIterator4.reset(rule);
                    for (NonTerminal nt2 : ruleIterator4) if (!isLexicalNonTerminal(nt2)) {
                        nt = nt2;
                        break;
                    }
                    // by now we assume that the separator, if present, is a lexical token
                    if (nt == null)
                        break;
                    // the above statements replace this code, allowing lexical Repeat rule
                    // NonTerminal nt = ruleIterator.next(GrammarsEntityDescriptorEnum.NonTerminal);
                    // while (isLexicalNonTerminal(nt)) {
                    // nt = ruleIterator.next(GrammarsEntityDescriptorEnum.NonTerminal);
                    // }
                    CompositeEntity ce = getModelDeclaration(eName, ModelsEntityDescriptorEnum.CompositeEntity);
                    ce.setComponentType(mf.createSimpleName(getMappedEntityName(nt)));
                    ce.getComponentModifiers().wAdd(mf.createComponentModifier(ComponentModifierEnum.ordered));
                }
                return;
            case GrammarsEntityDescriptorEnum.As_ord:
                As asRule = (As) rule;
                // normalization invariants assure that this branch is unreachable
                // if (Matcher.match(GrammarsEntityDescriptorEnum.LiteralTerminal, asRule.getRule())) {
                // EnumEntity ee = getModelDeclaration(eName, ModelsEntityDescriptorEnum.EnumEntity);
                // 
                // ee.getValues().wAdd(mf.createEnumValue(getMappedName(asRule)));
                // 
                // while (ruleIterator.skipTo(GrammarsEntityDescriptorEnum.As)) {
                // rule = ruleIterator.next(GrammarsEntityDescriptorEnum.As);
                // asRule = (As) rule;
                // 
                // ee.getValues().wAdd(mf.createEnumValue(getMappedName(asRule)));
                // }
                // } else {
                SimpleEntity se = getModelDeclaration(eName, ModelsEntityDescriptorEnum.SimpleEntity);
                Features features = se.getFeatures();
                ensureFeature(features, ruleIterator, asRule);
                while (ruleIterator.hasNext()) {
                    rule = ruleIterator.next();
                    switch(rule.wGetEntityOrd()) {
                        case GrammarsEntityDescriptorEnum.As_ord:
                            asRule = (As) rule;
                            ensureFeature(features, ruleIterator, asRule);
                            break;
                    }
                }
                // }
                return;
            case GrammarsEntityDescriptorEnum.Concatenate_ord:
                break;
        }
    }
    getModelDeclaration(eName, ModelsEntityDescriptorEnum.SimpleEntity);
}
Also used : EnumEntity(org.whole.lang.models.model.EnumEntity) SimpleEntity(org.whole.lang.models.model.SimpleEntity) ModelsEntityFactory(org.whole.lang.models.factories.ModelsEntityFactory) NonTerminal(org.whole.lang.grammars.model.NonTerminal) Repeat(org.whole.lang.grammars.model.Repeat) EnumValues(org.whole.lang.models.model.EnumValues) Template(org.whole.lang.grammars.model.Template) As(org.whole.lang.grammars.model.As) AbstractPatternFilterIterator(org.whole.lang.iterators.AbstractPatternFilterIterator) CompositeEntity(org.whole.lang.models.model.CompositeEntity) DataEntity(org.whole.lang.models.model.DataEntity) Features(org.whole.lang.models.model.Features) Rule(org.whole.lang.grammars.model.Rule)

Example 5 with ModelsEntityFactory

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

the class WorkflowsInterpreterVisitorTest method testCreateModel.

@Test
public void testCreateModel() {
    IEntity createModelTest = WorkflowsTestTemplateManager.instance().create("createModelTest");
    IBindingManager args = BindingManagerFactory.instance.createArguments();
    InterpreterOperation.interpret(createModelTest, args);
    ModelsEntityFactory mef = ModelsEntityFactory.instance;
    SimpleEntity se = mef.createSimpleEntity(mef.createEntityModifiers(mef.createEntityModifier(EntityModifierEnum._abstract)), mef.createSimpleName("Entity1"), mef.createTypes(0), mef.createFeatures(mef.buildFeature().set(ModelsFeatureDescriptorEnum.type, mef.createSimpleName("FType")).set(ModelsFeatureDescriptorEnum.name, mef.createSimpleName("fname")).getResult()));
    Assert.assertTrue(args.wIsSet("model"));
    IEntity model = args.wGet("model");
    Matcher.removeVars(model, false);
    Assert.assertTrue(Matcher.match(se, model));
}
Also used : IEntity(org.whole.lang.model.IEntity) SimpleEntity(org.whole.lang.models.model.SimpleEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) 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