@@ -12,35 +12,35 @@ import java
12
12
*/
13
13
predicate conditionCheckMethod ( Method m , boolean checkTrue ) {
14
14
conditionCheckMethod ( m , 0 , checkTrue )
15
+ }
16
+
17
+ /**
18
+ * Holds if `m` is a non-overridable method that checks that its zero-indexed `argument`
19
+ * is equal to `checkTrue` and throws otherwise.
20
+ */
21
+ predicate conditionCheckMethod ( Method m , int argument , boolean checkTrue ) {
22
+ condtionCheckMethodGooglePreconditions ( m , checkTrue ) and argument = 0
15
23
or
16
- m .getDeclaringType ( ) .hasQualifiedName ( "com.google.common.base" , "Preconditions" ) and
17
- checkTrue = true and
18
- ( m .hasName ( "checkArgument" ) or m .hasName ( "checkState" ) )
19
- or
20
- m .getDeclaringType ( ) .hasQualifiedName ( "org.apache.commons.lang3" , "Validate" ) and
21
- checkTrue = true and
22
- ( m .hasName ( "isTrue" ) or m .hasName ( "validState" ) )
24
+ conditionCheckMethodApacheCommonsLang3Validate ( m , checkTrue ) and argument = 0
23
25
or
24
- m .getDeclaringType ( ) .hasQualifiedName ( "org.junit" , "Assume" ) and
25
- checkTrue = true and
26
- m .hasName ( "assumeTrue" )
26
+ condtionCheckMethodTestingFramework ( m , argument , checkTrue )
27
27
or
28
- m . getDeclaringType ( ) . hasQualifiedName ( "org.junit.jupiter.api" , "Assertions" ) and
29
- (
30
- checkTrue = true and m . hasName ( "assertTrue" )
31
- or
32
- checkTrue = false and m . hasName ( "assertFalse" )
33
- )
34
- or
35
- m . getDeclaringType ( ) . hasQualifiedName ( "org.junit.jupiter.api" , "Assumptions" ) and
36
- (
37
- checkTrue = true and m . hasName ( "assumeTrue" )
38
- or
39
- checkTrue = false and m . hasName ( "assumeFalse" )
28
+ exists ( Parameter p , MethodAccess ma , int argIndex , boolean ct , Expr arg |
29
+ p = m . getParameter ( argument ) and
30
+ not m . isOverridable ( ) and
31
+ m . getBody ( ) . getStmt ( 0 ) . ( ExprStmt ) . getExpr ( ) = ma and
32
+ conditionCheck ( ma , argIndex , ct ) and
33
+ ma . getArgument ( argIndex ) = arg and
34
+ (
35
+ arg . ( LogNotExpr ) . getExpr ( ) . ( VarAccess ) . getVariable ( ) = p and
36
+ checkTrue = ct . booleanNot ( )
37
+ or
38
+ arg . ( VarAccess ) . getVariable ( ) = p and checkTrue = ct
39
+ )
40
40
)
41
41
or
42
42
exists ( Parameter p , IfStmt ifstmt , Expr cond |
43
- p = m .getParameter ( 0 ) and
43
+ p = m .getParameter ( argument ) and
44
44
not m .isOverridable ( ) and
45
45
p .getType ( ) instanceof BooleanType and
46
46
m .getBody ( ) .getStmt ( 0 ) = ifstmt and
@@ -57,12 +57,43 @@ predicate conditionCheckMethod(Method m, boolean checkTrue) {
57
57
)
58
58
}
59
59
60
+ private predicate condtionCheckMethodGooglePreconditions ( Method m , boolean checkTrue ) {
61
+ m .getDeclaringType ( ) .hasQualifiedName ( "com.google.common.base" , "Preconditions" ) and
62
+ checkTrue = true and
63
+ ( m .hasName ( "checkArgument" ) or m .hasName ( "checkState" ) )
64
+ }
65
+
66
+ private predicate conditionCheckMethodApacheCommonsLang3Validate ( Method m , boolean checkTrue ) {
67
+ m .getDeclaringType ( ) .hasQualifiedName ( "org.apache.commons.lang3" , "Validate" ) and
68
+ checkTrue = true and
69
+ ( m .hasName ( "isTrue" ) or m .hasName ( "validState" ) )
70
+ }
71
+
60
72
/**
61
- * Holds if `m` is a non-overridable method that checks that its zero-indexed ` argument`
73
+ * Holds if `m` is a non-overridable testing framework methopd that checks that its first argument
62
74
* is equal to `checkTrue` and throws otherwise.
63
75
*/
64
- predicate conditionCheckMethod ( Method m , int argument , boolean checkTrue ) {
65
- conditionCheckMethod ( m , checkTrue ) and argument = 0
76
+ private predicate condtionCheckMethodTestingFramework ( Method m , int argument , boolean checkTrue ) {
77
+ argument = 0 and
78
+ (
79
+ m .getDeclaringType ( ) .hasQualifiedName ( "org.junit" , "Assume" ) and
80
+ checkTrue = true and
81
+ m .hasName ( "assumeTrue" )
82
+ or
83
+ m .getDeclaringType ( ) .hasQualifiedName ( "org.junit.jupiter.api" , "Assertions" ) and
84
+ (
85
+ checkTrue = true and m .hasName ( "assertTrue" )
86
+ or
87
+ checkTrue = false and m .hasName ( "assertFalse" )
88
+ )
89
+ or
90
+ m .getDeclaringType ( ) .hasQualifiedName ( "org.junit.jupiter.api" , "Assumptions" ) and
91
+ (
92
+ checkTrue = true and m .hasName ( "assumeTrue" )
93
+ or
94
+ checkTrue = false and m .hasName ( "assumeFalse" )
95
+ )
96
+ )
66
97
or
67
98
m .getDeclaringType ( ) .hasQualifiedName ( [ "org.junit" , "org.testng" ] , "Assert" ) and
68
99
m .getParameter ( argument ) .getType ( ) instanceof BooleanType and
@@ -71,29 +102,13 @@ predicate conditionCheckMethod(Method m, int argument, boolean checkTrue) {
71
102
or
72
103
checkTrue = false and m .hasName ( "assertFalse" )
73
104
)
74
- or
75
- exists ( Parameter p , MethodAccess ma , int argIndex , boolean ct , Expr arg |
76
- p = m .getParameter ( argument ) and
77
- not m .isOverridable ( ) and
78
- m .getBody ( ) .getStmt ( 0 ) .( ExprStmt ) .getExpr ( ) = ma and
79
- conditionCheck ( ma , argIndex , ct ) and
80
- ma .getArgument ( argIndex ) = arg and
81
- (
82
- arg .( LogNotExpr ) .getExpr ( ) .( VarAccess ) .getVariable ( ) = p and
83
- checkTrue = ct .booleanNot ( )
84
- or
85
- arg .( VarAccess ) .getVariable ( ) = p and checkTrue = ct
86
- )
87
- )
88
105
}
89
106
90
107
/**
91
108
* Holds if `ma` is an access to a non-overridable method that checks that its
92
109
* first argument is equal to `checkTrue` and throws otherwise.
93
110
*/
94
- predicate conditionCheck ( MethodAccess ma , boolean checkTrue ) {
95
- conditionCheckMethod ( ma .getMethod ( ) .getSourceDeclaration ( ) , checkTrue )
96
- }
111
+ predicate conditionCheck ( MethodAccess ma , boolean checkTrue ) { conditionCheck ( ma , 0 , checkTrue ) }
97
112
98
113
/**
99
114
* Holds if `ma` is an access to a non-overridable method that checks that its
0 commit comments