From 6179bd2262301722e155175b8c1d114454865bf2 Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Mon, 28 Feb 2011 04:43:38 +0000 Subject: [PATCH] refactored per-problem launch mode: ui controls, internal structures, etc --- ...AbstractCheckerWithProblemPreferences.java | 47 ++++--- .../codan/core/model/CheckerLaunchMode.java | 4 - .../core/param/AbstractProblemPreference.java | 20 ++- .../param/FileScopeProblemPreference.java | 18 ++- ....java => LaunchModeProblemPreference.java} | 72 ++++++++--- .../core/param/MapProblemPreference.java | 41 ++++-- .../core/param/RootProblemPreference.java | 49 ++++++++ .../codan/internal/core/CheckersRegistry.java | 17 ++- .../internal/core/model/CodanProblem.java | 14 ++- .../.settings/org.eclipse.jdt.core.prefs | 6 +- .../.settings/org.eclipse.jdt.ui.prefs | 4 +- .../preferences/LaunchModesPropertyPage.java | 119 +----------------- .../ui/preferences/ProblemsTreeEditor.java | 18 +-- .../ui/widgets/LaunchingTabComposite.java | 26 ++-- .../ui/widgets/ParametersComposite.java | 4 +- 15 files changed, 230 insertions(+), 229 deletions(-) rename codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/{LaunchTypeProblemPreference.java => LaunchModeProblemPreference.java} (54%) create mode 100644 codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/RootProblemPreference.java diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractCheckerWithProblemPreferences.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractCheckerWithProblemPreferences.java index 4a01cff2612..e2e8234848f 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractCheckerWithProblemPreferences.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractCheckerWithProblemPreferences.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009,2010 Alena Laskavaia + * Copyright (c) 2009,2010 Alena Laskavaia * 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 @@ -13,13 +13,13 @@ package org.eclipse.cdt.codan.core.model; import java.util.Collection; import java.util.Iterator; -import org.eclipse.cdt.codan.core.param.AbstractProblemPreference; import org.eclipse.cdt.codan.core.param.BasicProblemPreference; import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference; import org.eclipse.cdt.codan.core.param.IProblemPreference; import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor.PreferenceType; import org.eclipse.cdt.codan.core.param.ListProblemPreference; import org.eclipse.cdt.codan.core.param.MapProblemPreference; +import org.eclipse.cdt.codan.core.param.RootProblemPreference; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IPath; @@ -34,20 +34,18 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec * Checker that actually has parameter must override this */ public void initPreferences(IProblemWorkingCopy problem) { - // by default add file scope preference - addPreference(problem, new FileScopeProblemPreference(), null); + getTopLevelPreference(problem); // initialize } /** * Scope preference - special preference that all file checkers should have, * it allows user to include/exclude files for this specific problem. - * + * * @param problem - problem for which scope preference is need * @return scope problem preference, null if not defined */ public FileScopeProblemPreference getScopePreference(IProblem problem) { - FileScopeProblemPreference scope = (FileScopeProblemPreference) getTopLevelPreferenceMap(problem).getChildDescriptor( - FileScopeProblemPreference.KEY); + FileScopeProblemPreference scope = getTopLevelPreference(problem).getScopePreference(); return scope; } @@ -57,7 +55,7 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec * be done within processResource method not in enabledInContext. * This test uses user "scope" preference for the all problems that this * checker can produce. - * + * * @param res - resource to test on * @return true if checker should report problems, fails otherwise. */ @@ -79,10 +77,10 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec * before printing of a problem. * This test uses user "scope" preference for the given problem. If scope is * not defined preference it returns true. - * + * * @param problem - problem to test for * @param resource - resource to test on - * + * * @return true if problem should be report for given resource, fails * otherwise. */ @@ -101,7 +99,7 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec /** * Add a parameter - * + * * @param problem * - problem that has parameter * @param key @@ -113,7 +111,7 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec * @return - parameter info object */ public IProblemPreference addPreference(IProblemWorkingCopy problem, String key, String label, Object defaultValue) { - MapProblemPreference map = getTopLevelPreferenceMap(problem); + MapProblemPreference map = getTopLevelPreference(problem); BasicProblemPreference info = new BasicProblemPreference(key, label, PreferenceType.typeOf(defaultValue)); map.addChildDescriptor(info); setDefaultPreferenceValue(problem, key, defaultValue); @@ -123,7 +121,7 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec /** * Add preference of type list of strings, list is empty by * default - * + * * @param problem * - problem * @param key @@ -133,10 +131,10 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec * @param itemLabel * @return preference instance of of the list, can be used to add default * values or set different element type - * + * */ public ListProblemPreference addListPreference(IProblemWorkingCopy problem, String key, String label, String itemLabel) { - MapProblemPreference map = getTopLevelPreferenceMap(problem); + MapProblemPreference map = getTopLevelPreference(problem); ListProblemPreference list = new ListProblemPreference(key, label); list.setChildDescriptor(new BasicProblemPreference(ListProblemPreference.COMMON_DESCRIPTOR_KEY, itemLabel, PreferenceType.TYPE_STRING)); @@ -145,14 +143,14 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec /** * Add preference for the given problem with default value - * + * * @param problem * @param pref - preference * @param defaultValue - default value of the preference * @return added preference */ public IProblemPreference addPreference(IProblemWorkingCopy problem, IProblemPreference pref, Object defaultValue) { - MapProblemPreference map = getTopLevelPreferenceMap(problem); + MapProblemPreference map = getTopLevelPreference(problem); String key = pref.getKey(); pref = map.addChildDescriptor(pref); setDefaultPreferenceValue(problem, key, defaultValue); @@ -162,13 +160,13 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec /** * Convenience method for setting default preference value for checker that * uses "map" as top level problem preference. - * + * * @param problem - problem for which to set default value for a prefence * @param key - preference key * @param defaultValue - value of preference to be set */ protected void setDefaultPreferenceValue(IProblemWorkingCopy problem, String key, Object defaultValue) { - MapProblemPreference map = getTopLevelPreferenceMap(problem); + MapProblemPreference map = getTopLevelPreference(problem); if (map.getChildValue(key) == null) map.setChildValue(key, defaultValue); } @@ -179,14 +177,15 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec * If top level preference does not exist create a map preference with name * "params" * and return it. - * + * * @param problem * @return top level preference if it is a map + * @since 2.0 */ - protected MapProblemPreference getTopLevelPreferenceMap(IProblem problem) { - MapProblemPreference map = (MapProblemPreference) problem.getPreference(); + public RootProblemPreference getTopLevelPreference(IProblem problem) { + RootProblemPreference map = (RootProblemPreference) problem.getPreference(); if (map == null) { - map = new MapProblemPreference(AbstractProblemPreference.PARAM, ""); //$NON-NLS-1$ + map = new RootProblemPreference(); if (problem instanceof IProblemWorkingCopy) { ((IProblemWorkingCopy) problem).setPreference(map); } @@ -197,7 +196,7 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec /** * Returns value of the preference for the key in the top level * preference map for the given problem - * + * * @param problem - problem for which to get the preference * @param key - preference key * @return value of the preference diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CheckerLaunchMode.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CheckerLaunchMode.java index 33d710be02e..4f1e7559954 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CheckerLaunchMode.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/CheckerLaunchMode.java @@ -11,10 +11,6 @@ package org.eclipse.cdt.codan.core.model; * @since 2.0 */ public enum CheckerLaunchMode { - /** - * use parent settings - */ - USE_PARENT, /** * checker run when full build is running */ diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/AbstractProblemPreference.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/AbstractProblemPreference.java index b45b68a2904..19c7c7a5212 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/AbstractProblemPreference.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/AbstractProblemPreference.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 Alena Laskavaia + * Copyright (c) 2009, 2010 Alena Laskavaia * 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 @@ -18,7 +18,7 @@ import java.io.StreamTokenizer; /** * Default implementation of problem preference. It keeps preference metadata * together with preference value. Some implementations may separate them. - * + * */ public abstract class AbstractProblemPreference implements IProblemPreference { /** @@ -49,7 +49,7 @@ public abstract class AbstractProblemPreference implements IProblemPreference { /** * Set preference key for itself - * + * * @param key */ public void setKey(String key) { @@ -77,7 +77,7 @@ public abstract class AbstractProblemPreference implements IProblemPreference { /** * Sets a label for UI control - * + * * @param label */ public void setLabel(String label) { @@ -88,7 +88,7 @@ public abstract class AbstractProblemPreference implements IProblemPreference { /** * Sets tooltip for ui control. Not supported now. - * + * * @param tooltip */ public void setToolTip(String tooltip) { @@ -97,7 +97,7 @@ public abstract class AbstractProblemPreference implements IProblemPreference { /** * Sets uiinfo for ui control. Not supported now. - * + * * @param uiinfo */ public void setUiInfo(String uiinfo) { @@ -196,4 +196,12 @@ public abstract class AbstractProblemPreference implements IProblemPreference { String sval = tokenizer.sval; return sval; } + + /** + * @return true when value if default (usually don't require storage in this case) + * @since 2.0 + */ + public boolean isDefault(){ + return false; + } } diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/FileScopeProblemPreference.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/FileScopeProblemPreference.java index 1f2206b3df6..58cf9008501 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/FileScopeProblemPreference.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/FileScopeProblemPreference.java @@ -28,7 +28,7 @@ import org.eclipse.core.runtime.Path; /** * Custom preference for resource scope - * + * * @noextend This class is not intended to be extended by clients. * @since 1.0 */ @@ -63,7 +63,7 @@ public class FileScopeProblemPreference extends AbstractProblemPreference { /** * Get attribute. Possible keys are EXCUSION and INCLUSION - * + * * @param key * @return class attribute for given key */ @@ -77,7 +77,7 @@ public class FileScopeProblemPreference extends AbstractProblemPreference { /** * Set attribute to a value. Possible keys are EXCUSION and INCLUSION - * + * * @param key * @param value */ @@ -124,6 +124,12 @@ public class FileScopeProblemPreference extends AbstractProblemPreference { return resource; } + @Override + public boolean isDefault(){ + if (inclusion.length==0 && exclusion.length==0) + return true; + return false; + } public String exportValue() { return exportPathList(INCLUSION, inclusion) + "," //$NON-NLS-1$ + exportPathList(EXCLUSION, exclusion); @@ -209,7 +215,7 @@ public class FileScopeProblemPreference extends AbstractProblemPreference { /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.codan.core.param.AbstractProblemPreference#clone() */ @Override @@ -224,7 +230,7 @@ public class FileScopeProblemPreference extends AbstractProblemPreference { * exclusion/inclusion settings of this class). In inclusion list is defined * check first if it belongs to it, returns false if not. * Then checks if it belongs to exclusion list and return false if it is. - * + * * @param path * - resource path * @return true is given path is in scope @@ -244,7 +250,7 @@ public class FileScopeProblemPreference extends AbstractProblemPreference { /** * Checks that given path matches on the paths provided as second argument - * + * * @param resourcePath - resource path * @param paths - array of path patterns, for pattern see * {@link CharOperation#pathMatch} diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/LaunchTypeProblemPreference.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/LaunchModeProblemPreference.java similarity index 54% rename from codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/LaunchTypeProblemPreference.java rename to codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/LaunchModeProblemPreference.java index 77ca9a38d7f..30e1483d673 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/LaunchTypeProblemPreference.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/LaunchModeProblemPreference.java @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.cdt.codan.core.param; +import java.io.IOException; +import java.io.StreamTokenizer; + import org.eclipse.cdt.codan.core.model.CheckerLaunchMode; /** @@ -17,7 +20,7 @@ import org.eclipse.cdt.codan.core.model.CheckerLaunchMode; * * @since 2.0 */ -public class LaunchTypeProblemPreference extends MapProblemPreference { +public class LaunchModeProblemPreference extends MapProblemPreference { /** * Propery key */ @@ -31,23 +34,34 @@ public class LaunchTypeProblemPreference extends MapProblemPreference { /** * constructor */ - public LaunchTypeProblemPreference() { - CheckerLaunchMode[] values = CheckerLaunchMode.values(); - for (int i = 0; i < values.length; i++) { - CheckerLaunchMode checkerLaunchMode = values[i]; - BasicProblemPreference desc = new BasicProblemPreference(checkerLaunchMode.name(), checkerLaunchMode.name(), - PreferenceType.TYPE_BOOLEAN); - IProblemPreference desc1 = addChildDescriptor(desc); - if (checkerLaunchMode == CheckerLaunchMode.USE_PARENT) - desc1.setValue(Boolean.TRUE); - } + public LaunchModeProblemPreference() { + } /** - * @return true if property is set to use parent mode + * @return true if values has not been set */ - public boolean isUsingParent() { - return isRunningInMode(CheckerLaunchMode.USE_PARENT); + @Override + public boolean isDefault(){ + CheckerLaunchMode[] values = CheckerLaunchMode.values(); + for (int i = 0; i < values.length; i++) { + CheckerLaunchMode checkerLaunchMode = values[i]; + if (getChildDescriptor(checkerLaunchMode.name())!=null) return false; + } + return true; + } + + /** + * @param checkerLaunchMode - launch mode + * @param value - value to set for the mode + * @return preference + */ + public IProblemPreference addLaunchMode(CheckerLaunchMode checkerLaunchMode, boolean value) { + BasicProblemPreference desc = new BasicProblemPreference(checkerLaunchMode.name(), checkerLaunchMode.name(), + PreferenceType.TYPE_BOOLEAN); + IProblemPreference desc1 = addChildDescriptor(desc); + desc1.setValue(value); + return desc1; } /** @@ -55,12 +69,15 @@ public class LaunchTypeProblemPreference extends MapProblemPreference { * @return true if this mode enabled for this preference */ public boolean isRunningInMode(CheckerLaunchMode mode) { + if (getChildDescriptor(mode.name())==null) { + if (mode == CheckerLaunchMode.RUN_ON_INC_BUILD) + return isRunningInMode(CheckerLaunchMode.RUN_ON_FULL_BUILD); + return true; // default is true + } Object value = getChildValue(mode.name()); if (value instanceof Boolean) { return (Boolean) value; } - if (mode == CheckerLaunchMode.USE_PARENT && value == null) - return true; return false; } @@ -69,7 +86,11 @@ public class LaunchTypeProblemPreference extends MapProblemPreference { * @param value */ public void setRunningMode(CheckerLaunchMode mode, boolean value) { - setChildValue(mode.name(), value); + if (getChildDescriptor(mode.name()) == null) { + addLaunchMode(mode, value); + } else { + setChildValue(mode.name(), value); + } } /** @@ -79,6 +100,7 @@ public class LaunchTypeProblemPreference extends MapProblemPreference { return isRunningInMode(CheckerLaunchMode.RUN_AS_YOU_TYPE) && isRunningInMode(CheckerLaunchMode.RUN_ON_DEMAND) && isRunningInMode(CheckerLaunchMode.RUN_ON_FULL_BUILD); } + /** * @return true if all modes are disabled */ @@ -86,4 +108,20 @@ public class LaunchTypeProblemPreference extends MapProblemPreference { return !isRunningInMode(CheckerLaunchMode.RUN_AS_YOU_TYPE) && !isRunningInMode(CheckerLaunchMode.RUN_ON_DEMAND) && !isRunningInMode(CheckerLaunchMode.RUN_ON_FULL_BUILD); } + + @Override + protected IProblemPreference importChildValue(String key, StreamTokenizer tokenizer) throws IOException { + IProblemPreference desc = getChildDescriptor(key); + if (desc==null) { + CheckerLaunchMode mode = CheckerLaunchMode.valueOf(key); + if (mode==null) + throw new IllegalArgumentException(key); + desc = addLaunchMode(mode, true); + } + if (desc != null && desc instanceof AbstractProblemPreference) { + ((AbstractProblemPreference) desc).importValue(tokenizer); + setChildValue(key, desc.getValue()); + } + return desc; + } } diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/MapProblemPreference.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/MapProblemPreference.java index 7a3e36ba245..4a8439e2e76 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/MapProblemPreference.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/MapProblemPreference.java @@ -27,7 +27,7 @@ import org.eclipse.cdt.codan.core.model.AbstractCheckerWithProblemPreferences; * "check setters". In this case you use this type. * {@link AbstractCheckerWithProblemPreferences} class has map as default top * level parameter preference. - * + * * @noextend This class is not intended to be extended by clients. */ public class MapProblemPreference extends AbstractProblemPreference implements IProblemPreferenceCompositeValue, @@ -58,7 +58,7 @@ public class MapProblemPreference extends AbstractProblemPreference implements I /** * Get parameter preference for element by key - * + * */ public IProblemPreference getChildDescriptor(String key) { return hash.get(key); @@ -68,7 +68,7 @@ public class MapProblemPreference extends AbstractProblemPreference implements I * Adds or replaces child descriptor and value for the element with the key * equals to desc.getKey(). The desc object would be put in the map, some of * its field may be modified. - * + * * @param desc */ public IProblemPreference addChildDescriptor(IProblemPreference desc) { @@ -130,6 +130,11 @@ public class MapProblemPreference extends AbstractProblemPreference implements I for (Iterator iterator = hash.keySet().iterator(); iterator.hasNext();) { String key = iterator.next(); IProblemPreference d = hash.get(key); + if (d instanceof AbstractProblemPreference) { + if (((AbstractProblemPreference) d).isDefault()) { + continue; + } + } buf.append(key + "=>" + d.exportValue()); //$NON-NLS-1$ if (iterator.hasNext()) buf.append(","); //$NON-NLS-1$ @@ -160,6 +165,8 @@ public class MapProblemPreference extends AbstractProblemPreference implements I } while (true) { token = tokenizer.nextToken(); + if (token == '}') + break; String key = tokenizer.sval; token = tokenizer.nextToken(); if (token != '=') @@ -167,15 +174,7 @@ public class MapProblemPreference extends AbstractProblemPreference implements I token = tokenizer.nextToken(); if (token != '>') throw new IllegalArgumentException(String.valueOf((char) token)); - IProblemPreference desc = getChildDescriptor(key); - if (desc == null && LaunchTypeProblemPreference.KEY.equals(key)) { - desc = new LaunchTypeProblemPreference(); - addChildDescriptor(desc); - } - if (desc != null && desc instanceof AbstractProblemPreference) { - ((AbstractProblemPreference) desc).importValue(tokenizer); - setChildValue(key, desc.getValue()); - } + importChildValue(key, tokenizer); token = tokenizer.nextToken(); if (token == '}') break; @@ -187,6 +186,22 @@ public class MapProblemPreference extends AbstractProblemPreference implements I } } + /** + * @param key + * @param tokenizer + * @return + * @throws IOException + * @since 2.0 + */ + protected IProblemPreference importChildValue(String key, StreamTokenizer tokenizer) throws IOException { + IProblemPreference desc = getChildDescriptor(key); + if (desc != null && desc instanceof AbstractProblemPreference) { + ((AbstractProblemPreference) desc).importValue(tokenizer); + setChildValue(key, desc.getValue()); + } + return desc; + } + /** * Removes child descriptor by its key */ @@ -233,7 +248,7 @@ public class MapProblemPreference extends AbstractProblemPreference implements I * this map would be removed. * Preference descriptors for the keys must be set before calling this * method, unless value if instanceof {@link IProblemPreference}. - * + * * @param value - must be Map */ @SuppressWarnings("unchecked") diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/RootProblemPreference.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/RootProblemPreference.java new file mode 100644 index 00000000000..fc92fcec846 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/param/RootProblemPreference.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * Copyright (c) 2009,2010 QNX Software Systems + * 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: + * QNX Software Systems (Alena Laskavaia) - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.core.param; + + +/** + * Common problem preference root for most of the codan problems + * + * @noextend This class is not intended to be extended by clients. + * @since 2.0 + */ +public class RootProblemPreference extends MapProblemPreference { + /** + * name of top level preference + */ + public static final String KEY = PARAM; + + /** + * Default constructor + */ + public RootProblemPreference() { + super(KEY, ""); //$NON-NLS-1$ + addChildDescriptor(new FileScopeProblemPreference()); + addChildDescriptor(new LaunchModeProblemPreference()); + } + + /** + * @return scope preference + */ + public FileScopeProblemPreference getScopePreference() { + return (FileScopeProblemPreference) getChildDescriptor( + FileScopeProblemPreference.KEY); + } + /** + * @return launch mode + */ + public LaunchModeProblemPreference getLaunchModePreference() { + return (LaunchModeProblemPreference) getChildDescriptor(LaunchModeProblemPreference.KEY); + + } +} 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 44874095ece..01069e43838 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 @@ -27,9 +27,8 @@ import org.eclipse.cdt.codan.core.model.IProblem; import org.eclipse.cdt.codan.core.model.IProblemCategory; import org.eclipse.cdt.codan.core.model.IProblemProfile; import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; -import org.eclipse.cdt.codan.core.param.IProblemPreference; -import org.eclipse.cdt.codan.core.param.LaunchTypeProblemPreference; -import org.eclipse.cdt.codan.core.param.MapProblemPreference; +import org.eclipse.cdt.codan.core.param.LaunchModeProblemPreference; +import org.eclipse.cdt.codan.core.param.RootProblemPreference; import org.eclipse.cdt.codan.internal.core.model.CodanProblem; import org.eclipse.cdt.codan.internal.core.model.CodanProblemCategory; import org.eclipse.cdt.codan.internal.core.model.ProblemProfile; @@ -443,13 +442,11 @@ public class CheckersRegistry implements Iterable, ICheckersRegistry { if (problem == null) throw new IllegalArgumentException("Id is not registered"); //$NON-NLS-1$ if (checker instanceof AbstractCheckerWithProblemPreferences) { - MapProblemPreference map = (MapProblemPreference) problem.getPreference(); - IProblemPreference pref1 = map.getChildDescriptor(LaunchTypeProblemPreference.KEY); - LaunchTypeProblemPreference pref = (LaunchTypeProblemPreference) pref1; - if (pref == null || pref.isRunningInMode(CheckerLaunchMode.USE_PARENT)) { - enabled = true; - break; - } + RootProblemPreference root = ((AbstractCheckerWithProblemPreferences)checker).getTopLevelPreference(problem); + + LaunchModeProblemPreference pref = root.getLaunchModePreference(); + // XXX: how to set defaults + if (pref.isRunningInMode(mode)) { enabled = true; break; diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanProblem.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanProblem.java index b2149d830ae..ab98e04f733 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanProblem.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/model/CodanProblem.java @@ -72,7 +72,7 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { /* * (non-Javadoc) - * + * * @see java.lang.Object#clone() */ @Override @@ -90,6 +90,8 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { } public void setPreference(IProblemPreference value) { + if (value==null) + throw new NullPointerException(); preference = value; } @@ -99,7 +101,7 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.codan.core.model.IProblem#getMessagePattern() */ public String getMessagePattern() { @@ -126,7 +128,7 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.codan.core.model.IProblem#getDescription() */ public String getDescription() { @@ -135,7 +137,7 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { /* * (non-Javadoc) - * + * * @see * org.eclipse.cdt.codan.core.model.IProblemWorkingCopy#setDescription(java * .lang.String) @@ -146,7 +148,7 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { /* * (non-Javadoc) - * + * * @see org.eclipse.cdt.codan.core.model.IProblem#getMarkerType() */ public String getMarkerType() { @@ -155,7 +157,7 @@ public class CodanProblem implements IProblemWorkingCopy, Cloneable { /** * Sets the marker id for the problem. - * + * * @param markerType */ public void setMarkerType(String markerType) { diff --git a/codan/org.eclipse.cdt.codan.ui/.settings/org.eclipse.jdt.core.prefs b/codan/org.eclipse.cdt.codan.ui/.settings/org.eclipse.jdt.core.prefs index da5d1448d05..408b1fe6f3c 100644 --- a/codan/org.eclipse.cdt.codan.ui/.settings/org.eclipse.jdt.core.prefs +++ b/codan/org.eclipse.cdt.codan.ui/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,12 @@ -#Wed Feb 23 19:44:07 EST 2011 +#Sun Feb 27 22:29:21 EST 2011 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.autoboxing=ignore diff --git a/codan/org.eclipse.cdt.codan.ui/.settings/org.eclipse.jdt.ui.prefs b/codan/org.eclipse.cdt.codan.ui/.settings/org.eclipse.jdt.ui.prefs index 023f9fc57f4..b75df6b1a88 100644 --- a/codan/org.eclipse.cdt.codan.ui/.settings/org.eclipse.jdt.ui.prefs +++ b/codan/org.eclipse.cdt.codan.ui/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,4 @@ -#Wed Feb 23 19:44:07 EST 2011 +#Sun Feb 27 22:29:21 EST 2011 eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_Eclipse [built-in] - Alena @@ -18,7 +18,7 @@ sp_cleanup.always_use_this_for_non_static_field_access=false sp_cleanup.always_use_this_for_non_static_method_access=false sp_cleanup.convert_to_enhanced_for_loop=false sp_cleanup.correct_indentation=false -sp_cleanup.format_source_code=false +sp_cleanup.format_source_code=true sp_cleanup.format_source_code_changes_only=false sp_cleanup.make_local_variable_final=false sp_cleanup.make_parameters_final=false 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 646698364cf..206b2c994d4 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,29 +11,15 @@ package org.eclipse.cdt.codan.internal.ui.preferences; import java.util.ArrayList; -import java.util.Iterator; import org.eclipse.cdt.codan.core.model.CheckerLaunchMode; -import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.FieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.jface.preference.PreferenceStore; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; public class LaunchModesPropertyPage extends FieldEditorPreferencePage { - private Button useParentSettingsButton; - private Button useLocalSettingsButton; - private Button configureButton; private ArrayList editors; - private Group useLocalGroup; /** * @param prefStore @@ -59,11 +45,10 @@ public class LaunchModesPropertyPage extends FieldEditorPreferencePage { */ @Override protected void createFieldEditors() { - createSelectionGroup(getFieldEditorParent()); - addField(new BooleanFieldEditor(CheckerLaunchMode.RUN_ON_FULL_BUILD.name(), "Run on full build", useLocalGroup)); - addField(new BooleanFieldEditor(CheckerLaunchMode.RUN_ON_DEMAND.name(), "Run on demand", useLocalGroup)); - addField(new BooleanFieldEditor(CheckerLaunchMode.RUN_AS_YOU_TYPE.name(), "Run as you type", useLocalGroup)); - updateFieldEditors(); + 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())); } /* @@ -79,56 +64,6 @@ public class LaunchModesPropertyPage extends FieldEditorPreferencePage { super.addField(editor); } - /** - * Creates and initializes a selection group with two choice buttons and one - * push button. - * - * @param parent - * - the parent composite - */ - private void createSelectionGroup(Composite parent) { - Composite comp = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - comp.setLayout(layout); - comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - Composite radioGroup = new Composite(comp, SWT.NONE); - radioGroup.setLayout(new GridLayout(2, false)); - radioGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - useParentSettingsButton = createRadioButton(radioGroup, CodanUIMessages.OverlayPage_Use_Project_Settings); - configureButton = new Button(radioGroup, SWT.PUSH); - configureButton.setText("Configure..."); - configureButton.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - configureProjectSettings(); - } - }); - useLocalSettingsButton = createRadioButton(radioGroup, "Use checker specific settings"); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); - gd.horizontalSpan = 2; - useLocalSettingsButton.setLayoutData(gd); - // Set workspace/project radio buttons - try { - Boolean useParent = getPreferenceStore().getBoolean(CheckerLaunchMode.USE_PARENT.name()); - if (useParent) { - useParentSettingsButton.setSelection(true); - } else { - useLocalSettingsButton.setSelection(true); - configureButton.setEnabled(false); - } - } catch (Exception e) { - useParentSettingsButton.setSelection(true); - } - useLocalGroup = new Group(radioGroup, SWT.NONE); - GridLayout layout2 = new GridLayout(2, false); - useLocalGroup.setLayout(layout2); - GridData gd2 = new GridData(GridData.FILL_BOTH); - gd2.horizontalSpan = 2; - useLocalGroup.setLayoutData(gd2); - } - /** * */ @@ -136,52 +71,6 @@ public class LaunchModesPropertyPage extends FieldEditorPreferencePage { // TODO Auto-generated method stub } - /** - * Convenience method creating a radio button - * - * @param parent - * - the parent composite - * @param label - * - the button label - * @return - the new button - */ - private Button createRadioButton(Composite parent, String label) { - final Button button = new Button(parent, SWT.RADIO); - button.setText(label); - button.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - boolean useParent = button == useParentSettingsButton; - configureButton.setEnabled(useParent); - getPreferenceStore().setValue(CheckerLaunchMode.USE_PARENT.name(), useParent); - updateFieldEditors(); - } - }); - return button; - } - - private void updateFieldEditors() { - // We iterate through all field editors - boolean enabled = useLocalSettingsButton.getSelection(); - updateFieldEditors(enabled); - } - - /** - * Enables or disables the field editors and buttons of this page Subclasses - * may override. - * - * @param enabled - * - true if enabled - */ - protected void updateFieldEditors(boolean enabled) { - Composite parent = useLocalGroup; - Iterator it = editors.iterator(); - while (it.hasNext()) { - FieldEditor editor = (FieldEditor) it.next(); - editor.setEnabled(enabled, parent); - } - } - @Override public boolean performOk() { boolean result = super.performOk(); diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java index 91323264784..b46b3bd2282 100644 --- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java +++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/preferences/ProblemsTreeEditor.java @@ -13,7 +13,6 @@ package org.eclipse.cdt.codan.internal.ui.preferences; import java.text.MessageFormat; import org.eclipse.cdt.codan.core.PreferenceConstants; -import org.eclipse.cdt.codan.core.model.CheckerLaunchMode; import org.eclipse.cdt.codan.core.model.CodanSeverity; import org.eclipse.cdt.codan.core.model.IProblem; import org.eclipse.cdt.codan.core.model.IProblemCategory; @@ -21,8 +20,8 @@ import org.eclipse.cdt.codan.core.model.IProblemElement; import org.eclipse.cdt.codan.core.model.IProblemProfile; import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; import org.eclipse.cdt.codan.core.param.IProblemPreference; -import org.eclipse.cdt.codan.core.param.LaunchTypeProblemPreference; -import org.eclipse.cdt.codan.core.param.MapProblemPreference; +import org.eclipse.cdt.codan.core.param.LaunchModeProblemPreference; +import org.eclipse.cdt.codan.core.param.RootProblemPreference; import org.eclipse.cdt.codan.internal.core.CodanPreferencesLoader; import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; import org.eclipse.core.resources.IMarker; @@ -91,16 +90,17 @@ public class ProblemsTreeEditor extends CheckedTreeEditor { if (element instanceof IProblem) { IProblem p = (IProblem) element; IProblemPreference preference = p.getPreference(); - if (preference instanceof MapProblemPreference) { - LaunchTypeProblemPreference pref = (LaunchTypeProblemPreference) ((MapProblemPreference) preference) - .getChildDescriptor(LaunchTypeProblemPreference.KEY); - if (pref == null || pref.isRunningInMode(CheckerLaunchMode.USE_PARENT)) { + if (preference instanceof RootProblemPreference) { + LaunchModeProblemPreference pref = ((RootProblemPreference) preference).getLaunchModePreference(); + if (pref == null) { return false; } boolean enabled = p.isEnabled(); boolean match = pref.isAllEnabled(); - if (enabled && match) return false; - if (!enabled && pref.isAllDisabled()) return false; + if (enabled && match) + return false; + if (!enabled && pref.isAllDisabled()) + return false; return true; } return false; 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 9c5fa7be311..96ed0e6d866 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 @@ -14,8 +14,9 @@ import org.eclipse.cdt.codan.core.model.CheckerLaunchMode; import org.eclipse.cdt.codan.core.model.IProblem; import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; import org.eclipse.cdt.codan.core.param.IProblemPreference; -import org.eclipse.cdt.codan.core.param.LaunchTypeProblemPreference; +import org.eclipse.cdt.codan.core.param.LaunchModeProblemPreference; import org.eclipse.cdt.codan.core.param.MapProblemPreference; +import org.eclipse.cdt.codan.core.param.RootProblemPreference; import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; import org.eclipse.cdt.codan.internal.ui.preferences.LaunchModesPropertyPage; import org.eclipse.core.resources.IResource; @@ -35,7 +36,7 @@ public class LaunchingTabComposite extends Composite { private LaunchModesPropertyPage page; private IProblem problem; private PreferenceStore prefStore; - private LaunchTypeProblemPreference launchPref; + private LaunchModeProblemPreference launchPref; /** * @param parent @@ -51,18 +52,13 @@ public class LaunchingTabComposite extends Composite { this.problem = problem; this.prefStore = new PreferenceStore(); IProblemPreference info = problem.getPreference(); - if (info == null || (!(info instanceof MapProblemPreference))) { + if (info == null || (!(info instanceof RootProblemPreference))) { Label label = new Label(this, 0); label.setText(CodanUIMessages.ParametersComposite_None); return; } - LaunchTypeProblemPreference launchModes = (LaunchTypeProblemPreference) ((MapProblemPreference) info) - .getChildDescriptor(LaunchTypeProblemPreference.KEY); - if (launchModes == null) { - launchPref = new LaunchTypeProblemPreference(); - } else { - launchPref = (LaunchTypeProblemPreference) launchModes.clone(); - } + LaunchModeProblemPreference launchModes = ((RootProblemPreference) info).getLaunchModePreference(); + launchPref = (LaunchModeProblemPreference) launchModes.clone(); initPrefStore(); page = new LaunchModesPropertyPage(prefStore); page.noDefaultAndApplyButton(); @@ -88,12 +84,14 @@ public class LaunchingTabComposite extends Composite { * @param launchPref2 * @param preferenceStore */ - private void saveToPref(LaunchTypeProblemPreference launchPref, IPreferenceStore preferenceStore) { + private void saveToPref(LaunchModeProblemPreference launchPref, IPreferenceStore preferenceStore) { CheckerLaunchMode[] values = CheckerLaunchMode.values(); for (int i = 0; i < values.length; i++) { CheckerLaunchMode checkerLaunchMode = values[i]; - if (!preferenceStore.isDefault(checkerLaunchMode.name())) { - launchPref.setRunningMode(checkerLaunchMode, preferenceStore.getBoolean(checkerLaunchMode.name())); + String name = checkerLaunchMode.name(); + if (!preferenceStore.isDefault(name)) { + boolean value = preferenceStore.getBoolean(name); + launchPref.setRunningMode(checkerLaunchMode, value); } } } @@ -101,10 +99,10 @@ public class LaunchingTabComposite extends Composite { private void initPrefStore() { if (launchPref == null) return; - prefStore.setDefault(CheckerLaunchMode.USE_PARENT.name(), true); CheckerLaunchMode[] values = CheckerLaunchMode.values(); for (int i = 0; i < values.length; i++) { CheckerLaunchMode checkerLaunchMode = values[i]; + prefStore.setDefault(checkerLaunchMode.name(), true); prefStore.setValue(checkerLaunchMode.name(), launchPref.isRunningInMode(checkerLaunchMode)); } } diff --git a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/ParametersComposite.java b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/ParametersComposite.java index e831813f6b8..fadadd8fa97 100644 --- a/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/ParametersComposite.java +++ b/codan/org.eclipse.cdt.codan.ui/src/org/eclipse/cdt/codan/internal/ui/widgets/ParametersComposite.java @@ -18,7 +18,7 @@ import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy; import org.eclipse.cdt.codan.core.param.FileScopeProblemPreference; import org.eclipse.cdt.codan.core.param.IProblemPreference; import org.eclipse.cdt.codan.core.param.IProblemPreferenceCompositeDescriptor; -import org.eclipse.cdt.codan.core.param.LaunchTypeProblemPreference; +import org.eclipse.cdt.codan.core.param.LaunchModeProblemPreference; import org.eclipse.cdt.codan.core.param.ListProblemPreference; import org.eclipse.cdt.codan.internal.ui.CodanUIMessages; import org.eclipse.jface.dialogs.InputDialog; @@ -90,7 +90,7 @@ public class ParametersComposite extends Composite { return; if (info.getKey() == FileScopeProblemPreference.KEY) return; // skip the scope - if (info.getKey() == LaunchTypeProblemPreference.KEY) + if (info.getKey() == LaunchModeProblemPreference.KEY) return; // skip the launch switch (info.getType()) { case TYPE_STRING: {