initial commit
diff --git a/org.eclipse.emf.refactor.refactoring.analyzer/.classpath b/org.eclipse.emf.refactor.refactoring.analyzer/.classpath
new file mode 100644
index 0000000..ad32c83
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/.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.analyzer/.project b/org.eclipse.emf.refactor.refactoring.analyzer/.project
new file mode 100644
index 0000000..2470c3e
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>

+<projectDescription>

+	<name>org.eclipse.emf.refactor.refactoring.analyzer</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.analyzer/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.emf.refactor.refactoring.analyzer/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..f287d53
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/.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.analyzer/META-INF/MANIFEST.MF b/org.eclipse.emf.refactor.refactoring.analyzer/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..a0e40ee
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/META-INF/MANIFEST.MF
@@ -0,0 +1,20 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: RefactoringAnalyzer
+Bundle-SymbolicName: org.eclipse.emf.refactor.refactoring.analyzer;singleton:=true
+Bundle-Version: 0.7.1
+Bundle-Activator: org.eclipse.emf.refactor.refactoring.analyzer.Activator
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ org.eclipse.core.resources;bundle-version="3.8.1",
+ 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.emf.refactor.smells.configuration;bundle-version="0.7.0",
+ org.eclipse.emf.refactor.refactoring;bundle-version="0.7.0",
+ org.eclipse.emf.refactor.refactoring.runtime;bundle-version="0.7.0",
+ org.eclipse.ltk.core.refactoring;bundle-version="3.6.0",
+ org.eclipse.ltk.ui.refactoring;bundle-version="3.7.0",
+ org.eclipse.emf.compare.ui;bundle-version="1.3.2"
+Bundle-ActivationPolicy: lazy
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
diff --git a/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/Activator.class b/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/Activator.class
new file mode 100644
index 0000000..4d1cb3f
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/Activator.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/core/CompareResult.class b/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/core/CompareResult.class
new file mode 100644
index 0000000..40c48bd
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/core/CompareResult.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/core/ModelSmellResultComparator.class b/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/core/ModelSmellResultComparator.class
new file mode 100644
index 0000000..78b316b
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/core/ModelSmellResultComparator.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/core/StatisticsButtonCreator$1.class b/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/core/StatisticsButtonCreator$1.class
new file mode 100644
index 0000000..24b4958
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/core/StatisticsButtonCreator$1.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/core/StatisticsButtonCreator.class b/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/core/StatisticsButtonCreator.class
new file mode 100644
index 0000000..600f4c1
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/bin/org/eclipse/emf/refactor/refactoring/analyzer/core/StatisticsButtonCreator.class
Binary files differ
diff --git a/org.eclipse.emf.refactor.refactoring.analyzer/build.properties b/org.eclipse.emf.refactor.refactoring.analyzer/build.properties
new file mode 100644
index 0000000..e9863e2
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/build.properties
@@ -0,0 +1,5 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+               .,\
+               plugin.xml
diff --git a/org.eclipse.emf.refactor.refactoring.analyzer/plugin.xml b/org.eclipse.emf.refactor.refactoring.analyzer/plugin.xml
new file mode 100644
index 0000000..95d6b85
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/plugin.xml
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+   <extension
+         point="org.eclipse.emf.refactor.inputpagebutton">
+      <inputpagebuttoncreator
+            creatorclass="org.eclipse.emf.refactor.refactoring.analyzer.core.StatisticsButtonCreator">
+      </inputpagebuttoncreator>
+   </extension>
+
+</plugin>
diff --git a/org.eclipse.emf.refactor.refactoring.analyzer/src/org/eclipse/emf/refactor/refactoring/analyzer/Activator.java b/org.eclipse.emf.refactor.refactoring.analyzer/src/org/eclipse/emf/refactor/refactoring/analyzer/Activator.java
new file mode 100644
index 0000000..d3af6a8
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/src/org/eclipse/emf/refactor/refactoring/analyzer/Activator.java
@@ -0,0 +1,50 @@
+package org.eclipse.emf.refactor.refactoring.analyzer;

