Search in sources :

Example 21 with IVisitor

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

the class CoreOperationsDeployer method deploy.

public void deploy(ReflectionFactory platform) {
    platform.addOperationFactory(EditorsLanguageKit.URI, ArtifactsGeneratorOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new EditorsArtifactsGeneratorVisitor((ArtifactsGeneratorOperation) operation);
        }
    });
    platform.addOperationFactory(GrammarsLanguageKit.URI, ContentAssistOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new GrammarsContentAssistVisitor();
        }
    });
    platform.addOperationFactory(GrammarsLanguageKit.URI, ValidatorOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new GrammarsValidatorVisitor();
        }
    });
    if (!ReflectionFactory.getLanguageKit(GrammarsLanguageKit.URI, false, null).hasVisitor(InterpreterOperation.ID))
        platform.addOperationFactory(GrammarsLanguageKit.URI, InterpreterOperation.ID, new IVisitorFactory() {

            public IVisitor create(IOperation operation, int stage) {
                if (stage == 0)
                    return new GrammarsInterpreterVisitor();
                else
                    return null;
            }
        });
    platform.addPersistenceKit("org.whole.lang.grammars.GrammarEditor", GrammarsPersistenceKit.instance());
    platform.addPersistenceKit("org.whole.lang.objectivec.ObjectiveCEditor", ObjectiveCPersistenceKit.instance());
    platform.addPersistenceKit("org.whole.lang.mediawiki.MediaWikiEditor", MediaWikiPersistenceKit.instance());
    platform.addOperationFactory(TemplatesLanguageKit.URI, ArtifactsGeneratorOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new AbstractVisitor() {

                public void visit(IEntity entity) {
                    BehaviorUtils.apply("whole:org.whole.lang.templates:TemplatesSemantics#toJava", entity, getBindings());
                }
            };
        }
    });
    platform.addOperationFactory(PojoLanguageKit.URI, ArtifactsGeneratorOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new PojoArtifactsGeneratorVisitor((ArtifactsGeneratorOperation) operation);
        }
    });
    platform.addOperationFactory(FramesLanguageKit.URI, InterpreterOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new FramesInterpreterVisitor();
            else
                return null;
        }
    });
    // TODO test
    // ReflectLibrary.deploy();
    new ReflectLibraryDeployer().deploy(platform);
    new ViewDerivationLibraryDeployer().deploy(platform);
}
Also used : IOperation(org.whole.lang.operations.IOperation) AbstractVisitor(org.whole.lang.visitors.AbstractVisitor) EditorsArtifactsGeneratorVisitor(org.whole.lang.editors.visitors.EditorsArtifactsGeneratorVisitor) GrammarsInterpreterVisitor(org.whole.lang.grammars.visitors.GrammarsInterpreterVisitor) IVisitor(org.whole.lang.visitors.IVisitor) IEntity(org.whole.lang.model.IEntity) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) FramesInterpreterVisitor(org.whole.lang.frames.visitors.FramesInterpreterVisitor) GrammarsContentAssistVisitor(org.whole.lang.grammars.visitors.GrammarsContentAssistVisitor) PojoArtifactsGeneratorVisitor(org.whole.lang.pojo.visitors.PojoArtifactsGeneratorVisitor) ReflectLibraryDeployer(org.whole.lang.ReflectLibraryDeployer) ArtifactsGeneratorOperation(org.whole.lang.operations.ArtifactsGeneratorOperation) ViewDerivationLibraryDeployer(org.whole.lang.ViewDerivationLibraryDeployer) GrammarsValidatorVisitor(org.whole.lang.grammars.visitors.GrammarsValidatorVisitor)

Example 22 with IVisitor

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

the class TestsLanguageDeployer method deploy.

