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.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
import org.eclipse.cdt.core.dom.ast.IASTFunctionDefinition;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,11 +45,11 @@ public class NamingConventionFunctionChecker extends AbstractIndexAstChecker
|
||||||
if (element instanceof IASTFunctionDefinition) {
|
if (element instanceof IASTFunctionDefinition) {
|
||||||
String parameter = (String) pt.getParameter(PARAM_KEY);
|
String parameter = (String) pt.getParameter(PARAM_KEY);
|
||||||
Pattern pattern = Pattern.compile(parameter);
|
Pattern pattern = Pattern.compile(parameter);
|
||||||
String name = ((IASTFunctionDefinition) element)
|
IASTName astName = ((IASTFunctionDefinition) element)
|
||||||
.getDeclarator().getName().toString();
|
.getDeclarator().getName();
|
||||||
|
String name = astName.toString();
|
||||||
if (!pattern.matcher(name).find()) {
|
if (!pattern.matcher(name).find()) {
|
||||||
reportProblem(ER_ID, getFile(), 1, // TODO: line
|
reportProblem(ER_ID, astName,
|
||||||
// number
|
|
||||||
name, parameter);
|
name, parameter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,7 +80,7 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reportProblem(String id, IASTNode astNode, String message) {
|
public void reportProblem(String id, IASTNode astNode, Object... args) {
|
||||||
IASTFileLocation astLocation = astNode.getFileLocation();
|
IASTFileLocation astLocation = astNode.getFileLocation();
|
||||||
IPath location = new Path(astLocation.getFileName());
|
IPath location = new Path(astLocation.getFileName());
|
||||||
IFile astFile = ResourcesPlugin.getWorkspace().getRoot()
|
IFile astFile = ResourcesPlugin.getWorkspace().getRoot()
|
||||||
|
@ -89,19 +89,20 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements
|
||||||
astFile = file;
|
astFile = file;
|
||||||
}
|
}
|
||||||
IProblemLocation loc;
|
IProblemLocation loc;
|
||||||
if (astLocation.getStartingLineNumber() == astLocation
|
int line = astLocation.getStartingLineNumber();
|
||||||
|
if (line == astLocation
|
||||||
.getEndingLineNumber())
|
.getEndingLineNumber())
|
||||||
loc = getRuntime().getProblemLocationFactory()
|
loc = getRuntime().getProblemLocationFactory()
|
||||||
.createProblemLocation(
|
.createProblemLocation(
|
||||||
astFile,
|
astFile,
|
||||||
astLocation.getNodeOffset(),
|
astLocation.getNodeOffset(),
|
||||||
astLocation.getNodeOffset()
|
astLocation.getNodeOffset()
|
||||||
+ astLocation.getNodeLength());
|
+ astLocation.getNodeLength(), line);
|
||||||
else
|
else
|
||||||
loc = getRuntime().getProblemLocationFactory()
|
loc = getRuntime().getProblemLocationFactory()
|
||||||
.createProblemLocation(astFile,
|
.createProblemLocation(astFile,
|
||||||
astLocation.getStartingLineNumber());
|
line);
|
||||||
getProblemReporter().reportProblem(id, loc, message);
|
getProblemReporter().reportProblem(id, loc, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,28 +17,52 @@ import org.eclipse.core.resources.IFile;
|
||||||
*
|
*
|
||||||
* Clients may implement and extend this interface.
|
* Clients may implement and extend this interface.
|
||||||
* <p>
|
* <p>
|
||||||
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as
|
* <strong>EXPERIMENTAL</strong>. This class or interface has been added as part
|
||||||
* part of a work in progress. There is no guarantee that this API will
|
* of a work in progress. There is no guarantee that this API will work or that
|
||||||
* work or that it will remain the same.
|
* it will remain the same.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public interface IProblemLocationFactory {
|
public interface IProblemLocationFactory {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and return instance of IProblemLocation
|
* 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
|
* @return instance of IProblemLocation
|
||||||
*/
|
*/
|
||||||
public IProblemLocation createProblemLocation(IFile file, int line);
|
public IProblemLocation createProblemLocation(IFile file, int line);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create and return instance of IProblemLocation
|
* 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 file
|
||||||
* @param endChar - end char of the problem in the file, is zero-relative and exclusive.
|
* - 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
|
* @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 class CodanProblemLocation extends AbstractProblemLocation {
|
||||||
|
|
||||||
public CodanProblemLocation(IFile file, int startChar, int endChar) {
|
public CodanProblemLocation(IFile file, int startChar, int endChar) {
|
||||||
super(file, startChar, 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) {
|
protected CodanProblemLocation(IFile file, int line) {
|
||||||
super(file, line);
|
super(file, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,17 +19,35 @@ import org.eclipse.core.resources.IFile;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ProblemLocationFactory implements IProblemLocationFactory {
|
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) {
|
public IProblemLocation createProblemLocation(IFile file, int line) {
|
||||||
return new CodanProblemLocation(file, 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);
|
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