Changeset 64 in default for v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src
- Timestamp:
- 04/28/14 14:38:07 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/quickfix/EbnfQuickfixProvider.xtend
r61 r64 7 7 import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor 8 8 import org.eclipse.xtext.validation.Issue 9 import de.ugoe.cs.swe.bnftools.validation.EbnfValidator 10 import org.eclipse.xtext.ui.editor.model.IXtextDocument 11 import org.eclipse.emf.ecore.EObject 12 import de.ugoe.cs.swe.bnftools.ebnf.Rule 13 import de.ugoe.cs.swe.bnftools.ebnf.EbnfFactory 14 import org.eclipse.xtext.nodemodel.util.NodeModelUtils 15 import org.eclipse.xtext.nodemodel.INode 16 import de.ugoe.cs.swe.bnftools.validation.EbnfAnalysisUtils 17 import java.util.List 18 import de.ugoe.cs.swe.bnftools.ebnf.RuleReference 19 import org.eclipse.xtext.nodemodel.ICompositeNode 20 import de.ugoe.cs.swe.bnftools.ebnf.EtsiBnf 21 import java.util.ArrayList 9 22 10 23 /** … … 14 27 */ 15 28 class EbnfQuickfixProvider extends org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider { 29 //works 30 @Fix(EbnfValidator.ruleReferencedOneDescription) 31 def void fixInlineRuleReferencedOnce(Issue issue, IssueResolutionAcceptor acceptor) { 32 acceptor.accept( 33 issue, 34 "Inline the rule", 35 "Delete the rule and replace its single reference by the rule's right side", 36 "upcase.png" 37 ) [ element, context | 38 var Rule rule = element as Rule; 39 var IXtextDocument xtextDocument = context.getXtextDocument(); 40 var ICompositeNode node = NodeModelUtils.findActualNodeFor(rule); 41 var String nodeText = node.text; 42 var int textLength = nodeText.length - 2; 43 var int offset = node.textRegion.offset; 44 //rename references 45 var ICompositeNode dList = NodeModelUtils.findActualNodeFor(rule.definitionList); 46 var String refText = "(" + dList.text + ")"; 47 var int refLength = rule.name.length; 48 var List<RuleReference> references = EbnfAnalysisUtils.findReferences(rule); 49 //is the reference in the rule itself? 50 var boolean foundRule = false; 51 var EObject r = references.get(0) as EObject; 52 var Rule containingRule=null; 53 while (!foundRule) { 54 r = r.eContainer; 55 if (r instanceof Rule) { 56 containingRule = r as Rule; 57 foundRule = true; 58 } 59 } 60 if (!rule.equals(containingRule)) { 61 for (ruleRef : references) { 62 var ICompositeNode refNode = NodeModelUtils.findActualNodeFor(ruleRef); 63 var int refOffset = refNode.textRegion.offset; 16 64 65 xtextDocument.replace(refOffset, refLength, refText); 66 if (refOffset < offset) { 67 offset += refText.length - refLength; 68 } 69 } 70 } 71 17 72 18 static final String ruleReferencedOneDescription = "The rule is only referenced by one other rule"; 19 20 // @Fix(MyDslValidator::INVALID_NAME) 21 // def capitalizeName(Issue issue, IssueResolutionAcceptor acceptor) { 22 // acceptor.accept(issue, 'Capitalize name', 'Capitalize the name.', 'upcase.png') [ 23 // context | 24 // val xtextDocument = context.xtextDocument 25 // val firstLetter = xtextDocument.get(issue.offset, 1) 26 // xtextDocument.replace(issue.offset, 1, firstLetter.toUpperCase) 27 // ] 73 // delete rule 74 xtextDocument.replace(offset, textLength, ""); 75 ] 76 77 } 78 79 //works 80 // @Fix(EbnfValidator.passthroughRuleDescription) 81 // def void fixRemovePassthroughRule(Issue issue, IssueResolutionAcceptor acceptor) { 82 // acceptor.accept( 83 // issue, 84 // "Remove passthrough rule", 85 // "Delete the passthrough rule and replace its references with its right side", 86 // "upcase.png", 87 // [ element, context | 88 // var Rule rule = element as Rule; 89 // var IXtextDocument xtextDocument = context.getXtextDocument(); 90 // var ICompositeNode node = NodeModelUtils.findActualNodeFor(rule); 91 // var String nodeText = node.text; 92 // var int textLength = nodeText.length - 2; 93 // var int offset = node.textRegion.offset; 94 // var ICompositeNode dList = NodeModelUtils.findActualNodeFor(rule.definitionList); 95 // var String refText = "(" + dList.text + ")"; 96 // var int refLength = rule.name.length; 97 // var List<RuleReference> references = EbnfAnalysisUtils.findReferences(rule); 98 // //sort references by offset 99 // var int i = 0; 100 // var List<RuleReference> referenceHleper = new ArrayList<RuleReference>(); 101 // while(i<references.length){ 102 // 103 // i++; 104 // } 105 // for (ruleRef : references) { 106 // var ICompositeNode refNode = NodeModelUtils.findActualNodeFor(ruleRef); 107 // var int refOffset = refNode.textRegion.offset; 108 // 109 // xtextDocument.replace(refOffset, refLength, refText); 110 // if (refOffset < offset) { 111 // offset += refText.length - refLength; 112 // } 113 // } 114 // ] 115 // ); 28 116 // } 29 117 118 @Fix(EbnfValidator.unusedRuleDescription) 119 def void fixUnusedRule(Issue issue, IssueResolutionAcceptor acceptor) { 30 120 31 // @Fix(value = ruleReferencedOneDescription) 32 // def void fixInlineRuleReferencedOnce(final Issue issue, IssueResolutionAcceptor acceptor) { 33 // InlineRuleModification inlineRuleModification = new InlineRuleModification( 34 // resourceDescriptions);35 // 36 // acceptor.accept( 37 // issue, 38 // "Inline the rule", 39 // "Delete the rule and replace its single reference by the rule's right side", 40 // "upcase.png", inlineRuleModification); 41 //}121 acceptor.accept(issue, "Remove unused rule", "Delete the unused rule", "upcase.png", 122 [ element, context | 123 var Rule rule = element as Rule; 124 var IXtextDocument xtextDocument = context.getXtextDocument(); 125 var ICompositeNode node = NodeModelUtils.findActualNodeFor(rule); 126 var int offset = node.textRegion.offset; 127 var String nodeText = node.text; 128 var int textLength = nodeText.length - 2; 129 xtextDocument.replace(offset, textLength, ""); 130 ]) 131 } 42 132 } 133
Note: See TracChangeset
for help on using the changeset viewer.