mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
- added abstract classes for parameter info
This commit is contained in:
parent
72ac8f6242
commit
92923566ce
5 changed files with 180 additions and 49 deletions
|
@ -11,8 +11,8 @@
|
||||||
package org.eclipse.cdt.codan.internal.checkers;
|
package org.eclipse.cdt.codan.internal.checkers;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.cxx.model.AbstractIndexAstChecker;
|
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.ICheckerWithParameters;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemParameterInfo;
|
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;
|
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
|
public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
||||||
implements ICheckerWithParameters {
|
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$
|
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$
|
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();
|
.getDeclarator().getName();
|
||||||
String name = astName.toString();
|
String name = astName.toString();
|
||||||
if (!pattern.matcher(name).find()) {
|
if (!pattern.matcher(name).find()) {
|
||||||
reportProblem(ER_ID, astName,
|
reportProblem(ER_ID, astName, name, parameter);
|
||||||
name, parameter);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return PROCESS_SKIP;
|
return PROCESS_SKIP;
|
||||||
|
@ -69,15 +69,7 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
||||||
* (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy)
|
* (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy)
|
||||||
*/
|
*/
|
||||||
public void initParameters(IProblemWorkingCopy problem) {
|
public void initParameters(IProblemWorkingCopy problem) {
|
||||||
IProblemParameterInfo info = new IProblemParameterInfo() {
|
IProblemParameterInfo info = new AbstractProblemParameterInfo() {
|
||||||
public String getUiInfo() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return IProblemParameterInfo.TYPE_STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return "Name Pattern";
|
return "Name Pattern";
|
||||||
}
|
}
|
||||||
|
@ -85,10 +77,6 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return PARAM_KEY;
|
return PARAM_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IProblemParameterInfo getElement(String key) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
problem.setParameterInfo(info);
|
problem.setParameterInfo(info);
|
||||||
problem.setParameter(PARAM_KEY, DEFAULT_PATTERN);
|
problem.setParameter(PARAM_KEY, DEFAULT_PATTERN);
|
||||||
|
@ -98,5 +86,4 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
||||||
public boolean runInEditor() {
|
public boolean runInEditor() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,9 +14,10 @@ package org.eclipse.cdt.codan.core.model;
|
||||||
* Problem parameter usually key=value settings that allows to alter checker
|
* Problem parameter usually key=value settings that allows to alter checker
|
||||||
* behaviour for given problem. For example if checker finds violation of naming
|
* behaviour for given problem. For example if checker finds violation of naming
|
||||||
* conventions for function, parameter would be the pattern of allowed names.
|
* conventions for function, parameter would be the pattern of allowed names.
|
||||||
* ProblemParameterInfo represent parameter meta-info for the ui.
|
* ProblemParameterInfo represent parameter meta-info for the ui. If more that
|
||||||
* If more that one parameter required ParameterInfo should describe hash or array of parameters.
|
* one parameter required ParameterInfo should describe hash or array of
|
||||||
* This is only needed for auto-generated ui for parameter editing. For complex case custom ui control should be used
|
* 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.
|
* @noextend This interface is not intended to be extended by clients.
|
||||||
* @noimplement This interface is not intended to be implemented by clients.
|
* @noimplement This interface is not intended to be implemented by clients.
|
||||||
|
@ -32,9 +33,10 @@ public interface IProblemParameterInfo {
|
||||||
String getKey();
|
String getKey();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* type of the parameter, supports boolean, integer, string, file, list and hash.
|
* type of the parameter, supports boolean, integer, string, file, list and
|
||||||
* If list is the value - it is an array - subparameter can be accessed by number, if
|
* hash. If list is the value - it is an array - subparameter can be
|
||||||
* hash is the value - it is a hash - subparameter can be accesses by name
|
* accessed by number, if hash is the value - it is a hash - subparameter
|
||||||
|
* can be accesses by name
|
||||||
*
|
*
|
||||||
* @return string value of the type
|
* @return string value of the type
|
||||||
*/
|
*/
|
||||||
|
@ -50,10 +52,18 @@ public interface IProblemParameterInfo {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User visible label for the parameter control in UI
|
* User visible label for the parameter control in UI
|
||||||
|
*
|
||||||
* @return the label
|
* @return the label
|
||||||
*/
|
*/
|
||||||
String getLabel();
|
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
|
* 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).
|
* name of key. For the "list" type key is the number (index).
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
package org.eclipse.cdt.codan.examples.checkers;
|
package org.eclipse.cdt.codan.examples.checkers;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.cxx.model.AbstractCIndexChecker;
|
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.ICheckerWithParameters;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblem;
|
import org.eclipse.cdt.codan.core.model.IProblem;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemParameterInfo;
|
import org.eclipse.cdt.codan.core.model.IProblemParameterInfo;
|
||||||
|
@ -26,9 +26,9 @@ import org.eclipse.core.runtime.CoreException;
|
||||||
* @author Alena
|
* @author Alena
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class NamingConventionFunctionIIndexChecker extends AbstractCIndexChecker
|
public class NamingConventionFunctionIIndexChecker extends
|
||||||
implements ICheckerWithParameters {
|
AbstractCIndexChecker 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]"; // name starts with english lowercase letter //$NON-NLS-1$
|
||||||
public static final String PARAM_KEY = "pattern"; //$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$
|
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);
|
Pattern pattern = Pattern.compile(parameter);
|
||||||
String name = element.getElementName();
|
String name = element.getElementName();
|
||||||
if (!pattern.matcher(name).find()) {
|
if (!pattern.matcher(name).find()) {
|
||||||
|
reportProblem(ER_ID, getFile(), 1, // TODO: line
|
||||||
reportProblem(ER_ID, getFile(), 1, // TODO: line number
|
// number
|
||||||
name, parameter);
|
name, parameter);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -71,15 +71,7 @@ public class NamingConventionFunctionIIndexChecker extends AbstractCIndexChecker
|
||||||
* (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy)
|
* (org.eclipse.cdt.codan.core.model.IProblemWorkingCopy)
|
||||||
*/
|
*/
|
||||||
public void initParameters(IProblemWorkingCopy problem) {
|
public void initParameters(IProblemWorkingCopy problem) {
|
||||||
IProblemParameterInfo info = new IProblemParameterInfo() {
|
IProblemParameterInfo info = new AbstractProblemParameterInfo() {
|
||||||
public String getUiInfo() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getType() {
|
|
||||||
return IProblemParameterInfo.TYPE_STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
public String getLabel() {
|
||||||
return "Name Pattern";
|
return "Name Pattern";
|
||||||
}
|
}
|
||||||
|
@ -87,19 +79,11 @@ public class NamingConventionFunctionIIndexChecker extends AbstractCIndexChecker
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return PARAM_KEY;
|
return PARAM_KEY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IProblemParameterInfo getElement(String key) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
problem.setParameterInfo(info);
|
problem.setParameterInfo(info);
|
||||||
|
problem.setParameter(PARAM_KEY, DEFAULT_PATTERN);
|
||||||
problem.setParameter(PARAM_KEY, DEFAULT_PATTERN);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean runInEditor() {
|
public boolean runInEditor() {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue