Search in sources :

Example 1 with Factorial

use of org.whole.lang.java.codebase.Factorial in project whole by wholeplatform.

the class ScannerTest method testSkip.

@Test
public void testSkip() {
    IEntity fact = new Factorial().create();
    ScannerIterator<IEntity> s = IteratorFactory.descendantOrSelfScannerIterator();
    s.reset(fact);
    try {
        s.skipTo(JavaEntityDescriptorEnum.SingleVariableDeclaration);
        s.next();
        String str1 = s.nextString();
        String str2 = s.nextString();
        Assert.assertEquals("int", str1);
        Assert.assertEquals("false", str2);
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : Factorial(org.whole.lang.java.codebase.Factorial) IEntity(org.whole.lang.model.IEntity) Test(org.junit.Test)

Example 2 with Factorial

use of org.whole.lang.java.codebase.Factorial in project whole by wholeplatform.

the class ScannerTest method testNext.

@Test
public void testNext() {
    IEntity fact = new Factorial().create();
    ScannerIterator<IEntity> s = IteratorFactory.descendantOrSelfScannerIterator();
    s.reset(fact);
    try {
        IEntity e1 = s.next(JavaEntityDescriptorEnum.CompilationUnit);
        IEntity e2 = s.next();
        s.next();
        s.next();
        s.next();
        s.next();
        String str = s.nextString();
        Assert.assertEquals(JavaEntityDescriptorEnum.CompilationUnit, e1.wGetEntityDescriptor());
        Assert.assertEquals(JavaEntityDescriptorEnum.PackageDeclaration, e2.wGetEntityDescriptor());
        Assert.assertEquals("Copyright 2004-2016 Riccardo Solmi.", str);
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : Factorial(org.whole.lang.java.codebase.Factorial) IEntity(org.whole.lang.model.IEntity) Test(org.junit.Test)

Example 3 with Factorial

use of org.whole.lang.java.codebase.Factorial in project whole by wholeplatform.

the class TraversalFactoryTest method testTraverseParent.

@Test
public void testTraverseParent() {
    IEntity fact = new Factorial().create();
    CommonsEntityFactory.instance.createRootFragment(fact.wGetAdapter(CommonsEntityDescriptorEnum.Any));
    List<IEntity> c = new ArrayList<IEntity>();
    tf.spineTopDown(tf.collect(tf.identity(), c), false).visit(fact);
    assertTrue(c.size() > 1);
    IEntity leaf = (IEntity) c.get(c.size() - 1);
    List<IEntity> c2 = new ArrayList<IEntity>();
    tf.ancestors(tf.collect(tf.identity(), c2)).visit(leaf);
    c.add(0, fact.wGetParent());
    Collections.reverse(c2);
    assertEquals(c, c2);
}
Also used : Factorial(org.whole.lang.java.codebase.Factorial) IEntity(org.whole.lang.model.IEntity) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with Factorial

use of org.whole.lang.java.codebase.Factorial in project whole by wholeplatform.

the class TraversalFactoryTest method testMatchDescriptor.

@Test
public void testMatchDescriptor() {
    IEntity fact = new Factorial().create();
    Set<IEntity> c = new HashSet<IEntity>();
    tf.collect(mf.hasTypeMatcher(JavaEntityDescriptorEnum.CompilationUnit), c).visit(fact);
    assertFalse(c.isEmpty());
}
Also used : Factorial(org.whole.lang.java.codebase.Factorial) IEntity(org.whole.lang.model.IEntity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Factorial

use of org.whole.lang.java.codebase.Factorial in project whole by wholeplatform.

the class TraversalFactoryTest method testMatchKind.

@Test
public void testMatchKind() {
    IEntity fact = new Factorial().create();
    Set<IEntity> c = new HashSet<IEntity>();
    tf.collect(mf.hasKindMatcher(EntityKinds.SIMPLE), c).visit(fact);
    assertFalse(c.isEmpty());
}
Also used : Factorial(org.whole.lang.java.codebase.Factorial) IEntity(org.whole.lang.model.IEntity) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)8 Factorial (org.whole.lang.java.codebase.Factorial)8 IEntity (org.whole.lang.model.IEntity)8 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 MethodDeclaration (org.whole.lang.java.model.MethodDeclaration)1