1
0
Fork 0
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:
Alena Laskavaia 2010-03-18 16:34:06 +00:00
parent 768092e26c
commit 30dffe83b5
5 changed files with 76 additions and 29 deletions

View file

@ -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);
}
}

View file

@ -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

View file

@ -14,31 +14,55 @@ import org.eclipse.core.resources.IFile;
/**
* Factory interface that allows to create problem locations.
*
*
* 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);
}

View file

@ -15,16 +15,19 @@ import org.eclipse.core.resources.IFile;
/**
* Codan Problem Location, so far same as abstract class
*
*
*/
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);
}
}

View file

@ -16,20 +16,38 @@ import org.eclipse.core.resources.IFile;
/**
* Factory class that allows to create problem locations
*
*
*/
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);
}
}