|
|
Re: quickfix for referenced object not found [message #1733673 is a reply to message #1733635] |
Mon, 30 May 2016 22:53 |
|
Christian Dietrich wrote on Mon, 30 May 2016 10:35customizing 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 #1733739 is a reply to message #1733684] |
Tue, 31 May 2016 10:23 |
|
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 #1733751 is a reply to message #1733742] |
Tue, 31 May 2016 12:13 |
|
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.
|
|
|
Powered by
FUDForum. Page generated in 0.03307 seconds