Skip to content

Commit 6d7d6e6

Browse files
committed
Show stacktrace
1 parent 38bd558 commit 6d7d6e6

File tree

5 files changed

+50
-43
lines changed

5 files changed

+50
-43
lines changed

tmc-plugin/src/fi/helsinki/cs/tmc/actions/DownloadSolutionAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public Void apply(Boolean yes) {
131131
private void downloadSolution(final Exercise ex, final TmcProjectInfo proj) {
132132
Exercise exercise = exerciseForProject(proj.getProject());
133133
Callable<Exercise> dlModelSolutionTask = TmcCore.get().downloadModelSolution(ProgressObserver.NULL_OBSERVER, exercise);
134-
BgTask.start("Downloading modelsolution", dlModelSolutionTask,
134+
BgTask.start("Downloading suggested solution", dlModelSolutionTask,
135135
new BgTaskListener<Object>() {
136136
@Override
137137
public void bgTaskReady(Object result) {

tmc-plugin/src/fi/helsinki/cs/tmc/model/SourceFileLookup.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public FileObject findSourceFileFor(Exercise exercise, String className) {
2929
for (FileObject sr : globalPathRegistry.getSourceRoots()) {
3030
TmcProjectInfo p = projectMediator.tryGetProjectOwningFile(sr);
3131
if (p != null && p.equals(correctProject)) {
32+
3233
FileObject result = sr.getFileObject(path);
3334
if (result != null) {
3435
return result;

tmc-plugin/src/fi/helsinki/cs/tmc/spyware/eventsources/WindowStatechangesEventSource.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ private Exercise getExercise(@NullAllowed FileObject obj) {
160160
}
161161
ProjectMediator pm = ProjectMediator.getInstance();
162162
TmcProjectInfo project = pm.tryGetProjectOwningFile(obj);
163+
if (project == null) {
164+
return null;
165+
}
163166
return pm.tryGetExerciseForProject(project, courseDb);
164167
}
165168

tmc-plugin/src/fi/helsinki/cs/tmc/ui/TestCaseResultCell.java

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import fi.helsinki.cs.tmc.model.SourceFileLookup;
66
import fi.helsinki.cs.tmc.utilities.ExceptionUtils;
77

8+
import com.google.common.collect.ImmutableList;
89
import java.awt.Color;
910
import java.awt.GridBagConstraints;
1011
import java.awt.GridBagLayout;
@@ -13,6 +14,8 @@
1314
import java.util.HashMap;
1415
import java.util.logging.Level;
1516
import java.util.logging.Logger;
17+
import java.util.regex.Matcher;
18+
import java.util.regex.Pattern;
1619

1720
import javax.swing.AbstractAction;
1821
import javax.swing.Action;
@@ -50,6 +53,9 @@ public final class TestCaseResultCell {
5053
private final GridBagConstraints gbc = new GridBagConstraints();
5154
private final JPanel detailView;
5255
private final ResultCell resultCell;
56+
57+
private static final Pattern JAVA_STACKTRACE_ELEMENT_PATTERN = Pattern.compile("([\\w.]+)(\\.\\w+|\\$([\\w\\.]+))\\((\\w+.java):(\\d+)\\)");
58+
5359

5460
public TestCaseResultCell(final Exercise exercise, final TestResult result, final SourceFileLookup sourceFileLookup) {
5561

@@ -65,10 +71,10 @@ public TestCaseResultCell(final Exercise exercise, final TestResult result, fina
6571
final String title = (result.isSuccessful() ? "PASS: " : "FAIL: ") + result.getName();
6672

6773
this.resultCell = new ResultCell(getResultColor(),
68-
getResultTextColor(),
69-
title,
70-
result.getMessage(),
71-
detailView);
74+
getResultTextColor(),
75+
title,
76+
result.getMessage(),
77+
detailView);
7278
}
7379

7480
public ResultCell getCell() {
@@ -218,57 +224,54 @@ public void actionPerformed(final ActionEvent event) {
218224
private Action detailedMessageAction = new AbstractAction("Show detailed message") {
219225

220226
@Override
221-
public void actionPerformed(final ActionEvent event) {
227+
public void actionPerformed(ActionEvent event) {
222228

223229
detailView.remove(detailedMessageButton);
224230

225-
final ExceptionDisplay display = new ExceptionDisplay();
226-
// TODO
227-
// addException(display, result.backtrace, false);
231+
ExceptionDisplay display = new ExceptionDisplay();
232+
addException(display, result.getException(), false);
228233
display.finish();
229234

230235
detailView.add(display, gbc);
231-
232236

233237
resultCell.revalidate();
234238
resultCell.repaint();
235239
}
236240

237-
// private void addException(ExceptionDisplay display, ImmutableList<String> ex, boolean isCause) {
238-
// String mainLine;
239-
// if (ex.message != null) {
240-
// mainLine = ex.className + ": " + ex.message;
241-
// } else {
242-
// mainLine = ex.className;
243-
// }
244-
// if (isCause) {
245-
// mainLine = "Caused by: " + mainLine;
246-
// }
247-
// display.addBoldTextLine(mainLine);
248-
//
249-
// addStackTraceLines(display, ex.stackTrace);
250-
//
251-
// if (ex.cause != null) {
252-
// addException(display, ex.cause, true);
253-
// }
254-
// }
255-
256-
private void addStackTraceLines(ExceptionDisplay display, StackTraceElement[] stackTrace) {
257-
for (final StackTraceElement ste : stackTrace) {
258-
final FileObject sourceFile = sourceFileLookup.findSourceFileFor(exercise, ste.getClassName());
259-
260-
if (sourceFile != null && ste.getLineNumber() > 0) {
261-
display.addLink(ste.toString(), new ActionListener() {
262-
@Override
263-
public void actionPerformed(ActionEvent e) {
264-
openAtLine(sourceFile, ste.getLineNumber());
265-
}
266-
});
267-
} else {
268-
display.addTextLine(ste.toString());
241+
private void addException(ExceptionDisplay display, ImmutableList<String> ex, boolean isCause) {
242+
if (ex.size() > 0) {
243+
display.addBoldTextLine(ex.get(0));
244+
}
245+
246+
addStackTraceLines(display, ex);
247+
}
248+
249+
private void addStackTraceLines(ExceptionDisplay display, ImmutableList<String> stackTrace) {
250+
for (final String ste : stackTrace) {
251+
Matcher matcher = JAVA_STACKTRACE_ELEMENT_PATTERN.matcher(ste);
252+
boolean added = false;
253+
if (matcher.matches()) {
254+
String packageAndClass = matcher.group(1);
255+
final int row = Integer.parseInt(matcher.group(5));
256+
final FileObject sourceFile = sourceFileLookup.findSourceFileFor(exercise, packageAndClass);
257+
258+
if (sourceFile != null && row > 0) {
259+
display.addLink(ste, new ActionListener() {
260+
@Override
261+
public void actionPerformed(ActionEvent e) {
262+
openAtLine(sourceFile, row);
263+
}
264+
});
265+
added = true;
266+
267+
}
268+
if (!added) {
269+
display.addTextLine(ste);
270+
}
269271
}
270272
}
271273
}
274+
272275

273276
private void openAtLine(FileObject sourceFile, final int lineNum) {
274277
try {

tmc-plugin/src/fi/helsinki/cs/tmc/utilities/BgTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void run() {
131131
});
132132
return null;
133133
} catch (final Exception ex) {
134-
:wingUtilities.invokeLater(new Runnable() {
134+
SwingUtilities.invokeLater(new Runnable() {
135135
@Override
136136
public void run() {
137137
listener.bgTaskFailed(ex);

0 commit comments

Comments
 (0)