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());
}
}
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());
}
}
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());
}
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));
}
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");
}
Aggregations