1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-20 15:35:24 +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:
Sergey Prigogin 2011-03-23 02:59:10 +00:00
parent 1b982e0418
commit 0a500299af
5 changed files with 74 additions and 19 deletions

View file

@ -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() {}
}

View file

@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import org.eclipse.cdt.codan.core.CodanCorePlugin; import org.eclipse.cdt.codan.core.CodanCorePlugin;
import org.eclipse.cdt.codan.core.PreferenceConstants; import org.eclipse.cdt.codan.core.PreferenceConstants;
@ -57,6 +58,7 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
private static boolean initialized = false; private static boolean initialized = false;
private HashMap<Object, IProblemProfile> profiles = new HashMap<Object, IProblemProfile>(); private HashMap<Object, IProblemProfile> profiles = new HashMap<Object, IProblemProfile>();
private HashMap<IChecker, Collection<IProblem>> problemList = new HashMap<IChecker, Collection<IProblem>>(); private HashMap<IChecker, Collection<IProblem>> problemList = new HashMap<IChecker, Collection<IProblem>>();
private Map<String, IChecker> problemCheckerMapping = new HashMap<String, IChecker>();
private CheckersRegistry() { private CheckersRegistry() {
instance = this; instance = this;
@ -304,6 +306,16 @@ public class CheckersRegistry implements Iterable<IChecker>, ICheckersRegistry {
problemList.put(c, plist); problemList.put(c, plist);
} }
plist.add(p); 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());
} }
/** /**

View file

@ -15,6 +15,7 @@ import java.util.Map;
import org.eclipse.cdt.codan.core.CodanCorePlugin; import org.eclipse.cdt.codan.core.CodanCorePlugin;
import org.eclipse.cdt.codan.core.Messages; import org.eclipse.cdt.codan.core.Messages;
import org.eclipse.cdt.codan.core.model.CheckerLaunchMode; 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.IChecker;
import org.eclipse.cdt.codan.core.model.ICodanBuilder; import org.eclipse.cdt.codan.core.model.ICodanBuilder;
import org.eclipse.cdt.codan.core.model.IRunnableInEditorChecker; 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) { private boolean doesCheckerSupportLaunchMode(IChecker checker, CheckerLaunchMode mode) {
if (mode == CheckerLaunchMode.RUN_AS_YOU_TYPE) if (mode == CheckerLaunchMode.RUN_AS_YOU_TYPE)
return checker.runInEditor() && checker instanceof IRunnableInEditorChecker; return Checkers.canCheckerRunAsYouType(checker);
return true; return true;
} }

View file

@ -11,22 +11,31 @@
package org.eclipse.cdt.codan.internal.ui.preferences; package org.eclipse.cdt.codan.internal.ui.preferences;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.codan.core.model.CheckerLaunchMode; 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.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditor; import org.eclipse.jface.preference.FieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.PreferenceStore; import org.eclipse.jface.preference.PreferenceStore;
public class LaunchModesPropertyPage extends FieldEditorPreferencePage { public class LaunchModesPropertyPage extends FieldEditorPreferencePage {
private ArrayList<FieldEditor> editors; private final List<FieldEditor> editors;
private final boolean runInEditor;
/** /**
* @param problem
* @param prefStore * @param prefStore
*
*/ */
public LaunchModesPropertyPage(PreferenceStore prefStore) { public LaunchModesPropertyPage(IProblem problem, PreferenceStore prefStore) {
super(GRID); super(GRID);
CheckersRegistry registry = CheckersRegistry.getInstance();
IChecker checker = registry.getCheckerForProblem(problem);
runInEditor = (checker != null) ? Checkers.canCheckerRunAsYouType(checker) : false;
setPreferenceStore(prefStore); setPreferenceStore(prefStore);
editors = new ArrayList<FieldEditor>(); 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_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_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_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()));
}
} }
/* /*

View file

@ -60,7 +60,7 @@ public class LaunchingTabComposite extends Composite {
LaunchModeProblemPreference launchModes = ((RootProblemPreference) info).getLaunchModePreference(); LaunchModeProblemPreference launchModes = ((RootProblemPreference) info).getLaunchModePreference();
launchPref = (LaunchModeProblemPreference) launchModes.clone(); launchPref = (LaunchModeProblemPreference) launchModes.clone();
initPrefStore(); initPrefStore();
page = new LaunchModesPropertyPage(prefStore); page = new LaunchModesPropertyPage(problem, prefStore);
page.noDefaultAndApplyButton(); page.noDefaultAndApplyButton();
page.createControl(parent); page.createControl(parent);
page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); page.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));