Search in sources :

Example 6 with LeafNode

use of org.eclipse.xtext.nodemodel.impl.LeafNode in project xtext-core by eclipse.

the class LazyURIEncoderTest method testNodePath.

@Test
public void testNodePath() throws Exception {
    NodeModelBuilder builder = new NodeModelBuilder();
    ICompositeNode n = new CompositeNode();
    ICompositeNode n1 = new CompositeNode();
    builder.addChild(n, (AbstractNode) n1);
    ICompositeNode n2 = new CompositeNode();
    builder.addChild(n, (AbstractNode) n2);
    ILeafNode l1 = new LeafNode();
    builder.addChild(n2, (AbstractNode) l1);
    ILeafNode l2 = new LeafNode();
    builder.addChild(n2, (AbstractNode) l2);
    assertEquals(n, find(n, n));
    assertEquals(n1, find(n, n1));
    assertEquals(n2, find(n, n2));
    assertEquals(l1, find(n, l1));
    assertEquals(l2, find(n, l2));
}
Also used : CompositeNode(org.eclipse.xtext.nodemodel.impl.CompositeNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) NodeModelBuilder(org.eclipse.xtext.nodemodel.impl.NodeModelBuilder) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) Test(org.junit.Test)

Example 7 with LeafNode

use of org.eclipse.xtext.nodemodel.impl.LeafNode in project xtext-core by eclipse.

the class DefaultEcoreElementFactoryTest method testNullInput.

@Test
public void testNullInput() throws Exception {
    EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    final ILeafNode node = new LeafNode();
    Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {

        @Override
        public Object apply(String lexerRule, INode nodeParam) {
            if ("foo".equals(lexerRule) && nodeParam.equals(node)) {
                return null;
            }
            fail();
            return null;
        }
    };
    DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
    factory.setConverterService(new MockedConverterService(toValueImpl));
    try {
        factory.set(eClass, "abstract", null, "foo", node);
        fail("Expected ValueConverterException");
    } catch (ValueConverterException ex) {
        assertNull(ex.getCause());
        assertTrue(ex.getMessage().indexOf("ValueConverter returned null for") >= 0);
        assertSame(node, ex.getNode());
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) ValueConverterException(org.eclipse.xtext.conversion.ValueConverterException) Test(org.junit.Test)

Example 8 with LeafNode

use of org.eclipse.xtext.nodemodel.impl.LeafNode in project xtext-core by eclipse.

the class DefaultEcoreElementFactoryTest method testValueConverterException.

@Test
public void testValueConverterException() throws Exception {
    EClass eClass = EcoreFactory.eINSTANCE.createEClass();
    final ILeafNode node = new LeafNode();
    final ValueConverterException expected = new ValueConverterException("Foo", node, null);
    Function2<String, INode, Object> toValueImpl = new Function2<String, INode, Object>() {

        @Override
        public Object apply(String lexerRule, INode nodeParam) {
            if ("foo".equals(lexerRule) && node.equals(nodeParam)) {
                throw expected;
            }
            fail();
            return null;
        }
    };
    DefaultEcoreElementFactory factory = new DefaultEcoreElementFactory();
    factory.setConverterService(new MockedConverterService(toValueImpl));
    try {
        factory.set(eClass, "abstract", null, "foo", node);
        fail("Expected ValueConverterException");
    } catch (ValueConverterException ex) {
        assertSame(expected, ex);
    }
}
Also used : EClass(org.eclipse.emf.ecore.EClass) INode(org.eclipse.xtext.nodemodel.INode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) ILeafNode(org.eclipse.xtext.nodemodel.ILeafNode) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) ValueConverterException(org.eclipse.xtext.conversion.ValueConverterException) Function2(org.eclipse.xtext.xbase.lib.Functions.Function2) Test(org.junit.Test)

Example 9 with LeafNode

use of org.eclipse.xtext.nodemodel.impl.LeafNode in project xtext-core by eclipse.

the class HiddenAndTokenNodeIteratorTest method setUp.

