|
Re: Using Quickfix to add elements to imported ECore resource [message #1701103 is a reply to message #1701102] |
Thu, 09 July 2015 10:45 |
|
adapt DiagnosticMessageProvider and provide a custom code and add the node text to the data of the issue and then write a normal quickfix
@Override
public DiagnosticMessage getUnresolvedProxyMessage(ILinkingDiagnosticContext context) {
if (XXXXPackage.Literals.YYYY_REF.equals(context.getReference())) {
final String msg = "Folgende Referenz kann nicht aufgelöst werden: " + " '" + context.getLinkText() + "'.";
return new DiagnosticMessage(msg, Severity.ERROR, "MyCode", context.getLinkText());
} else {
return super.getUnresolvedProxyMessage(context);
}
}
to fix stuff in other files you may have to open the editor of that other file and call xtexteditor.getDocument.modify
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Using Quickfix to add elements to imported ECore resource [message #1707336 is a reply to message #1701103] |
Thu, 03 September 2015 19:51 |
Florian König Messages: 30 Registered: June 2014 |
Member |
|
|
Hi Christian,
sorry for the late response.
I created a custom LinkingDiagnosticMessageProvider and implemented the getUnresolvedProxyMessage method as you said.
This works fine, thank you very much!
Then I implemented a quickfix like I would do for my xtext document.
@Fix(IssueCodes::OPERATION_NOT_FOUND)
def fixOperationNotFound(Issue issue, IssueResolutionAcceptor acceptor) {
createLinkingIssueResolutions(issue, acceptor);
acceptor.accept(
issue,
'Add operation to model',
'Add operation to model.',
null,
new ISemanticModification() {
override apply(EObject element, IModificationContext context) throws Exception {
// Retrieve
val greeting = element as Greeting
val type = greeting.ec as EClass
// Retrieve name of operation
val operationName = context.xtextDocument.get(issue.offset, issue.length)
// Create new operation
val newOperation = EcoreFactory.eINSTANCE.createEOperation()
newOperation.name = operationName
// Add to model
type.EOperations.add(newOperation)
// Save model
type.eResource.save(Collections.EMPTY_MAP)
}
}
)
}
This works and adds the new operation to the model, but the Xtext editor still shows the error.
To refresh the editor I have to change something and then save the document.
How can I change the quickfix to refresh the editor automatically?
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.01792 seconds