Skip to content

Commit 7bd3a4b

Browse files
committed
fix #31 / display callstack for multiple location warnings
1 parent c4fcbfa commit 7bd3a4b

4 files changed

Lines changed: 27 additions & 11 deletions

File tree

com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/Problem.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class Problem implements Cloneable {
1919
private static final String DELIMITER = ";";
2020

21-
private final String id, message, category;
21+
private final String id, message, category, stack;
2222
private final int lineNumber;
2323
private final File file; // either absolute or relative filename (to
2424
// project), maybe null for problem profiles or
@@ -33,7 +33,7 @@ public class Problem implements Cloneable {
3333
* Constructor is called for default problems (in problem profiles).
3434
*/
3535
public Problem(String id, String message, String category) {
36-
this(id, message, category, null, null, -1);
36+
this(id, message, category, null, null, -1, "");
3737
}
3838

3939
/**
@@ -49,13 +49,14 @@ public Problem(String id, String message, String category) {
4949
* (might be 0 for non line-specific problems)
5050
*/
5151
public Problem(String id, String message, String category, File file,
52-
IProject project, int line) {
52+
IProject project, int line, String stack) {
5353
this.id = id;
5454
this.message = message;
5555
this.category = category;
5656
this.lineNumber = line;
5757
this.file = file;
5858
this.project = project;
59+
this.stack = stack;
5960
setToDefault();
6061
}
6162

@@ -76,6 +77,10 @@ public String getMessage() {
7677
public String getCategory() {
7778
return category;
7879
}
80+
81+
public String getStack() {
82+
return stack;
83+
}
7984

8085
public ProblemSeverity getSeverity() {
8186
return severity;

com.googlecode.cppcheclipse.core/src/com/googlecode/cppcheclipse/core/command/CppcheckCommand.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class CppcheckCommand extends AbstractCppcheckCommand {
3838
private final static String DELIMITER = ";";
3939
private final static String ERROR_FORMAT = "{file}" + DELIMITER + "{line}"
4040
+ DELIMITER + "{severity}" + DELIMITER + "{id}" + DELIMITER
41-
+ "{message}";
41+
+ "{message}" + DELIMITER + "{callstack}";
4242
private final static String[] DEFAULT_ARGUMENTS = { "--template="
4343
+ ERROR_FORMAT };
4444

@@ -322,10 +322,10 @@ public static void parseResultLines(IProject project,
322322
}
323323

324324
public static Problem parseResult(String line, IProject project) {
325-
String[] lineParts = line.split(DELIMITER, 5);
326-
if (lineParts.length < 5) {
325+
String[] lineParts = line.split(DELIMITER, 6);
326+
if (lineParts.length < 6) {
327327
throw new IllegalArgumentException("Not enough tokens in line '"
328-
+ line + "'. Expected 5 tokens but got " + lineParts.length);
328+
+ line + "'. Expected 6 tokens but got " + lineParts.length);
329329
}
330330

331331
/**
@@ -352,8 +352,9 @@ public static Problem parseResult(String line, IProject project) {
352352
String severity = lineParts[2];
353353
String id = lineParts[3];
354354
String message = lineParts[4];
355+
String stack = lineParts[5];
355356
return new Problem(id, message, severity, filename, project,
356-
lineNumber);
357+
lineNumber, stack);
357358

358359
} catch (NumberFormatException e2) {
359360
throw new IllegalArgumentException(

com.googlecode.cppcheclipse.ui/plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
<attribute name="file" />
3939
<attribute name="originalLineNumber" />
4040
<attribute name="problemId" />
41+
<attribute name="stack" />
4142
</extension>
4243

4344
<extension point="org.eclipse.ui.commands">

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/marker/ProblemReporter.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class ProblemReporter implements IProblemReporter {
2323
public static final String ATTRIBUTE_ID = "problemId"; //$NON-NLS-1$
2424
public static final String ATTRIBUTE_ORIGINAL_LINE_NUMBER = "originalLineNumber"; //$NON-NLS-1$
2525
public static final String ATTRIBUTE_FILE = "file"; //$NON-NLS-1$
26+
public static final String ATTRIBUTE_STACK = "stack"; //$NON-NLS-1$
2627

2728
public ProblemReporter() {
2829
}
@@ -53,13 +54,13 @@ public void reportProblem(Problem problem) throws CoreException {
5354
// for each resource
5455
reportProblem(resource, completeMessage, problem
5556
.getSeverity().intValue(), lineNumber, problem.getId(),
56-
problem.getFile(), problem.getLineNumber());
57+
problem.getFile(), problem.getLineNumber(), problem.getStack());
5758
}
5859
}
5960

6061
private void reportProblem(IResource resource, String message,
6162
int severity, int lineNumber, String id, File file,
62-
int originalLineNumber) throws CoreException {
63+
int originalLineNumber, String stack) throws CoreException {
6364
// TODO: open external file, see
6465
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=151005 on how to
6566
// generate markers for external files
@@ -81,20 +82,28 @@ private void reportProblem(IResource resource, String message,
8182
}
8283
}
8384
}
85+
86+
// Only display stack if it contains multiple locations
87+
String stack_display = "";
88+
int locationCount = (stack.length() - stack.replace("->", "").length())/2;
89+
if (locationCount > 0) {
90+
stack_display = stack;
91+
}
8492

8593
// see
8694
// http://wiki.eclipse.org/FAQ_Why_don%27t_my_markers_appear_in_the_editor%27s_vertical_ruler%3F
8795
Map<String, Object> attributes = new HashMap<String, Object>();
8896
if (lineNumber != 0) {
8997
MarkerUtilities.setLineNumber(attributes, lineNumber);
9098
}
91-
MarkerUtilities.setMessage(attributes, message);
99+
MarkerUtilities.setMessage(attributes, message + " " + stack_display);
92100
attributes.put(IMarker.SEVERITY, severity);
93101
// the following attributes are only used for the quick fixes
94102
attributes.put(ATTRIBUTE_ID, id);
95103
if (file != null) {
96104
attributes.put(ATTRIBUTE_FILE, file.toString());
97105
}
106+
attributes.put(ATTRIBUTE_STACK, stack_display);
98107
attributes.put(ATTRIBUTE_ORIGINAL_LINE_NUMBER, originalLineNumber);
99108
MarkerUtilities.createMarker(resource, attributes, CHECKER_MARKER_TYPE);
100109
}

0 commit comments

Comments
 (0)