@Before
public void setUp() throws Exception {
    nodes = new INode[NUM_NODES];
    NodeModelBuilder builder = new NodeModelBuilder();
    nodes[0] = new CompositeNode();
    nodes[1] = new CompositeNode();
    nodes[2] = new HiddenLeafNode();
    nodes[3] = new LeafNode();
    nodes[4] = new HiddenLeafNode();
    nodes[5] = new CompositeNode();
    nodes[6] = new LeafNode();
    nodes[7] = new CompositeNode();
    nodes[8] = new HiddenLeafNode();
    nodes[9] = new LeafNode();
    builder.addChild((ICompositeNode) nodes[0], (AbstractNode) nodes[1]);
    builder.addChild((ICompositeNode) nodes[0], (AbstractNode) nodes[5]);
    builder.addChild((ICompositeNode) nodes[0], (AbstractNode) nodes[7]);
    builder.addChild((ICompositeNode) nodes[0], (AbstractNode) nodes[9]);
    builder.addChild((ICompositeNode) nodes[1], (AbstractNode) nodes[2]);
    builder.addChild((ICompositeNode) nodes[1], (AbstractNode) nodes[3]);
    builder.addChild((ICompositeNode) nodes[1], (AbstractNode) nodes[4]);
    builder.addChild((ICompositeNode) nodes[5], (AbstractNode) nodes[6]);
    builder.addChild((ICompositeNode) nodes[7], (AbstractNode) nodes[8]);
}
Also used : CompositeNode(org.eclipse.xtext.nodemodel.impl.CompositeNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) HiddenLeafNode(org.eclipse.xtext.nodemodel.impl.HiddenLeafNode) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) NodeModelBuilder(org.eclipse.xtext.nodemodel.impl.NodeModelBuilder) HiddenLeafNode(org.eclipse.xtext.nodemodel.impl.HiddenLeafNode) Before(org.junit.Before)

Example 10 with LeafNode

use of org.eclipse.xtext.nodemodel.impl.LeafNode in project xtext-core by eclipse.

the class NodeIteratorTest method setUp.

@Before
public void setUp() throws Exception {
    NodeModelBuilder builder = new NodeModelBuilder();
    nodes = new INode[NUM_NODES];
    nodes[0] = new CompositeNode();
    nodes[1] = new LeafNode();
    nodes[2] = new CompositeNode();
    nodes[3] = new CompositeNode();
    nodes[4] = new LeafNode();
    nodes[5] = new LeafNode();
    nodes[6] = new LeafNode();
    nodes[7] = new CompositeNode();
    nodes[8] = new LeafNode();
    nodes[9] = new LeafNode();
    nodes[10] = new CompositeNode();
    builder.addChild((ICompositeNode) nodes[0], (AbstractNode) nodes[1]);
    builder.addChild((ICompositeNode) nodes[0], (AbstractNode) nodes[2]);
    builder.addChild((ICompositeNode) nodes[2], (AbstractNode) nodes[3]);
    builder.addChild((ICompositeNode) nodes[3], (AbstractNode) nodes[4]);
    builder.addChild((ICompositeNode) nodes[3], (AbstractNode) nodes[5]);
    builder.addChild((ICompositeNode) nodes[2], (AbstractNode) nodes[6]);
    builder.addChild((ICompositeNode) nodes[2], (AbstractNode) nodes[7]);
    builder.addChild((ICompositeNode) nodes[2], (AbstractNode) nodes[8]);
    builder.addChild((ICompositeNode) nodes[0], (AbstractNode) nodes[9]);
    builder.addChild((ICompositeNode) nodes[0], (AbstractNode) nodes[10]);
}
Also used : CompositeNode(org.eclipse.xtext.nodemodel.impl.CompositeNode) ICompositeNode(org.eclipse.xtext.nodemodel.ICompositeNode) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) NodeModelBuilder(org.eclipse.xtext.nodemodel.impl.NodeModelBuilder) Before(org.junit.Before)

Aggregations

LeafNode (org.eclipse.xtext.nodemodel.impl.LeafNode)12 INode (org.eclipse.xtext.nodemodel.INode)8 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)6 Test (org.junit.Test)6 EObject (org.eclipse.emf.ecore.EObject)4 ILeafNode (org.eclipse.xtext.nodemodel.ILeafNode)4 List (java.util.List)3 CompositeNode (org.eclipse.xtext.nodemodel.impl.CompositeNode)3 NodeModelBuilder (org.eclipse.xtext.nodemodel.impl.NodeModelBuilder)3 EAnnotation (org.eclipse.emf.ecore.EAnnotation)2 EClass (org.eclipse.emf.ecore.EClass)2 EReference (org.eclipse.emf.ecore.EReference)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 InternalEList (org.eclipse.emf.ecore.util.InternalEList)2 ValueConverterException (org.eclipse.xtext.conversion.ValueConverterException)2 ILinkingService (org.eclipse.xtext.linking.ILinkingService)2 IllegalNodeException (org.eclipse.xtext.linking.impl.IllegalNodeException)2 LinkingDiagnosticMessageProvider (org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider)2 HiddenLeafNode (org.eclipse.xtext.nodemodel.impl.HiddenLeafNode)2