Changeset 66 in default for v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui
- Timestamp:
- 05/14/14 10:07:49 (10 years ago)
- Location:
- v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/outline/EbnfOutlineTreeProvider.xtend
r61 r66 10 10 */ 11 11 class EbnfOutlineTreeProvider extends org.eclipse.xtext.ui.editor.outline.impl.DefaultOutlineTreeProvider { 12 12 13 13 } -
v2/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/quickfix/EbnfQuickfixProvider.xtend
r65 r66 20 20 import de.ugoe.cs.swe.bnftools.ebnf.EtsiBnf 21 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 22 31 23 32 /** … … 28 37 class EbnfQuickfixProvider extends org.eclipse.xtext.ui.editor.quickfix.DefaultQuickfixProvider { 29 38 39 @Inject 40 IResourceDescriptions resourceDescriptions; 41 30 42 //***************************************************************************************** 31 //works 32 @Fix(EbnfValidator.ruleReferencedOneDescription) 33 def void fixInlineRuleReferencedOnce(Issue issue, IssueResolutionAcceptor acceptor) { 34 acceptor.accept( 35 issue, 36 "Inline the rule", 37 "Delete the rule and replace its single reference by the rule's right side", 38 "upcase.png" 39 ) [ element, context | 40 var Rule rule = element as Rule; 41 42 var IXtextDocument xtextDocument = context.getXtextDocument(); 43 var ICompositeNode node = NodeModelUtils.findActualNodeFor(rule); 44 var String nodeText = node.text; 45 var int textLength = nodeText.length - 2; 46 var int offset = node.textRegion.offset; 47 //rename references 48 var ICompositeNode dList = NodeModelUtils.findActualNodeFor(rule.definitionList); 49 var String refText = "(" + dList.text + ")"; 50 var int refLength = rule.name.length; 51 var List<RuleReference> references = EbnfAnalysisUtils.findReferences(rule); 52 //is the reference in the rule itself? 53 var boolean foundRule = false; 54 var EObject r = references.get(0) as EObject; 55 var Rule containingRule = null; 56 while (!foundRule) { 57 r = r.eContainer; 58 if (r instanceof Rule) { 59 containingRule = r as Rule; 60 foundRule = true; 61 } 62 } 63 if (!rule.equals(containingRule)) { 64 for (ruleRef : references) { 65 var ICompositeNode refNode = NodeModelUtils.findActualNodeFor(ruleRef); 66 var int refOffset = refNode.textRegion.offset; 67 68 xtextDocument.replace(refOffset, refLength, refText); 69 if (refOffset < offset) { 70 offset += refText.length - refLength; 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; 71 73 } 72 74 } 73 } 74 // delete rule 75 xtextDocument.replace(offset, textLength, ""); 76 ] 77 78 } 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 // acceptor.accept( 99 // issue, 100 // "Inline the rule", 101 // "Delete the rule and replace its single reference by the rule's right side", 102 // "upcase.png" 103 // ) [ element, context | 104 // var Rule rule = element as Rule; 105 // var DefinitionList dlist = rule.definitionList; 106 // var List<Rule> rules=EbnfAnalysisUtils.getAllRules(rule.eContainer().eContainer() as EtsiBnf); 107 // var SingleDefinition sDef = rules.get(1).definitionList.singleDefinition.get(1); 108 // dlist.singleDefinition.add(sDef); 109 // rule.name="bla"; 110 // ] 111 // 112 // } 79 113 80 114 //***************************************************************************************** 81 82 115 // @Fix(EbnfValidator.passthroughRuleDescription) 83 116 // def void fixRemovePassthroughRule(Issue issue, IssueResolutionAcceptor acceptor) {
Note: See TracChangeset
for help on using the changeset viewer.