Search in sources :

Example 71 with IBindingManager

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

the class WorkflowsInterpreterVisitor method visit.

@Override
public void visit(InvokeQuery entity) {
    Variable queryName = entity.getQueryName();
    Arguments arguments = entity.getArguments();
    IEntityIterator<? extends IEntity>[] argsIterators = new IEntityIterator<?>[0];
    Set<String> filterNames = getOperation().getResultsScope().wNames();
    IBindingManager args = BindingManagerFactory.instance.createBindingManager(BindingManagerFactory.instance.createExcludeFilterScope(filterNames).wWithEnclosingScope(getBindings()), getBindings().wGetEnvironmentManager());
    if (!EntityUtils.isNotResolver(arguments)) {
        setResultValue(argsIterators);
        arguments.accept(this);
        argsIterators = (IEntityIterator<?>[]) getResultValue();
    } else if (Matcher.match(WorkflowsEntityDescriptorEnum.Expressions, arguments)) {
        IEntity selfEntity = getBindings().wGet("self");
        argsIterators = new IEntityIterator<?>[arguments.wSize()];
        for (int i = 0; i < argsIterators.length; i++) {
            ((Expressions) arguments).get(i).accept(this);
            argsIterators[i] = getResultIterator();
            setResultIterator(null);
            resetSelfEntity(selfEntity);
        }
    } else
        define(args, (Assignments) arguments);
    IEntityIterator<?> iterator = QueriesIteratorFactory.callIterator(queryName.getValue(), argsIterators);
    iterator.setBindings(args);
    resetIterator(iterator);
    while (iterator.hasNext()) iterator.next();
}
Also used : Variable(org.whole.lang.workflows.model.Variable) IEntity(org.whole.lang.model.IEntity) Arguments(org.whole.lang.workflows.model.Arguments) IBindingManager(org.whole.lang.bindings.IBindingManager) Expressions(org.whole.lang.workflows.model.Expressions) IEntityIterator(org.whole.lang.iterators.IEntityIterator)

Example 72 with IBindingManager

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

the class GenericGrammarBasedPrettyPrinterVisitor method visit.

@Override
public void visit(IEntity entity) {
    IBindingManager bm = getBindings();
    Grammar grammar = null;
    String grammarUri = GrammarsUtils.getGrammarUri(bm);
    if (grammarUri != null)
        grammar = GrammarsRegistry.instance().getGrammar(grammarUri);
    if (grammar == null) {
        Collection<Grammar> grammars = GrammarsRegistry.instance().getGrammarsFor(entity);
        if (grammars.isEmpty())
            throw new IllegalArgumentException("cannot find a suitable grammar to unparse the entity");
        grammar = grammars.iterator().next();
    }
    new GrammarBasedPrettyPrinterVisitor(entity, out, bm).visit(grammar);
}
Also used : IBindingManager(org.whole.lang.bindings.IBindingManager) Grammar(org.whole.lang.grammars.model.Grammar)

Example 73 with IBindingManager

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

the class GrammarsInterpreterVisitor method visit.

@Override
public void visit(Grammar grammar) {
    grammar = normalize(grammar);
    GrammarsRegistry.instance().putGrammar(grammar);
    TargetLanguage targetLanguage = grammar.getTargetLanguage();
    ILanguageKit languageKit = null;
    final String languageUri;
    IBindingManager bm = getBindings();
    if (Matcher.match(GrammarsEntityDescriptorEnum.URI, targetLanguage)) {
        languageUri = targetLanguage.wStringValue();
        languageKit = ReflectionFactory.getLanguageKit(languageUri, true, bm);
    } else {
        languageUri = ((LanguageDescriptor) targetLanguage).getUri().getValue();
        stagedVisit(GrammarsUtils.deriveModel(grammar, false));
        languageKit = (ILanguageKit) bm.getResult().wGetValue();
    }
    if (languageKit.isDynamic()) {
        DynamicLanguageKit dynamicLanguageKit = (DynamicLanguageKit) languageKit;
        GrammarBasedDataTypeParser dataTypeParser = new GrammarBasedDataTypeParser(grammar.getUri().getValue());
        dynamicLanguageKit.setDataTypeParser(DataTypeParsers.PERSISTENCE, dataTypeParser);
        dynamicLanguageKit.setDataTypeParser(DataTypeParsers.PRESENTATION, dataTypeParser);
    }
    ReflectionFactory.updatePersistenceAndEditorKits(languageKit);
    ReflectionFactory.deploy(new AbstractLanguageExtensionDeployer() {

        public void deploy(ReflectionFactory platform) {
            platform.addOperationFactory(languageUri, PrettyPrinterOperation.ID, new IVisitorFactory() {

                public IVisitor create(IOperation operation, int stage) {
                    return new GenericGrammarBasedPrettyPrinterVisitor((PrettyPrinterOperation) operation);
                }
            });
            platform.addOperationFactory(languageUri, ValidatorOperation.ID, new IVisitorFactory() {

                public IVisitor create(IOperation operation, int stage) {
                    return new GenericGrammarBasedValidatorVisitor();
                }
            });
        }
    });
}
Also used : IOperation(org.whole.lang.operations.IOperation) GrammarBasedDataTypeParser(org.whole.lang.grammars.parsers.GrammarBasedDataTypeParser) LanguageDescriptor(org.whole.lang.grammars.model.LanguageDescriptor) AbstractLanguageExtensionDeployer(org.whole.lang.reflect.AbstractLanguageExtensionDeployer) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) ILanguageKit(org.whole.lang.reflect.ILanguageKit) DynamicLanguageKit(org.whole.lang.reflect.DynamicLanguageKit) ReflectionFactory(org.whole.lang.reflect.ReflectionFactory) IBindingManager(org.whole.lang.bindings.IBindingManager) TargetLanguage(org.whole.lang.grammars.model.TargetLanguage)

