Skip to content

Commit 3b7175e

Browse files
authored
Fix construction of Javac issue dialog (#3008)
Continuation of https://git.key-project.org/key/key/-/merge_requests/637
2 parents 07d79f0 + 72c13ea commit 3b7175e

7 files changed

Lines changed: 458 additions & 77 deletions

File tree

key.core/src/main/java/de/uka/ilkd/key/java/Position.java

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* superceded.
77
*/
88

9-
public class Position {
9+
public class Position implements Comparable<Position> {
1010

1111
/**
1212
* The line number.
@@ -93,18 +93,6 @@ public boolean equals(Object x) {
9393
return line == p.line && column == p.column;
9494
}
9595

96-
/**
97-
* Compares this position with the given object for order. An undefined position is less than
98-
* any defined position.
99-
*
100-
* @param x the position object to compare with.
101-
* @return a negative number, zero, or a positive number, if this position is lower than, equals
102-
* to, or higher than the given one.
103-
*/
104-
public int compareTo(Object x) {
105-
return compareTo((Position) x);
106-
}
107-
10896
/**
10997
* Compares this position with the given object for order. An undefined position is less than
11098
* any defined position.
@@ -113,6 +101,7 @@ public int compareTo(Object x) {
113101
* @return a negative number, zero, or a positive number, if this position is lower than, equals
114102
* to, or higher than the given one.
115103
*/
104+
@Override
116105
public int compareTo(Position p) {
117106
return (line == p.line) ? (column - p.column) : (line - p.line);
118107
}

key.core/src/main/java/de/uka/ilkd/key/proof/JavaModel.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
public final class JavaModel {
1111

12+
/**
13+
* Directory of Java source files. May be null if the proof doesn't refer to any Java code.
14+
*/
1215
private final String modelDir;
1316
private final String modelTag;
1417
private final String descr;

key.ui/src/main/java/de/uka/ilkd/key/gui/IssueDialog.java

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@
6060
public final class IssueDialog extends JDialog {
6161
private static final Logger LOGGER = LoggerFactory.getLogger(IssueDialog.class);
6262

63+
/**
64+
* Default text for critical issues (runtime exceptions).
65+
*/
66+
private static final String CRITICAL_ISSUE = "The following exception occurred:";
67+
/**
68+
* Default text for non-critical issues (JML specification warnings).
69+
*/
70+
private static final String NON_CRITICAL_ISSUE = String.format(
71+
"The following non-fatal problems occurred when translating your %s specifications:",
72+
SLEnvInput.getLanguage());
73+
6374
/** regex to find web urls in string messages */
6475
private static final Pattern HTTP_REGEX = Pattern.compile("https?://[^\\s]+");
6576

@@ -129,7 +140,20 @@ public final class IssueDialog extends JDialog {
129140

130141
public IssueDialog(Window owner, String title, Set<PositionedIssueString> issues,
131142
boolean critical) {
132-
this(owner, title, issues, critical, null);
143+
this(owner, title, critical ? CRITICAL_ISSUE : NON_CRITICAL_ISSUE, issues, critical, null);
144+
}
145+
146+
/**
147+
* Create an issue dialog with the given title and description.
148+
*
149+
* @param owner parent window
150+
* @param title window title
151+
* @param description description to show
152+
* @param issues the issues
153+
*/
154+
public IssueDialog(Window owner, String title, String description,
155+
Set<PositionedIssueString> issues) {
156+
this(owner, title, description, issues, false, null);
133157
}
134158

135159
/**
@@ -166,8 +190,34 @@ private static List<PositionedIssueString> decorateHTML(Set<PositionedIssueStrin
166190
}).collect(Collectors.toList());
167191
}
168192

193+
/**
194+
* Construct a new issue dialog based on the title, the warnings to show and the exception to
195+
* show.
196+
*
197+
* @param owner parent window
198+
* @param title dialog title
199+
* @param warnings warnings to show
200+
* @param critical whether the issue is critical
201+
* @param throwable exception to show (may be null)
202+
*/
169203
IssueDialog(Window owner, String title, Set<PositionedIssueString> warnings,
170204
boolean critical, Throwable throwable) {
205+
this(owner, title, critical ? CRITICAL_ISSUE : NON_CRITICAL_ISSUE, warnings, critical,
206+
throwable);
207+
}
208+
209+
/**
210+
* Construct a new issue dialog given the title, description, warnings and exception.
211+
*
212+
* @param owner parent window
213+
* @param title dialog title
214+
* @param head description
215+
* @param warnings warnings to show
216+
* @param critical criticality of the issue
217+
* @param throwable exception to show (may be null)
218+
*/
219+
IssueDialog(Window owner, String title, String head, Set<PositionedIssueString> warnings,
220+
boolean critical, Throwable throwable) {
171221
super(owner, title, ModalityType.APPLICATION_MODAL);
172222

173223
this.throwable = throwable;
@@ -195,14 +245,6 @@ private static List<PositionedIssueString> decorateHTML(Set<PositionedIssueStrin
195245
// stTextArea
196246

197247
// set descriptive text in top label
198-
final String head;
199-
if (critical) {
200-
head = "The following exception occurred:";
201-
} else {
202-
head = String.format(
203-
"The following non-fatal problems occurred when translating your %s specifications:",
204-
SLEnvInput.getLanguage());
205-
}
206248
JLabel label = new JLabel(head);
207249
label.setBorder(BorderFactory.createEmptyBorder(5, 5, 2, 5));
208250
add(label, BorderLayout.NORTH);
@@ -719,8 +761,11 @@ public Component getListCellRendererComponent(JList<? extends PositionedString>
719761
BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY),
720762
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
721763
if (isSelected) {
722-
textPane.setBackground(list.getSelectionBackground());
723-
textPane.setForeground(list.getSelectionForeground());
764+
// for some reason, this copy is needed to get correct colors
765+
Color bg = new Color(list.getSelectionBackground().getRGB());
766+
Color fg = new Color(list.getSelectionForeground().getRGB());
767+
textPane.setBackground(bg);
768+
textPane.setForeground(fg);
724769
} else {
725770
textPane.setBackground(list.getBackground());
726771
textPane.setForeground(list.getForeground());

key.ui/src/main/java/de/uka/ilkd/key/gui/PositionedIssueString.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
* (text, filename, position) contains a String for additional information which can be used to
1313
* store a stacktrace if present.
1414
*/
15-
public class PositionedIssueString extends PositionedString {
15+
public class PositionedIssueString extends PositionedString
16+
implements Comparable<PositionedIssueString> {
1617

1718
public enum Kind {
1819
ERROR, WARNING, INFO
@@ -73,4 +74,17 @@ public boolean equals(Object o) {
7374
public int hashCode() {
7475
return Objects.hash(super.hashCode(), additionalInfo, kind);
7576
}
77+
78+
@Override
79+
public int compareTo(PositionedIssueString o) {
80+
int compareFile = fileName.compareTo(o.fileName);
81+
if (compareFile != 0) {
82+
return compareFile;
83+
}
84+
int comparePosition = pos.compareTo(o.pos);
85+
if (comparePosition != 0) {
86+
return comparePosition;
87+
}
88+
return kind.compareTo(o.kind);
89+
}
7690
}

0 commit comments

Comments
 (0)