use of org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider in project xtext-core by eclipse.
the class PartialLinkingTest method replaceLinker.
protected void replaceLinker(XtextResource resource) {
Linker linker = new Linker();
DefaultLinkingService linkingService = new DefaultLinkingService();
getInjector().injectMembers(linkingService);
linkingService.setScopeProvider(this);
linker.setLinkingService(linkingService);
linker.setDiagnosticMessageProvider(new LinkingDiagnosticMessageProvider());
linker.setLinkingHelper(getInjector().getInstance(LinkingHelper.class));
resource.setLinker(linker);
}
use of org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider 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.impl.LinkingDiagnosticMessageProvider 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());
}
use of org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider in project xtext-core by eclipse.
the class Xtext2EcoreTransformerTest method doGetResource.
@Override
public XtextResource doGetResource(final InputStream in, final URI uri) throws Exception {
XtextResourceSet rs = this.<XtextResourceSet>get(XtextResourceSet.class);
rs.setClasspathURIContext(this.getClass());
Resource _createResource = this.getResourceFactory().createResource(uri);
final XtextResource resource = ((XtextResource) _createResource);
rs.getResources().add(resource);
XtextLinker linker = new XtextLinker() {
@Override
protected Xtext2EcoreTransformer createTransformer(final Grammar grammar, final IDiagnosticConsumer consumer) {
Xtext2EcoreTransformer result = super.createTransformer(grammar, consumer);
ErrorAcceptor _errorAcceptor = result.getErrorAcceptor();
Xtext2EcoreTransformerTest.MyErrorAcceptor _myErrorAcceptor = new Xtext2EcoreTransformerTest.MyErrorAcceptor(_errorAcceptor, Xtext2EcoreTransformerTest.this.errorAcceptorMock);
result.setErrorAcceptor(_myErrorAcceptor);
return result;
}
};
ILinker _linker = resource.getLinker();
linker.setScopeProvider(((XtextLinker) _linker).getScopeProvider());
ILinker _linker_1 = resource.getLinker();
linker.setLinkingService(((Linker) _linker_1).getLinkingService());
ILinker _linker_2 = resource.getLinker();
linker.setLinkingHelper(((Linker) _linker_2).getLinkingHelper());
XtextLinker.PackageRemover _packageRemover = new XtextLinker.PackageRemover();
linker.setPackageRemover(_packageRemover);
LinkingDiagnosticMessageProvider _linkingDiagnosticMessageProvider = new LinkingDiagnosticMessageProvider();
linker.setDiagnosticMessageProvider(_linkingDiagnosticMessageProvider);
OnChangeEvictingCache _onChangeEvictingCache = new OnChangeEvictingCache();
linker.setCache(_onChangeEvictingCache);
resource.setLinker(linker);
resource.load(in, null);
return resource;
}
Aggregations