Search in sources :

Example 1 with QueriesEntityFactory

use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.

the class TestsHelpers method createFilterRule.

public static FilterRule createFilterRule(Collection<IEntity> entities) {
    // create the filter logic
    QueriesEntityFactory qef = QueriesEntityFactory.instance;
    Sequence sequence = qef.createSequence(0);
    Iterator<IEntity> iterator = entities.iterator();
    IEntity baseEntity = iterator.next();
    while (iterator.hasNext()) updateFilterBody(baseEntity, iterator.next(), sequence);
    if (sequence.wIsEmpty())
        return createResolver(FilterRule);
    // create the filter rule
    TestsEntityFactory tef = TestsEntityFactory.instance;
    FilterRule filterRule = tef.createFilterRule(tef.createDescription("Auto-generated filter rule"), createVariable(Name, "filterName"), sequence.wGetAdapter(Statement));
    return filterRule;
}
Also used : IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) TestsEntityFactory(org.whole.lang.tests.factories.TestsEntityFactory) Sequence(org.whole.lang.queries.model.Sequence) FilterRule(org.whole.lang.tests.reflect.TestsEntityDescriptorEnum.FilterRule) FilterRule(org.whole.lang.tests.model.FilterRule)

Example 2 with QueriesEntityFactory

use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.

the class SemanticsInterpreterVisitor method visit.

@Override
public void visit(StructuredVariable entity) {
    ActionsEntityFactory aef = ActionsEntityFactory.instance;
    QueriesEntityFactory qef = QueriesEntityFactory.instance;
    ActionCall actionCall = aef.createActionCall(aef.createLabel("whole:org.whole.lang.semantics:SemanticsActions:1.0.0#toVariableFlatName"), qef.createVariableRefStep("variable").wGetAdapter(ActionsEntityDescriptorEnum.SelectedEntities));
    getBindings().wDef("variable", entity);
    IEntity varNameEntity = BehaviorUtils.evaluate(actionCall, 0, getOperation());
    if (isSelectedFeature(SemanticsUtils.USE_IDENTIFIER_SEMANTICS))
        setResult(varNameEntity);
    else {
        IEntity varValue = BindingUtils.wGet(getBindings(), varNameEntity.wStringValue());
        if (varValue == null)
            throw new MissingVariableException(entity.toString()).withSourceEntity(entity).withBindings(getBindings());
        setResult(varValue);
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ActionsEntityFactory(org.whole.lang.actions.factories.ActionsEntityFactory) ActionCall(org.whole.lang.actions.model.ActionCall) MissingVariableException(org.whole.lang.visitors.MissingVariableException)

Example 3 with QueriesEntityFactory

use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.

the class GrammarsContentAssistVisitor method calculateNonTerminalValues.

public static Set<String> calculateNonTerminalValues(IEntity e) {
    Grammar grammar = Matcher.findAncestor(Grammar, e);
    if (grammar != null) {
        Set<String> names = new HashSet<String>();
        IEntity parent = e.wGetParent();
        ILanguageKit languageKit = getLanguageKitIfExists(grammar);
        if (languageKit != null) {
            if (!grammar.getLexicalStructure().equals(parent.wGetParent()))
                names.addAll(languageKit.getEntityDescriptorEnum().names());
            if (!parent.wGetFeatureDescriptor(e).equals(name)) {
                QueriesEntityFactory qef = QueriesEntityFactory.instance;
                Path allTokenNames = qef.createPath(qef.createSequence(qef.createFeatureStep("lexicalStructure"), qef.createFeatureStep("phraseStructure")), qef.createChildStep(), qef.createFilter(qef.createFeatureStep("name"), qef.createKindTest(KindTestEnum.IMPL)));
                for (NonTerminal nt : BehaviorUtils.<NonTerminal>compileAndLazyEvaluate(allTokenNames, grammar)) names.add(nt.getValue());
            }
        } else {
            AbstractPatternFilterIterator<NonTerminal> i = IteratorFactory.<NonTerminal>descendantOrSelfMatcherIterator().withPattern(NonTerminal);
            i.reset(grammar);
            for (NonTerminal nt : i) if (EntityUtils.isNotResolver(nt))
                names.add(nt.getValue());
        }
        return names;
    }
    return Collections.emptySet();
}
Also used : Path(org.whole.lang.queries.model.Path) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) NonTerminal(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.NonTerminal) NonTerminal(org.whole.lang.grammars.model.NonTerminal) Grammar(org.whole.lang.grammars.reflect.GrammarsEntityDescriptorEnum.Grammar) Grammar(org.whole.lang.grammars.model.Grammar) ILanguageKit(org.whole.lang.reflect.ILanguageKit) HashSet(java.util.HashSet)

Example 4 with QueriesEntityFactory

use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.

the class ControlQueriesTest method testIf4.

@Test
public void testIf4() {
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("if4");
    QueriesEntityFactory qef = QueriesEntityFactory.instance;
    IEntity queryExp1 = qef.createDivision(qef.createIntLiteral(10), qef.createIntLiteral(8));
    IBindingManager bm = BindingManagerFactory.instance.createBindingManager();
    IEntityIterator<IEntity> iterator = BehaviorUtils.compileAndLazyEvaluate(query, queryExp1, bm);
    assertTrue(iterator.hasNext());
    IEntity exp1 = iterator.next();
    assertSame(queryExp1.wGet(0), exp1);
    assertTrue(bm.wIsSet("a"));
    assertFalse(bm.wIsSet("b"));
    assertFalse(bm.wIsSet("exp1"));
    assertFalse(bm.wIsSet("exp2"));
    assertTrue(iterator.hasNext());
    IEntity exp2 = iterator.next();
    assertSame(queryExp1.wGet(1), exp2);
    assertFalse(bm.wIsSet("a"));
    assertTrue(bm.wIsSet("b"));
    assertFalse(bm.wIsSet("exp1"));
    assertFalse(bm.wIsSet("exp2"));
    assertFalse(iterator.hasNext());
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) IBindingManager(org.whole.lang.bindings.IBindingManager) ITemplateManager(org.whole.lang.templates.ITemplateManager) Test(org.junit.Test)

Example 5 with QueriesEntityFactory

use of org.whole.lang.queries.factories.QueriesEntityFactory in project whole by wholeplatform.

the class ControlQueriesTest method testQueryDecl9.

@Test
public void testQueryDecl9() {
    QueriesEntityFactory qef = QueriesEntityFactory.instance;
    IEntity queryExp1 = qef.createAddition(qef.createAddition(qef.createIntLiteral(10), qef.createIntLiteral(8)), qef.createAddition(qef.createIntLiteral(2), qef.createIntLiteral(1)));
    ITemplateManager tm = ControlQueriesTemplateManager.instance();
    PathExpression query = (PathExpression) tm.create("queryDecl9");
    assertTrue(Matcher.match(queryExp1, BehaviorUtils.evaluateFirstResult(query, queryExp1)));
}
Also used : PathExpression(org.whole.lang.queries.model.PathExpression) IEntity(org.whole.lang.model.IEntity) QueriesEntityFactory(org.whole.lang.queries.factories.QueriesEntityFactory) ITemplateManager(org.whole.lang.templates.ITemplateManager) Test(org.junit.Test)

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