@@ -32,18 +32,41 @@ predicate hasReferenceInitializer(EnumConstant c) {
3232 )
3333}
3434
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+
3562// There exists another constant whose value is implicit, but it's
3663// not the last one: the last value is okay to use to get the highest
3764// enum value automatically. It can be followed by aliases though.
3865predicate enumThatHasConstantWithImplicitValue ( Enum e ) {
39- exists ( EnumConstant ec , int pos |
40- ec = e .getEnumConstant ( pos ) and
66+ exists ( EnumConstant ec |
67+ ec = e .getAnEnumConstant ( ) and
4168 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 )
4770 )
4871}
4972
0 commit comments