-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathVCImplication.java
More file actions
140 lines (115 loc) · 3.68 KB
/
Copy pathVCImplication.java
File metadata and controls
140 lines (115 loc) · 3.68 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package liquidjava.processor;
import java.util.Objects;
import liquidjava.rj_language.Predicate;
import liquidjava.rj_language.opt.VCSimplification;
import liquidjava.utils.Utils;
import spoon.reflect.reference.CtTypeReference;
/**
* @author cgamboa
*/
public class VCImplication {
String name;
CtTypeReference<?> type;
Predicate refinement;
VCImplication next;
public VCImplication(String name, CtTypeReference<?> type, Predicate ref) {
this.name = name;
this.type = type;
this.refinement = ref;
}
public VCImplication(Predicate ref) {
this.refinement = ref;
}
public VCImplication(VCImplication implication, Predicate ref) {
this.name = implication.name;
this.type = implication.type;
this.refinement = ref;
}
public VCImplication getOrigin() {
return null;
}
public Predicate getOriginRefinement() {
VCImplication origin = getOrigin();
if (origin == null)
return refinement.clone();
return origin.getRefinement().clone();
}
public VCImplication copyWithRefinement(Predicate refinement) {
return new VCImplication(this, refinement);
}
public void setNext(VCImplication c) {
next = c;
}
public String getName() {
return name;
}
public CtTypeReference<?> getType() {
return type;
}
public Predicate getRefinement() {
return refinement;
}
public void setRefinement(Predicate refinement) {
this.refinement = refinement;
}
public VCImplication getNext() {
return next;
}
public boolean hasNext() {
return next != null;
}
public boolean hasBinder() {
return name != null && type != null;
}
public String toString() {
if (name != null && type != null) {
String qualType = type.getQualifiedName();
String simpleType = qualType.contains(".") ? Utils.getSimpleName(qualType) : qualType;
return String.format("%-20s %s %s", "∀" + name + ":" + simpleType + ",", refinement.toString(),
next != null ? " => \n" + next : "");
} else
return String.format("%-20s %s", "", refinement.toString());
}
public VCImplication simplify() {
return VCSimplification.simplifyToFixedPoint(this);
}
public Predicate toConjunctions() {
Predicate c = new Predicate();
if (name == null && type == null && next == null)
return c;
c = auxConjunction(c);
return c;
}
private Predicate auxConjunction(Predicate c) {
Predicate t = Predicate.createConjunction(c, refinement);
if (next == null)
return t;
t = next.auxConjunction(t);
return t;
}
public VCImplication clone() {
VCImplication vc = new VCImplication(this.name, this.type, this.refinement.clone());
if (this.next != null)
vc.next = this.next.clone();
return vc;
}
@Override
public int hashCode() {
return Objects.hash(name, typeName(), refinement, next);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VCImplication other = (VCImplication) obj;
return Objects.equals(name, other.name) && Objects.equals(typeName(), other.typeName())
&& Objects.equals(refinement, other.refinement) && Objects.equals(next, other.next);
}
private String typeName() {
return type == null ? null : type.getQualifiedName();
}
}