mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
Bug 486610 - Fixed a highlight problem in reportProblem method
Every time we report a problem in a declaration/expression that occupies more than one line, the codan marks the entire line as a problem - including everything before the node. This patch solves this inconvenient behavior. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=486610 for a complete explanation. Change-Id: I742cbaac8a1392676695d574355597b0cfc87385 Signed-off-by: Alisson Linhares de Carvalho <arescarv@gmail.com>
This commit is contained in:
parent
99465c1604
commit
9ba50a9462
2 changed files with 20 additions and 5 deletions
|
@ -197,11 +197,11 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem
|
|||
return locFactory.createProblemLocation(getFile(), start, end, line);
|
||||
}
|
||||
}
|
||||
if (line == astLocation.getEndingLineNumber()) {
|
||||
return locFactory.createProblemLocation(getFile(), astLocation.getNodeOffset(),
|
||||
astLocation.getNodeOffset() + astLocation.getNodeLength(), line);
|
||||
}
|
||||
return locFactory.createProblemLocation(getFile(), line);
|
||||
// If the raw signature has more than one line, we highlight only the code
|
||||
// related to the problem.
|
||||
int start = astLocation.getNodeOffset();
|
||||
int end = start + astLocation.getNodeLength();
|
||||
return locFactory.createProblemLocation(getFile(), start, end, line);
|
||||
}
|
||||
|
||||
protected static boolean enclosedInMacroExpansion(IASTNode node) {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.codan.core.internal.checkers;
|
||||
|
||||
import org.eclipse.cdt.codan.core.test.CheckerTestCase;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
|
||||
/**
|
||||
* Test for {@see AssignmentToItselfChecker} class
|
||||
|
@ -63,4 +64,18 @@ public class AssignmentToItselfCheckerTest extends CheckerTestCase {
|
|||
loadCodeAndRun(getAboveComment());
|
||||
checkNoErrors();
|
||||
}
|
||||
|
||||
// void foo() {
|
||||
// int x = 0; x
|
||||
// = x;
|
||||
// }
|
||||
public void testMarkerOffset_Bug486610() throws Exception {
|
||||
String code = getAboveComment();
|
||||
loadCodeAndRun(code);
|
||||
IMarker marker = checkErrorLine(2);
|
||||
int start = marker.getAttribute(IMarker.CHAR_START, -1);
|
||||
int end = marker.getAttribute(IMarker.CHAR_END, -1);
|
||||
// The offset should start at the beginning of the expression "x = x"
|
||||
assertEquals("x\n = x", code.substring(start, end));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue