Skip to main content
summaryrefslogtreecommitdiffstats
blob: c5c17f53a53f5ca613b7131dff7841431e8fa51c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*******************************************************************************
 * Copyright (c) 2005, 2007 committers of openArchitectureWare and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     committers of openArchitectureWare - initial API and implementation
 *******************************************************************************/
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