+

+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.analyzer"; //$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.analyzer/src/org/eclipse/emf/refactor/refactoring/analyzer/core/CompareResult.java b/org.eclipse.emf.refactor.refactoring.analyzer/src/org/eclipse/emf/refactor/refactoring/analyzer/core/CompareResult.java
new file mode 100644
index 0000000..0432d61
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/src/org/eclipse/emf/refactor/refactoring/analyzer/core/CompareResult.java
@@ -0,0 +1,63 @@
+package org.eclipse.emf.refactor.refactoring.analyzer.core;

+

+import java.util.HashMap;

+import java.util.Map;

+

+import org.eclipse.emf.refactor.smells.core.ModelSmell;

+

+/**

+ * Data class representing the result of comparing two ResultModels during a quantitative analysis.

+ * The data is comprise of Maps containing counts of smell occurences which can be compared.

+ * 

+ * @author Matthias Burhenne

+ *

+ */

+public class CompareResult {

+	

+	private final HashMap<ModelSmell, Integer> occurencesInOriginalModel;

+	private final HashMap<ModelSmell, Integer> occurencesInChangedModel;

+	

+	CompareResult(HashMap<ModelSmell, Integer> occurencesInOriginalModel, HashMap<ModelSmell, Integer> occurencesInChangedModel){

+		this.occurencesInOriginalModel = occurencesInOriginalModel;

+		this.occurencesInChangedModel = occurencesInChangedModel;

+	}

+

+	/**

+	 * Getter for the field occurencesInOriginalModel

+	 * 

+	 * @return - Map<ModelSmell, Integer>

+	 */

+	public HashMap<ModelSmell, Integer> getOccurencesInOriginalModel() {

+		return occurencesInOriginalModel;

+	}

+

+	/**

+	 * Getter for the field occurencesInChangedModel

+	 * 

+	 * @return - Map<ModelSmell, Integer>

+	 */

+	public HashMap<ModelSmell, Integer> getOccurencesInChangedModel() {

+		return occurencesInChangedModel;

+	}

+	

+	/**

+	 * Compares the numbers of occurences in the original model and the changed model

+	 * and returns the differences as a map

+	 * 

+	 * @return - Map<ModelSmell, Integer>

+	 */

+	public Map<ModelSmell, Integer> getDifferences(){

+		HashMap<ModelSmell, Integer> result = new HashMap<ModelSmell, Integer>();

+		for(ModelSmell smell : occurencesInOriginalModel.keySet()){

+			Integer numberInOriginal = occurencesInOriginalModel.get(smell);

+			Integer numberInChanged = occurencesInChangedModel.get(smell);

+			if(numberInChanged != null){

+				result.put(smell, numberInChanged - numberInOriginal);

+			}else{

+				result.put(smell, 0 - numberInOriginal);

+			}

+		}

+		return result;

+	}

+	

+}

diff --git a/org.eclipse.emf.refactor.refactoring.analyzer/src/org/eclipse/emf/refactor/refactoring/analyzer/core/ModelSmellResultComparator.java b/org.eclipse.emf.refactor.refactoring.analyzer/src/org/eclipse/emf/refactor/refactoring/analyzer/core/ModelSmellResultComparator.java
new file mode 100644
index 0000000..0a946b8
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/src/org/eclipse/emf/refactor/refactoring/analyzer/core/ModelSmellResultComparator.java
@@ -0,0 +1,37 @@
+package org.eclipse.emf.refactor.refactoring.analyzer.core;

+

+import java.util.HashMap;

+import java.util.List;

+import org.eclipse.emf.refactor.smells.core.ModelSmell;

+import org.eclipse.emf.refactor.smells.runtime.core.Result;

+

+/**

+ * Utility class providing functionality to compare the results of two model smell searches.

+ * 

+ * @author Matthias Burhenne

+ *

+ */

