Question

Given a grammar that includes a rule like:

SomeStatement: ... (tokensExist?=TokensExist)? ...

TokensExist: 'TOKENONE' 'TOKENTWO';

Next I create a QuickFix that detects the missing tokens and proposes to add them by modifying the model:

acceptor.accept(issue, "Add missing tokens", "", null, new ISemanticModification() {
    @Override
    public void apply(EObject element, IModificationContext context) throws Exception {

        // Locate the model element
        EObject goal = element;
        while (goal != null && !(MyStatement.class.isAssignableFrom(goal.getClass()))) {
            goal = goal.eContainer();
        }
        MyStatement stmt = (MyStatement)goal;

        // Set the tokens in the model
        stmt.setTokensExists(true);
    }
});

The problem now is that when the model is updated in the editor it appears as:

TOKENONETOKENTWO

instead of TOKENONE TOKENTWO, e.g. no space between the tokens.

This seems to be because the generated class MySyntacticSequencer has been generated to return a token this way:

protected String getTokensExist(EObject semanticObject, RuleCall ruleCall, INode node) {
    if (node != null)
        return getTokenText(node);
    return "TOKENONETOKENTWO";
}

I would like to avoid modifying the editor text directly and instead manipulate the model. Is there a way to do this? Can the generated token string be overridden?

Was it helpful?

Solution

We got this to work by extending the MySyntacticSequencer class and then overriding the getTokensExist method to return "TOKENONE TOKENTWO".

Is there a better solution?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top