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

Last change on this file since 54 was 54, checked in by zeiss, 13 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                System.out.println(references);
51               
52                List<DeclarationReferencesPair> nodePairs = new ArrayList<DeclarationReferencesPair>();
53                nodePairs.add(new DeclarationReferencesPair((CompositeNode) declarationNode.getParserNode(), references));
54               
55                ReplacePassthroughRuleProcessor processor = new ReplacePassthroughRuleProcessor(
56                                editor, editor.getDocument(), nodePairs, true);
57
58                NullProgressMonitor pm = new NullProgressMonitor();
59                Change change;
60                try {
61                        change = processor.createChange(pm);
62                        change.initializeValidationData(pm);
63                        change.setEnabled(true);
64                        PerformChangeOperation operation = new PerformChangeOperation(
65                                        change);
66                        operation.setUndoManager(RefactoringCore.getUndoManager(),
67                                        processor.getProcessorName());
68                        operation.run(pm);
69                        change.dispose();
70                } catch (Exception e) {
71                        e.printStackTrace();
72                }
73
74        }
75
76}
Note: See TracBrowser for help on using the repository browser.