use of org.whole.lang.models.model.Features in project whole by wholeplatform.
the class ModelFragmentsBuilderTest method testModelFeaturesBuilderWithFeatureEvents.
@Test
public void testModelFeaturesBuilderWithFeatureEvents() {
ITemplateFactory<Model> modelsModel = new ModelsModelWithFeatureEvents();
Features features = ModelsEntityFactory.instance.createFeatures(0);
modelsModel.apply(new SpecificBuilderAdapterOperation(new ModelFeaturesBuilder(features)));
int count = 0;
Model model = modelsModel.create();
AbstractPatternFilterIterator<Feature> i = IteratorFactory.<Feature>descendantOrSelfMatcherIterator().withPattern(ModelsEntityDescriptorEnum.Feature);
i.reset(model);
for (Feature feature : i) if (EntityUtils.isNotResolver(feature))
count++;
assertEquals(features.wSize(), count);
}
use of org.whole.lang.models.model.Features in project whole by wholeplatform.
the class ModelFragmentsBuilderTest method testModelFeaturesBuilder.
@Test
public void testModelFeaturesBuilder() {
ITemplateFactory<Model> modelsModel = new ModelsModel();
final Features features = ModelsEntityFactory.instance.createFeatures(0);
modelsModel.apply(new SpecificBuilderAdapterOperation(new ModelFeaturesBuilder(features)));
int count = 0;
Model model = modelsModel.create();
AbstractPatternFilterIterator<Feature> i = IteratorFactory.<Feature>descendantOrSelfMatcherIterator().withPattern(ModelsEntityDescriptorEnum.Feature);
i.reset(model);
for (Feature feature : i) if (EntityUtils.isNotResolver(feature))
count++;
assertEquals(features.wSize(), count);
}
use of org.whole.lang.models.model.Features in project whole by wholeplatform.
the class ModelsJavaModelGeneratorVisitor method visit.
public void visit(SimpleEntity entity) {
entityModifiers.clear();
isConcrete = true;
entity.getModifiers().accept(this);
metaName = entity.getName().wStringValue();
// was entity.getName().wStringValue();
entityName = modelInfo.entityImplName(metaName);
qEntityName = modelsGen.entityInterfaceQName(entityName);
if (isConcrete)
simpleEntityBuilder = modelsGen.simpleEntityBuilder(entityName);
anyEntityBuilder = simpleEntityInterfaceBuilder = modelsGen.simpleEntityInterfaceBuilder(entityName);
// before factoryBuilder
if (!entityName.equals(modelsGen.entityVariableName())) {
entityAdapterBuilder = modelsGen.entityAdapterBuilder(entityName);
modelsGen.adapterRegistryBuilder().addFactoryProduct(entityName);
if (isConcrete)
modelsGen.implRegistryBuilder().addFactoryProduct(entityName);
}
Features features = entity.getFeatures();
if (isConcrete)
modelsGen.entityFactoryBuilder().addFactoryMethodWithBuild(entityName, features.wIsEmpty() ? 0 : features.wSize());
modelsGen.entityDescriptorEnumBuilder().addSimpleEntity(entityName, metaName, qEntityName, entityModifiers, modelInfo.entityImplNames(modelInfo.allSubTypes(metaName)));
// modelsGen.entityDescriptorEnumBuilder().addSupertypes(qEntityName, metaName, modelInfo.allSuperTypes(metaName));
entity.getTypes().accept(this);
features.accept(this);
if (isConcrete) {
simpleEntityBuilder.endBody();
modelsGen.visitorsBuilder().addSimpleEntity(entityName);
if (hasUI)
modelsGen.partFactoryVisitorBuilder().addPartFactoryVisitMethod(entityName, features.wSize());
}
}
use of org.whole.lang.models.model.Features in project whole by wholeplatform.
the class ModelInfo method sortFeatures.
public void sortFeatures(Model model) {
for (String entityName : simpleEntityTypes) {
SimpleEntity e = (SimpleEntity) nameEntityMap.get(entityName);
Features features = e.getFeatures();
Collections.sort(features, new Comparator<Feature>() {
public int compare(Feature f1, Feature f2) {
boolean f1IsReference = f1.getModifiers().wContainsValue(FeatureModifierEnum.reference);
boolean f2IsReference = f2.getModifiers().wContainsValue(FeatureModifierEnum.reference);
if (f2IsReference)
return f1IsReference ? 0 : -1;
else
return !f1IsReference ? 0 : +1;
}
});
}
}
use of org.whole.lang.models.model.Features in project whole by wholeplatform.
the class ControlQueriesTest method testChoose3.
@Test
public void testChoose3() {
Model model = new ModelsModel().create();
ModelDeclarations decls = model.getDeclarations();
ITemplateManager tm = ControlQueriesTemplateManager.instance();
PathExpression query = (PathExpression) tm.create("choose3");
int i = 0;
IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, model);
while (iterator.hasNext()) {
IEntity result = iterator.next();
IEntity decl = decls.wGet(i++);
switch(decl.wGetEntityOrd()) {
case ModelsEntityDescriptorEnum.SimpleEntity_ord:
Features features = ((SimpleEntity) decl).getFeatures();
if (!features.isEmpty())
assertEquals(features.get(0).getName().wStringValue(), result.wStringValue());
break;
case ModelsEntityDescriptorEnum.CompositeEntity_ord:
CompositeEntity compositeEntity = (CompositeEntity) decl;
assertEquals(compositeEntity.getComponentType().wStringValue(), result.wStringValue());
break;
case ModelsEntityDescriptorEnum.DataEntity_ord:
DataEntity dataEntity = (DataEntity) decl;
assertEquals(dataEntity.getDataType().wStringValue(), result.wStringValue());
break;
case ModelsEntityDescriptorEnum.EnumEntity_ord:
EnumEntity enumEntity = (EnumEntity) decl;
assertEquals(enumEntity.getValues().wGet(0).wStringValue(), result.wStringValue());
break;
}
}
}
Aggregations