7
7
import org .checkerframework .framework .type .StructuralEqualityComparer ;
8
8
import org .checkerframework .framework .type .StructuralEqualityVisitHistory ;
9
9
import org .checkerframework .framework .type .SubtypeVisitHistory ;
10
+ import org .checkerframework .javacutil .AnnotationUtils ;
10
11
import org .checkerframework .javacutil .BugInCF ;
11
12
12
13
import javax .lang .model .element .AnnotationMirror ;
13
14
15
+ import checkers .inference .model .ConstantSlot ;
16
+ import checkers .inference .model .ConstraintManager ;
14
17
import checkers .inference .model .Slot ;
18
+ import checkers .inference .qual .VarAnnot ;
15
19
16
20
/**
17
21
* The InferenceTypeHierarchy along with the InferenceQualifierHierarchy is responsible for
@@ -27,6 +31,8 @@ public class InferenceTypeHierarchy extends DefaultTypeHierarchy {
27
31
private final AnnotationMirror varAnnot ;
28
32
// TODO: Think this through, add any missing constraints
29
33
34
+ private final SlotManager slotMgr ;
35
+ private final ConstraintManager constraintMgr ;
30
36
31
37
/**
32
38
* Constructs an instance of {@code TypeHierarchy} for the type system
@@ -41,6 +47,9 @@ public InferenceTypeHierarchy(final BaseTypeChecker checker, final QualifierHier
41
47
checker .getOption ("ignoreRawTypeArguments" , "true" ).equals ("true" ),
42
48
checker .hasOption ("invariantArrays" ));
43
49
this .varAnnot = varAnnot ;
50
+
51
+ slotMgr = InferenceMain .getInstance ().getSlotManager ();
52
+ constraintMgr = InferenceMain .getInstance ().getConstraintManager ();
44
53
}
45
54
46
55
public boolean areEqual (AnnotatedTypeMirror type1 , AnnotatedTypeMirror type2 ) {
@@ -52,6 +61,37 @@ public StructuralEqualityComparer createEqualityComparer() {
52
61
return new InferenceEqualityComparer (this .typeargVisitHistory ,
53
62
InferenceQualifierHierarchy .findVarAnnot (qualifierHierarchy .getTopAnnotations ()));
54
63
}
64
+
65
+ @ Override
66
+ public boolean isSubtype (
67
+ final AnnotatedTypeMirror subtype , final AnnotatedTypeMirror supertype ) {
68
+ AnnotationMirror subAnno = subtype .getAnnotationInHierarchy (varAnnot );
69
+ AnnotationMirror superAnno = supertype .getAnnotationInHierarchy (varAnnot );
70
+
71
+ if (!isVarAnnot (subAnno ) || !isVarAnnot (superAnno )) {
72
+ return isSubtype (subtype , supertype , varAnnot );
73
+ }
74
+
75
+ final Slot subSlot = slotMgr .getSlot (subAnno );
76
+ final Slot superSlot = slotMgr .getSlot (superAnno );
77
+
78
+ if (subSlot instanceof ConstantSlot || superSlot instanceof ConstantSlot ) {
79
+ return isSubtype (subtype , supertype , varAnnot );
80
+ }
81
+
82
+ return constraintMgr .addSubtypeConstraintNoErrorMsg (subSlot , superSlot );
83
+ }
84
+
85
+ /**
86
+ * @return true if anno is an instance of @VarAnnot
87
+ */
88
+ public static boolean isVarAnnot (AnnotationMirror anno ) {
89
+ if (InferenceMain .isHackMode (anno == null )) {
90
+ return false ;
91
+ }
92
+
93
+ return AnnotationUtils .areSameByClass (anno , VarAnnot .class );
94
+ }
55
95
}
56
96
57
97
class InferenceEqualityComparer extends StructuralEqualityComparer {
0 commit comments