source: default/trunk/de.ugoe.cs.swe.bnftools.ebnf.ui/src/de/ugoe/cs/swe/bnftools/ui/quickfix/modifications/RemovePassthroughRuleModification.java @ 5

Last change on this file since 5 was 5, checked in by zeiss, 14 years ago
  • Property svn:mime-type set to text/plain
File size: 2.8 KB
Line 
1package de.ugoe.cs.swe.bnftools.ui.quickfix.modifications;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import org.eclipse.core.runtime.NullProgressMonitor;
7import org.eclipse.emf.ecore.EObject;
8import org.eclipse.ltk.core.refactoring.Change;
9import org.eclipse.ltk.core.refactoring.PerformChangeOperation;
10import org.eclipse.ltk.core.refactoring.RefactoringCore;
11import org.eclipse.ui.PlatformUI;
12import org.eclipse.xtext.parsetree.CompositeNode;
13import org.eclipse.xtext.parsetree.NodeAdapter;
14import org.eclipse.xtext.parsetree.NodeUtil;
15import org.eclipse.xtext.resource.IResourceDescriptions;
16import org.eclipse.xtext.ui.editor.XtextEditor;
17import org.eclipse.xtext.ui.editor.model.edit.IModificationContext;
18import org.eclipse.xtext.ui.editor.model.edit.ISemanticModification;
19
20import de.ugoe.cs.swe.bnftools.ebnf.Rule;
21import de.ugoe.cs.swe.bnftools.ui.quickfix.processors.ReplacePassthroughRuleProcessor;
22import de.ugoe.cs.swe.bnftools.utils.DeclarationReferencesPair;
23import de.ugoe.cs.swe.bnftools.utils.Utils;
24
25public class RemovePassthroughRuleModification implements ISemanticModification {
26
27        IResourceDescriptions resourceDescriptions;
28
29        // ----------------------------------------------------------------------------------------------------
30
31        public RemovePassthroughRuleModification(
32                        IResourceDescriptions resourceDescriptions) {
33                this.resourceDescriptions = resourceDescriptions;
34        }
35
36        // ----------------------------------------------------------------------------------------------------
37
38        public void apply(EObject element, IModificationContext context)
39                        throws Exception {
40                // get current editor
41                XtextEditor editor = (XtextEditor) PlatformUI.getWorkbench()
42                                .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
43                Rule rule = (Rule) element;
44
45                NodeAdapter declarationNode = NodeUtil.getNodeAdapter(rule);
46               
47                List<CompositeNode> references = Utils.findReferences(element,
48                                resourceDescriptions, editor);
49
50                List<DeclarationReferencesPair> nodePairs = new ArrayList<DeclarationReferencesPair>();
51                nodePairs.add(new DeclarationReferencesPair((CompositeNode) declarationNode.getParserNode(), references));
52               
53                ReplacePassthroughRuleProcessor processor = new ReplacePassthroughRuleProcessor(
54                                editor, editor.getDocument(), nodePairs, true);
55
56                NullProgressMonitor pm = new NullProgressMonitor();
57                Change change;
58                try {
59                        change = processor.createChange(pm);
60                        change.initializeValidationData(pm);
61                        change.setEnabled(true);
62                        PerformChangeOperation operation = new PerformChangeOperation(
63                                        change);
64                        operation.setUndoManager(RefactoringCore.getUndoManager(),
65                                        processor.getProcessorName());
66                        operation.run(pm);
67                        change.dispose();
68                } catch (Exception e) {
69                        e.printStackTrace();
70                }
71
72        }
73
74}
Note: See TracBrowser for help on using the repository browser.