Search in sources :

Example 6 with Misc

use of org.whole.lang.misc.model.Misc in project whole by wholeplatform.

the class IteratorFactoryTest method testAncestorOrSelfIteratorRemoveSet.

@Test
public void testAncestorOrSelfIteratorRemoveSet() {
    Grammar g = new TestXmlGrammar().create();
    MiscEntityFactory mef = MiscEntityFactory.instance(RegistryConfigurations.RESOLVER);
    Any any = CommonsEntityAdapterFactory.create(MiscEntityDescriptorEnum.Any, g);
    Misc innerMisc = mef.createMisc(any);
    any = CommonsEntityAdapterFactory.create(MiscEntityDescriptorEnum.Any, innerMisc);
    Misc outerMisc = mef.createMisc(any);
    Rule r = Matcher.find(GrammarsEntityDescriptorEnum.As, outerMisc, false);
    IEntityIterator<IEntity> i = IteratorFactory.ancestorOrSelfIterator();
    i.reset(r);
    IEntity next = null;
    while (i.hasNext()) {
        next = i.next();
        if (Matcher.match(MiscEntityDescriptorEnum.Misc, next))
            break;
    }
    assertSame(innerMisc, next);
    i.set(EntityUtils.clone(any));
    assertEquals(1, outerMisc.wSize());
    Rule r2 = Matcher.find(GrammarsEntityDescriptorEnum.As, outerMisc, false);
    assertTrue(Matcher.match(r, r2));
    assertNotSame(r, r2);
    i.remove();
    assertEquals(0, outerMisc.wSize());
    i.reset(r2);
    while (i.hasNext()) {
        next = i.next();
        if (i.hasNext())
            i.remove();
    }
    assertFalse(EntityUtils.hasParent(next));
}
Also used : MiscEntityFactory(org.whole.lang.misc.factories.MiscEntityFactory) IEntity(org.whole.lang.model.IEntity) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Misc(org.whole.lang.misc.model.Misc) TestXmlGrammar(org.whole.lang.grammars.util.TestXmlGrammar) Grammar(org.whole.lang.grammars.model.Grammar) Rule(org.whole.lang.grammars.model.Rule) Any(org.whole.lang.misc.model.Any) Test(org.junit.Test)

Aggregations

Misc (org.whole.lang.misc.model.Misc)6 MiscEntityFactory (org.whole.lang.misc.factories.MiscEntityFactory)4 Any (org.whole.lang.misc.model.Any)4 CompilationUnit (org.whole.lang.java.model.CompilationUnit)3 Test (org.junit.Test)2 JavaSourceTemplateFactory (org.whole.lang.java.codebase.JavaSourceTemplateFactory)2 IEntity (org.whole.lang.model.IEntity)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IType (org.eclipse.jdt.core.IType)1 ITypeRoot (org.eclipse.jdt.core.ITypeRoot)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 ISelection (org.eclipse.jface.viewers.ISelection)1 Category (org.junit.experimental.categories.Category)1 Grammar (org.whole.lang.grammars.model.Grammar)1 Rule (org.whole.lang.grammars.model.Rule)1 TestXmlGrammar (org.whole.lang.grammars.util.TestXmlGrammar)1 JavaClassTemplateFactory (org.whole.lang.java.codebase.JavaClassTemplateFactory)1