mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 339305 - Preference "Run as you type" should appear only if checker supports that launch mode. Patch by Alex Ruiz.
This commit is contained in:
parent
1b982e0418
commit
0a500299af
5 changed files with 74 additions and 19 deletions
|
@ -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() {}
|
||||
}
|
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Add table
Reference in a new issue