Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Quickfix does not appear in editor
Quickfix does not appear in editor [message #1866183] Wed, 22 May 2024 14:09 Go to next message
Alex Oli is currently offline Alex OliFriend
Messages: 18
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 #1866189 is a reply to message #1866183] Wed, 22 May 2024 14:24 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14685
Registered: July 2009
Senior Member
@Fix(CICDValidator.MANDATORY_STRING_EMPTY)

where is the validator side of that?

you need to call

error(message, object, feature, MANDATORY_STRING_EMPTY_ERRORCODE)

and then

@Fix(CICDValidator.MANDATORY_STRING_EMPTY_ERRORCODE)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Quickfix does not appear in editor [message #1866192 is a reply to message #1866189] Wed, 22 May 2024 14:33 Go to previous messageGo to next message
Alex Oli is currently offline Alex OliFriend
Messages: 18
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 #1866198 is a reply to message #1866192] Wed, 22 May 2024 14:46 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14685
Registered: July 2009
Senior Member
any non empty string, but should be unique among all error codes. and mybe something speaking.
so. e.g.

public static String MANDATORY_STRING_EMPTY_CODE = "MANDATORY_STRING_EMPTY";


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Quickfix does not appear in editor [message #1866201 is a reply to message #1866198] Wed, 22 May 2024 14:53 Go to previous messageGo to next message
Alex Oli is currently offline Alex OliFriend
Messages: 18
Registered: May 2024
Junior Member
Got it Christian,
Thanks again for your time
Re: Quickfix does not appear in editor [message #1866258 is a reply to message #1866201] Thu, 23 May 2024 21:37 Go to previous messageGo to next message
Alex Oli is currently offline Alex OliFriend
Messages: 18
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:
Job
	name "Executor Job"


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

Re: Quickfix does not appear in editor [message #1866270 is a reply to message #1866258] Fri, 24 May 2024 16:56 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14685
Registered: July 2009
Senior Member
Depends on the how and where you produce the issue
You can pass null as feature then everything should be squiggled

You can also look into semantic modifications and then delete the complete object from its parent


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Xtext 2.35.0.M2 for Eclipse 2024-06 M3 is available
Next Topic:Xtext 2.35.0 is released
Goto Forum:
  


Current Time: Sun Jun 16 17:27:28 GMT 2024

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

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

Back to the top