use of org.eclipse.xtext.linking.ILinkingService in project xtext-core by eclipse.
the class LazyLinkingResourceTest method testEObjectReference.
@Test
public void testEObjectReference() throws Exception {
final EAnnotation source = EcoreFactory.eINSTANCE.createEAnnotation();
final EObject referencedObject = XtextFactory.eINSTANCE.createGrammar();
LazyLinkingResource res = new LazyLinkingResource();
res.setLinkingHelper(new LinkingHelper() {
@Override
public String getCrossRefNodeAsString(INode node, boolean convert) {
return node.getText();
}
});
res.setEncoder(new LazyURIEncoder() {
@Override
public boolean isCrossLinkFragment(Resource res, String s) {
return "foo".equals(s);
}
@Override
public Triple<EObject, EReference, INode> decode(Resource res, String uriFragment) {
return Tuples.create((EObject) source, EcorePackage.Literals.EANNOTATION__REFERENCES, (INode) new LeafNode());
}
});
res.setLinkingService(new ILinkingService() {
@Override
public List<EObject> getLinkedObjects(EObject context, EReference reference, INode node) throws IllegalNodeException {
return Lists.newArrayList(referencedObject);
}
});
res.setDiagnosticMessageProvider(new LinkingDiagnosticMessageProvider());
assertEquals(referencedObject, res.getEObject("foo"));
}
use of org.eclipse.xtext.linking.ILinkingService in project xtext-core by eclipse.
the class LazyLinkingResourceTest method testWarningInsteadOfError.
@Test
public void testWarningInsteadOfError() throws Exception {
final EAnnotation source = EcoreFactory.eINSTANCE.createEAnnotation();
LazyLinkingResource res = new LazyLinkingResource();
res.setEncoder(new LazyURIEncoder() {
@Override
public boolean isCrossLinkFragment(Resource res, String s) {
return "foo".equals(s);
}
@Override
public Triple<EObject, EReference, INode> decode(Resource res, String uriFragment) {
return Tuples.create((EObject) source, EcorePackage.Literals.EANNOTATION__REFERENCES, (INode) new LeafNode());
}
});
res.setLinkingService(new ILinkingService() {
@Override
public List<EObject> getLinkedObjects(EObject context, EReference reference, INode node) throws IllegalNodeException {
return Collections.emptyList();
}
});
res.setDiagnosticMessageProvider(new LinkingDiagnosticMessageProvider() {
@Override
public DiagnosticMessage getUnresolvedProxyMessage(ILinkingDiagnosticContext context) {
return new DiagnosticMessage("myMessage", Severity.WARNING, null);
}
});
assertTrue(res.getWarnings().isEmpty());
assertNull(res.getEObject("foo"));
assertEquals(1, res.getWarnings().size());
assertTrue(res.getErrors().isEmpty());
assertEquals("myMessage", res.getWarnings().get(0).getMessage());
}
Aggregations