Search in sources :

Example 6 with QueriesEntityFactory

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));
}
Also used : IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) Test(org.junit.Test)

Example 7 with QueriesEntityFactory

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)));
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ITemplateManager(org.whole.lang.templates.ITemplateManager) Test(org.junit.Test)

Example 8 with QueriesEntityFactory

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");
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) ActionFactory(org.whole.lang.e4.ui.actions.ActionFactory)

Example 9 with QueriesEntityFactory

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;
}
Also used : EntityDescriptorEnum(org.whole.lang.reflect.EntityDescriptorEnum) QueriesEntityDescriptorEnum(org.whole.lang.queries.reflect.QueriesEntityDescriptorEnum) Actions(org.whole.lang.actions.model.Actions) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ArrayList(java.util.ArrayList) ILanguageKit(org.whole.lang.reflect.ILanguageKit) GroupAction(org.whole.lang.actions.model.GroupAction) EntityDescriptor(org.whole.lang.reflect.EntityDescriptor) ActionsUIEntityFactory(org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)

Example 10 with QueriesEntityFactory

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;
}
Also used : FeatureDescriptorEnum(org.whole.lang.reflect.FeatureDescriptorEnum) Actions(org.whole.lang.actions.model.Actions) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ArrayList(java.util.ArrayList) ILanguageKit(org.whole.lang.reflect.ILanguageKit) GroupAction(org.whole.lang.actions.model.GroupAction) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) ActionsUIEntityFactory(org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)

Aggregations

QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)21 IEntity (org.whole.lang.model.IEntity)17 Test (org.junit.Test)11 PathExpression (org.whole.lang.queries.model.PathExpression)6 ITemplateManager (org.whole.lang.templates.ITemplateManager)6 Actions (org.whole.lang.actions.model.Actions)4 GroupAction (org.whole.lang.actions.model.GroupAction)4 ActionsUIEntityFactory (org.whole.lang.actions.ui.factories.ActionsUIEntityFactory)4 ILanguageKit (org.whole.lang.reflect.ILanguageKit)4 XmlModel (org.whole.lang.models.codebase.XmlModel)3 Model (org.whole.lang.models.model.Model)3 ArrayList (java.util.ArrayList)2 IBindingManager (org.whole.lang.bindings.IBindingManager)2 ClasspathPersistenceProvider (org.whole.lang.codebase.ClasspathPersistenceProvider)2 Path (org.whole.lang.queries.model.Path)2 HashSet (java.util.HashSet)1 IEclipseContext (org.eclipse.e4.core.contexts.IEclipseContext)1 ActionsEntityFactory (org.whole.lang.actions.factories.ActionsEntityFactory)1 ActionCall (org.whole.lang.actions.model.ActionCall)1 ActionFactory (org.whole.lang.e4.ui.actions.ActionFactory)1