use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testKindTest.
@Test
public void testKindTest() throws Exception {
IEntity model = XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/templates/codebase/TemplateManagerArtifactsTemplates.xwl"));
QueriesEntityFactory ef = QueriesEntityFactory.instance;
for (IEntity e : BehaviorUtils.compileAndLazyEvaluate(ef.createFilter(ef.createDescendantOrSelfStep(), ef.createKindTest(KindTestEnum.RESOLVER)), model)) Assert.assertTrue(EntityUtils.isResolver(e));
for (IEntity e : BehaviorUtils.compileAndLazyEvaluate(ef.createFilter(ef.createDescendantOrSelfStep(), ef.createKindTest(KindTestEnum.DATA)), model)) Assert.assertTrue(EntityUtils.isData(e));
for (IEntity e : BehaviorUtils.compileAndLazyEvaluate(ef.createFilter(ef.createDescendantOrSelfStep(), ef.createKindTest(KindTestEnum.FRAGMENT)), model)) Assert.assertTrue(EntityUtils.isFragment(e));
}
use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.
the class PathExpressionsQueriesTest method testPrettyPrint.
@Test
public void testPrettyPrint() {
ITemplateManager tm = PathExpressionsQueriesTemplateManager.instance();
QueriesEntityFactory ef = QueriesEntityFactory.instance;
Assert.assertEquals("phraseStructure/child()[0]/rule/child()[0]/name", toPrettyPrintString((PathExpression) tm.create("path1")));
Assert.assertEquals("phraseStructure/child()[2]", toPrettyPrintString((PathExpression) tm.create("path1a")));
Assert.assertEquals("phraseStructure/child()[2][type() = Production]", toPrettyPrintString((PathExpression) tm.create("path1b")));
Assert.assertEquals("phraseStructure/child()[0]/following-sibling()[2]", toPrettyPrintString((PathExpression) tm.create("path1c")));
Assert.assertEquals("phraseStructure/child()[0]/following-sibling()[2][type() = Production]", toPrettyPrintString((PathExpression) tm.create("path1d")));
Assert.assertEquals("phraseStructure/child()[0]/rule/descendant()[kind() = SIMPLE]|[kind() = DATA]", toPrettyPrintString((PathExpression) tm.create("path2")));
Assert.assertEquals("phraseStructure/child()[0]/rule/descendant()![kind() = COMPOSITE]", toPrettyPrintString((PathExpression) tm.create("path3")));
Assert.assertEquals("phraseStructure/child()[type() <: Production]/rule/descendant()[type() <: Production]", toPrettyPrintString((PathExpression) tm.create("path4")));
Assert.assertEquals("(phraseStructure, lexicalStructure)/child()[type() <: Production][some rule[type() = Choose] satisfies ]", toPrettyPrintString((PathExpression) tm.create("path5")));
Assert.assertEquals("phraseStructure/child()[type() = Production][name[visitor: startsWith(\"I\")]]", toPrettyPrintString(buildPath9(ef)));
}
use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.
the class ActionsE4InterpreterVisitor method createAction.
protected IAction createAction(Value kind, IEnablerPredicate enablerPredicate, IEntityTransformer transformer, IEntity prototype, String text) {
// FIXME transformer always passed as null
IEclipseContext context = (IEclipseContext) getBindings().wGetValue("context");
ActionFactory actionRegistry = new ActionFactory(context);
QueriesEntityFactory qf = QueriesEntityFactory.instance;
IEntity predicate = enablerPredicate instanceof OpaqueEnablerPredicate ? ((OpaqueEnablerPredicate) enablerPredicate).value : qf.createBooleanLiteral(true);
switch(kind.getOrdinal()) {
case ActionKindEnum.REPLACE_ord:
return actionRegistry.createReplaceFragmentAction(text, predicate, prototype);
case ActionKindEnum.INSERT_ord:
return actionRegistry.createAddFragmentAction(text, predicate, prototype);
case ActionKindEnum.WRAP_ord:
IEntity behavior = qf.createPointwiseUpdate(qf.createVariableRefStep("focusEntity"), CommonsEntityAdapterFactory.createStageUpFragment(QueriesEntityDescriptorEnum.Expression, prototype));
return actionRegistry.createPerformAction(text, WRAP_ICON_URI, predicate, behavior);
case ActionKindEnum.PERFORM_ord:
return actionRegistry.createPerformAction(text, WRAP_ICON_URI, predicate, prototype);
default:
throw new IllegalArgumentException("not implemented yet");
}
}
use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.
the class QueriesContentAssistVisitor method allEntityTypes.
private boolean allEntityTypes(IEntity entity, EntityDescriptor<?> type) {
if (!EntityUtils.hasParent(entity))
return false;
EntityDescriptor<?> featureED = entity.wGetParent().wGetEntityDescriptor(entity);
if (!featureED.isPlatformSupertypeOf(EntityType) && !featureED.isPlatformSupertypeOf(TypeTest) && !featureED.isPlatformSupertypeOf(SubtypeTest) && !featureED.isPlatformSupertypeOf(SupertypeTest) && !featureED.isPlatformSupertypeOf(ExtendedSubtypeTest) && !featureED.isPlatformSupertypeOf(ExtendedSupertypeTest))
return false;
boolean alltypesTest = (type == SubtypeTest || type == SupertypeTest || type == ExtendedSubtypeTest || type == ExtendedSupertypeTest || type == AtTypeTest);
ActionsUIEntityFactory aef = ActionsUIEntityFactory.instance;
GroupAction languagesGroup = aef.createGroupAction();
languagesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
languagesGroup.getText().setValue("queries.languages");
Actions actions = aef.createActions(0);
QueriesEntityFactory qef = QueriesEntityFactory.instance;
String actualLanguageURI = "";
String actualEntityName = "";
EntityDescriptor<?> actualED = null;
EntityDescriptor<?> targetED = type;
try {
actualED = CommonsDataTypePersistenceParser.parseEntityDescriptor(entity.wStringValue());
actualLanguageURI = actualED.getLanguageKit().getURI();
actualEntityName = actualED.getName();
} catch (Exception e) {
if (DataTypeUtils.getDataKind(entity).isString())
actualEntityName = entity.wStringValue();
}
IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
for (ILanguageKit languageKit : registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR)) {
if (languageKit.getURI().equals(actualLanguageURI))
continue;
EntityDescriptorEnum edEnum = languageKit.getEntityDescriptorEnum();
EntityDescriptor<?> ed = null;
if (actualEntityName.length() > 0)
ed = edEnum.valueOf(actualEntityName);
if (ed == null) {
if (alltypesTest)
ed = edEnum.valueOf(0);
else {
Iterator<EntityDescriptor<?>> iterator = edEnum.values().iterator();
EntityDescriptor<?> nextED;
while (ed == null && iterator.hasNext()) if (!(nextED = iterator.next()).isAbstract())
ed = nextED;
if (ed == null)
continue;
}
}
IEntity prototype = qef.create(targetED, CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON));
}
languagesGroup.setActions(actions);
boolean addedLanguages = EntityUtils.isResolver(entity) ? mergeResult(targetED, languagesGroup) : mergeResult(languagesGroup);
if (actualED != null) {
GroupAction typenamesGroup = aef.createGroupAction();
typenamesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
typenamesGroup.getText().setValue(alltypesTest ? "queries.alltypenames" : "queries.typenames");
actions = aef.createActions(0);
EntityDescriptorEnum edEnum = actualED.getEntityDescriptorEnum();
List<EntityDescriptor<?>> eds = new ArrayList<EntityDescriptor<?>>(edEnum.values());
Collections.sort(eds, EnumValueImpl.getByNameComparator());
for (EntityDescriptor<?> ed : eds) {
if (ed.equals(actualED) || (!alltypesTest && ed.isAbstract()))
continue;
IEntity prototype = qef.create(targetED, CommonsDataTypePersistenceParser.unparseEntityDescriptor(ed));
actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ed.getName()));
}
typenamesGroup.setActions(actions);
addedLanguages |= EntityUtils.isResolver(entity) ? mergeResult(targetED, typenamesGroup) : mergeResult(typenamesGroup);
}
return addedLanguages;
}
use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.
the class QueriesContentAssistVisitor method allFeatureTypes.
private boolean allFeatureTypes(IEntity entity, EntityDescriptor<?> targetEd) {
if (!EntityUtils.hasParent(entity) || !entity.wGetParent().wGetEntityDescriptor(entity).isPlatformSupertypeOf(targetEd))
return false;
ActionsUIEntityFactory aef = ActionsUIEntityFactory.instance;
GroupAction languagesGroup = aef.createGroupAction();
languagesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
languagesGroup.getText().setValue("queries.languages");
Actions actions = aef.createActions(0);
QueriesEntityFactory qef = QueriesEntityFactory.instance;
String actualLanguageURI = "";
String actualFeatureName = "";
FeatureDescriptor actualFD = null;
try {
actualFD = CommonsDataTypePersistenceParser.parseFeatureDescriptor(entity.wStringValue());
actualLanguageURI = actualFD.getLanguageKit().getURI();
actualFeatureName = actualFD.getName();
} catch (Exception e) {
if (DataTypeUtils.getDataKind(entity).isString())
actualFeatureName = entity.wStringValue();
}
IResourceRegistry<ILanguageKit> registry = ReflectionFactory.getLanguageKitRegistry();
for (ILanguageKit languageKit : registry.getResources(false, ResourceUtils.SIMPLE_COMPARATOR)) {
if (languageKit.getURI().equals(actualLanguageURI))
continue;
FeatureDescriptorEnum fdEnum = languageKit.getFeatureDescriptorEnum();
if (fdEnum.values().isEmpty())
continue;
FeatureDescriptor fd = null;
if (actualFeatureName.length() > 0)
fd = fdEnum.valueOf(actualFeatureName);
if (fd == null)
fd = fdEnum.valueOf(0);
IEntity prototype = qef.create(targetEd, CommonsDataTypePersistenceParser.unparseFeatureDescriptor(fd));
actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, ResourceUtils.SIMPLE_NAME_PROVIDER.toString(registry, languageKit), IActionConstants.SELECT_LANGUAGE_ICON));
}
languagesGroup.setActions(actions);
boolean addedLanguages = EntityUtils.isResolver(entity) ? mergeResult(targetEd, languagesGroup) : mergeResult(languagesGroup);
if (actualFD != null) {
GroupAction featurenamesGroup = aef.createGroupAction();
featurenamesGroup.setFillStrategy(aef.createHierarchical(aef.createDistinctPrefix(), aef.createSize(10)));
featurenamesGroup.getText().setValue("queries.featurenames");
actions = aef.createActions(0);
FeatureDescriptorEnum fdEnum = actualFD.getFeatureDescriptorEnum();
List<FeatureDescriptor> fds = new ArrayList<FeatureDescriptor>(fdEnum.values());
Collections.sort(fds, EnumValueImpl.getByNameComparator());
for (FeatureDescriptor fd : fds) {
if (fd.equals(actualFD))
continue;
IEntity prototype = qef.create(targetEd, CommonsDataTypePersistenceParser.unparseFeatureDescriptor(fd));
actions.wAdd(aef.createReplaceDifferentTemplateAction(prototype, fd.getName()));
}
featurenamesGroup.setActions(actions);
addedLanguages |= EntityUtils.isResolver(entity) ? mergeResult(targetEd, languagesGroup) : mergeResult(featurenamesGroup);
}
return addedLanguages;
}
Aggregations