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 00000000000..161dc961df1 --- /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 {@link IChecker}. + * + * @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 30f4c987fb5..6f6f111ed6b 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, ICheckersRegistry { private static boolean initialized = false; private HashMap profiles = new HashMap(); private HashMap> problemList = new HashMap>(); + private Map problemCheckerMapping = new HashMap(); private CheckersRegistry() { instance = this; @@ -232,7 +234,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.codan.core.model.ICheckersRegistry#iterator() */ public Iterator iterator() { @@ -252,7 +254,7 @@ public class CheckersRegistry implements Iterable, 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, 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, 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, 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, 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 getRefProblems(IChecker checker) { @@ -317,7 +329,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { /* * (non-Javadoc) - * + * * @see * org.eclipse.cdt.codan.core.model.ICheckersRegistry#getDefaultProfile() */ @@ -327,7 +339,7 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { /* * (non-Javadoc) - * + * * @see * org.eclipse.cdt.codan.core.model.ICheckersRegistry#getWorkspaceProfile() */ @@ -355,7 +367,7 @@ public class CheckersRegistry implements Iterable, 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, 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, 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 true if the checker is enabled @@ -422,7 +434,7 @@ public class CheckersRegistry implements Iterable, 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, 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 4abb28954ad..4de58b2b010 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 206b2c994d4..b010f6c5306 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 editors; + private final List 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(); } @@ -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 b827ff58f6e..46ba197e6fd 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));