Quickfix does not appear in editor [message #1866183] |
Wed, 22 May 2024 10:09  |
Eclipse User |
|
|
|
Hi everyone,
I currently have a simple validator where it only checks if the Job name is empty and if so it gives an error in Xtext editor. I've implemented the validator using EStructuralFeature because I have my Xtext grammar project created from an existing ecore model.
@Check
public void checkNameNotEmpty(Job job) {
checkMandatoryStringNotEmpty(job.getName(), String.format(MANDATORY_STRING_EMPTY, "Job name"), job, "name");
}
/*
* Auxiliary methods
*/
private void checkMandatoryStringNotEmpty(String value, String errorMessage, Object object, String featureName) {
if (value == null || value.trim().isEmpty()) {
EStructuralFeature feature = ((EObject) object).eClass().getEStructuralFeature(featureName);
error(errorMessage, (EObject) object, feature);
}
}
This is my Quickfix method:
@Fix(CICDValidator.MANDATORY_STRING_EMPTY)
public void fixEmptyJobName(Issue issue, IssueResolutionAcceptor acceptor) {
fixEmptyString(issue, acceptor, "NewJobName");
}
private void fixEmptyString(Issue issue, IssueResolutionAcceptor acceptor, String suggestion) {
acceptor.accept(issue, "Fix Empty Value", suggestion, null, new IModification() {
public void apply(IModificationContext context) throws BadLocationException {
IXtextDocument xtextDocument = context.getXtextDocument();
String newValue = suggestion;
int offset = issue.getOffset();
xtextDocument.replace(offset, 0, newValue);
}
});
}
When I run the grammar in runtime, it gives the error but no Quickfix suggestion.
I checked Xtext book and I think that I didn't miss anything.
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05007 seconds