Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Prigogin2011-03-22 22:59:10 -0400
committerSergey Prigogin2011-03-22 22:59:10 -0400
commit0a500299af35323ad7adf917db3204e941a87749 (patch)
treebc69a872be5ff21601154c5d60d7162a4e6a3f5f
parent1b982e04185e0a68efa4988889a6ee66fa2670d9 (diff)
downloadorg.eclipse.cdt-0a500299af35323ad7adf917db3204e941a87749.tar.gz
org.eclipse.cdt-0a500299af35323ad7adf917db3204e941a87749.tar.xz
org.eclipse.cdt-0a500299af35323ad7adf917db3204e941a87749.zip
Bug 339305 - Preference "Run as you type" should appear only if checker supports that launch mode. Patch by Alex Ruiz.
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/Checkers.java31
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java38
-rw-r--r--codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java3
-rw-r--r--codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/LaunchModesPropertyPage.java19
-rw-r--r--codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/LaunchingTabComposite.java2
5 files changed, 74 insertions, 19 deletions
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/Checkers.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/Checkers.java
new file mode 100644
index 0000000000..161dc961df
--- /dev/null
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/Checkers.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright (c) 2011 Google Inc.
+ * 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:
+ * Alex Ruiz - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.codan.core.model;
+
+/**
+ * Utility methods related to <code>{@link IChecker}</code>.
+ *
+ * @since 2.0
+ */
+public final class Checkers {
+
+ /**
+ * Indicates whether the given checker can "run as you type."
+ * @param checker the checker to verify.
+ * @return {@code true} if the given checker can "run as you type"; {@code false} otherwise.
+ * @see IChecker#runInEditor()
+ */
+ public static boolean canCheckerRunAsYouType(IChecker checker) {
+ return checker.runInEditor() && checker instanceof IRunnableInEditorChecker;
+ }
+
+ private Checkers() {}
+}
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java
index 30f4c987fb..6f6f111ed6 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CheckersRegistry.java
@@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.Map;
import org.eclipse.cdt.codan.core.CodanCorePlugin;
import org.eclipse.cdt.codan.core.PreferenceConstants;
@@ -57,6 +58,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
private static boolean initialized = false;
private HashMap<Object, IProblemProfile> profiles = new HashMap<Object, IProblemProfile>();
private HashMap<IChecker, Collection<IProblem>> problemList = new HashMap<IChecker, Collection<IProblem>>();
+ private Map<String, IChecker> problemCheckerMapping = new HashMap<String, IChecker>();
private CheckersRegistry() {
instance = this;
@@ -232,7 +234,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#iterator()
*/
public Iterator<IChecker> iterator() {
@@ -252,7 +254,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#addChecker(org.eclipse
* .cdt.codan.core.model.IChecker)
@@ -263,7 +265,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#addProblem(org.eclipse
* .cdt.codan.core.model.IProblem, java.lang.String)
@@ -277,7 +279,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#addCategory(org.eclipse
* .cdt.codan.core.model.IProblemCategory, java.lang.String)
@@ -291,7 +293,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#addRefProblem(org.
* eclipse.cdt.codan.core.model.IChecker,
@@ -304,11 +306,21 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
problemList.put(c, plist);
}
plist.add(p);
+ problemCheckerMapping.put(p.getId(), c);
+ }
+
+ /**
+ * Returns the checker associated with a problem.
+ * @param problem the given problem.
+ * @return the checker associated with a problem.
+ */
+ public IChecker getCheckerForProblem(IProblem problem) {
+ return problemCheckerMapping.get(problem.getId());
}
/**
* Returns list of problems registered for given checker
- *
+ *
* @return collection of problems or null
*/
public Collection<IProblem> getRefProblems(IChecker checker) {
@@ -317,7 +329,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#getDefaultProfile()
*/
@@ -327,7 +339,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#getWorkspaceProfile()
*/
@@ -355,7 +367,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
- *
+ *
* @see
* org.eclipse.cdt.codan.core.model.ICheckersRegistry#getResourceProfile
* (org.eclipse.core.resources.IResource)
@@ -386,7 +398,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/*
* (non-Javadoc)
- *
+ *
* @seeorg.eclipse.cdt.codan.core.model.ICheckersRegistry#
* getResourceProfileWorkingCopy(org.eclipse.core.resources.IResource)
*/
@@ -399,7 +411,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
* Tests if a checker is enabled (needs to be run) or not. Checker is
* enabled
* if at least one problem it reports is enabled.
- *
+ *
* @param checker
* @param resource
* @return <code>true</code> if the checker is enabled
@@ -422,7 +434,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/**
* Tests if a checker needs to run in a specific launch mode.
- *
+ *
* @param checker
* @param resource
* @param mode
@@ -459,7 +471,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
/**
* Create a replicated problem - it has same check and same initial values
* as original but user can modify it further
- *
+ *
* @param problem
* @param profile
*/
diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java
index 4abb28954a..4de58b2b01 100644
--- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java
+++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/CodanBuilder.java
@@ -15,6 +15,7 @@ import java.util.Map;
import org.eclipse.cdt.codan.core.CodanCorePlugin;
import org.eclipse.cdt.codan.core.Messages;
import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
+import org.eclipse.cdt.codan.core.model.Checkers;
import org.eclipse.cdt.codan.core.model.IChecker;
import org.eclipse.cdt.codan.core.model.ICodanBuilder;
import org.eclipse.cdt.codan.core.model.IRunnableInEditorChecker;
@@ -180,7 +181,7 @@ public class CodanBuilder extends IncrementalProjectBuilder implements ICodanBui
private boolean doesCheckerSupportLaunchMode(IChecker checker, CheckerLaunchMode mode) {
if (mode == CheckerLaunchMode.RUN_AS_YOU_TYPE)
- return checker.runInEditor() && checker instanceof IRunnableInEditorChecker;
+ return Checkers.canCheckerRunAsYouType(checker);
return true;
}
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/LaunchModesPropertyPage.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/LaunchModesPropertyPage.java
index 206b2c994d..b010f6c530 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/LaunchModesPropertyPage.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/LaunchModesPropertyPage.java
@@ -11,22 +11,31 @@
package org.eclipse.cdt.codan.internal.ui.preferences;
import java.util.ArrayList;
+import java.util.List;
import org.eclipse.cdt.codan.core.model.CheckerLaunchMode;
+import org.eclipse.cdt.codan.core.model.Checkers;
+import org.eclipse.cdt.codan.core.model.IChecker;
+import org.eclipse.cdt.codan.core.model.IProblem;
+import org.eclipse.cdt.codan.internal.core.CheckersRegistry;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.PreferenceStore;
public class LaunchModesPropertyPage extends FieldEditorPreferencePage {
- private ArrayList<FieldEditor> editors;
+ private final List<FieldEditor> editors;
+ private final boolean runInEditor;
/**
+ * @param problem
* @param prefStore
- *
*/
- public LaunchModesPropertyPage(PreferenceStore prefStore) {
+ public LaunchModesPropertyPage(IProblem problem, PreferenceStore prefStore) {
super(GRID);
+ CheckersRegistry registry = CheckersRegistry.getInstance();
+ IChecker checker = registry.getCheckerForProblem(problem);
+ runInEditor = (checker != null) ? Checkers.canCheckerRunAsYouType(checker) : false;
setPreferenceStore(prefStore);
editors = new ArrayList<FieldEditor>();
}
@@ -48,7 +57,9 @@ public class LaunchModesPropertyPage extends FieldEditorPreferencePage {
addField(new BooleanFieldEditor(CheckerLaunchMode.RUN_ON_FULL_BUILD.name(), "Run on full build", getFieldEditorParent()));
addField(new BooleanFieldEditor(CheckerLaunchMode.RUN_ON_INC_BUILD.name(), "Run on incremental build", getFieldEditorParent()));
addField(new BooleanFieldEditor(CheckerLaunchMode.RUN_ON_DEMAND.name(), "Run on demand", getFieldEditorParent()));
- addField(new BooleanFieldEditor(CheckerLaunchMode.RUN_AS_YOU_TYPE.name(), "Run as you type", getFieldEditorParent()));
+ if (runInEditor) {
+ addField(new BooleanFieldEditor(CheckerLaunchMode.RUN_AS_YOU_TYPE.name(), "Run as you type", getFieldEditorParent()));
+ }
}
/*
diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/LaunchingTabComposite.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/LaunchingTabComposite.java
index b827ff58f6..46ba197e6f 100644
--- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/LaunchingTabComposite.java
+++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/LaunchingTabComposite.java
@@ -60,7 +60,7 @@ public class LaunchingTabComposite extends Composite {
LaunchModeProblemPreference launchModes = ((RootProblemPreference) info).getLaunchModePreference();
launchPref = (LaunchModeProblemPreference) launchModes.clone();
initPrefStore();
- page = new LaunchModesPropertyPage(prefStore);
+ page = new LaunchModesPropertyPage(problem, prefStore);
page.noDefaultAndApplyButton();
page.createControl(parent);
page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));

Back to the top