Skip to main content
summaryrefslogtreecommitdiffstats
path: root/codan
diff options
context:
space:
mode:
authorAlisson Linhares de Carvalho2016-02-16 10:43:50 -0500
committerSergey Prigogin2016-02-23 16:59:59 -0500
commit9ba50a946241a94f0d870b70e0c148038f5df3a0 (patch)
treed6a98b0fa1bffa788b99f4a6d66f52f103de47e4 /codan
parent99465c1604a0d9010a310441d830bfbb4b6cfb98 (diff)
downloadorg.eclipse.cdt-9ba50a946241a94f0d870b70e0c148038f5df3a0.tar.gz
org.eclipse.cdt-9ba50a946241a94f0d870b70e0c148038f5df3a0.tar.xz
org.eclipse.cdt-9ba50a946241a94f0d870b70e0c148038f5df3a0.zip
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>
Diffstat (limited to 'codan')
-rw-r--r--codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java10
-rw-r--r--codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java15
2 files changed, 20 insertions, 5 deletions
diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java
index 44287f7ea5..92cbfed1b0 100644
--- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java
+++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java
@@ -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) {
diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java
index e3c5968d7f..18c39ada40 100644
--- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java
+++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/core/internal/checkers/AssignmentToItselfCheckerTest.java
@@ -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));
+ }
}

Back to the top