Search in sources :

Example 1 with GenericIdentityVisitor

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

the class TestsMatcherFactory method same.

public IVisitor same(final IEntity asEntity) {
    return new GenericIdentityVisitor() {

        @Override
        public void visit(IEntity entity) {
            if (entity != asEntity)
                throw new VisitException();
        }

        public void toString(StringBuilder sb) {
            sb.append("same(");
            sb.append(asEntity);
            sb.append(")");
        }
    };
}
Also used : IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException) GenericIdentityVisitor(org.whole.lang.visitors.GenericIdentityVisitor)

Example 2 with GenericIdentityVisitor

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

the class IteratorFactoryTest method testTopDownIterator.

@Test
public void testTopDownIterator() throws Exception {
    Grammar g = new TestXmlGrammar().create();
    final Productions productions = g.getPhraseStructure();
    final IEntityIterator<IEntity> ci = IteratorFactory.<IEntity>descendantOrSelfIterator();
    ci.reset(productions);
    IVisitor v = GenericTraversalFactory.instance.topDown(new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            if (ci.hasNext())
                assertSame(entity, ci.next());
            else
                fail();
        }
    }, false);
    v.visit(productions);
    final IEntityIterator<IEntity> ci2 = IteratorFactory.<IEntity>descendantOrSelfScannerIterator();
    ci2.reset(productions);
    v = GenericTraversalFactory.instance.topDown(new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            if (EntityUtils.isResolver(entity))
                return;
            if (ci2.hasNext())
                assertSame(entity, ci2.next());
            else
                fail();
        }
    }, false);
    v.visit(productions);
    final IEntityIterator<IEntity> ci3 = IteratorFactory.<IEntity>descendantOrSelfMatcherIterator().withPattern(GrammarsEntityDescriptorEnum.Production);
    ci3.reset(productions);
    v = GenericTraversalFactory.instance.topDown(new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            if (!Matcher.match(GrammarsEntityDescriptorEnum.Production, entity))
                return;
            if (ci3.hasNext())
                assertSame(entity, ci3.next());
            else
                fail();
        }
    }, false);
    v.visit(productions);
    IEntity artifactsModel = XmlBuilderPersistenceKit.instance().readModel(new ClasspathPersistenceProvider("org/whole/lang/artifacts/ArtifactsModel.xwl"));
    Set<Type> typeSet = new HashSet<Type>();
    IEntityIterator<Type> ci4 = IteratorFactory.<Type>descendantOrSelfMatcherIterator().withPattern(ModelsEntityFactory.instance.createSimpleName("Atifacts"));
    ci4.reset(artifactsModel);
    while (ci4.hasNext()) assertTrue(typeSet.add(ci4.next()));
}
Also used : Productions(org.whole.lang.grammars.model.Productions) Type(org.whole.lang.models.model.Type) IEntity(org.whole.lang.model.IEntity) IVisitor(org.whole.lang.visitors.IVisitor) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) ClasspathPersistenceProvider(org.whole.lang.codebase.ClasspathPersistenceProvider) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) GenericIdentityVisitor(org.whole.lang.visitors.GenericIdentityVisitor) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with GenericIdentityVisitor

use of org.whole.lang.visitors.GenericIdentityVisitor 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 4 with GenericIdentityVisitor

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

the class ActionsUIEntityFactory method createAllVariablesGroupAction.

public GroupAction createAllVariablesGroupAction(ActionKindEnum.Value kind, Set<String> excludeSet, EntityDescriptor<?> resultEd, IEntity model) {
    MatcherIterator<IEntity> i = IteratorFactory.<IEntity>descendantOrSelfMatcherIterator();
    i.reset(EntityUtils.safeGetRootEntity(model));
    return createVariablesGroupAction(kind, excludeSet, resultEd, i.withPattern(new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            if (!isVariable(entity.wGetAdaptee(false).wGetEntityDescriptor()))
                throw new VisitException();
        }
    }));
}
Also used : IEntity(org.whole.lang.model.IEntity) VisitException(org.whole.lang.visitors.VisitException) GenericIdentityVisitor(org.whole.lang.visitors.GenericIdentityVisitor)

Example 5 with GenericIdentityVisitor

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

the class GenericNormalizer method removeResolversFromComposites.

public static void removeResolversFromComposites(final boolean removeEmptyComposites, IEntity entity) {
    IVisitor visitor = GenericTraversalFactory.instance.downUp(new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            beforeRemovingResolvers(entity);
        }
    }, new GenericIdentityVisitor() {

        public void visit(IEntity entity) {
            if (removeEmptyComposites)
                afterRemovingResolvers(entity);
        }
    }, false);
    visitor.visit(entity);
}
Also used : IVisitor(org.whole.lang.visitors.IVisitor) IEntity(org.whole.lang.model.IEntity) GenericIdentityVisitor(org.whole.lang.visitors.GenericIdentityVisitor)

Aggregations

GenericIdentityVisitor (org.whole.lang.visitors.GenericIdentityVisitor)5 IEntity (org.whole.lang.model.IEntity)4 VisitException (org.whole.lang.visitors.VisitException)3 IVisitor (org.whole.lang.visitors.IVisitor)2 HashSet (java.util.HashSet)1 Test (org.junit.Test)1 ClasspathPersistenceProvider (org.whole.lang.codebase.ClasspathPersistenceProvider)1 Grammar (org.whole.lang.grammars.model.Grammar)1 Productions (org.whole.lang.grammars.model.Productions)1 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)1 Type (org.whole.lang.models.model.Type)1