public void deploy(ReflectionFactory platform) {
    platform.addLanguageKit(new TestsLanguageKit());
    platform.addOperationFactory(TestsLanguageKit.URI, GenericBuilderAdapterOperation.ID, new IBuilderFactory() {

        public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
            return new TestsGenericBuilderAdapter((ITestsBuilder) strategy, entityContext);
        }
    });
    platform.addOperationFactory(TestsLanguageKit.URI, SpecificBuilderAdapterOperation.ID, new IBuilderFactory() {

        public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
            return new TestsSpecificBuilderAdapter(strategy, entityContext);
        }
    });
    platform.addOperationFactory(TestsLanguageKit.URI, PrettyPrinterOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new TestsPrettyPrinterVisitor((PrettyPrinterOperation) operation);
        }
    });
    platform.addOperationFactory(TestsLanguageKit.URI, InterpreterOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new TestsLearningInterpreterVisitor();
            else
                return null;
        }
    });
    platform.addOperationFactory(TestsLanguageKit.URI, ContentAssistOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new TestsContentAssistVisitor();
        }
    });
}
Also used : IBuilder(org.whole.lang.builders.IBuilder) IOperation(org.whole.lang.operations.IOperation) PrettyPrinterOperation(org.whole.lang.operations.PrettyPrinterOperation) IVisitor(org.whole.lang.visitors.IVisitor) TestsLearningInterpreterVisitor(org.whole.lang.tests.visitors.TestsLearningInterpreterVisitor) IEntityContext(org.whole.lang.contexts.IEntityContext) ITestsBuilder(org.whole.lang.tests.builders.ITestsBuilder) TestsSpecificBuilderAdapter(org.whole.lang.tests.builders.TestsSpecificBuilderAdapter) IBuilderFactory(org.whole.lang.builders.IBuilderFactory) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) TestsContentAssistVisitor(org.whole.lang.tests.visitors.TestsContentAssistVisitor) TestsGenericBuilderAdapter(org.whole.lang.tests.builders.TestsGenericBuilderAdapter) TestsPrettyPrinterVisitor(org.whole.lang.tests.visitors.TestsPrettyPrinterVisitor)

Example 23 with IVisitor

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

the class SchemeLanguageDeployer method deploy.

public void deploy(ReflectionFactory platform) {
    platform.addLanguageKit(new SchemeLanguageKit());
    platform.addOperationFactory(SchemeLanguageKit.URI, GenericBuilderAdapterOperation.ID, new IBuilderFactory() {

        public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
            return new SchemeGenericBuilderAdapter((ISchemeBuilder) strategy, entityContext);
        }
    });
    platform.addOperationFactory(SchemeLanguageKit.URI, SpecificBuilderAdapterOperation.ID, new IBuilderFactory() {

        public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
            return new SchemeSpecificBuilderAdapter(strategy, entityContext);
        }
    });
    platform.addOperationFactory(SchemeLanguageKit.URI, InterpreterOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new SchemeInterpreterVisitor((InterpreterOperation) operation);
            else
                return null;
        }
    });
    platform.addEditorKit(SchemeTextualEditorKit.ID);
}
Also used : IBuilder(org.whole.lang.builders.IBuilder) IOperation(org.whole.lang.operations.IOperation) IVisitor(org.whole.lang.visitors.IVisitor) IEntityContext(org.whole.lang.contexts.IEntityContext) SchemeGenericBuilderAdapter(org.whole.lang.scheme.builders.SchemeGenericBuilderAdapter) SchemeSpecificBuilderAdapter(org.whole.lang.scheme.builders.SchemeSpecificBuilderAdapter) ISchemeBuilder(org.whole.lang.scheme.builders.ISchemeBuilder) IBuilderFactory(org.whole.lang.builders.IBuilderFactory) SchemeInterpreterVisitor(org.whole.lang.scheme.visitors.SchemeInterpreterVisitor) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory)

Example 24 with IVisitor

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

the class ImpLanguageDeployer method deploy.

