Quickfix does not appear in editor [message #1866183] |
Wed, 22 May 2024 14:09 |
Alex Oli Messages: 19 Registered: May 2024 |
Junior Member |
|
|
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.
|
|
|
|
Re: Quickfix does not appear in editor [message #1866192 is a reply to message #1866189] |
Wed, 22 May 2024 14:33 |
Alex Oli Messages: 19 Registered: May 2024 |
Junior Member |
|
|
MANDATORY_STRING_EMPTY is my error message defined in my Validator as: public static final String MANDATORY_STRING_EMPTY = "%s cannot be empty";
Can I define MANDATORY_STRING_EMPTY_ERRORCODE as any String or does it need to have a specific syntax?
Just asking for convention purposes, as I defined an empty string and just tested and it works
[Updated on: Wed, 22 May 2024 14:36] Report message to a moderator
|
|
|
|
|
Re: Quickfix does not appear in editor [message #1866258 is a reply to message #1866201] |
Thu, 23 May 2024 21:37 |
Alex Oli Messages: 19 Registered: May 2024 |
Junior Member |
|
|
An off-topic question:
Lets say I have this configuration in my Xtext run-time editor:
Job
name "Executor Job"
reuseExecutor "my-executor"
How can I remove a reuseExecutor from my dsl with the quickfix option?
The final result after clicking the quickfix would be:
This is my Quickfix method that right now only changes the issue content (wanted to delete the issue in my dsl):
@Fix(CICDValidator.REQUIRED_JOB_NOT_EXIST_ERRORCODE)
public void fixRequiredJob(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, "Remove Required Job", "Remove the non-existing required job.", null, new IModification() {
public void apply(IModificationContext context) throws BadLocationException {
IXtextDocument xtextDocument = context.getXtextDocument();
xtextDocument.replace(issue.getOffset(), issue.getLength(), "");
}
});
}
[Updated on: Thu, 23 May 2024 21:46] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04188 seconds