mirror of
https://github.com/github/codeql.git
synced 2026-04-27 01:35:13 +02:00
Kotlin: Pull Kotlin type for methods/constrs out into their own tables
This commit is contained in:
@@ -2,6 +2,8 @@ import java
|
||||
|
||||
predicate badKotlinType(Element e, int i) {
|
||||
e = any(Expr expr | count(expr.getKotlinType()) = i) or
|
||||
e = any(Constructor c | count(c.getReturnKotlinType()) = i) or
|
||||
e = any(Method m | count(m.getReturnKotlinType()) = i) or
|
||||
e = any(Field f | count(f.getKotlinType()) = i)
|
||||
}
|
||||
|
||||
|
||||
@@ -413,21 +413,29 @@ constrs(
|
||||
string nodeName: string ref,
|
||||
string signature: string ref,
|
||||
int typeid: @type ref,
|
||||
int kttypeid: @kt_type ref,
|
||||
int parentid: @reftype ref,
|
||||
int sourceid: @constructor ref
|
||||
);
|
||||
|
||||
constrsKotlinType(
|
||||
unique int id: @constructor ref,
|
||||
int kttypeid: @kt_type ref
|
||||
)
|
||||
|
||||
methods(
|
||||
unique int id: @method,
|
||||
string nodeName: string ref,
|
||||
string signature: string ref,
|
||||
int typeid: @type ref,
|
||||
int kttypeid: @kt_type ref,
|
||||
int parentid: @reftype ref,
|
||||
int sourceid: @method ref
|
||||
);
|
||||
|
||||
methodsKotlinType(
|
||||
unique int id: @method ref,
|
||||
int kttypeid: @kt_type ref
|
||||
)
|
||||
|
||||
#keyset[parentid,pos]
|
||||
params(
|
||||
unique int id: @param,
|
||||
|
||||
@@ -16,9 +16,9 @@ predicate hasName(Element e, string name) {
|
||||
or
|
||||
primitives(e, name)
|
||||
or
|
||||
constrs(e, name, _, _, _, _, _)
|
||||
constrs(e, name, _, _, _, _)
|
||||
or
|
||||
methods(e, name, _, _, _, _, _)
|
||||
methods(e, name, _, _, _, _)
|
||||
or
|
||||
fields(e, name, _, _, _)
|
||||
or
|
||||
|
||||
@@ -138,11 +138,11 @@ class AnnotationType extends Interface {
|
||||
|
||||
/** Gets the annotation element with the specified `name`. */
|
||||
AnnotationElement getAnnotationElement(string name) {
|
||||
methods(result, _, _, _, _, this, _) and result.hasName(name)
|
||||
methods(result, _, _, _, this, _) and result.hasName(name)
|
||||
}
|
||||
|
||||
/** Gets an annotation element that is a member of this annotation type. */
|
||||
AnnotationElement getAnAnnotationElement() { methods(result, _, _, _, _, this, _) }
|
||||
AnnotationElement getAnAnnotationElement() { methods(result, _, _, _, this, _) }
|
||||
|
||||
/** Holds if this annotation type is annotated with the meta-annotation `@Inherited`. */
|
||||
predicate isInherited() {
|
||||
@@ -158,8 +158,8 @@ class AnnotationElement extends Member {
|
||||
AnnotationElement() { isAnnotElem(this) }
|
||||
|
||||
/** Gets the type of this annotation element. */
|
||||
Type getType() { methods(this, _, _, result, _, _, _) }
|
||||
Type getType() { methods(this, _, _, result, _, _) }
|
||||
|
||||
/** Gets the Kotlin type of this annotation element. */
|
||||
KotlinType getKotlinType() { methods(this, _, _, _, result, _, _) }
|
||||
KotlinType getKotlinType() { methodsKotlinType(this, result) }
|
||||
}
|
||||
|
||||
@@ -57,9 +57,9 @@ private predicate hasChildElement(Element parent, Element e) {
|
||||
not enclInReftype(e, _) and
|
||||
e.(Interface).getCompilationUnit() = parent
|
||||
or
|
||||
methods(e, _, _, _, _, parent, _)
|
||||
methods(e, _, _, _, parent, _)
|
||||
or
|
||||
constrs(e, _, _, _, _, parent, _)
|
||||
constrs(e, _, _, _, parent, _)
|
||||
or
|
||||
params(e, _, _, _, parent, _)
|
||||
or
|
||||
|
||||
@@ -439,7 +439,7 @@ class RawInterface extends Interface, RawType {
|
||||
class GenericCallable extends Callable {
|
||||
GenericCallable() {
|
||||
exists(Callable srcDecl |
|
||||
methods(this, _, _, _, _, _, srcDecl) or constrs(this, _, _, _, _, _, srcDecl)
|
||||
methods(this, _, _, _, _, srcDecl) or constrs(this, _, _, _, _, srcDecl)
|
||||
|
|
||||
typeVars(_, _, _, _, srcDecl)
|
||||
)
|
||||
|
||||
@@ -57,8 +57,8 @@ class Callable extends StmtParent, Member, @callable {
|
||||
* constructors).
|
||||
*/
|
||||
Type getReturnType() {
|
||||
constrs(this, _, _, result, _, _, _) or
|
||||
methods(this, _, _, result, _, _, _)
|
||||
constrs(this, _, _, result, _, _) or
|
||||
methods(this, _, _, result, _, _)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,8 +66,8 @@ class Callable extends StmtParent, Member, @callable {
|
||||
* constructors).
|
||||
*/
|
||||
KotlinType getReturnKotlinType() {
|
||||
constrs(this, _, _, _, result, _, _) or
|
||||
methods(this, _, _, _, result, _, _)
|
||||
constrsKotlinType(this, result) or
|
||||
methodsKotlinType(this, result)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -285,8 +285,8 @@ class Callable extends StmtParent, Member, @callable {
|
||||
* For example, method `void m(String s, int i)` has the signature `m(java.lang.String,int)`.
|
||||
*/
|
||||
string getSignature() {
|
||||
constrs(this, _, result, _, _, _, _) or
|
||||
methods(this, _, result, _, _, _, _)
|
||||
constrs(this, _, result, _, _, _) or
|
||||
methods(this, _, result, _, _, _)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ predicate overridesIgnoringAccess(Method m1, RefType t1, Method m2, RefType t2)
|
||||
}
|
||||
|
||||
private predicate virtualMethodWithSignature(string sig, RefType t, Method m) {
|
||||
methods(m, _, _, _, _, t, _) and
|
||||
methods(m, _, _, _, t, _) and
|
||||
sig = m.getSignature() and
|
||||
m.isVirtual()
|
||||
}
|
||||
@@ -377,7 +377,7 @@ class Method extends Callable, @method {
|
||||
exists(Method m | this.overrides(m) and result = m.getSourceDeclaration())
|
||||
}
|
||||
|
||||
override string getSignature() { methods(this, _, result, _, _, _, _) }
|
||||
override string getSignature() { methods(this, _, result, _, _, _) }
|
||||
|
||||
/**
|
||||
* Holds if this method and method `m` are declared in the same type
|
||||
@@ -394,7 +394,7 @@ class Method extends Callable, @method {
|
||||
not exists(int n | this.getParameterType(n) != m.getParameterType(n))
|
||||
}
|
||||
|
||||
override SrcMethod getSourceDeclaration() { methods(this, _, _, _, _, _, result) }
|
||||
override SrcMethod getSourceDeclaration() { methods(this, _, _, _, _, result) }
|
||||
|
||||
/**
|
||||
* All the methods that could possibly be called when this method
|
||||
@@ -471,7 +471,7 @@ class Method extends Callable, @method {
|
||||
|
||||
/** A method that is the same as its source declaration. */
|
||||
class SrcMethod extends Method {
|
||||
SrcMethod() { methods(_, _, _, _, _, _, this) }
|
||||
SrcMethod() { methods(_, _, _, _, _, this) }
|
||||
|
||||
/**
|
||||
* All the methods that could possibly be called when this method
|
||||
@@ -557,9 +557,9 @@ class Constructor extends Callable, @constructor {
|
||||
/** Holds if this is a default constructor, not explicitly declared in source code. */
|
||||
predicate isDefaultConstructor() { isDefConstr(this) }
|
||||
|
||||
override Constructor getSourceDeclaration() { constrs(this, _, _, _, _, _, result) }
|
||||
override Constructor getSourceDeclaration() { constrs(this, _, _, _, _, result) }
|
||||
|
||||
override string getSignature() { constrs(this, _, result, _, _, _, _) }
|
||||
override string getSignature() { constrs(this, _, result, _, _, _) }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Constructor" }
|
||||
}
|
||||
|
||||
@@ -315,9 +315,9 @@ private predicate hasSubtypeStar2(RefType t, RefType sub) {
|
||||
|
||||
/** Holds if type `t` declares member `m`. */
|
||||
predicate declaresMember(Type t, @member m) {
|
||||
methods(m, _, _, _, _, t, _)
|
||||
methods(m, _, _, _, t, _)
|
||||
or
|
||||
constrs(m, _, _, _, _, t, _)
|
||||
constrs(m, _, _, _, t, _)
|
||||
or
|
||||
fields(m, _, _, t, _)
|
||||
or
|
||||
@@ -511,16 +511,16 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
|
||||
sup.hasNonInterfaceMethod(m, declaringType, h2) and
|
||||
hidden = h1.booleanOr(h2) and
|
||||
exists(string signature |
|
||||
methods(m, _, signature, _, _, _, _) and not methods(_, _, signature, _, _, this, _)
|
||||
methods(m, _, signature, _, _, _) and not methods(_, _, signature, _, this, _)
|
||||
) and
|
||||
m.isInheritable()
|
||||
)
|
||||
}
|
||||
|
||||
private predicate cannotInheritInterfaceMethod(string signature) {
|
||||
methods(_, _, signature, _, _, this, _)
|
||||
methods(_, _, signature, _, this, _)
|
||||
or
|
||||
exists(Method m | this.hasNonInterfaceMethod(m, _, false) and methods(m, _, signature, _, _, _, _))
|
||||
exists(Method m | this.hasNonInterfaceMethod(m, _, false) and methods(m, _, signature, _, _, _))
|
||||
}
|
||||
|
||||
private predicate interfaceMethodCandidateWithSignature(
|
||||
@@ -529,7 +529,7 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
|
||||
m = this.getAMethod() and
|
||||
this = declaringType and
|
||||
declaringType instanceof Interface and
|
||||
methods(m, _, signature, _, _, _, _)
|
||||
methods(m, _, signature, _, _, _)
|
||||
or
|
||||
exists(RefType sup |
|
||||
sup.interfaceMethodCandidateWithSignature(m, signature, declaringType) and
|
||||
|
||||
Reference in New Issue
Block a user