1+ /**
2+ * Contains predicates and classes relating to support methods for tests, such as the `source()` and `sink()`.
3+ */
4+
15import java
26private import semmle.code.java.dataflow.internal.DataFlowUtil
37private import semmle.code.java.dataflow.ExternalFlow
@@ -53,22 +57,27 @@ private Content getContent(SummaryComponent component) {
5357 component = SummaryComponent:: content ( result )
5458}
5559
60+ /** Contains utility predicates for getting relevant support methods. */
5661module SupportMethod {
62+ /** Gets a generator method for the content type of the head of the component stack `c`. */
5763 GenMethod genMethodForContent ( SummaryComponentStack c ) {
5864 result = genMethodFor ( any ( VoidType v ) , c )
5965 }
6066
67+ /** Gets a generator method for the type `t` and the content type of the head of the component stack `c`. */
6168 GenMethod genMethodFor ( Type t , SummaryComponentStack c ) {
6269 result =
6370 min ( GenMethod g |
6471 g = min ( GenMethod g1 | g1 .appliesTo ( t , getContent ( c .head ( ) ) ) | g1 order by g1 .getPriority ( ) )
6572 )
6673 }
6774
75+ /** Gets a getter method for the content type of the head of the component stack `c`. */
6876 GetMethod getMethodForContent ( SummaryComponentStack c ) {
6977 result = getMethodFor ( any ( VoidType v ) , c )
7078 }
7179
80+ /** Gets a getter method for the type `t` and the content type of the head of the component stack `c`. */
7281 GetMethod getMethodFor ( Type t , SummaryComponentStack c ) {
7382 result =
7483 min ( GetMethod g |
@@ -77,10 +86,15 @@ module SupportMethod {
7786 }
7887}
7988
89+ /**
90+ * A support method for tests, such as `source()` or `sink()`.
91+ */
8092bindingset [ this ]
8193abstract class SupportMethod extends string {
94+ /** Gets an import that is required for this support method. */
8295 string getARequiredImport ( ) { none ( ) }
8396
97+ /** Gets the Java definition of this support method, if one is necessary. */
8498 string getDefinition ( ) { none ( ) }
8599
86100 /** 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 {
96110 string getCsvModel ( ) { none ( ) }
97111}
98112
113+ /**
114+ * The method `source()` which is considered as the source for the flow test.
115+ */
99116class SourceMethod extends SupportMethod {
100117 SourceMethod ( ) { this = "source" }
101118
102119 override string getDefinition ( ) { result = "Object source() { return null; }" }
103120}
104121
122+ /**
123+ * The method `sink()` which is considered as the sink for the flow test.
124+ */
105125class SinkMethod extends SupportMethod {
106126 SinkMethod ( ) { this = "sink" }
107127
108128 override string getDefinition ( ) { result = "void sink(Object o) { }" }
109129}
110130
131+ /**
132+ * A method for getting content from a type.
133+ */
111134bindingset [ this ]
112135abstract class GetMethod extends SupportMethod {
113136 /**
@@ -245,6 +268,9 @@ private class ArrayGetMethod extends GetMethod {
245268 override string getCall ( string arg ) { result = "getArrayElement(" + arg + ")" }
246269}
247270
271+ /**
272+ * A method for generating a type with content.
273+ */
248274bindingset [ this ]
249275abstract class GenMethod extends SupportMethod {
250276 /**
0 commit comments