initial commit smells xtext
diff --git a/org.eclipse.emf.refactor.smells.xtext/.classpath b/org.eclipse.emf.refactor.smells.xtext/.classpath
new file mode 100644
index 0000000..8a8f166
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.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.smells.xtext/.project b/org.eclipse.emf.refactor.smells.xtext/.project
new file mode 100644
index 0000000..d7b1d98
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.emf.refactor.smells.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.smells.xtext/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.emf.refactor.smells.xtext/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..f287d53
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.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.smells.xtext/META-INF/MANIFEST.MF b/org.eclipse.emf.refactor.smells.xtext/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..e060317
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/META-INF/MANIFEST.MF
@@ -0,0 +1,23 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: SmellsXtext
+Bundle-SymbolicName: org.eclipse.emf.refactor.smells.xtext;singleton:=true
+Bundle-Version: 0.7.1
+Bundle-Activator: org.eclipse.emf.refactor.smells.xtext.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.emf.ecore;bundle-version="2.8.1",
+ org.eclipse.emf.refactor.smells;bundle-version="0.7.0",
+ org.eclipse.emf.refactor.smells.runtime;bundle-version="0.7.0",
+ org.eclipse.jface.text;bundle-version="3.8.1",
+ org.eclipse.core.resources;bundle-version="3.8.1",
+ org.eclipse.xtext;bundle-version="2.3.1",
+ org.eclipse.xtext.ui;bundle-version="2.3.1",
+ org.eclipse.emf.refactor.smells.eraser;bundle-version="0.7.1",
+ org.eclipse.emf.refactor.refactoring;bundle-version="0.7.0",
+ org.eclipse.ltk.ui.refactoring;bundle-version="3.7.0",
+ org.eclipse.emf.refactor.refactoring.xtext;bundle-version="0.7.1",
+ org.eclipse.emf.transaction;bundle-version="1.4.0"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Import-Package: org.eclipse.ui
diff --git a/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/Activator.class b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/Activator.class
new file mode 100644
index 0000000..8c24589
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/Activator.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/XtextStartup.class b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/XtextStartup.class
new file mode 100644
index 0000000..fb6a310
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/XtextStartup.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/handler/FindModelSmellHandler.class b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/handler/FindModelSmellHandler.class
new file mode 100644
index 0000000..7fcf8f6
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/handler/FindModelSmellHandler.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/handler/SuggestRefactoringAction$1.class b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/handler/SuggestRefactoringAction$1.class
new file mode 100644
index 0000000..9316391
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/handler/SuggestRefactoringAction$1.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/handler/SuggestRefactoringAction$2.class b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/handler/SuggestRefactoringAction$2.class
new file mode 100644
index 0000000..1394642
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/handler/SuggestRefactoringAction$2.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/handler/SuggestRefactoringAction.class b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/handler/SuggestRefactoringAction.class
new file mode 100644
index 0000000..065ddfd
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/handler/SuggestRefactoringAction.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/managers/XtextHighlightManager.class b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/managers/XtextHighlightManager.class
new file mode 100644
index 0000000..7b976b2
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/managers/XtextHighlightManager.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/managers/XtextProjectManager.class b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/managers/XtextProjectManager.class
new file mode 100644
index 0000000..d6eb4da
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/managers/XtextProjectManager.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/managers/XtextSelectionManager$1.class b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/managers/XtextSelectionManager$1.class
new file mode 100644
index 0000000..5abf53a
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/managers/XtextSelectionManager$1.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/managers/XtextSelectionManager.class b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/managers/XtextSelectionManager.class
new file mode 100644
index 0000000..5eded91
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/managers/XtextSelectionManager.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/ui/XtextHighlighting.class b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/ui/XtextHighlighting.class
new file mode 100644
index 0000000..c6c6b88
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/bin/org/eclipse/emf/refactor/smells/xtext/ui/XtextHighlighting.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.xtext/build.properties b/org.eclipse.emf.refactor.smells.xtext/build.properties
new file mode 100644
index 0000000..6f20375
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ plugin.xml
diff --git a/org.eclipse.emf.refactor.smells.xtext/icons/refactoring.png b/org.eclipse.emf.refactor.smells.xtext/icons/refactoring.png
new file mode 100644
index 0000000..011556a
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/icons/refactoring.png
Binary files differ
diff --git a/org.eclipse.emf.refactor.smells.xtext/plugin.xml b/org.eclipse.emf.refactor.smells.xtext/plugin.xml
new file mode 100644
index 0000000..24c761c
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/plugin.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+ <extension
+ id="org.eclipse.emf.refactor.qa.menu"
+ point="org.eclipse.ui.menus">
+ <menuContribution
+ allPopups="true"
+ locationURI="popup:org.eclipse.ui.popup.any?after=additions">
+ <menu
+ id="org.eclipse.emf.refactor.runtime.menu"
+ label="EMF Quality Assurance (use existing techniques)">
+ <command
+ commandId="org.eclipse.emf.refactor.smells.xtext.findModelSmellCommand"
+ label="Find Configured Model Smells"
+ style="push">
+ <visibleWhen
+ checkEnabled="true">
+ <iterate
+ ifEmpty="false">
+ <instanceof
+ value="org.eclipse.jface.text.TextSelection">
+ </instanceof>
+ </iterate>
+ </visibleWhen>
+ </command>
+ </menu>
+ </menuContribution>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.commands">
+ <command
+ id="org.eclipse.emf.refactor.smells.xtext.findModelSmellCommand"
+ name="FindModelSmellCommand">
+ </command>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.handlers">
+ <handler
+ class="org.eclipse.emf.refactor.smells.xtext.handler.FindModelSmellHandler"
+ commandId="org.eclipse.emf.refactor.smells.xtext.findModelSmellCommand">
+ </handler>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.popupMenus">
+ <objectContribution
+ adaptable="false"
+ id="org.eclipse.emf.refactor.smells.xtext.eraser"
+ objectClass="org.eclipse.emf.refactor.smells.runtime.core.EObjectGroup">
+ <action
+ class="org.eclipse.emf.refactor.smells.xtext.handler.SuggestRefactoringAction"
+ icon="icons/refactoring.png"
+ id="org.eclipse.emf.refactor.smells.xtext.eraser.suggestRefactoringAction"
+ label="Suggest Xtext Refactorings">
+ </action>
+ </objectContribution>
+ </extension>
+
+ <extension
+ point="org.eclipse.ui.startup">
+ <startup
+ class="org.eclipse.emf.refactor.smells.xtext.XtextStartup">
+ </startup>
+ </extension>
+
+</plugin>
diff --git a/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/Activator.java b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/Activator.java
new file mode 100644
index 0000000..4733f04
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/Activator.java
@@ -0,0 +1,50 @@
+package org.eclipse.emf.refactor.smells.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.smells.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.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/XtextStartup.java b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/XtextStartup.java
new file mode 100644
index 0000000..091efe9
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/XtextStartup.java
@@ -0,0 +1,15 @@
+package org.eclipse.emf.refactor.smells.xtext;
+
+import org.eclipse.emf.refactor.smells.runtime.managers.RuntimeManager;
+import org.eclipse.emf.refactor.smells.xtext.ui.XtextHighlighting;
+import org.eclipse.ui.IStartup;
+
+public class XtextStartup implements IStartup {
+
+ @Override
+ public void earlyStartup() {
+ RuntimeManager.getInstance(new XtextHighlighting());
+ System.out.println("Started");
+ }
+
+}
\ No newline at end of file
diff --git a/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/handler/FindModelSmellHandler.java b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/handler/FindModelSmellHandler.java
new file mode 100644
index 0000000..6c09b56
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/handler/FindModelSmellHandler.java
@@ -0,0 +1,84 @@
+package org.eclipse.emf.refactor.smells.xtext.handler;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.core.commands.IHandlerListener;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.refactor.smells.runtime.managers.RuntimeManager;
+import org.eclipse.emf.refactor.smells.xtext.managers.XtextProjectManager;
+import org.eclipse.emf.refactor.smells.xtext.managers.XtextSelectionManager;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.PlatformUI;
+
+public class FindModelSmellHandler implements IHandler {
+
+ private Shell shell;
+ private EObject selectedEObject;
+ private IProject selectedProject;
+
+ @Override
+ public void addHandlerListener(IHandlerListener handlerListener) { }
+
+ @Override
+ public void dispose() { }
+
+ @SuppressWarnings("finally")
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ Cursor oldCursor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getCursor();
+ shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ shell.setCursor(new Cursor(null,SWT.CURSOR_WAIT));
+ ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+// PapyrusManager.setComponents(PapyrusSelectionManager.getObject(selection));
+ selectedProject = XtextProjectManager.getActualProject(selection);
+ selectedEObject = XtextSelectionManager.getRoot(selection);
+ if (selectedEObject == null) {
+ MessageDialog.openError(
+ shell,
+ "EMF Quality Assurance: Error when trying to execute smell search",
+ "No selected EMF model element!");
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setCursor(oldCursor);
+ return null;
+ }
+ try {
+ RuntimeManager.findConfiguredModelSmells(selectedProject, selectedEObject, null);
+ } catch (Exception ex) {
+ Throwable cause = ex.getCause();
+ if(!(cause == null) && cause.getClass().getName().equals("org.eclipse.emf.ecore.xmi.PackageNotFoundException")){
+ MessageDialog.openError(
+ shell,
+ "EMF Quality Assurance: Error when trying to open File",
+ "The file you selected is not a (valid) EMF model.");
+ } else {
+ MessageDialog.openError(
+ shell,
+ "EMF Quality Assurance: Error when trying to execute smell search",
+ ex.toString());
+ ex.printStackTrace();
+ }
+ } finally {
+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().setCursor(oldCursor);
+ return null;
+ }
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return true;
+ }
+
+ @Override
+ public boolean isHandled() {
+ return true;
+ }
+
+ @Override
+ public void removeHandlerListener(IHandlerListener handlerListener) { }
+
+}
diff --git a/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/handler/SuggestRefactoringAction.java b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/handler/SuggestRefactoringAction.java
new file mode 100644
index 0000000..8e33990
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/handler/SuggestRefactoringAction.java
@@ -0,0 +1,222 @@
+package org.eclipse.emf.refactor.smells.xtext.handler;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.eclipse.emf.common.command.Command;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.refactor.refactoring.core.Refactoring;
+import org.eclipse.emf.refactor.refactoring.xtext.interfaces.IXtextDataManagement;
+import org.eclipse.emf.refactor.smells.core.ModelSmell;
+import org.eclipse.emf.refactor.smells.eraser.managers.EraseManager;
+import org.eclipse.emf.refactor.smells.eraser.ui.SuggestionDialog;
+import org.eclipse.emf.refactor.smells.runtime.core.EObjectGroup;
+import org.eclipse.emf.transaction.TransactionalEditingDomain;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.ui.editor.model.XtextDocument;
+import org.eclipse.xtext.ui.editor.utils.EditorUtils;
+import org.eclipse.xtext.util.concurrent.IUnitOfWork;
+
+public class SuggestRefactoringAction implements IObjectActionDelegate {
+
+ private Shell shell;
+ private ISelection selection;
+ Refactoring selectedRefactoring = null;
+ EObject contextObject = null;
+
+ public SuggestRefactoringAction() {
+ super();
+ }
+
+ @Override
+ public void run(IAction action) {
+ try {
+ System.out.println("Here I am ...");
+ EObjectGroup group = null;
+ if(selection instanceof IStructuredSelection){
+ IStructuredSelection structSelect = (IStructuredSelection)selection;
+ if(!structSelect.isEmpty() && structSelect.getFirstElement() instanceof EObjectGroup)
+ group = (EObjectGroup) structSelect.getFirstElement();
+ }
+ if(group != null){
+ System.out.println("Group: " + group);
+ ModelSmell smell = group.getModelSmell();
+ SuggestionDialog dialog = new SuggestionDialog(shell, EraseManager.getCausedModelSmells(EraseManager.getFixingRefactorings(smell)), group);
+ int dialogResult = dialog.open();
+ if(dialogResult == Dialog.OK) {
+ selectedRefactoring = dialog.getSelectedRefactoring();
+ contextObject = dialog.getSelectedContextObject();
+ IXtextDataManagement dm =
+ (IXtextDataManagement) selectedRefactoring.getController().getDataManagementObject();
+ XtextDocument doc = dm.getXtextDocument();
+ XtextEditor editor = EditorUtils.getActiveXtextEditor();
+ System.out.println("Active XtextEditor: " + editor);
+ doc.modify(new IUnitOfWork.Void<XtextResource>() {
+
+ @Override
+ public void process(XtextResource state) throws Exception {
+ refactor();
+ }
+
+ });
+// ArrayList<EObject> contextList = new ArrayList<EObject>();
+// contextList.add(contextObject);
+// selectedRefactoring.getController().setSelection(contextList);
+// selectedRefactoring.getController().getDataManagementObject().preselect(contextList);
+// RefactoringWizard wizard = selectedRefactoring.getGui().show();
+// RefactoringWizardOpenOperation wizardDialog = new RefactoringWizardOpenOperation(wizard);
+// try {
+// wizardDialog.run(shell, "EMF Refactor");
+// } catch (InterruptedException e) {
+// e.printStackTrace();
+// }
+ }
+ }
+ } catch (Exception e2) {
+ MessageDialog
+ .openError(null, "Error", e2.getMessage());
+ }
+ }
+
+// private void doXtextRefactoring(Refactoring r, EObject contextObject) {
+//
+//
+// }
+
+ @Override
+ public void selectionChanged(IAction action, ISelection selection) {
+ this.selection = selection;
+ }
+
+ @Override
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ shell = targetPart.getSite().getShell();
+ }
+
+ private void refactor() {
+ try {
+ // 1. Register EditingDomain for ResourceSet
+ ResourceSet synRset = contextObject.eResource().getResourceSet();
+ TransactionalEditingDomain domain = TransactionalEditingDomain.Factory.INSTANCE
+ .createEditingDomain(synRset);
+ TransactionalEditingDomain.Registry.INSTANCE.add("xtext.domain", domain);
+ domain.getCommandStack()
+ .execute(new Command() {
+
+ @Override
+ public boolean canExecute() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void execute() {
+ // 2. Set Selection:
+ ArrayList<EObject> contextList = new ArrayList<EObject>();
+ contextList.add(contextObject);
+ selectedRefactoring.getController().setSelection(contextList);
+ // 3. Preselect Values:
+ selectedRefactoring.getController().getDataManagementObject().preselect(contextList);
+ // 4. Start Refactoring:
+ Shell shell = Display.getDefault().getActiveShell();
+ RefactoringWizardOpenOperation dialog =
+ new RefactoringWizardOpenOperation (selectedRefactoring.getGui().show());
+ try {
+ dialog.run(shell, "Refactoring: " + selectedRefactoring.getName());
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public boolean canUndo() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void undo() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void redo() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Collection<?> getResult() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Collection<?> getAffectedObjects() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getLabel() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public String getDescription() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public void dispose() {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public Command chain(Command command) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ });
+// // 2. Set Selection:
+// ArrayList<EObject> contextList = new ArrayList<EObject>();
+// contextList.add(contextObject);
+// r.getController().setSelection(contextList);
+// // 3. Preselect Values:
+// r.getController().getDataManagementObject().preselect(contextList);
+// // 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");
+ }
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/managers/XtextHighlightManager.java b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/managers/XtextHighlightManager.java
new file mode 100644
index 0000000..23bc939
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/managers/XtextHighlightManager.java
@@ -0,0 +1,59 @@
+package org.eclipse.emf.refactor.smells.xtext.managers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.refactor.smells.runtime.core.EObjectGroup;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.xtext.nodemodel.ICompositeNode;
+import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
+import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.ui.editor.utils.EditorUtils;
+
+import com.google.inject.Inject;
+
+public class XtextHighlightManager {
+
+ private static XtextHighlightManager instance = null;
+ private List<EObject> selected;
+
+ private XtextHighlightManager() {
+ selected = new ArrayList<EObject>();
+ }
+
+ public static XtextHighlightManager getInstance() {
+ if(instance == null) {
+ instance = new XtextHighlightManager();
+ }
+ return instance;
+ }
+
+ @Inject
+ public void highlight(Object selection) {
+ // clear former selected eObjects
+ selected.clear();
+ // set selected eObjects from selection
+ if (selection instanceof EObjectGroup) {
+ selected.addAll(((EObjectGroup) selection).getEObjects());
+ }
+ if (selection instanceof EObject) {
+ selected.add((EObject) selection);
+ }
+ // highlight each eObject in editor
+ for (EObject eObject : selected) {
+ XtextEditor xEditor = EditorUtils.getActiveXtextEditor();
+ ICompositeNode node = NodeModelUtils.findActualNodeFor(eObject);
+ int offset = node.getOffset();
+ int length = node.getLength();
+ ISourceViewer textViewer = xEditor.getInternalSourceViewer();
+ textViewer.setRangeIndication(offset, length, true);
+ textViewer.revealRange(offset, length);
+ textViewer.setSelectedRange(offset, length);
+ }
+ }
+
+ public List<EObject> getSelected() {
+ return selected;
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/managers/XtextProjectManager.java b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/managers/XtextProjectManager.java
new file mode 100644
index 0000000..d9320f8
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/managers/XtextProjectManager.java
@@ -0,0 +1,35 @@
+package org.eclipse.emf.refactor.smells.xtext.managers;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.emf.refactor.smells.managers.ProjectManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.xtext.ui.editor.XtextEditor;
+import org.eclipse.xtext.ui.editor.utils.EditorUtils;
+
+public class XtextProjectManager extends ProjectManager {
+
+ @SuppressWarnings("finally")
+ public static IProject getActualProject(ISelection selection) {
+ IProject actualProject = ProjectManager.getActualProject();
+ System.out.println("Project: " + actualProject);
+ try {
+ XtextEditor editor = EditorUtils.getActiveXtextEditor();
+ if (editor != null) {
+ IEditorInput input = editor.getEditorInput();
+ System.out.println("Editor Input: " + input);
+ if (input instanceof IFileEditorInput) {
+ IFileEditorInput fileInput = (IFileEditorInput) input;
+ actualProject = fileInput.getFile().getProject();
+ System.out.println("Project: " + actualProject);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ return actualProject;
+ }
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/managers/XtextSelectionManager.java b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/managers/XtextSelectionManager.java
new file mode 100644
index 0000000..881c42c
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/managers/XtextSelectionManager.java
@@ -0,0 +1,44 @@
+package org.eclipse.emf.refactor.smells.xtext.managers;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
+import org.eclipse.emf.refactor.smells.managers.SelectionManager;
+import org.eclipse.jface.text.TextSelection;
+import org.eclipse.jface.viewers.ISelection;
+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 extends SelectionManager {
+
+ public static EObject getRoot(ISelection selection) {
+ 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) {
+ System.out.println("Root: " + EcoreUtil.getRootContainer(eObject));
+ return EcoreUtil.getRootContainer(eObject);
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/ui/XtextHighlighting.java b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/ui/XtextHighlighting.java
new file mode 100644
index 0000000..bb42097
--- /dev/null
+++ b/org.eclipse.emf.refactor.smells.xtext/src/org/eclipse/emf/refactor/smells/xtext/ui/XtextHighlighting.java
@@ -0,0 +1,13 @@
+package org.eclipse.emf.refactor.smells.xtext.ui;
+
+import org.eclipse.emf.refactor.smells.interfaces.IHighlighting;
+import org.eclipse.emf.refactor.smells.xtext.managers.XtextHighlightManager;
+
+public class XtextHighlighting implements IHighlighting {
+
+ @Override
+ public void highlight(Object selection) {
+ XtextHighlightManager.getInstance().highlight(selection);
+ }
+
+}