Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class Problem implements Cloneable {
private static final String DELIMITER = ";";

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

/**
Expand All @@ -49,13 +49,14 @@ public Problem(String id, String message, String category) {
* (might be 0 for non line-specific problems)
*/
public Problem(String id, String message, String category, File file,
IProject project, int line) {
IProject project, int line, String stack) {
this.id = id;
this.message = message;
this.category = category;
this.lineNumber = line;
this.file = file;
this.project = project;
this.stack = stack;
setToDefault();
}

Expand All @@ -76,6 +77,10 @@ public String getMessage() {
public String getCategory() {
return category;
}

public String getStack() {
return stack;
}

public ProblemSeverity getSeverity() {
return severity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class CppcheckCommand extends AbstractCppcheckCommand {
private final static String DELIMITER = ";";
private final static String ERROR_FORMAT = "{file}" + DELIMITER + "{line}"
+ DELIMITER + "{severity}" + DELIMITER + "{id}" + DELIMITER
+ "{message}";
+ "{message}" + DELIMITER + "{callstack}";
private final static String[] DEFAULT_ARGUMENTS = { "--template="
+ ERROR_FORMAT };

Expand Down Expand Up @@ -322,10 +322,10 @@ public static void parseResultLines(IProject project,
}

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

/**
Expand All @@ -352,8 +352,9 @@ public static Problem parseResult(String line, IProject project) {
String severity = lineParts[2];
String id = lineParts[3];
String message = lineParts[4];
String stack = lineParts[5];
return new Problem(id, message, severity, filename, project,
lineNumber);
lineNumber, stack);

} catch (NumberFormatException e2) {
throw new IllegalArgumentException(
Expand Down
1 change: 1 addition & 0 deletions com.googlecode.cppcheclipse.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<attribute name="file" />
<attribute name="originalLineNumber" />
<attribute name="problemId" />
<attribute name="stack" />
</extension>

<extension point="org.eclipse.ui.commands">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ProblemReporter implements IProblemReporter {
public static final String ATTRIBUTE_ID = "problemId"; //$NON-NLS-1$
public static final String ATTRIBUTE_ORIGINAL_LINE_NUMBER = "originalLineNumber"; //$NON-NLS-1$
public static final String ATTRIBUTE_FILE = "file"; //$NON-NLS-1$
public static final String ATTRIBUTE_STACK = "stack"; //$NON-NLS-1$

public ProblemReporter() {
}
Expand Down Expand Up @@ -53,13 +54,13 @@ public void reportProblem(Problem problem) throws CoreException {
// for each resource
reportProblem(resource, completeMessage, problem
.getSeverity().intValue(), lineNumber, problem.getId(),
problem.getFile(), problem.getLineNumber());
problem.getFile(), problem.getLineNumber(), problem.getStack());
}
}

private void reportProblem(IResource resource, String message,
int severity, int lineNumber, String id, File file,
int originalLineNumber) throws CoreException {
int originalLineNumber, String stack) throws CoreException {
// TODO: open external file, see
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=151005 on how to
// generate markers for external files
Expand All @@ -81,20 +82,28 @@ private void reportProblem(IResource resource, String message,
}
}
}

// Only display stack if it contains multiple locations
String message_display = message;
int locationCount = (stack.length() - stack.replace("->", "").length())/2;
if (locationCount > 0) {
message_display = message + " " + stack;
}

// see
// http://wiki.eclipse.org/FAQ_Why_don%27t_my_markers_appear_in_the_editor%27s_vertical_ruler%3F
Map<String, Object> attributes = new HashMap<String, Object>();
if (lineNumber != 0) {
MarkerUtilities.setLineNumber(attributes, lineNumber);
}
MarkerUtilities.setMessage(attributes, message);
MarkerUtilities.setMessage(attributes, message_display);
attributes.put(IMarker.SEVERITY, severity);
// the following attributes are only used for the quick fixes
attributes.put(ATTRIBUTE_ID, id);
if (file != null) {
attributes.put(ATTRIBUTE_FILE, file.toString());
}
attributes.put(ATTRIBUTE_STACK, stack);
attributes.put(ATTRIBUTE_ORIGINAL_LINE_NUMBER, originalLineNumber);
MarkerUtilities.createMarker(resource, attributes, CHECKER_MARKER_TYPE);
}
Expand Down
Loading