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(")");
}
};
}
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()));
}
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);
}
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();
}
}));
}
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);
}
Aggregations