mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-19 22:25:52 +02:00
Bug 496628 - Avoid codan markers that cover an entire class declaration
This fixes a regression from bug 486610 which introduced these in some cases. Change-Id: I791528ce7f0bc061386aaa97dd9cecb7abeecd72
This commit is contained in:
parent
e8280ebd19
commit
80f0c9e329
2 changed files with 22 additions and 1 deletions
|
@ -22,6 +22,7 @@ import org.eclipse.cdt.codan.core.model.IProblemLocation;
|
||||||
import org.eclipse.cdt.codan.core.model.IProblemLocationFactory;
|
import org.eclipse.cdt.codan.core.model.IProblemLocationFactory;
|
||||||
import org.eclipse.cdt.codan.core.model.IRunnableInEditorChecker;
|
import org.eclipse.cdt.codan.core.model.IRunnableInEditorChecker;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
import org.eclipse.cdt.core.dom.ast.IASTComment;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTImageLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTImageLocation;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
|
import org.eclipse.cdt.core.dom.ast.IASTMacroExpansionLocation;
|
||||||
|
@ -198,7 +199,12 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If the raw signature has more than one line, we highlight only the code
|
// If the raw signature has more than one line, we highlight only the code
|
||||||
// related to the problem.
|
// related to the problem. However, if the problem is associated with a
|
||||||
|
// node representing a class definition, do not highlight the entire class
|
||||||
|
// definition, because that can result in many lines being highlighted.
|
||||||
|
if (astNode instanceof IASTCompositeTypeSpecifier) {
|
||||||
|
return locFactory.createProblemLocation(getFile(), line);
|
||||||
|
}
|
||||||
int start = astLocation.getNodeOffset();
|
int start = astLocation.getNodeOffset();
|
||||||
int end = start + astLocation.getNodeLength();
|
int end = start + astLocation.getNodeLength();
|
||||||
return locFactory.createProblemLocation(getFile(), start, end, line);
|
return locFactory.createProblemLocation(getFile(), start, end, line);
|
||||||
|
|
|
@ -14,6 +14,7 @@ package org.eclipse.cdt.codan.core.internal.checkers;
|
||||||
|
|
||||||
import org.eclipse.cdt.codan.core.test.CheckerTestCase;
|
import org.eclipse.cdt.codan.core.test.CheckerTestCase;
|
||||||
import org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructor;
|
import org.eclipse.cdt.codan.internal.checkers.NonVirtualDestructor;
|
||||||
|
import org.eclipse.core.resources.IMarker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link NonVirtualDestructor} class.
|
* Test for {@link NonVirtualDestructor} class.
|
||||||
|
@ -203,4 +204,18 @@ public class NonVirtualDestructorCheckerTest extends CheckerTestCase {
|
||||||
loadCodeAndRun(getAboveComment());
|
loadCodeAndRun(getAboveComment());
|
||||||
assertMessageContains("Foo", markers[0]);
|
assertMessageContains("Foo", markers[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// class Foo {
|
||||||
|
// virtual void bar();
|
||||||
|
// };
|
||||||
|
public void testBug496628_MarkerBounds() throws Exception {
|
||||||
|
String code = getAboveComment();
|
||||||
|
loadCodeAndRun(code);
|
||||||
|
IMarker marker = checkErrorLine(1);
|
||||||
|
int start = marker.getAttribute(IMarker.CHAR_START, -1);
|
||||||
|
int end = marker.getAttribute(IMarker.CHAR_END, -1);
|
||||||
|
// The error should not cover the entire class
|
||||||
|
assertTrue((start == -1 && end == -1) || // ok, not multi-line
|
||||||
|
!code.substring(start, end).contains("\n"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue