Search in sources :

Example 1 with IBindingScope

use of org.whole.lang.bindings.IBindingScope in project whole by wholeplatform.

the class TemplateInterpreterIterator method lookahead.

public E lookahead() {
    if (nextEntityIterator != null)
        return nextEntityIterator.lookahead();
    clearLookaheadScope();
    getBindings().wEnterScope(lookaheadScope(), true);
    IEntity selfEntity = getBindings().wGet("self");
    if (selfEntity != resetEntity)
        getBindings().wDef("self", resetEntity);
    IBindingScope results = InterpreterOperation.interpret(pattern, getBindings(), true);
    getBindings().wExitScope();
    nextEntityIterator = results.getResultIterator();
    if (results.hasResultIterator()) {
        results.setResultIterator(null);
        selfEntity = getBindings().wGet("self");
        if (selfEntity != resetEntity)
            getBindings().wDef("self", resetEntity);
        nextEntityIterator.reset(resetEntity);
        lookaheadScope = null;
    }
    return nextEntityIterator.lookahead();
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingScope(org.whole.lang.bindings.IBindingScope)

Example 2 with IBindingScope

use of org.whole.lang.bindings.IBindingScope in project whole by wholeplatform.

the class BindingUtils method wOuterScope.

// public static IBindingManager getEnvironment(IBindingManager bm, String variable) {
// String environmentName = getEnvironmentName(variable);
// if (environmentName != null) {
// if (!bm.wIsSet(environmentName)) {
// IBindingManager environment = bm.wGetEnvironmentManager().getEnvironment(environmentName);
// bm.wDefValue(environmentName, environment);
// }
// bm = (IBindingManager) bm.wGetValue(environmentName);
// }
// return bm;
// }
// 
// public static boolean wIsSet(IBindingManager bm, String variable) {
// return getEnvironment(bm, variable).wIsSet(getVariableName(variable));
// }
// public static IEntity wGet(IBindingManager bm, String variable) {
// return getEnvironment(bm, variable).wGet(getVariableName(variable));
// }
// public static void wSet(IBindingManager bm, String variable, IEntity value) {
// getEnvironment(bm, variable).wSet(getVariableName(variable), value);
// }
// public static void wDef(IBindingManager bm, String variable, IEntity value) {
// getEnvironment(bm, variable).wDef(getVariableName(variable), value);
// }
public static IBindingScope wOuterScope(IBindingScope scope, boolean preceding) {
    IBindingScope precedingScope = scope;
    switch(scope.getKind()) {
        case OUTER_GROUP_ADAPTER:
            return wOuterScope(scope.wTargetScope(), preceding);
        case OUTER_SCOPE_ADAPTER:
            do {
                precedingScope = scope;
                scope = scope.wEnclosingScope();
            } while (scope.getKind().equals(IBindingScope.Kind.OUTER_SCOPE_ADAPTER));
            if (scope == NullScope.instance)
                break;
        case SCOPE:
        case INNER_SCOPE_ADAPTER:
            do {
                precedingScope = scope;
                scope = scope.wEnclosingScope();
            } while (scope.getKind().equals(IBindingScope.Kind.INNER_SCOPE_ADAPTER));
            break;
    }
    return preceding ? precedingScope : scope;
}
Also used : IBindingScope(org.whole.lang.bindings.IBindingScope)

Example 3 with IBindingScope

use of org.whole.lang.bindings.IBindingScope in project whole by wholeplatform.

the class TestsHelpers method applyFilter.

public static IEntity applyFilter(IEntity filter, IEntity subject, IBindingManager bm) {
    bm.wDef("self", subject);
    IBindingScope bs = InterpreterOperation.interpret(EntityUtils.isFragment(filter) ? filter.wGetRoot() : filter, bm);
    if (bs.hasResultIterator()) {
        IEntityIterator<?> iterator = bs.getResultIterator();
        bs.setResultIterator(null);
        iterator.reset(subject);
        while (iterator.hasNext()) iterator.next();
        return subject;
    } else {
        IEntity result = bs.getResult();
        return result != null ? result : subject;
    }
}
Also used : IBindingScope(org.whole.lang.bindings.IBindingScope) IEntity(org.whole.lang.model.IEntity)

Example 4 with IBindingScope

use of org.whole.lang.bindings.IBindingScope in project whole by wholeplatform.

the class ActionCallIterator method lookahead.

public IEntity lookahead() {
    if (nextEntity != null)
        return nextEntity;
    if (functionIterator == null && resetEntity == null)
        return null;
    IBindingScope laScope = lookaheadScope();
    for (String name : laScope.wLocalNames()) getBindings().wUnset(name);
    getBindings().wEnterScope();
    nextEntity = functionIterator().lookahead();
    getBindings().wExitScope();
    return nextEntity;
}
Also used : IBindingScope(org.whole.lang.bindings.IBindingScope)

Example 5 with IBindingScope

use of org.whole.lang.bindings.IBindingScope in project whole by wholeplatform.

the class MatcherTest method testMultipleSubstitute.

@Test
public void testMultipleSubstitute() {
    Model modelPattern = new ModelPattern().create();
    IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
    bindings.wDefValue("dataEntity", "DE");
    IBindingScope args = BindingManagerFactory.instance.createSimpleScope();
    args.wDefValue("dataEntity", "DE");
    Matcher.substitute(modelPattern, args, false);
    SimpleName var1 = (SimpleName) modelPattern.getDeclarations().wGet(0).wGet(ModelsFeatureDescriptorEnum.features).wGet(0).wGet(ModelsFeatureDescriptorEnum.type);
    SimpleName var2 = (SimpleName) modelPattern.getDeclarations().wGet(1).wGet(ModelsFeatureDescriptorEnum.name);
    assertEquals("DE", var1.wStringValue());
    assertEquals("DE", var2.wStringValue());
    assertNotSame(var1, var2);
}
Also used : IBindingScope(org.whole.lang.bindings.IBindingScope) SimpleName(org.whole.lang.models.model.SimpleName) TestingModel(org.whole.lang.testentities.codebase.TestingModel) Model(org.whole.lang.models.model.Model) IBindingManager(org.whole.lang.bindings.IBindingManager) Test(org.junit.Test)

Aggregations

IBindingScope (org.whole.lang.bindings.IBindingScope)13 IEntity (org.whole.lang.model.IEntity)8 IBindingManager (org.whole.lang.bindings.IBindingManager)5 Test (org.junit.Test)3 CoreException (org.eclipse.core.runtime.CoreException)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 IFile (org.eclipse.core.resources.IFile)1 Status (org.eclipse.core.runtime.Status)1 IOConsole (org.eclipse.ui.console.IOConsole)1 IFilePersistenceProvider (org.whole.lang.codebase.IFilePersistenceProvider)1 IPersistenceKit (org.whole.lang.codebase.IPersistenceKit)1 StringPersistenceProvider (org.whole.lang.codebase.StringPersistenceProvider)1 Model (org.whole.lang.models.model.Model)1 SimpleEntity (org.whole.lang.models.model.SimpleEntity)1 SimpleName (org.whole.lang.models.model.SimpleName)1 IOperationProgressMonitor (org.whole.lang.operations.IOperationProgressMonitor)1 OperationProgressMonitorAdapter (org.whole.lang.operations.OperationProgressMonitorAdapter)1 IReusablesEntity (org.whole.lang.reusables.model.IReusablesEntity)1