+public class ModelSmellResultComparator {

+	

+	/**

+	 * Compares the two lists of Result objects and creates a wrapping CompareResult with the numbers of occurences

+	 * 

+	 * @param resultsFromOriginalModel - Map<ModelSmell, Integer> the number of search results before the change

+	 * @param resultsFromChangedModel - Map<ModelSmell, Integer> the number of search results after the change

+	 * @return CompareResult

+	 */

+	public static CompareResult compareModelSmellSearchResults(List<Result> resultsFromOriginalModel, List<Result> resultsFromChangedModel){

+		HashMap<ModelSmell, Integer> occurencesInOriginalModel = new HashMap<ModelSmell, Integer>();

+		HashMap<ModelSmell, Integer> occurencesInChangedModel = new HashMap<ModelSmell, Integer>();

+		

+		for(Result result : resultsFromOriginalModel){

+			occurencesInOriginalModel.put(result.getSmell(), result.getModelelements().size());

+		}

+

+		for(Result result : resultsFromChangedModel){

+			occurencesInChangedModel.put(result.getSmell(), result.getModelelements().size());

+		}

+		

+		return new CompareResult(occurencesInOriginalModel, occurencesInChangedModel);

+	}

+}

diff --git a/org.eclipse.emf.refactor.refactoring.analyzer/src/org/eclipse/emf/refactor/refactoring/analyzer/core/StatisticsButtonCreator.java b/org.eclipse.emf.refactor.refactoring.analyzer/src/org/eclipse/emf/refactor/refactoring/analyzer/core/StatisticsButtonCreator.java
new file mode 100644
index 0000000..43aad95
--- /dev/null
+++ b/org.eclipse.emf.refactor.refactoring.analyzer/src/org/eclipse/emf/refactor/refactoring/analyzer/core/StatisticsButtonCreator.java
@@ -0,0 +1,120 @@
+package org.eclipse.emf.refactor.refactoring.analyzer.core;

+

+import java.util.List;

+import java.util.Map;

+

+import org.eclipse.core.resources.IFile;

+import org.eclipse.core.runtime.CoreException;

+import org.eclipse.core.runtime.NullProgressMonitor;

+import org.eclipse.core.runtime.OperationCanceledException;

+import org.eclipse.emf.ecore.EObject;

+import org.eclipse.emf.refactor.refactoring.interfaces.IController;

+import org.eclipse.emf.refactor.refactoring.runtime.ltk.LtkEmfRefactoringProcessorAdapter;

+import org.eclipse.emf.refactor.refactoring.runtime.ltk.change.RefactoringChange;

+import org.eclipse.emf.refactor.refactoring.runtime.ltk.ui.AbstractRefactoringWizard;

+import org.eclipse.emf.refactor.refactoring.runtime.ui.IInputPageButtonCreator;

+import org.eclipse.emf.refactor.smells.configuration.managers.ConfigurationManager;

+import org.eclipse.emf.refactor.smells.core.ModelSmell;

+import org.eclipse.emf.refactor.smells.runtime.core.ModelSmellFinder;

+import org.eclipse.emf.refactor.smells.runtime.core.Result;

+import org.eclipse.jface.dialogs.MessageDialog;

+import org.eclipse.ltk.core.refactoring.RefactoringStatus;

+import org.eclipse.swt.SWT;

+import org.eclipse.swt.events.MouseEvent;

+import org.eclipse.swt.events.MouseListener;

+import org.eclipse.swt.widgets.Button;

+import org.eclipse.swt.widgets.Composite;

+

+/**

+ * Class implementing the Interface IInputPageButtonCreator from EMF Refactor. It provides a method

+ * to create a button for the input page of the refactoring wizard of EMF Refactor.

+ * 

+ * @author Matthias Burhenne

+ *

+ */

