Skip to content

Commit 0b312b6

Browse files
committed
Kotlin: qlformat some test queries
1 parent 31b3c1f commit 0b312b6

File tree

8 files changed

+77
-55
lines changed

8 files changed

+77
-55
lines changed
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import java
22

33
class ExtLibParameter extends Parameter {
4-
ExtLibParameter() {
5-
this.getCallable().getName() = ["testParameterTypes", "takesSelfMethod"]
6-
}
4+
ExtLibParameter() { this.getCallable().getName() = ["testParameterTypes", "takesSelfMethod"] }
75
}
86

9-
query predicate parameterTypes(ExtLibParameter p, string t) {
10-
p.getType().toString() = t
11-
}
7+
query predicate parameterTypes(ExtLibParameter p, string t) { p.getType().toString() = t }
128

13-
query predicate arrayTypes(ExtLibParameter p, Array at, string elementType, int dimension, string componentType) {
9+
query predicate arrayTypes(
10+
ExtLibParameter p, Array at, string elementType, int dimension, string componentType
11+
) {
1412
p.getType() = at and
1513
at.getElementType().toString() = elementType and
1614
at.getDimension() = dimension and
@@ -19,7 +17,11 @@ query predicate arrayTypes(ExtLibParameter p, Array at, string elementType, int
1917

2018
query predicate wildcardTypes(ExtLibParameter p, Wildcard wc, string boundKind, string bound) {
2119
// Expose details of wildcard types:
22-
wc = [p.getType().(ParameterizedType).getATypeArgument(), p.getType().(ParameterizedType).getATypeArgument().(ParameterizedType).getATypeArgument()] and
20+
wc =
21+
[
22+
p.getType().(ParameterizedType).getATypeArgument(),
23+
p.getType().(ParameterizedType).getATypeArgument().(ParameterizedType).getATypeArgument()
24+
] and
2325
(
2426
boundKind = "upper" and bound = wc.getUpperBoundType().toString()
2527
or
@@ -35,6 +37,4 @@ query predicate parameterizedTypes(ExtLibParameter p, string ptstr, string typeA
3537
)
3638
}
3739

38-
query predicate libCallables(Callable c) {
39-
c.getFile().getBaseName().matches("%Lib.java")
40-
}
40+
query predicate libCallables(Callable c) { c.getFile().getBaseName().matches("%Lib.java") }

java/ql/integration-tests/posix-only/kotlin/extractor_crash/compilationFiles.ql

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@ class AnonymousCompilation extends Compilation {
77
from Compilation c, int i, File f
88
where f = c.getFileCompiled(i)
99
select c, i, f,
10-
any(string s | if c.fileCompiledSuccessful(i) then s = "Extraction successful" else s = "Not extraction successful"),
11-
any(string s | if c.fileCompiledRecoverableErrors(i) then s = "Recoverable errors" else s = "Not recoverable errors"),
12-
any(string s | if c.fileCompiledNonRecoverableErrors(i) then s = "Non-recoverable errors" else s = "Not non-recoverable errors")
13-
10+
any(string s |
11+
if c.fileCompiledSuccessful(i)
12+
then s = "Extraction successful"
13+
else s = "Not extraction successful"
14+
),
15+
any(string s |
16+
if c.fileCompiledRecoverableErrors(i)
17+
then s = "Recoverable errors"
18+
else s = "Not recoverable errors"
19+
),
20+
any(string s |
21+
if c.fileCompiledNonRecoverableErrors(i)
22+
then s = "Non-recoverable errors"
23+
else s = "Not non-recoverable errors"
24+
)

java/ql/integration-tests/posix-only/kotlin/extractor_crash/compilations.ql

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,19 @@ class AnonymousCompilation extends Compilation {
66

77
from Compilation c
88
select c,
9-
any(string s | if c.normalTermination() then s = "Normal termination" else s = "Not normal termination"),
10-
any(string s | if c.extractionSuccessful() then s = "Extraction successful" else s = "Not extraction successful"),
11-
any(string s | if c.recoverableErrors() then s = "Recoverable errors" else s = "Not recoverable errors"),
12-
any(string s | if c.nonRecoverableErrors() then s = "Non-recoverable errors" else s = "Not non-recoverable errors")
13-
9+
any(string s |
10+
if c.normalTermination() then s = "Normal termination" else s = "Not normal termination"
11+
),
12+
any(string s |
13+
if c.extractionSuccessful()
14+
then s = "Extraction successful"
15+
else s = "Not extraction successful"
16+
),
17+
any(string s |
18+
if c.recoverableErrors() then s = "Recoverable errors" else s = "Not recoverable errors"
19+
),
20+
any(string s |
21+
if c.nonRecoverableErrors()
22+
then s = "Non-recoverable errors"
23+
else s = "Not non-recoverable errors"
24+
)

java/ql/integration-tests/posix-only/kotlin/kotlin_java_lowering_wildcards/test.ql

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@ predicate isInterestingClass(Class c) {
66

77
from Callable c, string paramOrReturnName, Type paramOrReturnType
88
where
9-
isInterestingClass(c.getDeclaringType()) and
10-
(
11-
exists(Parameter p |
12-
p = c.getAParameter() and
13-
paramOrReturnName = p.getName() and
14-
paramOrReturnType = p.getType()
9+
isInterestingClass(c.getDeclaringType()) and
10+
(
11+
exists(Parameter p |
12+
p = c.getAParameter() and
13+
paramOrReturnName = p.getName() and
14+
paramOrReturnType = p.getType()
15+
)
16+
or
17+
paramOrReturnName = "return" and
18+
paramOrReturnType = c.getReturnType() and
19+
not paramOrReturnType instanceof VoidType
1520
)
16-
or
17-
paramOrReturnName = "return" and
18-
paramOrReturnType = c.getReturnType() and
19-
not paramOrReturnType instanceof VoidType
20-
)
21-
select c.getDeclaringType().getQualifiedName(), c.getName(), paramOrReturnName, paramOrReturnType.toString()
21+
select c.getDeclaringType().getQualifiedName(), c.getName(), paramOrReturnName,
22+
paramOrReturnType.toString()

java/ql/integration-tests/posix-only/kotlin/kotlin_java_static_fields/test.ql

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
import java
2-
32
import semmle.code.java.dataflow.DataFlow
43
import DataFlow::PathGraph
54

65
class Config extends DataFlow::Configuration {
7-
86
Config() { this = "Config" }
97

10-
override predicate isSource(DataFlow::Node n) {
11-
n.asExpr().(StringLiteral).getValue() = "taint"
12-
}
8+
override predicate isSource(DataFlow::Node n) { n.asExpr().(StringLiteral).getValue() = "taint" }
139

1410
override predicate isSink(DataFlow::Node n) {
1511
n.asExpr().(Argument).getCall().getCallee().getName() = "sink"
1612
}
17-
1813
}
1914

2015
from DataFlow::PathNode source, DataFlow::PathNode sink, Config c

java/ql/integration-tests/posix-only/kotlin/logs/logs.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ import external.ExternalArtifact
33
from ExternalData ed
44
where ed.getDataPath().matches("%logs.csv")
55
select ed.getFieldAsInt(0), ed.getFieldAsInt(1), ed.getField(2), ed.getField(3), ed.getField(4)
6-

java/ql/integration-tests/posix-only/kotlin/nested_generic_types/test.ql

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,27 @@ query predicate nestedTypes(NestedType nt, RefType parent) {
3030
parent = nt.getEnclosingType()
3131
}
3232

33-
query predicate javaKotlinCalleeAgreement(MethodAccess javaMa, MethodAccess kotlinMa, Callable callee) {
33+
query predicate javaKotlinCalleeAgreement(
34+
MethodAccess javaMa, MethodAccess kotlinMa, Callable callee
35+
) {
3436
javaMa.getCallee() = callee and
3537
kotlinMa.getCallee() = callee and
3638
javaMa.getFile().getExtension() = "java" and
3739
kotlinMa.getFile().getExtension() = "kt"
3840
}
3941

40-
query predicate javaKotlinConstructorAgreement(ClassInstanceExpr javaCie, ClassInstanceExpr kotlinCie, Constructor constructor) {
42+
query predicate javaKotlinConstructorAgreement(
43+
ClassInstanceExpr javaCie, ClassInstanceExpr kotlinCie, Constructor constructor
44+
) {
4145
javaCie.getConstructor() = constructor and
4246
kotlinCie.getConstructor() = constructor and
4347
javaCie.getFile().getExtension() = "java" and
4448
kotlinCie.getFile().getExtension() = "kt"
4549
}
4650

47-
query predicate javaKotlinLocalTypeAgreement(LocalVariableDecl javaDecl, LocalVariableDecl kotlinDecl, RefType agreedType) {
51+
query predicate javaKotlinLocalTypeAgreement(
52+
LocalVariableDecl javaDecl, LocalVariableDecl kotlinDecl, RefType agreedType
53+
) {
4854
javaDecl.getType() = agreedType and
4955
kotlinDecl.getType() = agreedType and
5056
javaDecl.getFile().getExtension() = "java" and

java/ql/integration-tests/posix-only/kotlin/raw_generic_types/test.ql

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import java
33
// Stop external filepaths from appearing in the results
44
class ClassOrInterfaceLocation extends ClassOrInterface {
55
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
6-
exists(string fullPath |
7-
super.hasLocationInfo(fullPath, sl, sc, el, ec) |
8-
if exists(this.getFile().getRelativePath())
9-
then path = fullPath
10-
else path = fullPath.regexpReplaceAll(".*/", "<external>/"))
6+
exists(string fullPath | super.hasLocationInfo(fullPath, sl, sc, el, ec) |
7+
if exists(this.getFile().getRelativePath())
8+
then path = fullPath
9+
else path = fullPath.regexpReplaceAll(".*/", "<external>/")
10+
)
1111
}
1212
}
1313

@@ -17,15 +17,14 @@ query predicate rawTypeSupertypes(RawType rt, RefType superType) {
1717
}
1818

1919
query predicate rawTypeMethod(RefType rt, string name, string sig, string paramType, string retType) {
20-
2120
exists(Method m | m.getDeclaringType() = rt and rt.getName().matches("RawTypesInSignature%") |
22-
name = m.getName()
23-
and
24-
sig = m.getSignature()
25-
and
26-
(if exists(m.getAParamType()) then paramType = m.getAParamType().toString() else paramType = "No parameter")
27-
and
21+
name = m.getName() and
22+
sig = m.getSignature() and
23+
(
24+
if exists(m.getAParamType())
25+
then paramType = m.getAParamType().toString()
26+
else paramType = "No parameter"
27+
) and
2828
retType = m.getReturnType().toString()
2929
)
30-
3130
}

0 commit comments

Comments
 (0)