1 | /* |
---|
2 | * generated by Xtext |
---|
3 | */
|
---|
4 | package de.ugoe.cs.swe.bnftools.ui.quickfix
|
---|
5 |
|
---|
6 | import org.eclipse.xtext.ui.editor.quickfix.Fix
|
---|
7 | import org.eclipse.xtext.ui.editor.quickfix.IssueResolutionAcceptor
|
---|
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
|
---|
22 | import org.eclipse.xtext.EcoreUtil2
|
---|
23 | import de.ugoe.cs.swe.bnftools.ebnf.BnfEntry
|
---|
24 | import org.eclipse.emf.ecore.util.EcoreUtil
|
---|
25 | import org.eclipse.emf.common.util.EList
|
---|
26 | import org.eclipse.xtext.resource.IResourceDescriptions
|
---|
27 | import com.google.inject.Inject
|
---|
28 | import de.ugoe.cs.swe.bnftools.ebnf.DefinitionList
|
---|
29 | import de.ugoe.cs.swe.bnftools.ebnf.SingleDefinition
|
---|
30 | import de.ugoe.cs.swe.bnftools.ebnf.util.EbnfAdapterFactory
|
---|
31 |
|
---|
32 | /** |
---|
33 | * Custom quickfixes. |
---|
34 | * |
---|
35 | * see http://www.eclipse.org/Xtext/documentation.html#quickfixes |
---|
36 | */
|
---|
37 | class EbnfQuickfixProvider extends org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider {
|
---|
38 |
|
---|
39 | @Inject
|
---|
40 | IResourceDescriptions resourceDescriptions;
|
---|
41 |
|
---|
42 | //***************************************************************************************** |
---|
43 | //works but only in one file
|
---|
44 | // @Fix(EbnfValidator.ruleReferencedOneDescription)
|
---|
45 | // def void fixInlineRuleReferencedOnce(Issue issue, IssueResolutionAcceptor acceptor) {
|
---|
46 | // acceptor.accept(
|
---|
47 | // issue,
|
---|
48 | // "Inline the rule",
|
---|
49 | // "Delete the rule and replace its single reference by the rule's right side",
|
---|
50 | // "upcase.png"
|
---|
51 | // ) [ element, context |
|
---|
52 | // var Rule rule = element as Rule;
|
---|
53 | // var IXtextDocument xtextDocument = context.getXtextDocument();
|
---|
54 | // var ICompositeNode node = NodeModelUtils.findActualNodeFor(rule);
|
---|
55 | // var String nodeText = node.text;
|
---|
56 | // var int textLength = nodeText.length - 2;
|
---|
57 | // var int offset = node.textRegion.offset;
|
---|
58 | // //rename references |
---|
59 | // var ICompositeNode dList = NodeModelUtils.findActualNodeFor(rule.definitionList);
|
---|
60 | // var String refText = "(" + dList.text + ")";
|
---|
61 | // var int refLength = rule.name.length;
|
---|
62 | // var List<RuleReference> references = EbnfAnalysisUtils.findReferences(rule);
|
---|
63 | // //********************************* |
---|
64 | // //is the reference in the rule itself?
|
---|
65 | // var boolean foundRule = false;
|
---|
66 | // var EObject r = references.get(0) as EObject;
|
---|
67 | // var Rule containingRule = null;
|
---|
68 | // while (!foundRule) {
|
---|
69 | // r = r.eContainer;
|
---|
70 | // if (r instanceof Rule) {
|
---|
71 | // containingRule = r as Rule;
|
---|
72 | // foundRule = true;
|
---|
73 | // }
|
---|
74 | // }
|
---|
75 | // if (!rule.equals(containingRule)) {
|
---|
76 | //
|
---|
77 | // for (ruleRef : references) {
|
---|
78 | // var ICompositeNode refNode = NodeModelUtils.findActualNodeFor(ruleRef);
|
---|
79 | // var int refOffset = refNode.textRegion.offset;
|
---|
80 | //
|
---|
81 | // xtextDocument.replace(refOffset, refLength, refText);
|
---|
82 | // if (refOffset < offset) {
|
---|
83 | // offset += refText.length - refLength;
|
---|
84 | // }
|
---|
85 | // } |
---|
86 | // |
---|
87 | // // delete rule
|
---|
88 | // } |
---|
89 | // |
---|
90 | // xtextDocument.replace(offset, textLength, "");
|
---|
91 | // ]
|
---|
92 | //
|
---|
93 | // } |
---|
94 | |
---|
95 | // // this is not working by unknown reasons |
---|
96 | // @Fix(EbnfValidator.ruleReferencedOneDescription)
|
---|
97 | // def void fixInlineRuleReferencedOnce(Issue issue, IssueResolutionAcceptor acceptor) { |
---|
98 | // System.out.println("test");
|
---|
99 | // acceptor.accept(
|
---|
100 | // issue,
|
---|
101 | // "Inline the rule",
|
---|
102 | // "Delete the rule and replace its single reference by the rule's right side",
|
---|
103 | // "upcase.png"
|
---|
104 | // ) [ element, context |
|
---|
105 | // var Rule rule = element as Rule; |
---|
106 | // var DefinitionList dlist = rule.definitionList; |
---|
107 | // var List<Rule> rules=EbnfAnalysisUtils.getAllRules(rule.eContainer().eContainer() as EtsiBnf); |
---|
108 | // var SingleDefinition sDef = rules.get(0).definitionList.singleDefinition.get(0); |
---|
109 | // |
---|
110 | // System.out.println(dlist.singleDefinition); |
---|
111 | // dlist.singleDefinition.add(sDef); |
---|
112 | // System.out.println(dlist.singleDefinition); |
---|
113 | // |
---|
114 | // rule.name="bla"; |
---|
115 | // ]
|
---|
116 |
|
---|
117 | // }
|
---|
118 |
|
---|
119 | //***************************************************************************************** |
---|
120 | // @Fix(EbnfValidator.passthroughRuleDescription)
|
---|
121 | // def void fixRemovePassthroughRule(Issue issue, IssueResolutionAcceptor acceptor) {
|
---|
122 | // acceptor.accept(
|
---|
123 | // issue,
|
---|
124 | // "Remove passthrough rule",
|
---|
125 | // "Delete the passthrough rule and replace its references with its right side",
|
---|
126 | // "upcase.png",
|
---|
127 | // [ element, context |
|
---|
128 | // var Rule rule = element as Rule;
|
---|
129 | // var IXtextDocument xtextDocument = context.getXtextDocument();
|
---|
130 | // var ICompositeNode node = NodeModelUtils.findActualNodeFor(rule);
|
---|
131 | // var String nodeText = node.text;
|
---|
132 | // var int textLength = nodeText.length - 2;
|
---|
133 | // var int offset = node.textRegion.offset;
|
---|
134 | // var ICompositeNode dList = NodeModelUtils.findActualNodeFor(rule.definitionList);
|
---|
135 | // var String refText = "(" + dList.text + ")";
|
---|
136 | // var int refLength = rule.name.length;
|
---|
137 | // var List<RuleReference> references = EbnfAnalysisUtils.findReferences(rule); |
---|
138 | // //sort references by offset |
---|
139 | // var int i = 0; |
---|
140 | // var List<RuleReference> referenceHleper = new ArrayList<RuleReference>(); |
---|
141 | // while(i<references.length){ |
---|
142 | // |
---|
143 | // i++; |
---|
144 | // }
|
---|
145 | // for (ruleRef : references) {
|
---|
146 | // var ICompositeNode refNode = NodeModelUtils.findActualNodeFor(ruleRef);
|
---|
147 | // var int refOffset = refNode.textRegion.offset;
|
---|
148 | //
|
---|
149 | // xtextDocument.replace(refOffset, refLength, refText);
|
---|
150 | // if (refOffset < offset) {
|
---|
151 | // offset += refText.length - refLength;
|
---|
152 | // }
|
---|
153 | // }
|
---|
154 | // ]
|
---|
155 | // );
|
---|
156 | // } |
---|
157 | |
---|
158 | //***************************************************************************************** |
---|
159 | //works
|
---|
160 | @Fix(EbnfValidator.unusedRuleDescription)
|
---|
161 | def void fixUnusedRule(Issue issue, IssueResolutionAcceptor acceptor) {
|
---|
162 |
|
---|
163 | acceptor.accept(issue, "Remove unused rule", "Delete the unused rule", "upcase.png",
|
---|
164 | [ element, context |
|
---|
165 | var Rule rule = element as Rule;
|
---|
166 | var IXtextDocument xtextDocument = context.getXtextDocument();
|
---|
167 | var ICompositeNode node = NodeModelUtils.findActualNodeFor(rule);
|
---|
168 | var int offset = node.textRegion.offset;
|
---|
169 | var String nodeText = node.text;
|
---|
170 | var int textLength = nodeText.length - 2;
|
---|
171 | xtextDocument.replace(offset, textLength, "");
|
---|
172 | ])
|
---|
173 | }
|
---|
174 | }
|
---|