+public class StatisticsButtonCreator implements IInputPageButtonCreator {

+

+	@Override

+	public Button createButton(final Composite parent, final IController controller, final AbstractRefactoringWizard wizard) {

+		Button statButton = new Button(parent, SWT.NONE);

+		statButton.setText("Model smell statistics");

+		statButton.addMouseListener(new MouseListener() {

+			boolean mouseDown = false;

+			AbstractRefactoringWizard abstrWizard = wizard;

+			

+			@Override

+			public void mouseUp(MouseEvent e) {

+				if(mouseDown){

+					abstrWizard.getNextPage(abstrWizard.getStartingPage());

+					LtkEmfRefactoringProcessorAdapter processor = (LtkEmfRefactoringProcessorAdapter) controller.getLtkRefactoringProcessor();

+					try {

+						RefactoringStatus status = processor.checkFinalConditions();

+						boolean applicable = status.isOK(); 

+						if(applicable) {

+							RefactoringChange c = (RefactoringChange) processor.createChange(new NullProgressMonitor());

+							c.getModelCompareInput();

+							EObject rootAfterRefactoring = (EObject) c.getModifiedElement();

+							EObject rootBeforeRefactoring = (EObject) c.getModifiedElement();

+							String path = rootBeforeRefactoring.eResource().getURI().toPlatformString(false);

+							IFile iFile = (IFile)org.eclipse.core.resources.ResourcesPlugin.getWorkspace().getRoot().findMember(path);

+							List<Result> smellResultsBefore = ModelSmellFinder.findModelSmells(ConfigurationManager.getSelectedModelSmells(iFile.getProject()), rootBeforeRefactoring);

+							List<Result> smellResultsAfter = ModelSmellFinder.findModelSmells(ConfigurationManager.getSelectedModelSmells(iFile.getProject()), rootAfterRefactoring);

+							CompareResult result = ModelSmellResultComparator.compareModelSmellSearchResults(smellResultsBefore, smellResultsAfter);

+							String message = buildStatisticsMessage(result);

+							MessageDialog.openInformation(parent.getShell(), "Changes in model smell occurrences", message);

+						} else {

+							String message = "The provided input parameter(s) lead to a failure of the final check:\n" + status.getEntryWithHighestSeverity().getMessage();

+							MessageDialog.openInformation(parent.getShell(), "Condition checks not passed", message);

+						}

+					} catch (OperationCanceledException e1) {

+						e1.printStackTrace();

+					} catch (CoreException e1) {

+						e1.printStackTrace();

+					}

+				}

+				mouseDown = false;

+			}

+			

+			/*

+			 * Creates the message for the dialog called by the created button.

+			 */

+			private String buildStatisticsMessage(CompareResult result) {

+				String message = "Following model smell occurences are found before\n applying refactoring '" + controller.getParent().getName() + "':\n\n";

+				Map<ModelSmell, Integer> originalSmells = result.getOccurencesInOriginalModel();

+				for(ModelSmell smell : originalSmells.keySet()){

+					if(originalSmells.get(smell) != 0){

+						message += smell.getName() + ": " + originalSmells.get(smell) + "\n";

+					}

+				}

+				message += "\n\nFollowing model smells are found after\n applying refactoring '" + controller.getParent().getName() + "':\n\n";

+				Map<ModelSmell, Integer> changedSmells = result.getOccurencesInChangedModel();

+				for(ModelSmell smell : changedSmells.keySet()){

+					if(changedSmells.get(smell) != 0){

+						message += smell.getName() + ": " + changedSmells.get(smell) + "\n";

+					}

+				}

+				message += "\n\nFollowing model smell occurrences will change when\napplying refactoring '" + controller.getParent().getName() + "':\n\n";

+				Map<ModelSmell, Integer> differences = result.getDifferences();

+				for(ModelSmell smell : differences.keySet()){

+					if(differences.get(smell) != 0){

+						message += smell.getName() + ": " + differences.get(smell) + "\n";

+					}

+				}

+				return message;

+			}

+

+			@Override

+			public void mouseDown(MouseEvent e) {

+				mouseDown = true;

+				

+			}

+			

+			@Override

+			public void mouseDoubleClick(MouseEvent e) {

+				

+			}

+		});

+		return statButton;

+	}

+

+}