Skip to content

Commit f734edf

Browse files
committed
C#/Java: Minor refactor and re-arranging of code to align the CaptureModel specific implementations.
1 parent dd267b3 commit f734edf

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

csharp/ql/src/utils/model-generator/internal/CaptureModelsSpecific.qll

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ predicate asPartialModel = DataFlowPrivate::Csv::asPartialModel/1;
4545
*/
4646
predicate isRelevantType(CS::Type t) { not t instanceof CS::Enum }
4747

48+
/**
49+
* Gets the CSV string representation of the qualifier.
50+
*/
51+
string qualifierString() { result = "Argument[Qualifier]" }
52+
4853
private string parameterAccess(CS::Parameter p) {
4954
if Collections::isCollectionType(p.getType())
5055
then result = "Argument[" + p.getPosition() + "].Element"
@@ -57,7 +62,7 @@ private string parameterAccess(CS::Parameter p) {
5762
string parameterNodeAsInput(DataFlow::ParameterNode p) {
5863
result = parameterAccess(p.asParameter())
5964
or
60-
result = "Argument[Qualifier]" and p instanceof DataFlowPrivate::InstanceParameterNode
65+
result = qualifierString() and p instanceof DataFlowPrivate::InstanceParameterNode
6166
}
6267

6368
pragma[nomagic]
@@ -78,7 +83,7 @@ string returnNodeAsOutput(DataFlowImplCommon::ReturnNodeExt node) {
7883
result = parameterAccess(getParameter(node, pos))
7984
or
8085
pos.isThisParameter() and
81-
result = "Argument[Qualifier]"
86+
result = qualifierString()
8287
)
8388
}
8489

@@ -96,17 +101,6 @@ predicate isOwnInstanceAccessNode(DataFlowPrivate::ReturnNode node) {
96101
node.asExpr() instanceof CS::ThisAccess
97102
}
98103

99-
/**
100-
* Gets the CSV string representation of the qualifier.
101-
*/
102-
string qualifierString() { result = "Argument[Qualifier]" }
103-
104-
/**
105-
* Holds if `kind` is a relevant sink kind for creating sink models.
106-
*/
107-
bindingset[kind]
108-
predicate isRelevantSinkKind(string kind) { any() }
109-
110104
private predicate isRelevantMemberAccess(DataFlow::Node node) {
111105
exists(CS::MemberAccess access | access = node.asExpr() |
112106
access.hasThisQualifier() and
@@ -143,3 +137,9 @@ string asInputArgument(DataFlow::Node source) {
143137
source.asExpr() instanceof DataFlowPrivate::FieldOrPropertyAccess and
144138
result = qualifierString()
145139
}
140+
141+
/**
142+
* Holds if `kind` is a relevant sink kind for creating sink models.
143+
*/
144+
bindingset[kind]
145+
predicate isRelevantSinkKind(string kind) { any() }

java/ql/src/utils/model-generator/internal/CaptureModelsSpecific.qll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ predicate isRelevantType(J::Type t) {
137137
)
138138
}
139139

140+
/**
141+
* Gets the CSV string representation of the qualifier.
142+
*/
143+
string qualifierString() { result = "Argument[-1]" }
144+
140145
private string parameterAccess(J::Parameter p) {
141146
if
142147
p.getType() instanceof J::Array and
@@ -154,7 +159,7 @@ private string parameterAccess(J::Parameter p) {
154159
string parameterNodeAsInput(DataFlow::ParameterNode p) {
155160
result = parameterAccess(p.asParameter())
156161
or
157-
result = "Argument[-1]" and p instanceof DataFlow::InstanceParameterNode
162+
result = qualifierString() and p instanceof DataFlow::InstanceParameterNode
158163
}
159164

160165
/**
@@ -169,7 +174,7 @@ string returnNodeAsOutput(DataFlowImplCommon::ReturnNodeExt node) {
169174
|
170175
result = parameterAccess(node.getEnclosingCallable().getParameter(pos))
171176
or
172-
result = "Argument[-1]" and pos = -1
177+
result = qualifierString() and pos = -1
173178
)
174179
}
175180

@@ -187,11 +192,6 @@ predicate isOwnInstanceAccessNode(ReturnNode node) {
187192
node.asExpr().(J::ThisAccess).isOwnInstanceAccess()
188193
}
189194

190-
/**
191-
* Gets the CSV string representation of the qualifier.
192-
*/
193-
string qualifierString() { result = "Argument[-1]" }
194-
195195
/**
196196
* Language specific parts of the `PropagateToSinkConfiguration`.
197197
*/

0 commit comments

Comments
 (0)