mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
- fixed problem locations
This commit is contained in:
parent
768092e26c
commit
30dffe83b5
5 changed files with 76 additions and 29 deletions
|
@ -20,6 +20,7 @@ import org.eclipse.cdt.codan.core.model.IProblemWorkingCopy;
|
|||
import org.eclipse.cdt.core.dom.ast.ASTVisitor;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
|
||||
/**
|
||||
|
@ -44,11 +45,11 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
|||
if (element instanceof IASTFunctionDefinition) {
|
||||
String parameter = (String) pt.getParameter(PARAM_KEY);
|
||||
Pattern pattern = Pattern.compile(parameter);
|
||||
String name = ((IASTFunctionDefinition) element)
|
||||
.getDeclarator().getName().toString();
|
||||
IASTName astName = ((IASTFunctionDefinition) element)
|
||||
.getDeclarator().getName();
|
||||
String name = astName.toString();
|
||||
if (!pattern.matcher(name).find()) {
|
||||
reportProblem(ER_ID, getFile(), 1, // TODO: line
|
||||
// number
|
||||
reportProblem(ER_ID, astName,
|
||||
name, parameter);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements
|
|||
return true;
|
||||
}
|
||||
|
||||
public void reportProblem(String id, IASTNode astNode, String message) {
|
||||
public void reportProblem(String id, IASTNode astNode, Object... args) {
|
||||
IASTFileLocation astLocation = astNode.getFileLocation();
|
||||
IPath location = new Path(astLocation.getFileName());
|
||||
IFile astFile = ResourcesPlugin.getWorkspace().getRoot()
|
||||
|
@ -89,19 +89,20 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements
|
|||
astFile = file;
|
||||
}
|
||||
IProblemLocation loc;
|
||||
if (astLocation.getStartingLineNumber() == astLocation
|
||||
int line = astLocation.getStartingLineNumber();
|
||||
if (line == astLocation
|
||||
.getEndingLineNumber())
|
||||
loc = getRuntime().getProblemLocationFactory()
|
||||
.createProblemLocation(
|
||||
astFile,
|
||||
astLocation.getNodeOffset(),
|
||||
astLocation.getNodeOffset()
|
||||
+ astLocation.getNodeLength());
|
||||
+ astLocation.getNodeLength(), line);
|
||||
else
|
||||
loc = getRuntime().getProblemLocationFactory()
|
||||
.createProblemLocation(astFile,
|
||||
astLocation.getStartingLineNumber());
|
||||
getProblemReporter().reportProblem(id, loc, message);
|
||||
line);
|
||||
getProblemReporter().reportProblem(id, loc, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,28 +17,52 @@ import org.eclipse.core.resources.IFile;
|
|||
*
|
||||
* Clients may implement and extend this interface.
|
||||
* <p>
|
||||
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
|
||||
* part of a work in progress. There is no guarantee that this API will
|
||||
* work or that it will remain the same.
|
||||
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as part
|
||||
* of a work in progress. There is no guarantee that this API will work or that
|
||||
* it will remain the same.
|
||||
* </p>
|
||||
*/
|
||||
public interface IProblemLocationFactory {
|
||||
|
||||
/**
|
||||
* Create and return instance of IProblemLocation
|
||||
* @param file - file where problem is found
|
||||
* @param line - line number where problem is found, starts with 1
|
||||
*
|
||||
* @param file
|
||||
* - file where problem is found
|
||||
* @param line
|
||||
* - line number where problem is found, starts with 1
|
||||
* @return instance of IProblemLocation
|
||||
*/
|
||||
public IProblemLocation createProblemLocation(IFile file, int line);
|
||||
|
||||
/**
|
||||
* Create and return instance of IProblemLocation
|
||||
* @param file - file where problem is found
|
||||
* @param startChar - start char of the problem in the file, is zero-relative
|
||||
* @param endChar - end char of the problem in the file, is zero-relative and exclusive.
|
||||
*
|
||||
* @param file
|
||||
* - file where problem is found
|
||||
* @param startChar
|
||||
* - start char of the problem in the file, is zero-relative
|
||||
* @param endChar
|
||||
* - end char of the problem in the file, is zero-relative and
|
||||
* exclusive.
|
||||
* @return instance of IProblemLocation
|
||||
*/
|
||||
public IProblemLocation createProblemLocation(IFile file, int startChar, int endChar);
|
||||
public IProblemLocation createProblemLocation(IFile file, int startChar,
|
||||
int endChar);
|
||||
|
||||
/**
|
||||
* Create and return instance of IProblemLocation
|
||||
*
|
||||
* @param file
|
||||
* - file where problem is found
|
||||
* @param startChar
|
||||
* - start char of the problem in the file, is zero-relative
|
||||
* @param endChar
|
||||
* - end char of the problem in the file, is zero-relative and
|
||||
* exclusive.
|
||||
* @param line
|
||||
* - start line number (for visualisation purposes)
|
||||
* @return instance of IProblemLocation
|
||||
*/
|
||||
public IProblemLocation createProblemLocation(IFile astFile,
|
||||
int nodeOffset, int i, int line);
|
||||
}
|
|
@ -18,13 +18,16 @@ import org.eclipse.core.resources.IFile;
|
|||
*
|
||||
*/
|
||||
public class CodanProblemLocation extends AbstractProblemLocation {
|
||||
|
||||
public CodanProblemLocation(IFile file, int startChar, int endChar) {
|
||||
super(file, startChar, endChar);
|
||||
}
|
||||
|
||||
public CodanProblemLocation(IFile file, int startChar, int endChar, int line) {
|
||||
super(file, startChar, endChar);
|
||||
this.line = line;
|
||||
}
|
||||
|
||||
protected CodanProblemLocation(IFile file, int line) {
|
||||
super(file, line);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,17 +19,35 @@ import org.eclipse.core.resources.IFile;
|
|||
*
|
||||
*/
|
||||
public class ProblemLocationFactory implements IProblemLocationFactory {
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.core.model.IProblemLocationFactory#createProblemLocation(org.eclipse.core.resources.IFile, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @seeorg.eclipse.cdt.codan.core.model.IProblemLocationFactory#
|
||||
* createProblemLocation(org.eclipse.core.resources.IFile, int)
|
||||
*/
|
||||
public IProblemLocation createProblemLocation(IFile file, int line) {
|
||||
return new CodanProblemLocation(file, line);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.codan.core.model.IProblemLocationFactory#createProblemLocation(org.eclipse.core.resources.IFile, int, int)
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @seeorg.eclipse.cdt.codan.core.model.IProblemLocationFactory#
|
||||
* createProblemLocation(org.eclipse.core.resources.IFile, int, int)
|
||||
*/
|
||||
public IProblemLocation createProblemLocation(IFile file, int startChar, int endChar) {
|
||||
public IProblemLocation createProblemLocation(IFile file, int startChar,
|
||||
int endChar) {
|
||||
return new CodanProblemLocation(file, startChar, endChar);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @seeorg.eclipse.cdt.codan.core.model.IProblemLocationFactory#
|
||||
* createProblemLocation(org.eclipse.core.resources.IFile, int, int, int)
|
||||
*/
|
||||
public IProblemLocation createProblemLocation(IFile file, int startChar,
|
||||
int endChar, int line) {
|
||||
return new CodanProblemLocation(file, startChar, endChar, line);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue