Search in sources :

Example 11 with VisitException

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

the class WorkflowsInterpreterVisitorTest method testTask.

@Test
public void testTask() {
    IEntity taskTest = WorkflowsTestTemplateManager.instance().create("taskTest");
    IBindingManager args = BindingManagerFactory.instance.createArguments();
    args.wDefValue("reader", new StringReader("yep!\n"));
    try {
        InterpreterOperation.interpret(taskTest, args, (Reader) null, (Writer) null);
    } catch (VisitException e) {
        Assert.fail();
    }
    args.wDefValue("reader", new StringReader("NO\n"));
    try {
        InterpreterOperation.interpret(taskTest, args, (Reader) null, (Writer) null);
        Assert.fail();
    } catch (VisitException e) {
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException) IBindingManager(org.whole.lang.bindings.IBindingManager) StringReader(java.io.StringReader) Test(org.junit.Test)

Example 12 with VisitException

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

the class CheckPaternityVisitor method visit.

@Override
public void visit(IEntity entity) {
    bm.wDef("parent", entity.wGetParent());
    GenericTraversalFactory.instance.downUp(new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            bm.wEnterScope();
            bm.wDef("parent", entity);
        }
    }, new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            bm.wExitScope();
            if (bm.wGet("parent") != entity.wGetParent())
                throw new VisitException();
        }
    }, false).visit(entity);
}
Also used : VisitException(org.whole.lang.visitors.VisitException) GenericIdentityVisitor(org.whole.lang.visitors.GenericIdentityVisitor)

Example 13 with VisitException

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

the class Matcher method indexOf.

public static int indexOf(IVisitor matcherVisitor, IEntity model) {
    GenericTraversalFactory tf = GenericTraversalFactory.instance;
    try {
        Set<IEntity> c = new HashSet<IEntity>();
        tf.traverseOne(tf.collect(matcherVisitor, c), true).visit(model);
        return model.wIndexOf(c.iterator().next());
    } catch (VisitException e) {
        return -1;
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException) GenericTraversalFactory(org.whole.lang.visitors.GenericTraversalFactory) HashSet(java.util.HashSet)

Example 14 with VisitException

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

the class GenericMatcherFactory method rewrite.

public IVisitor rewrite(final IEntity oldPattern, final IEntity newPattern, final boolean includeAdjacents) {
    return new AbstractVisitor() {

        public void visit(IEntity entity) {
            IBindingManager bindings = BindingManagerFactory.instance.createBindingManager();
            if (!Matcher.match(oldPattern, entity, bindings))
                throw new VisitException();
            IEntity rewritePattern = EntityUtils.clone(newPattern);
            if (!entity.wGetParent().wSet(entity, rewritePattern))
                throw new VisitException();
            Matcher.substitute(rewritePattern, bindings, includeAdjacents);
        }
    };
}
Also used : AbstractVisitor(org.whole.lang.visitors.AbstractVisitor) IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException) IBindingManager(org.whole.lang.bindings.IBindingManager)

Example 15 with VisitException

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

the class GenericMatcherFactory method match.

public IVisitor match(final IEntity pattern) {
    return new AbstractVisitor() {

        public void visit(IEntity entity) {
            if (!Matcher.match(pattern, entity))
                throw new VisitException();
        }

        public void toString(StringBuilder sb) {
            sb.append("match(");
            // TODO startOf
            sb.append(pattern);
            sb.append(")");
        }
    };
}
Also used : AbstractVisitor(org.whole.lang.visitors.AbstractVisitor) IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException)

Aggregations

VisitException (org.whole.lang.visitors.VisitException)35 IEntity (org.whole.lang.model.IEntity)25 IBindingManager (org.whole.lang.bindings.IBindingManager)6 File (java.io.File)4 AbstractVisitor (org.whole.lang.visitors.AbstractVisitor)4 HashSet (java.util.HashSet)3 GenericIdentityVisitor (org.whole.lang.visitors.GenericIdentityVisitor)3 IOException (java.io.IOException)2 PrintWriter (java.io.PrintWriter)2 PrettyPrinterOperation.toPrettyPrintString (org.whole.lang.operations.PrettyPrinterOperation.toPrettyPrintString)2 GenericTraversalFactory (org.whole.lang.visitors.GenericTraversalFactory)2 IVisitor (org.whole.lang.visitors.IVisitor)2 EvalError (bsh.EvalError)1 Interpreter (bsh.Interpreter)1 BufferedReader (java.io.BufferedReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 Writer (java.io.Writer)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1