Skip to content

Commit 0e5591f

Browse files
author
Stephan Brandauer
committed
move getCallable to signature module implementation, and document it
1 parent a616a78 commit 0e5591f

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

java/ql/src/Telemetry/AutomodelFrameworkModeCharacteristics.qll

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ private import semmle.code.java.dataflow.internal.ModelExclusions as ModelExclus
1717
import AutomodelSharedCharacteristics as SharedCharacteristics
1818
import AutomodelEndpointTypes as AutomodelEndpointTypes
1919

20-
Callable getCallable(DataFlow::ParameterNode e) { result = e.getEnclosingCallable() }
21-
2220
/**
2321
* A meta data extractor. Any Java extraction mode needs to implement exactly
2422
* one instance of this class.
@@ -94,22 +92,29 @@ module FrameworkCandidatesImpl implements SharedCharacteristics::CandidateSig {
9492
Endpoint e, string package, string type, boolean subtypes, string name, string signature,
9593
string ext, string input
9694
) {
97-
package = getCallable(e).getDeclaringType().getPackage().toString() and
98-
type = getCallable(e).getDeclaringType().getName() and
95+
package = FrameworkCandidatesImpl::getCallable(e).getDeclaringType().getPackage().toString() and
96+
type = FrameworkCandidatesImpl::getCallable(e).getDeclaringType().getName() and
9997
subtypes = false and
100-
name = getCallable(e).getName() and
98+
name = FrameworkCandidatesImpl::getCallable(e).getName() and
10199
signature = ExternalFlow::paramsString(getCallable(e)) and
102100
ext = "" and
103101
exists(int paramIdx | e.isParameterOf(_, paramIdx) | input = "Argument[" + paramIdx + "]")
104102
}
105103

106104
RelatedLocation getRelatedLocation(Endpoint e, string name) {
107105
name = "Callable-JavaDoc" and
108-
result = getCallable(e).(Documentable).getJavadoc()
106+
result = FrameworkCandidatesImpl::getCallable(e).(Documentable).getJavadoc()
109107
or
110108
name = "Class-JavaDoc" and
111-
result = getCallable(e).getDeclaringType().(Documentable).getJavadoc()
109+
result = FrameworkCandidatesImpl::getCallable(e).getDeclaringType().(Documentable).getJavadoc()
112110
}
111+
112+
/**
113+
* Returns the callable that contains the given endpoint.
114+
*
115+
* Each Java mode should implement this predicate.
116+
*/
117+
additional Callable getCallable(Endpoint e) { result = e.getEnclosingCallable() }
113118
}
114119

115120
module CharacteristicsImpl = SharedCharacteristics::SharedCharacteristics<FrameworkCandidatesImpl>;
@@ -169,8 +174,8 @@ private class UnexploitableIsCharacteristic extends CharacteristicsImpl::NotASin
169174

170175
override predicate appliesToEndpoint(Endpoint e) {
171176
not FrameworkCandidatesImpl::isSink(e, _) and
172-
getCallable(e).getName().matches("is%") and
173-
getCallable(e).getReturnType() instanceof BooleanType
177+
FrameworkCandidatesImpl::getCallable(e).getName().matches("is%") and
178+
FrameworkCandidatesImpl::getCallable(e).getReturnType() instanceof BooleanType
174179
}
175180
}
176181

@@ -188,7 +193,7 @@ private class UnexploitableExistsCharacteristic extends CharacteristicsImpl::Not
188193
override predicate appliesToEndpoint(Endpoint e) {
189194
not FrameworkCandidatesImpl::isSink(e, _) and
190195
exists(Callable callable |
191-
callable = getCallable(e) and
196+
callable = FrameworkCandidatesImpl::getCallable(e) and
192197
callable.getName().toLowerCase() = ["exists", "notexists"] and
193198
callable.getReturnType() instanceof BooleanType
194199
)
@@ -202,7 +207,8 @@ private class ExceptionCharacteristic extends CharacteristicsImpl::NotASinkChara
202207
ExceptionCharacteristic() { this = "exception" }
203208

204209
override predicate appliesToEndpoint(Endpoint e) {
205-
getCallable(e).getDeclaringType().getASupertype*() instanceof TypeThrowable
210+
FrameworkCandidatesImpl::getCallable(e).getDeclaringType().getASupertype*() instanceof
211+
TypeThrowable
206212
}
207213
}
208214

@@ -243,7 +249,9 @@ private class NonPublicMethodCharacteristic extends CharacteristicsImpl::Uninter
243249
{
244250
NonPublicMethodCharacteristic() { this = "non-public method" }
245251

246-
override predicate appliesToEndpoint(Endpoint e) { not getCallable(e).isPublic() }
252+
override predicate appliesToEndpoint(Endpoint e) {
253+
not FrameworkCandidatesImpl::getCallable(e).isPublic()
254+
}
247255
}
248256

249257
/**

0 commit comments

Comments
 (0)