mirror of
https://github.com/github/codeql.git
synced 2026-04-28 18:25:24 +02:00
Kotlin: qlformat some test queries
This commit is contained in:
@@ -1,16 +1,14 @@
|
||||
import java
|
||||
|
||||
class ExtLibParameter extends Parameter {
|
||||
ExtLibParameter() {
|
||||
this.getCallable().getName() = ["testParameterTypes", "takesSelfMethod"]
|
||||
}
|
||||
ExtLibParameter() { this.getCallable().getName() = ["testParameterTypes", "takesSelfMethod"] }
|
||||
}
|
||||
|
||||
query predicate parameterTypes(ExtLibParameter p, string t) {
|
||||
p.getType().toString() = t
|
||||
}
|
||||
query predicate parameterTypes(ExtLibParameter p, string t) { p.getType().toString() = t }
|
||||
|
||||
query predicate arrayTypes(ExtLibParameter p, Array at, string elementType, int dimension, string componentType) {
|
||||
query predicate arrayTypes(
|
||||
ExtLibParameter p, Array at, string elementType, int dimension, string componentType
|
||||
) {
|
||||
p.getType() = at and
|
||||
at.getElementType().toString() = elementType and
|
||||
at.getDimension() = dimension and
|
||||
@@ -19,7 +17,11 @@ query predicate arrayTypes(ExtLibParameter p, Array at, string elementType, int
|
||||
|
||||
query predicate wildcardTypes(ExtLibParameter p, Wildcard wc, string boundKind, string bound) {
|
||||
// Expose details of wildcard types:
|
||||
wc = [p.getType().(ParameterizedType).getATypeArgument(), p.getType().(ParameterizedType).getATypeArgument().(ParameterizedType).getATypeArgument()] and
|
||||
wc =
|
||||
[
|
||||
p.getType().(ParameterizedType).getATypeArgument(),
|
||||
p.getType().(ParameterizedType).getATypeArgument().(ParameterizedType).getATypeArgument()
|
||||
] and
|
||||
(
|
||||
boundKind = "upper" and bound = wc.getUpperBoundType().toString()
|
||||
or
|
||||
@@ -35,6 +37,4 @@ query predicate parameterizedTypes(ExtLibParameter p, string ptstr, string typeA
|
||||
)
|
||||
}
|
||||
|
||||
query predicate libCallables(Callable c) {
|
||||
c.getFile().getBaseName().matches("%Lib.java")
|
||||
}
|
||||
query predicate libCallables(Callable c) { c.getFile().getBaseName().matches("%Lib.java") }
|
||||
|
||||
@@ -7,7 +7,18 @@ class AnonymousCompilation extends Compilation {
|
||||
from Compilation c, int i, File f
|
||||
where f = c.getFileCompiled(i)
|
||||
select c, i, f,
|
||||
any(string s | if c.fileCompiledSuccessful(i) then s = "Extraction successful" else s = "Not extraction successful"),
|
||||
any(string s | if c.fileCompiledRecoverableErrors(i) then s = "Recoverable errors" else s = "Not recoverable errors"),
|
||||
any(string s | if c.fileCompiledNonRecoverableErrors(i) then s = "Non-recoverable errors" else s = "Not non-recoverable errors")
|
||||
|
||||
any(string s |
|
||||
if c.fileCompiledSuccessful(i)
|
||||
then s = "Extraction successful"
|
||||
else s = "Not extraction successful"
|
||||
),
|
||||
any(string s |
|
||||
if c.fileCompiledRecoverableErrors(i)
|
||||
then s = "Recoverable errors"
|
||||
else s = "Not recoverable errors"
|
||||
),
|
||||
any(string s |
|
||||
if c.fileCompiledNonRecoverableErrors(i)
|
||||
then s = "Non-recoverable errors"
|
||||
else s = "Not non-recoverable errors"
|
||||
)
|
||||
|
||||
@@ -6,8 +6,19 @@ class AnonymousCompilation extends Compilation {
|
||||
|
||||
from Compilation c
|
||||
select c,
|
||||
any(string s | if c.normalTermination() then s = "Normal termination" else s = "Not normal termination"),
|
||||
any(string s | if c.extractionSuccessful() then s = "Extraction successful" else s = "Not extraction successful"),
|
||||
any(string s | if c.recoverableErrors() then s = "Recoverable errors" else s = "Not recoverable errors"),
|
||||
any(string s | if c.nonRecoverableErrors() then s = "Non-recoverable errors" else s = "Not non-recoverable errors")
|
||||
|
||||
any(string s |
|
||||
if c.normalTermination() then s = "Normal termination" else s = "Not normal termination"
|
||||
),
|
||||
any(string s |
|
||||
if c.extractionSuccessful()
|
||||
then s = "Extraction successful"
|
||||
else s = "Not extraction successful"
|
||||
),
|
||||
any(string s |
|
||||
if c.recoverableErrors() then s = "Recoverable errors" else s = "Not recoverable errors"
|
||||
),
|
||||
any(string s |
|
||||
if c.nonRecoverableErrors()
|
||||
then s = "Non-recoverable errors"
|
||||
else s = "Not non-recoverable errors"
|
||||
)
|
||||
|
||||
@@ -6,16 +6,17 @@ predicate isInterestingClass(Class c) {
|
||||
|
||||
from Callable c, string paramOrReturnName, Type paramOrReturnType
|
||||
where
|
||||
isInterestingClass(c.getDeclaringType()) and
|
||||
(
|
||||
exists(Parameter p |
|
||||
p = c.getAParameter() and
|
||||
paramOrReturnName = p.getName() and
|
||||
paramOrReturnType = p.getType()
|
||||
isInterestingClass(c.getDeclaringType()) and
|
||||
(
|
||||
exists(Parameter p |
|
||||
p = c.getAParameter() and
|
||||
paramOrReturnName = p.getName() and
|
||||
paramOrReturnType = p.getType()
|
||||
)
|
||||
or
|
||||
paramOrReturnName = "return" and
|
||||
paramOrReturnType = c.getReturnType() and
|
||||
not paramOrReturnType instanceof VoidType
|
||||
)
|
||||
or
|
||||
paramOrReturnName = "return" and
|
||||
paramOrReturnType = c.getReturnType() and
|
||||
not paramOrReturnType instanceof VoidType
|
||||
)
|
||||
select c.getDeclaringType().getQualifiedName(), c.getName(), paramOrReturnName, paramOrReturnType.toString()
|
||||
select c.getDeclaringType().getQualifiedName(), c.getName(), paramOrReturnName,
|
||||
paramOrReturnType.toString()
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
import java
|
||||
|
||||
import semmle.code.java.dataflow.DataFlow
|
||||
import DataFlow::PathGraph
|
||||
|
||||
class Config extends DataFlow::Configuration {
|
||||
|
||||
Config() { this = "Config" }
|
||||
|
||||
override predicate isSource(DataFlow::Node n) {
|
||||
n.asExpr().(StringLiteral).getValue() = "taint"
|
||||
}
|
||||
override predicate isSource(DataFlow::Node n) { n.asExpr().(StringLiteral).getValue() = "taint" }
|
||||
|
||||
override predicate isSink(DataFlow::Node n) {
|
||||
n.asExpr().(Argument).getCall().getCallee().getName() = "sink"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
from DataFlow::PathNode source, DataFlow::PathNode sink, Config c
|
||||
|
||||
@@ -3,4 +3,3 @@ import external.ExternalArtifact
|
||||
from ExternalData ed
|
||||
where ed.getDataPath().matches("%logs.csv")
|
||||
select ed.getFieldAsInt(0), ed.getFieldAsInt(1), ed.getField(2), ed.getField(3), ed.getField(4)
|
||||
|
||||
|
||||
@@ -30,21 +30,27 @@ query predicate nestedTypes(NestedType nt, RefType parent) {
|
||||
parent = nt.getEnclosingType()
|
||||
}
|
||||
|
||||
query predicate javaKotlinCalleeAgreement(MethodAccess javaMa, MethodAccess kotlinMa, Callable callee) {
|
||||
query predicate javaKotlinCalleeAgreement(
|
||||
MethodAccess javaMa, MethodAccess kotlinMa, Callable callee
|
||||
) {
|
||||
javaMa.getCallee() = callee and
|
||||
kotlinMa.getCallee() = callee and
|
||||
javaMa.getFile().getExtension() = "java" and
|
||||
kotlinMa.getFile().getExtension() = "kt"
|
||||
}
|
||||
|
||||
query predicate javaKotlinConstructorAgreement(ClassInstanceExpr javaCie, ClassInstanceExpr kotlinCie, Constructor constructor) {
|
||||
query predicate javaKotlinConstructorAgreement(
|
||||
ClassInstanceExpr javaCie, ClassInstanceExpr kotlinCie, Constructor constructor
|
||||
) {
|
||||
javaCie.getConstructor() = constructor and
|
||||
kotlinCie.getConstructor() = constructor and
|
||||
javaCie.getFile().getExtension() = "java" and
|
||||
kotlinCie.getFile().getExtension() = "kt"
|
||||
}
|
||||
|
||||
query predicate javaKotlinLocalTypeAgreement(LocalVariableDecl javaDecl, LocalVariableDecl kotlinDecl, RefType agreedType) {
|
||||
query predicate javaKotlinLocalTypeAgreement(
|
||||
LocalVariableDecl javaDecl, LocalVariableDecl kotlinDecl, RefType agreedType
|
||||
) {
|
||||
javaDecl.getType() = agreedType and
|
||||
kotlinDecl.getType() = agreedType and
|
||||
javaDecl.getFile().getExtension() = "java" and
|
||||
|
||||
@@ -3,11 +3,11 @@ import java
|
||||
// Stop external filepaths from appearing in the results
|
||||
class ClassOrInterfaceLocation extends ClassOrInterface {
|
||||
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
|
||||
exists(string fullPath |
|
||||
super.hasLocationInfo(fullPath, sl, sc, el, ec) |
|
||||
if exists(this.getFile().getRelativePath())
|
||||
then path = fullPath
|
||||
else path = fullPath.regexpReplaceAll(".*/", "<external>/"))
|
||||
exists(string fullPath | super.hasLocationInfo(fullPath, sl, sc, el, ec) |
|
||||
if exists(this.getFile().getRelativePath())
|
||||
then path = fullPath
|
||||
else path = fullPath.regexpReplaceAll(".*/", "<external>/")
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,15 +17,14 @@ query predicate rawTypeSupertypes(RawType rt, RefType superType) {
|
||||
}
|
||||
|
||||
query predicate rawTypeMethod(RefType rt, string name, string sig, string paramType, string retType) {
|
||||
|
||||
exists(Method m | m.getDeclaringType() = rt and rt.getName().matches("RawTypesInSignature%") |
|
||||
name = m.getName()
|
||||
and
|
||||
sig = m.getSignature()
|
||||
and
|
||||
(if exists(m.getAParamType()) then paramType = m.getAParamType().toString() else paramType = "No parameter")
|
||||
and
|
||||
name = m.getName() and
|
||||
sig = m.getSignature() and
|
||||
(
|
||||
if exists(m.getAParamType())
|
||||
then paramType = m.getAParamType().toString()
|
||||
else paramType = "No parameter"
|
||||
) and
|
||||
retType = m.getReturnType().toString()
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user