-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathRefinementError.java
More file actions
71 lines (58 loc) · 2.39 KB
/
RefinementError.java
File metadata and controls
71 lines (58 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package liquidjava.diagnostics.errors;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import liquidjava.diagnostics.TranslationTable;
import liquidjava.rj_language.opt.derivation_node.ValDerivationNode;
import liquidjava.smt.Counterexample;
import spoon.reflect.cu.SourcePosition;
/**
* Error indicating that a refinement constraint either was violated or cannot be proven
*
* @see LJError
*/
public class RefinementError extends LJError {
private final ValDerivationNode expected;
private final ValDerivationNode found;
private final Counterexample counterexample;
public RefinementError(SourcePosition position, ValDerivationNode expected, ValDerivationNode found,
TranslationTable translationTable, Counterexample counterexample, String customMessage) {
super("Refinement Error", String.format("%s is not a subtype of %s", found.getValue(), expected.getValue()),
position, translationTable, customMessage);
this.expected = expected;
this.found = found;
this.counterexample = counterexample;
}
@Override
public String getDetails() {
String counterexampleString = getCounterExampleString();
if (counterexampleString == null)
return "";
return "Counterexample: " + counterexampleString;
}
public String getCounterExampleString() {
if (counterexample == null || counterexample.assignments().isEmpty())
return null;
List<String> foundVarNames = new ArrayList<>();
found.getValue().getVariableNames(foundVarNames);
String counterexampleString = counterexample.assignments().stream()
// only include variables that appear in the found value
.filter(a -> foundVarNames.contains(a.first()))
// format as "var == value"
.map(a -> a.first() + " == " + a.second())
// join with "&&"
.collect(Collectors.joining(" && "));
if (counterexampleString.isEmpty() || counterexampleString.equals(found.getValue().toString()))
return null;
return counterexampleString;
}
public Counterexample getCounterexample() {
return counterexample;
}
public ValDerivationNode getExpected() {
return expected;
}
public ValDerivationNode getFound() {
return found;
}
}