1
+ /**
2
+ * Contains predicates and classes relating to support methods for tests, such as the `source()` and `sink()`.
3
+ */
4
+
1
5
import java
2
6
private import semmle.code.java.dataflow.internal.DataFlowUtil
3
7
private import semmle.code.java.dataflow.ExternalFlow
@@ -53,22 +57,27 @@ private Content getContent(SummaryComponent component) {
53
57
component = SummaryComponent:: content ( result )
54
58
}
55
59
60
+ /** Contains utility predicates for getting relevant support methods. */
56
61
module SupportMethod {
62
+ /** Gets a generator method for the content type of the head of the component stack `c`. */
57
63
GenMethod genMethodForContent ( SummaryComponentStack c ) {
58
64
result = genMethodFor ( any ( VoidType v ) , c )
59
65
}
60
66
67
+ /** Gets a generator method for the type `t` and the content type of the head of the component stack `c`. */
61
68
GenMethod genMethodFor ( Type t , SummaryComponentStack c ) {
62
69
result =
63
70
min ( GenMethod g |
64
71
g = min ( GenMethod g1 | g1 .appliesTo ( t , getContent ( c .head ( ) ) ) | g1 order by g1 .getPriority ( ) )
65
72
)
66
73
}
67
74
75
+ /** Gets a getter method for the content type of the head of the component stack `c`. */
68
76
GetMethod getMethodForContent ( SummaryComponentStack c ) {
69
77
result = getMethodFor ( any ( VoidType v ) , c )
70
78
}
71
79
80
+ /** Gets a getter method for the type `t` and the content type of the head of the component stack `c`. */
72
81
GetMethod getMethodFor ( Type t , SummaryComponentStack c ) {
73
82
result =
74
83
min ( GetMethod g |
@@ -77,10 +86,15 @@ module SupportMethod {
77
86
}
78
87
}
79
88
89
+ /**
90
+ * A support method for tests, such as `source()` or `sink()`.
91
+ */
80
92
bindingset [ this ]
81
93
abstract class SupportMethod extends string {
94
+ /** Gets an import that is required for this support method. */
82
95
string getARequiredImport ( ) { none ( ) }
83
96
97
+ /** Gets the Java definition of this support method, if one is necessary. */
84
98
string getDefinition ( ) { none ( ) }
85
99
86
100
/** Gets the priority of this support method. Lower priorities are preferred when multiple support methods apply. */
@@ -96,18 +110,27 @@ abstract class SupportMethod extends string {
96
110
string getCsvModel ( ) { none ( ) }
97
111
}
98
112
113
+ /**
114
+ * The method `source()` which is considered as the source for the flow test.
115
+ */
99
116
class SourceMethod extends SupportMethod {
100
117
SourceMethod ( ) { this = "source" }
101
118
102
119
override string getDefinition ( ) { result = "Object source() { return null; }" }
103
120
}
104
121
122
+ /**
123
+ * The method `sink()` which is considered as the sink for the flow test.
124
+ */
105
125
class SinkMethod extends SupportMethod {
106
126
SinkMethod ( ) { this = "sink" }
107
127
108
128
override string getDefinition ( ) { result = "void sink(Object o) { }" }
109
129
}
110
130
131
+ /**
132
+ * A method for getting content from a type.
133
+ */
111
134
bindingset [ this ]
112
135
abstract class GetMethod extends SupportMethod {
113
136
/**
@@ -245,6 +268,9 @@ private class ArrayGetMethod extends GetMethod {
245
268
override string getCall ( string arg ) { result = "getArrayElement(" + arg + ")" }
246
269
}
247
270
271
+ /**
272
+ * A method for generating a type with content.
273
+ */
248
274
bindingset [ this ]
249
275
abstract class GenMethod extends SupportMethod {
250
276
/**
0 commit comments