Example 74 with IBindingManager

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

the class GrammarsDefaultDataTypeParser method format.

protected String format(EntityDescriptor<?> ed, Object value) {
    Format format = grammarBasedDataTypeParser.getDataTerminal(ed).getFormat();
    if (EntityUtils.isFragment(format)) {
        IBindingManager bindings = getBindings();
        bindings.wEnterScope();
        bindings.wDefValue("self", value);
        IEntity entity = BehaviorUtils.evaluate(format, 0, bindings);
        bindings.wExitScope();
        return entity.wStringValue();
    } else {
        Formatter formatter = new Formatter(grammarBasedDataTypeParser.getLocale());
        return formatter.format(format.getValue(), value).toString();
    }
}
Also used : Format(org.whole.lang.grammars.model.Format) IEntity(org.whole.lang.model.IEntity) Formatter(java.util.Formatter) IBindingManager(org.whole.lang.bindings.IBindingManager)

Example 75 with IBindingManager

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

the class TestsUIInterpreterVisitor method reportError.

@Override
protected void reportError(String name, RuntimeException e) {
    super.reportError(name, e);
    IBindingManager debugEnv = getBindings();
    IEclipseContext context = (IEclipseContext) debugEnv.wGetValue("eclipse#eclipseContext");
    if ((debugEnv.wIsSet("debug#reportModeEnabled") && !debugEnv.wBooleanValue("debug#reportModeEnabled")) || (debugEnv.wIsSet("debug#debugModeEnabled") && !debugEnv.wBooleanValue("debug#debugModeEnabled")) || (debugEnv.wIsSet("debug#breakpointsEnabled") && !debugEnv.wBooleanValue("debug#breakpointsEnabled")))
        return;
    else
        E4Utils.suspendOrReportException(context, SuspensionKind.RECOVERABLE_ERROR, "Model test error", "Error while executing " + name + " test", e, debugEnv);
}
Also used : IBindingManager(org.whole.lang.bindings.IBindingManager) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Aggregations

IBindingManager (org.whole.lang.bindings.IBindingManager)223 IEntity (org.whole.lang.model.IEntity)141 Test (org.junit.Test)91 PathExpression (org.whole.lang.queries.model.PathExpression)49 ITemplateManager (org.whole.lang.templates.ITemplateManager)40 Grammar (org.whole.lang.grammars.model.Grammar)28 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)27 ESelectionService (org.eclipse.e4.ui.workbench.modeling.ESelectionService)17 Model (org.whole.lang.models.model.Model)15 Production (org.whole.lang.grammars.model.Production)14 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)14 File (java.io.File)12 QueriesGrammar (org.whole.lang.grammars.codebase.QueriesGrammar)12 XmlModel (org.whole.lang.models.codebase.XmlModel)11 SimpleEntity (org.whole.lang.models.model.SimpleEntity)10 VisitException (org.whole.lang.visitors.VisitException)9 IBindingScope (org.whole.lang.bindings.IBindingScope)6 ModelBuilderOperation (org.whole.lang.builders.ModelBuilderOperation)6 HashMap (java.util.HashMap)5 IFile (org.eclipse.core.resources.IFile)5