Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » quickfix for referenced object not found(Is it possible to add a quickfix for a referenced object not found error ?)
quickfix for referenced object not found [message #1733632] Mon, 30 May 2016 14:27 Go to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
I want to provide a quickfix for the error that a referenced object is not found.
How can I do that ?
Re: quickfix for referenced object not found [message #1733635 is a reply to message #1733632] Mon, 30 May 2016 14:35 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
customizing LinkingDiagnosticMessageProvider and return a custom error code + then implement a quickfix does not work.
see org.eclipse.xtext.xtext.XtextLinkingDiagnosticMessageProvider and XtextGrammarQuickfixProvider (for missing rule in xtext)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: quickfix for referenced object not found [message #1733673 is a reply to message #1733635] Mon, 30 May 2016 22:53 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
Christian Dietrich wrote on Mon, 30 May 2016 10:35
customizing LinkingDiagnosticMessageProvider and return a custom error code + then implement a quickfix does not work.
see org.eclipse.xtext.xtext.XtextLinkingDiagnosticMessageProvider and XtextGrammarQuickfixProvider (for missing rule in xtext)


Thank you for the quick answer.

I have inherited LinkingDiagnosticMessageProvider and overriden getUnresolvedProxyMessage ?
Btw. the mentioned class LinkingDiagnosticMessageProvider is restricted API.

I have implemented my QuickfixProvider.

Where do I have to register my LinkingDiagnosticMessageProvider ?
Re: quickfix for referenced object not found [message #1733684 is a reply to message #1733673] Tue, 31 May 2016 03:02 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
Inside the runtime module

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: quickfix for referenced object not found [message #1733739 is a reply to message #1733684] Tue, 31 May 2016 10:23 Go to previous messageGo to next message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
I have the following implementation:
	@Override
	public DiagnosticMessage getUnresolvedProxyMessage(final ILinkingDiagnosticContext context) {
		EObject context2 = context.getContext();
		DiagnosticMessage diagnosticMessage = new SponsorGroupModelSwitch<DiagnosticMessage>() {
			@Override
			public DiagnosticMessage caseSponsorGroup(SponsorGroup sponsorGroup) {
				return new DiagnosticMessage(context.getLinkText()+" cannot be resolved to a SponsorGroup", Severity.ERROR,
						UNRESOLVED_SPONSOR_GROUP, context.getLinkText());
			}

		}.doSwitch(context2);
		return diagnosticMessage != null ? diagnosticMessage : super.getUnresolvedProxyMessage(context);
	}


I'm expecting a missing reference to a SponsorGroup. Or do I need to check for the parent object of the missing reference ?
Re: quickfix for referenced object not found [message #1733740 is a reply to message #1733739] Tue, 31 May 2016 10:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
depends on your grammar.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: quickfix for referenced object not found [message #1733742 is a reply to message #1733740] Tue, 31 May 2016 10:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14665
Registered: July 2009
Senior Member
maybe you wantr to simply test for org.eclipse.xtext.linking.ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext.getReference()

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: quickfix for referenced object not found [message #1733751 is a reply to message #1733742] Tue, 31 May 2016 12:13 Go to previous message
Olaf Bigalk is currently offline Olaf BigalkFriend
Messages: 155
Registered: July 2009
Location: Berlin
Senior Member
Thankx, I solved the issue.

You need to inherit from
org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider
and check for the parent object in
org.eclipse.xtext.linking.impl.LinkingDiagnosticMessageProvider.getUnresolvedProxyMessage()
and then check the reference with
org.eclipse.xtext.linking.ILinkingDiagnosticMessageProvider.ILinkingDiagnosticContext.getReference()


The result is:
@Override
	public DiagnosticMessage getUnresolvedProxyMessage(final ILinkingDiagnosticContext context) {
		DiagnosticMessage diagnosticMessage = new YourModelSwitch<DiagnosticMessage>() {
			@Override
			public DiagnosticMessage caseYourParentObject(YourParentObject parent) {
				if (context.getReference().equals(YourModelPackage.Literals.YOUR_PARENT_OBJECT__YOUR_REFERENCE)) {
					return new DiagnosticMessage(context.getLinkText() + " cannot be resolved to a YourReferencedObject",
								Severity.ERROR, YOUR_QUICK_FIX_CODE) context.getLinkText());
                             }
                             return null;
			}

		}.doSwitch(context.getContext());
		return diagnosticMessage != null ? diagnosticMessage : super.getUnresolvedProxyMessage(context);
	}


to activate this solution you need to register your ddd in the YourModelRuntimeModule:
    public Class<? extends LinkingDiagnosticMessageProvider> bindLinkingDiagnosticMessageProvider() {
        return YourModelLinkingDiagnosticMessageProvider.class;
    }
 


The corresponding QuickFix goes to the usual location.
Previous Topic:How to add files to the build?
Next Topic:Unresolved proxy classpath.. Make sure the EPackage has been registered.
Goto Forum:
  


Current Time: Thu Apr 25 04:02:39 GMT 2024

Powered by FUDForum. Page generated in 0.02872 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top