1 | package de.ugoe.cs.swe.bnftools.ui.quickfix.modifications;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import org.eclipse.core.runtime.NullProgressMonitor;
|
---|
7 | import org.eclipse.emf.ecore.EObject;
|
---|
8 | import org.eclipse.ltk.core.refactoring.Change;
|
---|
9 | import org.eclipse.ltk.core.refactoring.PerformChangeOperation;
|
---|
10 | import org.eclipse.ltk.core.refactoring.RefactoringCore;
|
---|
11 | import org.eclipse.ui.PlatformUI;
|
---|
12 | import org.eclipse.xtext.parsetree.CompositeNode;
|
---|
13 | import org.eclipse.xtext.parsetree.NodeAdapter;
|
---|
14 | import org.eclipse.xtext.parsetree.NodeUtil;
|
---|
15 | import org.eclipse.xtext.resource.IResourceDescriptions;
|
---|
16 | import org.eclipse.xtext.ui.editor.XtextEditor;
|
---|
17 | import org.eclipse.xtext.ui.editor.model.edit.IModificationContext;
|
---|
18 | import org.eclipse.xtext.ui.editor.model.edit.ISemanticModification;
|
---|
19 |
|
---|
20 | import de.ugoe.cs.swe.bnftools.ebnf.Rule;
|
---|
21 | import de.ugoe.cs.swe.bnftools.ui.quickfix.processors.RemoveUnusedRulesProcessor;
|
---|
22 |
|
---|
23 | public class RemoveUnusedRuleModification implements ISemanticModification {
|
---|
24 |
|
---|
25 | IResourceDescriptions resourceDescriptions;
|
---|
26 |
|
---|
27 | // ----------------------------------------------------------------------------------------------------
|
---|
28 |
|
---|
29 | public RemoveUnusedRuleModification(
|
---|
30 | IResourceDescriptions resourceDescriptions) {
|
---|
31 | this.resourceDescriptions = resourceDescriptions;
|
---|
32 | }
|
---|
33 |
|
---|
34 | // ----------------------------------------------------------------------------------------------------
|
---|
35 |
|
---|
36 | public void apply(EObject element, IModificationContext context)
|
---|
37 | throws Exception {
|
---|
38 | // get current editor
|
---|
39 | XtextEditor editor = (XtextEditor) PlatformUI.getWorkbench()
|
---|
40 | .getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
---|
41 | Rule rule = (Rule) element;
|
---|
42 |
|
---|
43 | NodeAdapter declarationNode = NodeUtil.getNodeAdapter(rule);
|
---|
44 |
|
---|
45 | List<CompositeNode> unusedNodes = new ArrayList<CompositeNode>();
|
---|
46 |
|
---|
47 | unusedNodes.add(declarationNode.getParserNode());
|
---|
48 |
|
---|
49 | RemoveUnusedRulesProcessor processor = new RemoveUnusedRulesProcessor(
|
---|
50 | editor, editor.getDocument(), unusedNodes);
|
---|
51 |
|
---|
52 | NullProgressMonitor pm = new NullProgressMonitor();
|
---|
53 | Change change;
|
---|
54 | try {
|
---|
55 | change = processor.createChange(pm);
|
---|
56 | change.initializeValidationData(pm);
|
---|
57 | change.setEnabled(true);
|
---|
58 | PerformChangeOperation operation = new PerformChangeOperation(
|
---|
59 | change);
|
---|
60 | operation.setUndoManager(RefactoringCore.getUndoManager(),
|
---|
61 | processor.getProcessorName());
|
---|
62 | operation.run(pm);
|
---|
63 | change.dispose();
|
---|
64 | } catch (Exception e) {
|
---|
65 | e.printStackTrace();
|
---|
66 | }
|
---|
67 |
|
---|
68 | }
|
---|
69 |
|
---|
70 | }
|
---|