@@ -16,7 +16,9 @@ import codeql_ql.ast.Ast
16
16
* Identifies predicates whose names start with "get", "as" followed by an uppercase letter.
17
17
* This ensures that only predicates like "getValue" are matched, excluding names like "getter".
18
18
*/
19
- predicate isGetPredicate ( Predicate pred ) { pred .getName ( ) .regexpMatch ( "(get|as)[A-Z].*" ) }
19
+ predicate isGetPredicate ( Predicate pred , string prefix ) {
20
+ prefix = pred .getName ( ) .regexpCapture ( "(get|as)[A-Z].*" , 1 )
21
+ }
20
22
21
23
/**
22
24
* Checks if a predicate has a return type.
@@ -28,21 +30,9 @@ predicate hasReturnType(Predicate pred) { exists(pred.getReturnTypeExpr()) }
28
30
*/
29
31
predicate isAlias ( Predicate pred ) { exists ( pred .( ClasslessPredicate ) .getAlias ( ) ) }
30
32
31
- /**
32
- * Returns "get" if the predicate name starts with "get", otherwise "as".
33
- */
34
- string getPrefix ( Predicate pred ) {
35
- if pred .getName ( ) .matches ( "get%" )
36
- then result = "get"
37
- else
38
- if pred .getName ( ) .matches ( "as%" )
39
- then result = "as"
40
- else result = ""
41
- }
42
-
43
- from Predicate pred
33
+ from Predicate pred , string prefix
44
34
where
45
- isGetPredicate ( pred ) and
35
+ isGetPredicate ( pred , prefix ) and
46
36
not hasReturnType ( pred ) and
47
37
not isAlias ( pred )
48
- select pred , "This predicate starts with '" + getPrefix ( pred ) + "' but does not return a value."
38
+ select pred , "This predicate starts with '" + prefix + "' but does not return a value."
0 commit comments