@@ -32,18 +32,41 @@ predicate hasReferenceInitializer(EnumConstant c) {
32
32
)
33
33
}
34
34
35
+ /**
36
+ * Gets the `rnk`'th (1-based) enumeration constant in `e` that does not have a
37
+ * reference initializer (i.e., an initializer that refers to an enumeration
38
+ * constant from the same enumeration).
39
+ */
40
+ EnumConstant getNonReferenceInitializedEnumConstantByRank ( Enum e , int rnk ) {
41
+ result =
42
+ rank [ rnk ] ( EnumConstant cand , int pos , string filepath , int startline , int startcolumn |
43
+ e .getEnumConstant ( pos ) = cand and
44
+ not hasReferenceInitializer ( cand ) and
45
+ cand .getLocation ( ) .hasLocationInfo ( filepath , startline , startcolumn , _, _)
46
+ |
47
+ cand order by pos , filepath , startline , startcolumn
48
+ )
49
+ }
50
+
51
+ /**
52
+ * Holds if `ec` is not the last enumeration constant in `e` that has a non-
53
+ * reference initializer.
54
+ */
55
+ predicate hasNextWithoutReferenceInitializer ( Enum e , EnumConstant ec ) {
56
+ exists ( int rnk |
57
+ ec = getNonReferenceInitializedEnumConstantByRank ( e , rnk ) and
58
+ exists ( getNonReferenceInitializedEnumConstantByRank ( e , rnk + 1 ) )
59
+ )
60
+ }
61
+
35
62
// There exists another constant whose value is implicit, but it's
36
63
// not the last one: the last value is okay to use to get the highest
37
64
// enum value automatically. It can be followed by aliases though.
38
65
predicate enumThatHasConstantWithImplicitValue ( Enum e ) {
39
- exists ( EnumConstant ec , int pos |
40
- ec = e .getEnumConstant ( pos ) and
66
+ exists ( EnumConstant ec |
67
+ ec = e .getAnEnumConstant ( ) and
41
68
not hasInitializer ( ec ) and
42
- exists ( EnumConstant ec2 , int pos2 |
43
- ec2 = e .getEnumConstant ( pos2 ) and
44
- pos2 > pos and
45
- not hasReferenceInitializer ( ec2 )
46
- )
69
+ hasNextWithoutReferenceInitializer ( e , ec )
47
70
)
48
71
}
49
72
0 commit comments