use of org.whole.lang.models.model.DataEntity in project whole by wholeplatform.
the class RewriteQueriesTest method testUpdate8.
@Test
public void testUpdate8() {
Model model = new ModelsModel().create();
ModelDeclarations declarations = model.getDeclarations();
ITemplateManager tm = RewriteQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("update8");
for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.DataEntity, entity));
for (int i = 0; i < declarations.wSize(); i++) {
IEntity decl = declarations.wGet(i);
if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
assertEquals("Object", ((DataEntity) decl).getDataType().getValue());
assertTrue(((DataEntity) decl).getName().getValue().startsWith("My"));
}
}
}
use of org.whole.lang.models.model.DataEntity 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);
}
use of org.whole.lang.models.model.DataEntity in project whole by wholeplatform.
the class DataEntityTablePart method getModelSpecificChildren.
protected List<IEntity> getModelSpecificChildren() {
DataEntity entity = getModelEntity();
List<IEntity> list = new ArrayList<IEntity>(4);
list.add(entity.getModifiers());
list.add(entity.getName());
list.add(entity.getTypes());
list.add(entity.getDataType());
return list;
}
use of org.whole.lang.models.model.DataEntity in project whole by wholeplatform.
the class RewriteQueriesTest method testUpdate2.
@Test
public void testUpdate2() {
Model model = new ModelsModel().create();
ModelDeclarations declarations = model.getDeclarations();
ITemplateManager tm = RewriteQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("update2");
for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.SimpleName, entity) || Matcher.match(ModelsEntityDescriptorEnum.DataType, entity));
for (int i = 0; i < declarations.wSize(); i++) {
IEntity decl = declarations.wGet(i);
if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
assertEquals("MyDataEntityName", ((DataEntity) decl).getName().getValue());
assertEquals("MyDataType", ((DataEntity) decl).getDataType().getValue());
}
}
}
use of org.whole.lang.models.model.DataEntity in project whole by wholeplatform.
the class RewriteQueriesTest method testUpdate11.
@Test
public void testUpdate11() {
Model model = new ModelsModel().create();
ModelDeclarations declarations = model.getDeclarations();
ITemplateManager tm = RewriteQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("update11");
for (IEntity entity : BehaviorUtils.compileAndLazyEvaluate(query, model)) assertTrue(Matcher.match(ModelsEntityDescriptorEnum.SimpleName, entity) || Matcher.match(ModelsEntityDescriptorEnum.DataType, entity));
for (int i = 0; i < declarations.wSize(); i++) {
IEntity decl = declarations.wGet(i);
if (Matcher.match(ModelsEntityDescriptorEnum.DataEntity, decl)) {
String name = ((DataEntity) decl).getName().getValue();
assertEquals(StringUtils.toLowerCap(name), name);
assertEquals("MyDataType", ((DataEntity) decl).getDataType().getValue());
}
}
}
Aggregations