|
|
|
|
|
|
|
|
Re: Tutorial about Quick Fixes [message #1386627 is a reply to message #1386622] |
Wed, 18 June 2014 16:13   |
Eclipse User |
|
|
|
Hi,
there is actually a difference between quickfixes and quick assist.
xtext can only quick fixes for Isses Produced by the validator
But let us asume you have the xtext hello world example
Model:
greetings+=Greeting*;
Greeting:
'Hello' name=ID '!';
class MyDslValidator extends AbstractMyDslValidator {
public static val GREETING_NOT_USED = 'GREETING_NOT_USED'
@Check
def checkGreetingStartsWithCapital(Greeting greeting) {
warning('Greeting is not in use',
MyDslPackage.Literals.GREETING__NAME,
GREETING_NOT_USED)
}
}
class MyDslQuickfixProvider extends DefaultQuickfixProvider {
@Fix(MyDslValidator.GREETING_NOT_USED)
def capitalizeName(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, 'Remove Greeting', 'Remove the Greeting from the file', 'upcase.png') [
eobject, context |
if (eobject instanceof Greeting) {
val g = eobject as Greeting
EcoreUtil2.getContainerOfType(g, Model).greetings -= g
}
]
}
}
for real quick assist i thing you have to do all the stuff yourself (XtextQuickAssistProcessor)
|
|
|
Re: Tutorial about Quick Fixes [message #1386731 is a reply to message #1386627] |
Thu, 19 June 2014 19:03   |
Eclipse User |
|
|
|
Hi Christian,
I have tried what you told for a specific element in my grammar. I can have a quick fixes remove. But When I am clicking on it, no element is remove.
Here is my code:
grammar org.ramses.mydsl.RamsesDsl with org.eclipse.xtext.common.Terminals
generate ramsesDSL "http://www.ramses.org/mydsl/RamsesDSL"
import 'http://www.eclipse.org/emf/2002/Ecore' as refModel
Ramses: contents+=Contents*;
Contents: Altern | Decision | Result ;
Altern: name=Alternative;
/********************** Alternative *************************/
Alternative:
'Alternative' id=INT ':'
'for' element=ElementSyntaxName 'select' ':'
rule=Rule (params+=RuleList)* ';' ;
RuleList: 'or' rule=Rule ;
...
...
...
/********************** End Alternative **********************/
class RamsesDslValidator extends AbstractRamsesDslValidator {
public static val REMOVE_ELT = 'RomevedElement'
@Check
def removeAlternativeDecision(Altern altern) {
// faire un traitement pour vérifier que les éléments doivent être enlever
error('Alternative and decision should be remove after taking your decision', RamsesDSLPackage.Literals.ALTERN__NAME, REMOVE_ELT)
}
}
class RamsesDslQuickfixProvider extends DefaultQuickfixProvider {
@Fix(RamsesDslValidator::REMOVE_ELT)
def removeGreeting(Issue issue, IssueResolutionAcceptor acceptor) {
acceptor.accept(issue, 'Remove Alternative and decision', 'Remove Alternative and decision from the file after making your choice', 'upcase.png') [
eobject, context |
if (eobject instanceof Altern) {
val g = eobject as Altern
EcoreUtil2.getContainerOfType(g, Ramses).contents -= g
}
]
}
}
Best Regards,
Felix
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.34967 seconds