forked from typetools/checker-framework-inference
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathVariableSlot.java
More file actions
65 lines (55 loc) · 2.13 KB
/
VariableSlot.java
File metadata and controls
65 lines (55 loc) · 2.13 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
package checkers.inference.model;
import javax.lang.model.type.TypeMirror;
import java.util.HashSet;
import java.util.Set;
/**
* VariableSlot is a Slot representing an undetermined value (i.e. a variable we are solving for).
* After the Solver is run, each VariableSlot has an assigned value which is then written
* to the output Jaif file for later insertion into the original source code.
*
* The {@link checkers.inference.InferenceVisitor} and other code can convert between VarAnnots in
* AnnotatedTypeMirrors and VariableSlots, which are then used to generate constraints.
*
* E.g. @VarAnnot(0) String s;
*
* The above example implies that a VariableSlot with id 0 represents the possible annotations
* on the declaration of s.
*
* Every VariableSlot has an {@link AnnotationLocation} and the {@link RefinementVariableSlot}s
* it is refined by.
*
*/
public abstract class VariableSlot extends Slot {
/**
* Used to locate this Slot in source code. {@code AnnotationLocation}s are written to Jaif files
* along with the annotations determined for this slot by the Solver.
*/
private AnnotationLocation location;
/** Variable slots that refine this slot, which can be {@link RefinementVariableSlot} in an assignment
* and {@link ComparisonVariableSlot} in a comparison. */
private final Set<VariableSlot> refinedToSlots = new HashSet<>();
/**
* Create a Slot with the given annotation location.
*
* @param id Unique identifier for this variable
* @param location an AnnotationLocation for which the slot is attached to
*/
public VariableSlot(int id, AnnotationLocation location) {
super(id);
this.location = location;
}
public AnnotationLocation getLocation() {
return location;
}
// TODO: remove this method and make location final.
public void setLocation(AnnotationLocation location) {
this.location = location;
}
public Set<VariableSlot> getRefinedToSlots() {
return refinedToSlots;
}
@Override
public String toString() {
return this.getClass().getSimpleName() + "(" + id + ")";
}
}