Question

Is anyone out there who has an example of a customized rename refactoring example in xtext ?

I guess it has to be similar to the customized syntax highlighting, binding some classes override some implementations and then crawl trough the EObjects you want to rename.

But i don't know where to start, has anyone an idea ? Or is there even someone who has allready implemented a customized rename refactoring in xtext ?

kind regards,

Example: If i do rename, the ruleName of a Rule, i also want to rename the ruleReferenceName of the RuleReference

Rule:
    ruleName=(RuleName)':' ruleContent=RuleContent ';'
;

RuleContent: 
       ruleReferences+=RuleReference 
;

RuleReference:
    ruleReferenceName=RuleName (cardinality=Cardinality)?
;

RuleName:
    value=RuleReferenceNameTerminal
;
Was it helpful?

Solution

I guess what i first planned to do isn't intended by the xtext rename refactoring. So I took again a closer look at the crossreference concept. I tried rename refactoring through crossreferencing earlier, but stumbled across the fact that i didn't had an "ID" Terminal defined. What solved my issue was to let the crossreference know which terminal rule it should use and to set the name-attribute at the right place.

Here is what the grammar should look like to have the rename refactoring work like i wanted it to(note the square brackets and the name attribute). No binding and overriding needed at all.

Rule:
    ruleName=(RuleName)':' ruleContent=RuleContent ';'
;

RuleContent: 
       ruleReferences+=RuleReference 
;

RuleReference:
    ruleReferenceName=[RuleName | RuleReferenceNameTerminal] (cardinality=Cardinality)?
;

RuleName:
    name=RuleReferenceNameTerminal
;

It is important to know that the " | " between the square brackets is not an alternative.

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