public void deploy(ReflectionFactory platform) {
    platform.addLanguageKit(new ImpLanguageKit());
    platform.addOperationFactory(ImpLanguageKit.URI, GenericBuilderAdapterOperation.ID, new IBuilderFactory() {

        public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
            return new ImpGenericBuilderAdapter((IImpBuilder) strategy, entityContext);
        }
    });
    platform.addOperationFactory(ImpLanguageKit.URI, SpecificBuilderAdapterOperation.ID, new IBuilderFactory() {

        public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
            return new ImpSpecificBuilderAdapter(strategy, entityContext);
        }
    });
    platform.addOperationFactory(ImpLanguageKit.URI, PrettyPrinterOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new ImpPrettyPrinterVisitor((PrettyPrinterOperation) operation);
        }
    });
    platform.addOperationFactory(ImpLanguageKit.URI, InterpreterOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new ImpInterpreterVisitor((InterpreterOperation) operation);
            else
                return null;
        }
    });
    platform.addOperationFactory(ImpLanguageKit.URI, ValidatorOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return ImpTraversalFactory.instance.topDown(ImpTraversalFactory.instance.sequence(new ImpResolverValidatorVisitor((ValidatorOperation) operation), new ImpDefUseValidatorVisitor((ValidatorOperation) operation)), false);
        }
    });
    platform.addOperationFactory(ImpLanguageKit.URI, BytecodeGeneratorOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new ImpBytecodeGeneratorVisitor((BytecodeGeneratorOperation) operation);
        }
    });
}
Also used : IBuilder(org.whole.lang.builders.IBuilder) IOperation(org.whole.lang.operations.IOperation) PrettyPrinterOperation(org.whole.lang.operations.PrettyPrinterOperation) IVisitor(org.whole.lang.visitors.IVisitor) IEntityContext(org.whole.lang.contexts.IEntityContext) IBuilderFactory(org.whole.lang.builders.IBuilderFactory) ValidatorOperation(org.whole.lang.operations.ValidatorOperation) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) ImpResolverValidatorVisitor(org.whole.examples.lang.imp.visitors.ImpResolverValidatorVisitor) ImpGenericBuilderAdapter(org.whole.examples.lang.imp.builders.ImpGenericBuilderAdapter) ImpSpecificBuilderAdapter(org.whole.examples.lang.imp.builders.ImpSpecificBuilderAdapter) BytecodeGeneratorOperation(org.whole.examples.lang.imp.visitors.BytecodeGeneratorOperation) ImpBytecodeGeneratorVisitor(org.whole.examples.lang.imp.visitors.ImpBytecodeGeneratorVisitor) IImpBuilder(org.whole.examples.lang.imp.builders.IImpBuilder) ImpDefUseValidatorVisitor(org.whole.examples.lang.imp.visitors.ImpDefUseValidatorVisitor) ImpInterpreterVisitor(org.whole.examples.lang.imp.visitors.ImpInterpreterVisitor) ImpPrettyPrinterVisitor(org.whole.examples.lang.imp.visitors.ImpPrettyPrinterVisitor)

Example 25 with IVisitor

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

IVisitor (org.whole.lang.visitors.IVisitor)63 IOperation (org.whole.lang.operations.IOperation)34 IVisitorFactory (org.whole.lang.visitors.IVisitorFactory)34 IBuilder (org.whole.lang.builders.IBuilder)20 IBuilderFactory (org.whole.lang.builders.IBuilderFactory)20 IEntityContext (org.whole.lang.contexts.IEntityContext)20 PrettyPrinterOperation (org.whole.lang.operations.PrettyPrinterOperation)13 IEntity (org.whole.lang.model.IEntity)9 ILanguageKit (org.whole.lang.reflect.ILanguageKit)4 MethodInvocation (org.eclipse.jdt.core.dom.MethodInvocation)3 IBindingManager (org.whole.lang.bindings.IBindingManager)3 Test (org.junit.Test)2 ITransactionScope (org.whole.lang.bindings.ITransactionScope)2 GenericMatcherFactory (org.whole.lang.matchers.GenericMatcherFactory)2 AbstractOperation (org.whole.lang.operations.AbstractOperation)2 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)2 VisitException (org.whole.lang.visitors.VisitException)2 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1