Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortarendt2013-07-16 04:52:20 -0400
committertarendt2013-07-16 04:52:20 -0400
commitefa92bebeff658a72efc82242987d6af922b031b (patch)
tree0b5979f73655ebf4db4ca3130c86f7623cf2e8c9
parent4c25c8f5dc2d6f56e50c4022c012c3c531ccb02a (diff)
downloadorg.eclipse.emf.refactor.refactoring-efa92bebeff658a72efc82242987d6af922b031b.tar.gz
org.eclipse.emf.refactor.refactoring-efa92bebeff658a72efc82242987d6af922b031b.tar.xz
org.eclipse.emf.refactor.refactoring-efa92bebeff658a72efc82242987d6af922b031b.zip
initial commit refactorings xtext
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/.classpath7
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/.project28
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/META-INF/MANIFEST.MF18
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/Activator.classbin0 -> 974 bytes
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/interfaces/IXtextDataManagement.classbin0 -> 327 bytes
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/managers/XtextSelectionManager$1.classbin0 -> 1234 bytes
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/managers/XtextSelectionManager.classbin0 -> 3028 bytes
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu$1$1.classbin0 -> 5038 bytes
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu$1.classbin0 -> 2683 bytes
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu.classbin0 -> 3395 bytes
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/build.properties5
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/plugin.xml28
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/Activator.java50
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/interfaces/IXtextDataManagement.java10
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/managers/XtextSelectionManager.java48
-rw-r--r--org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu.java105
17 files changed, 306 insertions, 0 deletions
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/.classpath b/org.eclipse.emf.refactor.refactoring.xtext/.classpath
new file mode 100644
index 0000000..8a8f166
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/.project b/org.eclipse.emf.refactor.refactoring.xtext/.project
new file mode 100644
index 0000000..0046ada
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.emf.refactor.refactoring.xtext</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.emf.refactor.refactoring.xtext/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..f287d53
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/META-INF/MANIFEST.MF b/org.eclipse.emf.refactor.refactoring.xtext/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..a96082a
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/META-INF/MANIFEST.MF
@@ -0,0 +1,18 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: RefactoringXtext
+Bundle-SymbolicName: org.eclipse.emf.refactor.refactoring.xtext;singleton:=true
+Bundle-Version: 0.7.1
+Bundle-Activator: org.eclipse.emf.refactor.refactoring.xtext.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.jface.text;bundle-version="3.8.1",
+ org.eclipse.emf.ecore;bundle-version="2.8.1",
+ org.eclipse.xtext.ui;bundle-version="2.3.1",
+ org.eclipse.emf.refactor.refactoring;bundle-version="0.7.0",
+ org.eclipse.emf.refactor.refactoring.configuration;bundle-version="0.7.0",
+ org.eclipse.ltk.ui.refactoring;bundle-version="3.7.0",
+ org.eclipse.emf.transaction;bundle-version="1.4.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Export-Package: org.eclipse.emf.refactor.refactoring.xtext.interfaces
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/Activator.class b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/Activator.class
new file mode 100644
index 0000000..810b6c4
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/Activator.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/interfaces/IXtextDataManagement.class b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/interfaces/IXtextDataManagement.class
new file mode 100644
index 0000000..ecfa5e2
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/interfaces/IXtextDataManagement.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/managers/XtextSelectionManager$1.class b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/managers/XtextSelectionManager$1.class
new file mode 100644
index 0000000..eff2dd7
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/managers/XtextSelectionManager$1.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/managers/XtextSelectionManager.class b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/managers/XtextSelectionManager.class
new file mode 100644
index 0000000..17aa10c
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/managers/XtextSelectionManager.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu$1$1.class b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu$1$1.class
new file mode 100644
index 0000000..7241b4d
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu$1$1.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu$1.class b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu$1.class
new file mode 100644
index 0000000..259edc6
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu$1.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu.class b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu.class
new file mode 100644
index 0000000..0816e91
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/bin/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/build.properties b/org.eclipse.emf.refactor.refactoring.xtext/build.properties
new file mode 100644
index 0000000..6f20375
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/plugin.xml b/org.eclipse.emf.refactor.refactoring.xtext/plugin.xml
new file mode 100644
index 0000000..f3fab90
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/plugin.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="false"
+ locationURI="popup:org.eclipse.ui.popup.any">
+ <menu
+ label="Xtext Refactorings provided by EMF Refactor">
+ <visibleWhen
+ checkEnabled="true">
+ <iterate
+ ifEmpty="false">
+ <instanceof
+ value="org.eclipse.jface.text.TextSelection">
+ </instanceof>
+ </iterate>
+ </visibleWhen>
+ <dynamic
+ class="org.eclipse.emf.refactor.refactoring.xtext.ui.XtextApplicationMenu"
+ id="org.eclipse.emf.refactor.xtext.dynamicmenu">
+ </dynamic>
+ </menu>
+ </menuContribution>
+ </extension>
+
+</plugin>
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/Activator.java b/org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/Activator.java
new file mode 100644
index 0000000..96e19be
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/Activator.java
@@ -0,0 +1,50 @@
+package org.eclipse.emf.refactor.refactoring.xtext;
+
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.emf.refactor.refactoring.xtext"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/interfaces/IXtextDataManagement.java b/org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/interfaces/IXtextDataManagement.java
new file mode 100644
index 0000000..ef17b27
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/interfaces/IXtextDataManagement.java
@@ -0,0 +1,10 @@
+package org.eclipse.emf.refactor.refactoring.xtext.interfaces;
+
+import org.eclipse.emf.refactor.refactoring.interfaces.IDataManagement;
+import org.eclipse.xtext.ui.editor.model.XtextDocument;
+
+public interface IXtextDataManagement extends IDataManagement {
+
+ public XtextDocument getXtextDocument();
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/managers/XtextSelectionManager.java b/org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/managers/XtextSelectionManager.java
new file mode 100644
index 0000000..ffd66c6
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/managers/XtextSelectionManager.java
@@ -0,0 +1,48 @@
+package org.eclipse.emf.refactor.refactoring.xtext.managers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.xtext.resource.EObjectAtOffsetHelper;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.ui.editor.model.IXtextDocument;
+import org.eclipse.xtext.ui.editor.model.XtextDocumentUtil;
+import org.eclipse.xtext.ui.editor.utils.EditorUtils;
+import org.eclipse.xtext.util.concurrent.IUnitOfWork;
+
+public class XtextSelectionManager {
+
+ public static List<EObject> getESelection() {
+ ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
+ .getSelectionService().getSelection();
+ List<EObject> list = new ArrayList<EObject>();
+ if (null != selection && selection instanceof TextSelection) {
+ TextSelection tSelection = (TextSelection) selection;
+ XtextEditor xEditor = EditorUtils.getActiveXtextEditor();
+ if (null != xEditor) {
+ IXtextDocument doc = XtextDocumentUtil.get(xEditor);
+ if (null != doc) {
+ XtextResource resource;
+ resource = doc.readOnly(new IUnitOfWork<XtextResource, XtextResource>() {
+ public XtextResource exec(XtextResource state) throws Exception {
+ return state;
+ }
+ });
+ EObjectAtOffsetHelper helper = new EObjectAtOffsetHelper();
+ EObject eObject = helper.resolveElementAt(resource , tSelection.getOffset());
+ System.out.println("EObject: " + eObject);
+ if (eObject != null) {
+ list.add(eObject);
+ }
+ }
+ }
+ }
+ return list;
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu.java b/org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu.java
new file mode 100644
index 0000000..1669366
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.xtext/src/org/eclipse/emf/refactor/refactoring/xtext/ui/XtextApplicationMenu.java
@@ -0,0 +1,105 @@
+package org.eclipse.emf.refactor.refactoring.xtext.ui;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.refactor.refactoring.configuration.managers.ConfigurationManager;
+import org.eclipse.emf.refactor.refactoring.core.Refactoring;
+import org.eclipse.emf.refactor.refactoring.managers.ProjectManager;
+import org.eclipse.emf.refactor.refactoring.xtext.interfaces.IXtextDataManagement;
+import org.eclipse.emf.refactor.refactoring.xtext.managers.XtextSelectionManager;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.ui.editor.model.XtextDocument;
+import org.eclipse.xtext.util.concurrent.IUnitOfWork;
+
+public class XtextApplicationMenu extends ContributionItem {
+
+ private final List<EObject> selection;
+
+ public XtextApplicationMenu() {
+ selection = XtextSelectionManager.getESelection();
+ System.out.println("selection: " + selection);
+ }
+
+ public XtextApplicationMenu(String id) {
+ super(id);
+ selection = XtextSelectionManager.getESelection();
+ System.out.println("selection: " + selection);
+ }
+
+ @Override
+ public void fill(Menu menu, int index) {
+ ConfigurationManager.getInstance();
+ IProject project = ProjectManager.getActualProject();
+ LinkedList<Refactoring> refactorings =
+ ConfigurationManager.getSelectedRefactorings(project);
+ for(final Refactoring r : refactorings){
+ if(r.getGui().showInMenu(this.selection)){
+ MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
+ menuItem.setText(r.getName());
+ menuItem.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ try {
+ IXtextDataManagement dm = (IXtextDataManagement) r.getController()
+ .getDataManagementObject();
+ XtextDocument doc = dm.getXtextDocument();
+ doc.modify(new IUnitOfWork.Void<XtextResource>() {
+
+ @Override
+ public void process(XtextResource state)
+ throws Exception {
+ try {
+ // 1. Register EditingDomain for ResourceSet
+ ResourceSet synRset = selection.get(0).eResource().getResourceSet();
+ TransactionalEditingDomain domain = TransactionalEditingDomain.Factory.INSTANCE
+ .createEditingDomain(synRset);
+ TransactionalEditingDomain.Registry.INSTANCE.add("xtext.domain", domain);
+ // 2. Set Selection:
+ r.getController().setSelection(selection);
+ // 3. Preselect Values:
+ r.getController().getDataManagementObject().preselect(selection);
+ // 4. Start Refactoring:
+ Shell shell = Display.getDefault().getActiveShell();
+ RefactoringWizardOpenOperation dialog =
+ new RefactoringWizardOpenOperation (r.getGui().show());
+ dialog.run(shell, "Refactoring: " + r.getName());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ finally {
+ // 5. Remove EditingDomain from Registry
+ TransactionalEditingDomain transEditingDomain
+ = TransactionalEditingDomain.Registry.INSTANCE.getEditingDomain("xtext.domain");
+ transEditingDomain.dispose();
+ TransactionalEditingDomain.Registry.INSTANCE.remove("xtext.domain");
+ }
+
+ }
+
+ } );
+
+ } catch (Exception e2) {
+ MessageDialog
+ .openError(null, "Error", e2.getMessage());
+ }
+ }
+ });
+ }
+ }
+ }
+
+}

Back to the top