diff options
author | Alena Laskavaia | 2010-03-22 02:14:41 +0000 |
---|---|---|
committer | Alena Laskavaia | 2010-03-22 02:14:41 +0000 |
commit | 92923566ce752894fc6ce7abd238dd85071e8d66 (patch) | |
tree | cd971e2f59d544b633a6fcfa394d995a9852d8c1 /codan | |
parent | 72ac8f6242061cc05ef21636d86716db4d9c9943 (diff) | |
download | org.eclipse.cdt-92923566ce752894fc6ce7abd238dd85071e8d66.tar.gz org.eclipse.cdt-92923566ce752894fc6ce7abd238dd85071e8d66.tar.xz org.eclipse.cdt-92923566ce752894fc6ce7abd238dd85071e8d66.zip |
- added abstract classes for parameter info
Diffstat (limited to 'codan')
5 files changed, 180 insertions, 49 deletions
diff --git a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NamingConventionFunctionChecker.java b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NamingConventionFunctionChecker.java index 51cfde8f810..eca4d28e0b0 100644 --- a/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NamingConventionFunctionChecker.java +++ b/codan/org.eclipse.cdt.codan.checkers/src/org/eclipse/cdt/codan/internal/checkers/NamingConventionFunctionChecker.java @@ -11,8 +11,8 @@ package org.eclipse.cdt.codan.internal.checkers; import java.util.regex.Pattern; - import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker; +import org.eclipse.cdt.codan.core.model.AbstractProblemParameterInfo; import org.eclipse.cdt.codan.core.model.ICheckerWithParameters; import org.eclipse.cdt.codan.core.model.IProblem; import org.eclipse.cdt.codan.core.model.IProblemParameterInfo; @@ -24,12 +24,13 @@ import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; /** - * @author Alena + * This is style checker for function name code style. Pattern parameter is + * regular expression defining the style. * */ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker implements ICheckerWithParameters { - private static final String DEFAULT_PATTERN = "^[a-z]"; // name starts with english lowercase letter //$NON-NLS-1$ + private static final String DEFAULT_PATTERN = "^[a-z]"; // default pattern name starts with english lowercase letter //$NON-NLS-1$ public static final String PARAM_KEY = "pattern"; //$NON-NLS-1$ private static final String ER_ID = "org.eclipse.cdt.codan.internal.checkers.NamingConventionFunctionChecker"; //$NON-NLS-1$ @@ -49,8 +50,7 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker .getDeclarator().getName(); String name = astName.toString(); if (!pattern.matcher(name).find()) { - reportProblem(ER_ID, astName, - name, parameter); + reportProblem(ER_ID, astName, name, parameter); } } return PROCESS_SKIP; @@ -69,15 +69,7 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker * (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy) */ public void initParameters(IProblemWorkingCopy problem) { - IProblemParameterInfo info = new IProblemParameterInfo() { - public String getUiInfo() { - return null; - } - - public String getType() { - return IProblemParameterInfo.TYPE_STRING; - } - + IProblemParameterInfo info = new AbstractProblemParameterInfo() { public String getLabel() { return "Name Pattern"; } @@ -85,10 +77,6 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker public String getKey() { return PARAM_KEY; } - - public IProblemParameterInfo getElement(String key) { - return null; - } }; problem.setParameterInfo(info); problem.setParameter(PARAM_KEY, DEFAULT_PATTERN); @@ -98,5 +86,4 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker public boolean runInEditor() { return true; } - } diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractListParameterInfo.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractListParameterInfo.java new file mode 100644 index 00000000000..a558268c8aa --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractListParameterInfo.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2009 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.core.model; + +import java.util.ArrayList; + +/** + * @author Alena + * + */ +public class AbstractListParameterInfo extends AbstractProblemParameterInfo { + protected ArrayList<IProblemParameterInfo> list = new ArrayList<IProblemParameterInfo>( + 1); + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.AbstractProblemParameterInfo#getType() + */ + @Override + public String getType() { + return TYPE_LIST; + } + + /** + * Get parameter into for element equal to key's int value, + * + * @throws NumberFormatException + * if key is not number + * @throws ArrayIndexOutOfBoundsException + * is index is out of bound + */ + @Override + public IProblemParameterInfo getElement(String key) + throws NumberFormatException, ArrayIndexOutOfBoundsException { + if (key == null) { + // special case if all element are the same return first, if key is + // null + return list.get(0); + } + Integer iv = Integer.valueOf(key); + if (iv.intValue() >= list.size() && list.size() == 1) { + // special case if all element are the same return first + return list.get(0); + } + return list.get(iv.intValue()); + } + + /** + * Set i'th element of parameter info, if all are the same i is 0 + * + * @param i + * @param info + */ + protected void setElement(int i, IProblemParameterInfo info) { + while (i >= list.size()) { + list.add(null); + } + list.set(i, info); + } + + protected IProblemParameterInfo getElement(int i) { + return list.get(i); + } +} diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractProblemParameterInfo.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractProblemParameterInfo.java new file mode 100644 index 00000000000..18954539e84 --- /dev/null +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/AbstractProblemParameterInfo.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2009 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alena Laskavaia - initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.codan.core.model; + +/** + * Default implementation for single parameter checker of type string. + * + */ +public abstract class AbstractProblemParameterInfo implements + IProblemParameterInfo { + public static final String PARAM = "param"; //$NON-NLS-1$ + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getKey() + */ + public String getKey() { + return PARAM; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getType() + */ + public String getType() { + return TYPE_STRING; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getUiInfo() + */ + public String getUiInfo() { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getLabel() + */ + public String getLabel() { + return getKey(); + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getElement(java + * .lang.String) + */ + public IProblemParameterInfo getElement(String key) { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.codan.core.model.IProblemParameterInfo#getToolTip() + */ + public String getToolTip() { + return null; + } +} diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemParameterInfo.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemParameterInfo.java index 2f7f95126ae..2c918f605f3 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemParameterInfo.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/core/model/IProblemParameterInfo.java @@ -14,9 +14,10 @@ package org.eclipse.cdt.codan.core.model; * Problem parameter usually key=value settings that allows to alter checker * behaviour for given problem. For example if checker finds violation of naming * conventions for function, parameter would be the pattern of allowed names. - * ProblemParameterInfo represent parameter meta-info for the ui. - * If more that one parameter required ParameterInfo should describe hash or array of parameters. - * This is only needed for auto-generated ui for parameter editing. For complex case custom ui control should be used + * ProblemParameterInfo represent parameter meta-info for the ui. If more that + * one parameter required ParameterInfo should describe hash or array of + * parameters. This is only needed for auto-generated ui for parameter editing. + * For complex case custom ui control should be used * * @noextend This interface is not intended to be extended by clients. * @noimplement This interface is not intended to be implemented by clients. @@ -32,9 +33,10 @@ public interface IProblemParameterInfo { String getKey(); /** - * type of the parameter, supports boolean, integer, string, file, list and hash. - * If list is the value - it is an array - subparameter can be accessed by number, if - * hash is the value - it is a hash - subparameter can be accesses by name + * type of the parameter, supports boolean, integer, string, file, list and + * hash. If list is the value - it is an array - subparameter can be + * accessed by number, if hash is the value - it is a hash - subparameter + * can be accesses by name * * @return string value of the type */ @@ -50,11 +52,19 @@ public interface IProblemParameterInfo { /** * User visible label for the parameter control in UI + * * @return the label */ String getLabel(); /** + * Detailed explanation of parameter + * + * @return the tooltip text + */ + String getToolTip(); + + /** * Available if type is list or hash. Returns value of subparamer with the * name of key. For the "list" type key is the number (index). * diff --git a/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/NamingConventionFunctionIIndexChecker.java b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/NamingConventionFunctionIIndexChecker.java index 93f93a0715a..d23a587914a 100644 --- a/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/NamingConventionFunctionIIndexChecker.java +++ b/codan/org.eclipse.cdt.codan.examples/src/org/eclipse/cdt/codan/examples/checkers/NamingConventionFunctionIIndexChecker.java @@ -11,8 +11,8 @@ package org.eclipse.cdt.codan.examples.checkers; import java.util.regex.Pattern; - import org.eclipse.cdt.codan.core.cxx.model.AbstractCIndexChecker; +import org.eclipse.cdt.codan.core.model.AbstractProblemParameterInfo; import org.eclipse.cdt.codan.core.model.ICheckerWithParameters; import org.eclipse.cdt.codan.core.model.IProblem; import org.eclipse.cdt.codan.core.model.IProblemParameterInfo; @@ -26,9 +26,9 @@ import org.eclipse.core.runtime.CoreException; * @author Alena * */ -public class NamingConventionFunctionIIndexChecker extends AbstractCIndexChecker - implements ICheckerWithParameters { - private static final String DEFAULT_PATTERN = "^[a-z]"; // name starts with english lowercase letter //$NON-NLS-1$ +public class NamingConventionFunctionIIndexChecker extends + AbstractCIndexChecker implements ICheckerWithParameters { + private static final String DEFAULT_PATTERN = "^[a-z]"; // name starts with english lowercase letter //$NON-NLS-1$ public static final String PARAM_KEY = "pattern"; //$NON-NLS-1$ private static final String ER_ID = "org.eclipse.cdt.codan.examples.checkers.NamingConventionFunctionProblem"; //$NON-NLS-1$ @@ -49,8 +49,8 @@ public class NamingConventionFunctionIIndexChecker extends AbstractCIndexChecker Pattern pattern = Pattern.compile(parameter); String name = element.getElementName(); if (!pattern.matcher(name).find()) { - - reportProblem(ER_ID, getFile(), 1, // TODO: line number + reportProblem(ER_ID, getFile(), 1, // TODO: line + // number name, parameter); } return false; @@ -71,15 +71,7 @@ public class NamingConventionFunctionIIndexChecker extends AbstractCIndexChecker * (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy) */ public void initParameters(IProblemWorkingCopy problem) { - IProblemParameterInfo info = new IProblemParameterInfo() { - public String getUiInfo() { - return null; - } - - public String getType() { - return IProblemParameterInfo.TYPE_STRING; - } - + IProblemParameterInfo info = new AbstractProblemParameterInfo() { public String getLabel() { return "Name Pattern"; } @@ -87,19 +79,11 @@ public class NamingConventionFunctionIIndexChecker extends AbstractCIndexChecker public String getKey() { return PARAM_KEY; } - - public IProblemParameterInfo getElement(String key) { - return null; - } }; problem.setParameterInfo(info); - - problem.setParameter(PARAM_KEY, DEFAULT_PATTERN); - + problem.setParameter(PARAM_KEY, DEFAULT_PATTERN); } - - @Override public boolean runInEditor() { return false; |