1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 09:16:02 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2011-04-10 01:20:27 +00:00
parent cf018dec6c
commit 0a5580f3d3

View file

@ -1,12 +1,12 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2009,2010 Alena Laskavaia * Copyright (c) 2009, 2010 Alena Laskavaia
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Alena Laskavaia - initial API and implementation * Alena Laskavaia - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.codan.core.model; package org.eclipse.cdt.codan.core.model;
@ -25,12 +25,13 @@ import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
/** /**
* AbstarctChecker that has extra methods to simplify adding problem * AbstractChecker that has extra methods to simplify adding problem
* preferences. * preferences.
* Checker can produce several problems, but preferences are per problem. * Checker can produce several problems, but preferences are per problem.
* Sharing preferences between problems is not supported now. * Sharing preferences between problems is not supported now.
*/ */
public abstract class AbstractCheckerWithProblemPreferences extends AbstractChecker implements ICheckerWithPreferences { public abstract class AbstractCheckerWithProblemPreferences extends AbstractChecker
implements ICheckerWithPreferences {
/** /**
* Checker that actually has parameter must override this * Checker that actually has parameter must override this
*/ */
@ -41,13 +42,12 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec
/** /**
* Scope preference - special preference that all file checkers should have, * Scope preference - special preference that all file checkers should have,
* it allows user to include/exclude files for this specific problem. * it allows user to include/exclude files for this specific problem.
* *
* @param problem - problem for which scope preference is need * @param problem - problem for which scope preference is need
* @return scope problem preference, null if not defined * @return scope problem preference, null if not defined
*/ */
public FileScopeProblemPreference getScopePreference(IProblem problem) { public FileScopeProblemPreference getScopePreference(IProblem problem) {
FileScopeProblemPreference scope = getTopLevelPreference(problem).getScopePreference(); return getTopLevelPreference(problem).getScopePreference();
return scope;
} }
/** /**
@ -56,8 +56,7 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec
* @since 2.0 * @since 2.0
*/ */
public LaunchModeProblemPreference getLaunchModePreference(IProblem problem) { public LaunchModeProblemPreference getLaunchModePreference(IProblem problem) {
LaunchModeProblemPreference launchModes = getTopLevelPreference(problem).getLaunchModePreference(); return getTopLevelPreference(problem).getLaunchModePreference();
return launchModes;
} }
/** /**
@ -66,7 +65,7 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec
* be done within processResource method not in enabledInContext. * be done within processResource method not in enabledInContext.
* This test uses user "scope" preference for the all problems that this * This test uses user "scope" preference for the all problems that this
* checker can produce. * checker can produce.
* *
* @param res - resource to test on * @param res - resource to test on
* @return true if checker should report problems, fails otherwise. * @return true if checker should report problems, fails otherwise.
*/ */
@ -82,16 +81,16 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec
/** /**
* User can scope out some resources for this checker. Checker can use this * User can scope out some resources for this checker. Checker can use this
* call to test if it should run on this resource at all or produce a * call to test if it should run on this resource at all or produce
* specific problem on this resource. Test should * a specific problem on this resource. Test should
* be done within processResource method not in enabledInContext, or just * be done within processResource method not in enabledInContext, or just
* before printing of a problem. * before printing of a problem.
* This test uses user "scope" preference for the given problem. If scope is * This test uses user "scope" preference for the given problem. If scope is
* not defined preference it returns true. * not defined preference it returns true.
* *
* @param problem - problem to test for * @param problem - problem to test for
* @param resource - resource to test on * @param resource - resource to test on
* *
* @return true if problem should be report for given resource, fails * @return true if problem should be report for given resource, fails
* otherwise. * otherwise.
*/ */
@ -104,17 +103,19 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec
@Override @Override
public void reportProblem(String problemId, IProblemLocation loc, Object... args) { public void reportProblem(String problemId, IProblemLocation loc, Object... args) {
if (shouldProduceProblem(getProblemById(problemId, loc.getFile()), loc.getFile().getLocation())) if (shouldProduceProblem(getProblemById(problemId, loc.getFile()),
loc.getFile().getLocation())) {
super.reportProblem(problemId, loc, args); super.reportProblem(problemId, loc, args);
}
} }
/** /**
* report a problem * Reports a problem
* *
* @param pr - problem (kind) instance * @param pr - problem (kind) instance
* @param loc - problem location * @param loc - problem location
* @param args - extra problem arguments * @param args - extra problem arguments
* *
* @since 2.0 * @since 2.0
*/ */
public void reportProblem(IProblem pr, IProblemLocation loc, Object... args) { public void reportProblem(IProblem pr, IProblemLocation loc, Object... args) {
@ -123,8 +124,8 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec
} }
/** /**
* Add a parameter * Adds a parameter
* *
* @param problem * @param problem
* - problem that has parameter * - problem that has parameter
* @param key * @param key
@ -135,9 +136,11 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec
* - parameter default value * - parameter default value
* @return - parameter info object * @return - parameter info object
*/ */
public IProblemPreference addPreference(IProblemWorkingCopy problem, String key, String label, Object defaultValue) { public IProblemPreference addPreference(IProblemWorkingCopy problem, String key, String label,
Object defaultValue) {
MapProblemPreference map = getTopLevelPreference(problem); MapProblemPreference map = getTopLevelPreference(problem);
BasicProblemPreference info = new BasicProblemPreference(key, label, PreferenceType.typeOf(defaultValue)); BasicProblemPreference info = new BasicProblemPreference(key, label,
PreferenceType.typeOf(defaultValue));
map.addChildDescriptor(info); map.addChildDescriptor(info);
setDefaultPreferenceValue(problem, key, defaultValue); setDefaultPreferenceValue(problem, key, defaultValue);
return info; return info;
@ -146,7 +149,7 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec
/** /**
* Add preference of type list of strings, list is empty by * Add preference of type list of strings, list is empty by
* default * default
* *
* @param problem * @param problem
* - problem * - problem
* @param key * @param key
@ -156,25 +159,27 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec
* @param itemLabel * @param itemLabel
* @return preference instance of of the list, can be used to add default * @return preference instance of of the list, can be used to add default
* values or set different element type * values or set different element type
* *
*/ */
public ListProblemPreference addListPreference(IProblemWorkingCopy problem, String key, String label, String itemLabel) { public ListProblemPreference addListPreference(IProblemWorkingCopy problem, String key,
String label, String itemLabel) {
MapProblemPreference map = getTopLevelPreference(problem); MapProblemPreference map = getTopLevelPreference(problem);
ListProblemPreference list = new ListProblemPreference(key, label); ListProblemPreference list = new ListProblemPreference(key, label);
list.setChildDescriptor(new BasicProblemPreference(ListProblemPreference.COMMON_DESCRIPTOR_KEY, itemLabel, list.setChildDescriptor(new BasicProblemPreference(ListProblemPreference.COMMON_DESCRIPTOR_KEY,
PreferenceType.TYPE_STRING)); itemLabel, PreferenceType.TYPE_STRING));
return (ListProblemPreference) map.addChildDescriptor(list); return (ListProblemPreference) map.addChildDescriptor(list);
} }
/** /**
* Add preference for the given problem with default value * Adds preference for the given problem with default value
* *
* @param problem * @param problem
* @param pref - preference * @param pref - preference
* @param defaultValue - default value of the preference * @param defaultValue - default value of the preference
* @return added preference * @return added preference
*/ */
public IProblemPreference addPreference(IProblemWorkingCopy problem, IProblemPreference pref, Object defaultValue) { public IProblemPreference addPreference(IProblemWorkingCopy problem, IProblemPreference pref,
Object defaultValue) {
MapProblemPreference map = getTopLevelPreference(problem); MapProblemPreference map = getTopLevelPreference(problem);
String key = pref.getKey(); String key = pref.getKey();
pref = map.addChildDescriptor(pref); pref = map.addChildDescriptor(pref);
@ -185,24 +190,25 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec
/** /**
* Convenience method for setting default preference value for checker that * Convenience method for setting default preference value for checker that
* uses "map" as top level problem preference. * uses "map" as top level problem preference.
* *
* @param problem - problem for which to set default value for a prefence * @param problem - problem for which to set default value for a preference
* @param key - preference key * @param key - preference key
* @param defaultValue - value of preference to be set * @param defaultValue - value of preference to be set
*/ */
protected void setDefaultPreferenceValue(IProblemWorkingCopy problem, String key, Object defaultValue) { protected void setDefaultPreferenceValue(IProblemWorkingCopy problem, String key,
Object defaultValue) {
MapProblemPreference map = getTopLevelPreference(problem); MapProblemPreference map = getTopLevelPreference(problem);
if (map.getChildValue(key) == null) if (map.getChildValue(key) == null)
map.setChildValue(key, defaultValue); map.setChildValue(key, defaultValue);
} }
/** /**
* Return "map" problem preference for a give problem, if problem * Returns "map" problem preference for a give problem, if problem
* has preference different than a map, it will throw ClassCastException. * has preference different than a map, it will throw ClassCastException.
* If top level preference does not exist create a map preference with name * If top level preference does not exist create a map preference with name
* "params" * "params"
* and return it. * and return it.
* *
* @param problem * @param problem
* @return top level preference if it is a map * @return top level preference if it is a map
* @since 2.0 * @since 2.0
@ -221,7 +227,7 @@ public abstract class AbstractCheckerWithProblemPreferences extends AbstractChec
/** /**
* Returns value of the preference for the key in the top level * Returns value of the preference for the key in the top level
* preference map for the given problem * preference map for the given problem
* *
* @param problem - problem for which to get the preference * @param problem - problem for which to get the preference
* @param key - preference key * @param key - preference key
* @return value of the preference * @return value of the preference