Search in sources :

Example 1 with MissingVariableException

use of org.whole.lang.visitors.MissingVariableException in project whole by wholeplatform.

the class TestsInterpreterVisitor method visit.

@Override
public void visit(DataName entity) {
    String name = entity.getValue();
    IEntity result = getBindings().wGet(name);
    if (result == null)
        throw new MissingVariableException(name).withSourceEntity(entity).withBindings(getBindings());
    else
        setResult(result);
}
Also used : IEntity(org.whole.lang.model.IEntity) MissingVariableException(org.whole.lang.visitors.MissingVariableException)

Example 2 with MissingVariableException

use of org.whole.lang.visitors.MissingVariableException 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 MissingVariableException

use of org.whole.lang.visitors.MissingVariableException in project whole by wholeplatform.

the class SemanticsInterpreterVisitor method visit.

@Override
public void visit(EnvironmentVariable entity) {
    IEntity oldSematics = setFeature(SemanticsUtils.USE_IDENTIFIER_SEMANTICS, true);
    try {
        entity.getEnvironment().accept(this);
        IBindingManager bm = getBindings().wGetEnvironmentManager().getEnvironment(getResult().wStringValue());
        entity.getVariable().accept(this);
        String varName = getResult().wStringValue();
        IEntity varValue = bm.wGet(varName);
        if (varValue == null)
            throw new MissingVariableException(entity.getVariable().toString()).withSourceEntity(entity).withBindings(getBindings());
        setResult(varValue);
    } finally {
        setFeature(SemanticsUtils.USE_IDENTIFIER_SEMANTICS, oldSematics);
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) IBindingManager(org.whole.lang.bindings.IBindingManager) MissingVariableException(org.whole.lang.visitors.MissingVariableException)

Example 4 with MissingVariableException

use of org.whole.lang.visitors.MissingVariableException in project whole by wholeplatform.

the class SemanticsInterpreterVisitor method visit.

@Override
public void visit(Variable entity) {
    if (isSelectedFeature(SemanticsUtils.USE_IDENTIFIER_SEMANTICS))
        setResult(entity);
    else {
        IEntity varValue = BindingUtils.wGet(getBindings(), entity.getValue());
        if (varValue == null)
            throw new MissingVariableException(entity.toString()).withSourceEntity(entity).withBindings(getBindings());
        setResult(varValue);
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) MissingVariableException(org.whole.lang.visitors.MissingVariableException)

Example 5 with MissingVariableException

use of org.whole.lang.visitors.MissingVariableException in project whole by wholeplatform.

the class ExecuteSampleModelRunnable method run.

@Override
public void run(IOperationProgressMonitor pm) throws InvocationTargetException, InterruptedException {
    IEntity selfEntity = EntityUtils.mapEntity(selfModel, EntityUtils.clone(EntityUtils.getCompoundRoot(selfModel)));
    Set<String> initialNames = bm.wNames();
    pm.beginTask("Executing sample...", IOperationProgressMonitor.TOTAL_WORK);
    behaviorModel = BehaviorUtils.apply("whole:org.whole.lang.ui.views:SamplePerspectiveSemantics#SampleViewBehavior", behaviorModel, bm);
    IEntity derivedModel = null;
    try {
        IEntityIterator<?> iterator = BehaviorUtils.lazyEvaluate(behaviorModel, 0, bm);
        iterator.setBindings(selfBindings);
        iterator.reset(selfEntity);
        if (iterator.getClass().equals(ConstantIterator.class)) {
            IEntity result = iterator.next();
            if (result == null || !EntityUtils.isData(result))
                derivedModel = result;
            else {
                Object resultValue = result.wGetValue();
                derivedModel = IVisitor.class.isInstance(resultValue) ? BindingManagerFactory.instance.createValue(Matcher.match((IVisitor) resultValue, selfEntity)) : result;
            }
        } else if (iterator.hasNext()) {
            derivedModel = MiscEntityFactory.instance.createMisc(0);
            ITransactionScope transactionScope = BindingManagerFactory.instance.createTransactionScope();
            bm.wEnterScope(transactionScope);
            try {
                for (IEntity result : iterator) {
                    transactionScope.commit();
                    derivedModel.wAdd(GenericEntityFactory.instance.create(CommonsEntityDescriptorEnum.SameStageFragment, // CommonsEntityFactory.instance.createSameStageFragment(
                    EntityUtils.clone(// TODO substitute with a no containment fragment
                    result)));
                }
            } finally {
                transactionScope.rollback();
                bm.wExitScope();
            }
        }
    } catch (MissingVariableException e) {
        addMissingVariables(contextModel, e);
    } catch (OperationCanceledException e) {
    // gracefully terminate execution
    } catch (Exception e) {
        if (e.getCause() instanceof MissingVariableException)
            addMissingVariables(contextModel, (MissingVariableException) e.getCause());
    } finally {
        pm.endTask();
    }
    IEntity variablesModel = null;
    if (derivedModel != null) {
        EnvironmentEntityFactory ef = EnvironmentEntityFactory.instance;
        variablesModel = ef.createBindings(0);
        for (String name : new TreeSet<String>(bm.wLocalNames())) if (!initialNames.contains(name))
            variablesModel.wAdd(ef.createBinding(ef.createName(name), ef.createValue(BindingUtils.wGet(bm, name))));
        final IEntity contents = derivedModel;
        final IEntity variables = variablesModel;
        context.get(UISynchronize.class).asyncExec(new Runnable() {

            public void run() {
                context.get(IEntityPartViewer.class).setContents(null, contents);
                context.get(IEventBroker.class).post(IE4UIConstants.TOPIC_UPDATE_VARIABLES, variables);
            }
        });
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) IEntity(org.whole.lang.model.IEntity) IVisitor(org.whole.lang.visitors.IVisitor) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) EnvironmentEntityFactory(org.whole.lang.environment.factories.EnvironmentEntityFactory) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MissingVariableException(org.whole.lang.visitors.MissingVariableException) MissingVariableException(org.whole.lang.visitors.MissingVariableException) TreeSet(java.util.TreeSet) UISynchronize(org.eclipse.e4.ui.di.UISynchronize)

Aggregations

IEntity (org.whole.lang.model.IEntity)12 MissingVariableException (org.whole.lang.visitors.MissingVariableException)12 IBindingManager (org.whole.lang.bindings.IBindingManager)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 NoSuchElementException (java.util.NoSuchElementException)1 TreeSet (java.util.TreeSet)1 UISynchronize (org.eclipse.e4.ui.di.UISynchronize)1 ActionsEntityFactory (org.whole.lang.actions.factories.ActionsEntityFactory)1 ActionCall (org.whole.lang.actions.model.ActionCall)1 ITransactionScope (org.whole.lang.bindings.ITransactionScope)1 Variable (org.whole.lang.commons.model.Variable)1 EnvironmentEntityFactory (org.whole.lang.environment.factories.EnvironmentEntityFactory)1 WholeIllegalStateException (org.whole.lang.exceptions.WholeIllegalStateException)1 IEntityIterator (org.whole.lang.iterators.IEntityIterator)1 SubstituteException (org.whole.lang.matchers.SubstituteException)1 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)1 QueriesEntityFactory (org.whole.lang.queries.factories.QueriesEntityFactory)1 IVisitor (org.whole.lang.visitors.IVisitor)1 VisitException (org.whole.lang.visitors.VisitException)1