Search in sources :

Example 1 with LinkingDiagnosticMessageProvider

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);
}
Also used : DefaultLinkingService(org.eclipse.xtext.linking.impl.DefaultLinkingService) LinkingDiagnosticMessageProvider(org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider) LinkingHelper(org.eclipse.xtext.linking.impl.LinkingHelper) Linker(org.eclipse.xtext.linking.impl.Linker)

Example 2 with LinkingDiagnosticMessageProvider

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"));
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Resource(org.eclipse.emf.ecore.resource.Resource) Triple(org.eclipse.xtext.util.Triple) EAnnotation(org.eclipse.emf.ecore.EAnnotation) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) IllegalNodeException(org.eclipse.xtext.linking.impl.IllegalNodeException) ILinkingService(org.eclipse.xtext.linking.ILinkingService) LinkingDiagnosticMessageProvider(org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider) List(java.util.List) InternalEList(org.eclipse.emf.ecore.util.InternalEList) LinkingHelper(org.eclipse.xtext.linking.impl.LinkingHelper) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 3 with LinkingDiagnosticMessageProvider

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());
}
Also used : INode(org.eclipse.xtext.nodemodel.INode) Resource(org.eclipse.emf.ecore.resource.Resource) Triple(org.eclipse.xtext.util.Triple) EAnnotation(org.eclipse.emf.ecore.EAnnotation) DiagnosticMessage(org.eclipse.xtext.diagnostics.DiagnosticMessage) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) LeafNode(org.eclipse.xtext.nodemodel.impl.LeafNode) IllegalNodeException(org.eclipse.xtext.linking.impl.IllegalNodeException) ILinkingService(org.eclipse.xtext.linking.ILinkingService) LinkingDiagnosticMessageProvider(org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider) List(java.util.List) InternalEList(org.eclipse.emf.ecore.util.InternalEList) EReference(org.eclipse.emf.ecore.EReference) Test(org.junit.Test)

Example 4 with LinkingDiagnosticMessageProvider

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;
}
Also used : ILinker(org.eclipse.xtext.linking.ILinker) XtextLinker(org.eclipse.xtext.xtext.XtextLinker) Xtext2EcoreTransformer(org.eclipse.xtext.xtext.ecoreInference.Xtext2EcoreTransformer) OnChangeEvictingCache(org.eclipse.xtext.util.OnChangeEvictingCache) XtextResource(org.eclipse.xtext.resource.XtextResource) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) Grammar(org.eclipse.xtext.Grammar) TestErrorAcceptor(org.eclipse.xtext.tests.TestErrorAcceptor) ErrorAcceptor(org.eclipse.xtext.xtext.ecoreInference.ErrorAcceptor) IDiagnosticConsumer(org.eclipse.xtext.diagnostics.IDiagnosticConsumer) XtextResourceSet(org.eclipse.xtext.resource.XtextResourceSet) LinkingDiagnosticMessageProvider(org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider)

Aggregations

LinkingDiagnosticMessageProvider (org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider)4 Resource (org.eclipse.emf.ecore.resource.Resource)3 List (java.util.List)2 EAnnotation (org.eclipse.emf.ecore.EAnnotation)2 EObject (org.eclipse.emf.ecore.EObject)2 EReference (org.eclipse.emf.ecore.EReference)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 InternalEList (org.eclipse.emf.ecore.util.InternalEList)2 ILinkingService (org.eclipse.xtext.linking.ILinkingService)2 IllegalNodeException (org.eclipse.xtext.linking.impl.IllegalNodeException)2 LinkingHelper (org.eclipse.xtext.linking.impl.LinkingHelper)2 INode (org.eclipse.xtext.nodemodel.INode)2 LeafNode (org.eclipse.xtext.nodemodel.impl.LeafNode)2 Triple (org.eclipse.xtext.util.Triple)2 Test (org.junit.Test)2 Grammar (org.eclipse.xtext.Grammar)1 DiagnosticMessage (org.eclipse.xtext.diagnostics.DiagnosticMessage)1 IDiagnosticConsumer (org.eclipse.xtext.diagnostics.IDiagnosticConsumer)1 ILinker (org.eclipse.xtext.linking.ILinker)1 DefaultLinkingService (org.eclipse.xtext.linking.impl.DefaultLinkingService)1