Search in sources :

Example 6 with IVisitor

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

the class MiscLanguageDeployer method deploy.

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

        public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
            return new MiscGenericBuilderAdapter((IMiscBuilder) strategy, entityContext);
        }
    });
    platform.addOperationFactory(MiscLanguageKit.URI, SpecificBuilderAdapterOperation.ID, new IBuilderFactory() {

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

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

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

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

        public IVisitor create(IOperation operation, int stage) {
            return new MiscOperationVisitor();
        }
    });
    platform.addOperationFactory(MiscLanguageKit.URI, NormalizerOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new MiscOperationVisitor();
        }
    });
    platform.addOperationFactory(MiscLanguageKit.URI, DynamicCompilerOperation.ID, new IVisitorFactory() {

        public IVisitor create(IOperation operation, int stage) {
            return new MiscDynamicCompilerVisitor();
        }
    });
}
Also used : IBuilder(org.whole.lang.builders.IBuilder) IOperation(org.whole.lang.operations.IOperation) MiscDynamicCompilerVisitor(org.whole.lang.misc.visitors.MiscDynamicCompilerVisitor) IVisitor(org.whole.lang.visitors.IVisitor) IEntityContext(org.whole.lang.contexts.IEntityContext) IMiscBuilder(org.whole.lang.misc.builders.IMiscBuilder) IBuilderFactory(org.whole.lang.builders.IBuilderFactory) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) MiscGenericBuilderAdapter(org.whole.lang.misc.builders.MiscGenericBuilderAdapter) MiscSpecificBuilderAdapter(org.whole.lang.misc.builders.MiscSpecificBuilderAdapter) MiscOperationVisitor(org.whole.lang.misc.visitors.MiscOperationVisitor)

Example 7 with IVisitor

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

the class MathLanguageDeployer method deploy.

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

        public IBuilder create(IBuilder strategy, IEntityContext entityContext) {
            return new MathGenericBuilderAdapter((IMathBuilder) strategy, entityContext);
        }
    });
    platform.addOperationFactory(MathLanguageKit.URI, SpecificBuilderAdapterOperation.ID, new IBuilderFactory() {

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

        public IVisitor create(IOperation operation, int stage) {
            if (stage == 0)
                return new MathInterpreterVisitor();
            else
                return null;
        }
    });
}
Also used : IBuilder(org.whole.lang.builders.IBuilder) IOperation(org.whole.lang.operations.IOperation) MathInterpreterVisitor(org.whole.lang.math.visitors.MathInterpreterVisitor) IMathBuilder(org.whole.lang.math.builders.IMathBuilder) IVisitor(org.whole.lang.visitors.IVisitor) IEntityContext(org.whole.lang.contexts.IEntityContext) MathGenericBuilderAdapter(org.whole.lang.math.builders.MathGenericBuilderAdapter) IBuilderFactory(org.whole.lang.builders.IBuilderFactory) IVisitorFactory(org.whole.lang.visitors.IVisitorFactory) MathSpecificBuilderAdapter(org.whole.lang.math.builders.MathSpecificBuilderAdapter)

Example 8 with IVisitor

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

the class TestsInterpreterVisitor method visit.

@Override
public void visit(IsUndef entity) {
    IVisitor v = GenericTraversalFactory.instance.not(TestsMatcherFactory.instance.defined());
    v.withSourceEntity(entity).setBindings(getBindings());
    setResultVisitor(v);
}
Also used : IVisitor(org.whole.lang.visitors.IVisitor)

Example 9 with IVisitor

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

the class TestsInterpreterVisitor method visit.

@Override
public void visit(AnyOf entity) {
    int size = entity.wSize();
    IVisitor[] visitors = new IVisitor[size];
    for (int i = 0; i < size; i++) {
        entity.get(i).accept(this);
        visitors[i] = getResultVisitor();
    }
    setResultVisitor(GenericTraversalFactory.instance.one(visitors).withSourceEntity(entity));
}
Also used : IVisitor(org.whole.lang.visitors.IVisitor) Constraint(org.whole.lang.tests.model.Constraint)

Example 10 with IVisitor

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

the class TestsInterpreterVisitor method evaluate.

protected void evaluate(SubjectStatement entity) {
    ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
    getBindings().wEnterScope(ts);
    try {
        IEntity subject = evaluate(entity.getSubject(), true);
        if (!EntityUtils.isNull(subject))
            subject = applyFilterRule(subject);
        IVisitor constraint = evaluate(entity.getConstraint());
        boolean result = Matcher.match(constraint, subject);
        if (getBindings().wIsSet("thrownException"))
            throw (RuntimeException) getBindings().wGetValue("thrownException");
        if (!result)
            throw new TestsException(entity, subject, constraint, getBindings());
    } finally {
        ts.rollback();
        getBindings().wExitScope();
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) IEntity(org.whole.lang.model.IEntity) IVisitor(org.whole.lang.visitors.IVisitor)

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