Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.m2t.common.recipe.ui/src/org/eclipse/m2t/common/recipe/ui/recipeBrowser/providers/QuickFixerProvider.java')
-rw-r--r--plugins/org.eclipse.m2t.common.recipe.ui/src/org/eclipse/m2t/common/recipe/ui/recipeBrowser/providers/QuickFixerProvider.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/plugins/org.eclipse.m2t.common.recipe.ui/src/org/eclipse/m2t/common/recipe/ui/recipeBrowser/providers/QuickFixerProvider.java b/plugins/org.eclipse.m2t.common.recipe.ui/src/org/eclipse/m2t/common/recipe/ui/recipeBrowser/providers/QuickFixerProvider.java
new file mode 100644
index 00000000..edc36316
--- /dev/null
+++ b/plugins/org.eclipse.m2t.common.recipe.ui/src/org/eclipse/m2t/common/recipe/ui/recipeBrowser/providers/QuickFixerProvider.java
@@ -0,0 +1,61 @@
+package org.eclipse.m2t.common.recipe.ui.recipeBrowser.providers;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.m2t.common.recipe.core.Check;
+
+public class QuickFixerProvider {
+
+ // public QuickFixer getQuickFixer(Check check) {
+ public Object getQuickFixer(Check check) {
+
+ // The policy for QuickFixers is intentionnally the same
+ // than for Checks, that is to say at the total opposite of a possible
+ // chained structure we might think of.
+ // IMPORTANT NOTICE : However the possibility of the optimistic
+ // functionning of the quickFixers is only allowed because of
+ // the choice to quick fix COMPOSITE CHECKS ONLY, since their list of
+ // ATOMIC CHECKS HAPPENS TO BE IN THE GOOD RESOLUTION ORDER ! (no
+ // more...no less.)
+ // ...maybe one would one day want to change it, and that wouldn't be a
+ // bad idea at all !
+
+ String problemNature = check.getClass().getSimpleName().split("Check")[0];
+
+ String pack = check.getClass().getName().split(problemNature)[0];
+ String quickFixerClassName = pack + problemNature + "QuickFixer";
+ quickFixerClassName = quickFixerClassName.replaceAll("checks", "quickFixers");
+ String checkEvaluatorClassName = pack + problemNature + "CheckEvaluator";
+
+ try {
+ Class<?> checkEvaluatorClass = this.resolveClass(checkEvaluatorClassName);
+ return this.resolveClass(quickFixerClassName).getConstructor(check.getClass(), checkEvaluatorClass).newInstance(check.getClass().cast(check),
+ checkEvaluatorClass.newInstance());
+
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (IllegalArgumentException e) {
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+
+ MessageDialog.openError(null, "Error getting a QuickFixer", "Reason: QuickFixer not found for Check " + check.toString());
+ return null;
+
+ }
+
+ private Class<?> resolveClass(String className) throws ClassNotFoundException {
+ return Class.forName(className);
+ }
+
+}

Back to the top