1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

- fixed implemenation of processModel - to set a file

This commit is contained in:
Alena Laskavaia 2010-03-18 15:02:37 +00:00
parent eadd67178c
commit b4ff99ca8f
2 changed files with 53 additions and 22 deletions

View file

@ -117,7 +117,13 @@ public abstract class AbstractIndexAstChecker extends AbstractChecker implements
* (java.lang.Object) * (java.lang.Object)
*/ */
public void processModel(Object model) { public void processModel(Object model) {
if (model instanceof IASTTranslationUnit) if (model instanceof IASTTranslationUnit) {
processAst((IASTTranslationUnit) model); IASTTranslationUnit ast = (IASTTranslationUnit) model;
IPath location = new Path(ast.getFilePath());
IFile astFile = ResourcesPlugin.getWorkspace().getRoot()
.getFileForLocation(location);
file = astFile;
processAst(ast);
}
} }
} }

View file

@ -16,9 +16,9 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResource;
/** /**
* Convenience implementation of IChecker interface. * Convenience implementation of IChecker interface. Has a default
* Has a default implementation for common methods. * implementation for common methods.
* *
* Clients may extend this class. * Clients may extend this class.
*/ */
public abstract class AbstractChecker implements IChecker { public abstract class AbstractChecker implements IChecker {
@ -49,19 +49,27 @@ public abstract class AbstractChecker implements IChecker {
* it will be error message (not recommended because of * it will be error message (not recommended because of
* internationalization) * internationalization)
*/ */
public void reportProblem(String id, IFile file, int lineNumber, Object... args) { public void reportProblem(String id, IFile file, int lineNumber,
getProblemReporter().reportProblem(id, createProblemLocation(file, lineNumber), args); Object... args) {
getProblemReporter().reportProblem(id,
createProblemLocation(file, lineNumber), args);
} }
/** /**
* Finds an instance of problem by given id, in user profile registered for specific file * Finds an instance of problem by given id, in user profile registered for
* @param id - problem id * specific file
* @param file - file in scope *
* @param id
* - problem id
* @param file
* - file in scope
* @return problem instance * @return problem instance
*/ */
public IProblem getProblemById(String id, IFile file) { public IProblem getProblemById(String id, IFile file) {
IProblem problem = CheckersRegisry.getInstance().getResourceProfile(file).findProblem(id); IProblem problem = CheckersRegisry.getInstance().getResourceProfile(
if (problem == null) throw new IllegalArgumentException("Id is not registered"); //$NON-NLS-1$ file).findProblem(id);
if (problem == null)
throw new IllegalArgumentException("Id is not registered"); //$NON-NLS-1$
return problem; return problem;
} }
@ -77,7 +85,8 @@ public abstract class AbstractChecker implements IChecker {
* - line * - line
*/ */
public void reportProblem(String id, IFile file, int lineNumber) { public void reportProblem(String id, IFile file, int lineNumber) {
getProblemReporter().reportProblem(id, createProblemLocation(file, lineNumber), new Object[] {}); getProblemReporter().reportProblem(id,
createProblemLocation(file, lineNumber), new Object[] {});
} }
/** /**
@ -89,6 +98,7 @@ public abstract class AbstractChecker implements IChecker {
/** /**
* Convenience method to return codan runtime * Convenience method to return codan runtime
*
* @return * @return
*/ */
protected CodanRuntime getRuntime() { protected CodanRuntime getRuntime() {
@ -97,26 +107,41 @@ public abstract class AbstractChecker implements IChecker {
/** /**
* Convenience method to create and return instance of IProblemLocation * Convenience method to create and return instance of IProblemLocation
* @param file - file where problem is found *
* @param line - line number 1-relative * @param file
* - file where problem is found
* @param line
* - line number 1-relative
* @return instance of IProblemLocation * @return instance of IProblemLocation
*/ */
protected IProblemLocation createProblemLocation(IFile file, int line) { protected IProblemLocation createProblemLocation(IFile file, int line) {
return getRuntime().getProblemLocationFactory().createProblemLocation(file, line); return getRuntime().getProblemLocationFactory().createProblemLocation(
file, line);
} }
/** /**
* Convenience method to create and return instance of IProblemLocation * Convenience method to 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
*/ */
protected IProblemLocation createProblemLocation(IFile file, int startChar, int endChar) { protected IProblemLocation createProblemLocation(IFile file, int startChar,
return getRuntime().getProblemLocationFactory().createProblemLocation(file, startChar, endChar); int endChar) {
return getRuntime().getProblemLocationFactory().createProblemLocation(
file, startChar, endChar);
} }
/**
* Defines if checker should be run as user type in C editor. Override this
* method is checker is too heavy for that (runs too long)
*/
public boolean runInEditor() { public boolean runInEditor() {
return false; return this instanceof IRunnableInEditorChecker;
} }
} }