Search in sources :

Example 6 with Feature

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

the class SelectQueriesTest method testSelectTemplateWithTwoNestedSimpleQueries.

@Test
public void testSelectTemplateWithTwoNestedSimpleQueries() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar g = new TestXmlGrammar().create();
    PathExpression pe1 = (PathExpression) tm.create("selectTemplateWithTwoNestedSimpleQueries");
    for (Feature f : BehaviorUtils.<Feature>compileAndLazyEvaluate(pe1, g)) {
        assertEquals(ModelsEntityDescriptorEnum.Feature, f.wGetEntityDescriptor());
    }
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Feature(org.whole.lang.models.model.Feature) Test(org.junit.Test)

Example 7 with Feature

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

the class SelectQueriesTest method testSelectTemplate1.

@Test
public void testSelectTemplate1() {
    ITemplateManager tm = SelectQueriesTemplateManager.instance();
    Grammar model = new TestXmlGrammar().create();
    IBindingManager bm = BindingManagerFactory.instance.createArguments();
    PathExpression query = (PathExpression) tm.create("selectTemplate1");
    for (IEntity tuple : BehaviorUtils.compileAndLazyEvaluate(query, model, bm)) {
        Feature f = (Feature) tuple.wGet(0);
        As e = (As) tuple.wGet(1);
        assertEquals(e.getName().getValue(), f.getName().wStringValue());
        assertEquals(e.getRule().wStringValue(), f.getType().wStringValue());
    }
}
Also used : As(org.whole.lang.grammars.model.As) PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Feature(org.whole.lang.models.model.Feature) Test(org.junit.Test)

Example 8 with Feature

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

the class MatcherTest method testRenameMap.

@Test
public void testRenameMap() {
    Feature featurePattern = new FeaturePattern().create();
    Variable var1 = (Variable) featurePattern.getType().wGetAdaptee(false);
    Variable var2 = (Variable) featurePattern.getName().wGetAdaptee(false);
    assertEquals("featureType", var1.getVarName().getValue());
    assertEquals("featureName", var2.getVarName().getValue());
    Map<String, String> map = new HashMap<String, String>();
    map.put("featureType", "fType");
    map.put("featureName", "fName");
    Matcher.rename(featurePattern, map, false);
    assertEquals("fType", var1.getVarName().getValue());
    assertEquals("fName", var2.getVarName().getValue());
}
Also used : Variable(org.whole.lang.commons.model.Variable) HashMap(java.util.HashMap) Feature(org.whole.lang.models.model.Feature) Test(org.junit.Test)

Example 9 with Feature

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

the class Grammars2ModelsVisitor method ensureFeature.

protected void ensureFeature(Features features, IEntityIterator<Rule> ruleIterator, As asRule) {
    String featureName = getMappedName(asRule);
    AbstractPatternFilterIterator<Feature> i = IteratorFactory.<Feature>childMatcherIterator().withPattern(ModelsEntityDescriptorEnum.Feature);
    i.reset(features);
    for (Feature feature : i) if (featureName.equals(feature.getName().getValue()))
        return;
    features.wAdd(createFeature(ruleIterator, featureName));
}
Also used : Feature(org.whole.lang.models.model.Feature)

Example 10 with Feature

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

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