Skip to content

Commit b42457c

Browse files
authored
Merge pull request #2540 from github/koesie10/update-external-api-qll
Update ExternalApi.qll dependencies
2 parents cd69e59 + 2e7c86d commit b42457c

File tree

2 files changed

+23
-30
lines changed

2 files changed

+23
-30
lines changed

extensions/ql-vscode/src/data-extensions-editor/queries/csharp.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ class ExternalApi extends DotNet::Callable {
7575
not isUninteresting(this)
7676
}
7777
78+
/**
79+
* Gets the unbound type, name and parameter types of this API.
80+
*/
81+
bindingset[this]
82+
private string getSignature() {
83+
result =
84+
this.getDeclaringType().getUnboundDeclaration() + "." + this.getName() + "(" +
85+
parameterQualifiedTypeNamesToString(this) + ")"
86+
}
87+
7888
/**
7989
* Gets the namespace of this API.
8090
*/
@@ -85,8 +95,7 @@ class ExternalApi extends DotNet::Callable {
8595
* Gets the namespace and signature of this API.
8696
*/
8797
bindingset[this]
88-
string getApiName() { result = this.getNamespace() + "." + this.getDeclaringType().getUnboundDeclaration() + "#" + this.getName() + "(" +
89-
parameterQualifiedTypeNamesToString(this) + ")" }
98+
string getApiName() { result = this.getNamespace() + "#" + this.getSignature() }
9099
91100
/** Gets a node that is an input to a call to this API. */
92101
private ArgumentNode getAnInput() {
@@ -146,7 +155,7 @@ class ExternalApi extends DotNet::Callable {
146155
int resultLimit() { result = 1000 }
147156
148157
/**
149-
* Holds if it is relevant to count usages of "api".
158+
* Holds if it is relevant to count usages of \`api\`.
150159
*/
151160
signature predicate relevantApi(ExternalApi api);
152161
@@ -174,7 +183,7 @@ module Results<relevantApi/1 getRelevantUsages> {
174183
}
175184
176185
/**
177-
* Holds if there exists an API with "apiName" that is being used "usages" times
186+
* Holds if there exists an API with \`apiName\` that is being used \`usages\` times
178187
* and if it is in the top results (guarded by resultLimit).
179188
*/
180189
predicate restrict(string apiName, int usages) {

extensions/ql-vscode/src/data-extensions-editor/queries/java.ts

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,7 @@ private import semmle.code.java.dataflow.FlowSummary
4141
private import semmle.code.java.dataflow.internal.DataFlowPrivate
4242
private import semmle.code.java.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
4343
private import semmle.code.java.dataflow.TaintTracking
44-
45-
pragma[nomagic]
46-
private predicate isTestPackage(Package p) {
47-
p.getName()
48-
.matches([
49-
"org.junit%", "junit.%", "org.mockito%", "org.assertj%",
50-
"com.github.tomakehurst.wiremock%", "org.hamcrest%", "org.springframework.test.%",
51-
"org.springframework.mock.%", "org.springframework.boot.test.%", "reactor.test%",
52-
"org.xmlunit%", "org.testcontainers.%", "org.opentest4j%", "org.mockserver%",
53-
"org.powermock%", "org.skyscreamer.jsonassert%", "org.rnorth.visibleassertions",
54-
"org.openqa.selenium%", "com.gargoylesoftware.htmlunit%", "org.jboss.arquillian.testng%",
55-
"org.testng%"
56-
])
57-
}
58-
59-
/**
60-
* A test library.
61-
*/
62-
private class TestLibrary extends RefType {
63-
TestLibrary() { isTestPackage(this.getPackage()) }
64-
}
65-
66-
private string containerAsJar(Container container) {
67-
if container instanceof JarFile then result = container.getBaseName() else result = "rt.jar"
68-
}
44+
private import semmle.code.java.dataflow.internal.ModelExclusions
6945
7046
/** Holds if the given callable is not worth supporting. */
7147
private predicate isUninteresting(Callable c) {
@@ -88,10 +64,18 @@ class ExternalApi extends Callable {
8864
"#" + this.getName() + paramsString(this)
8965
}
9066
67+
private string getJarName() {
68+
result = this.getCompilationUnit().getParentContainer*().(JarFile).getBaseName()
69+
}
70+
9171
/**
9272
* Gets the jar file containing this API. Normalizes the Java Runtime to "rt.jar" despite the presence of modules.
9373
*/
94-
string jarContainer() { result = containerAsJar(this.getCompilationUnit().getParentContainer*()) }
74+
string jarContainer() {
75+
result = this.getJarName()
76+
or
77+
not exists(this.getJarName()) and result = "rt.jar"
78+
}
9579
9680
/** Gets a node that is an input to a call to this API. */
9781
private DataFlow::Node getAnInput() {

0 commit comments

Comments
 (0)