@@ -81,9 +81,50 @@ class DisjunctionEqualsLiteral extends DisjunctionChain {
8181 }
8282}
8383
84- from DisjunctionChain d , int c
84+ /**
85+ * A call with a single `Literal` argument. For example:
86+ * ```
87+ * myPredicate(4)
88+ * ```
89+ */
90+ class CallLiteral extends Call {
91+ CallLiteral ( ) {
92+ getNumberOfArguments ( ) = 1 and
93+ getArgument ( 0 ) instanceof Literal
94+ }
95+ }
96+
97+ /**
98+ * A chain of disjunctions where each operand is a call to the same predicate
99+ * using various `Literal`s. For example:
100+ * ```
101+ * myPredicate(4) or
102+ * myPredicate(5) or
103+ * myPredicate(6)
104+ * ```
105+ */
106+ class DisjunctionPredicateLiteral extends DisjunctionChain {
107+ DisjunctionPredicateLiteral ( ) {
108+ // Call to the same target
109+ exists ( PredicateOrBuiltin target |
110+ forex ( Formula f | f = getAnOperandRec ( ) | f .( CallLiteral ) .getTarget ( ) = target )
111+ )
112+ }
113+ }
114+
115+ from DisjunctionChain d , string msg , int c
85116where
86- d instanceof DisjunctionEqualsLiteral and
117+ (
118+ d instanceof DisjunctionEqualsLiteral and
119+ msg =
120+ "This formula of " + c .toString ( ) +
121+ " comparisons can be replaced with a single equality on a set literal, improving readability."
122+ or
123+ d instanceof DisjunctionPredicateLiteral and
124+ msg =
125+ "This formula of " + c .toString ( ) +
126+ " predicate calls can be replaced with a single call on a set literal, improving readability."
127+ ) and
87128 c = count ( d .getAnOperandRec ( ) ) and
88129 c >= 4
89- select d , "This formula can be replaced with equality on a set literal, improving readability."
130+ select d , msg
0 commit comments