Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7862229

Browse files
committed
Kotlin: Pull Kotlin type for params out into its own table
1 parent dc26abe commit 7862229

7 files changed

Lines changed: 18 additions & 12 deletions

File tree

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ open class KotlinFileExtractor(
440440
private fun extractValueParameter(id: Label<out DbParam>, t: IrType, name: String, locId: Label<DbLocation>, parent: Label<out DbCallable>, idx: Int, typeSubstitution: TypeSubstitution?, paramSourceDeclaration: Label<out DbParam>): TypeResults {
441441
val substitutedType = typeSubstitution?.let { it(t, TypeContext.OTHER, pluginContext) } ?: t
442442
val type = useType(substitutedType)
443-
tw.writeParams(id, type.javaResult.id, type.kotlinResult.id, idx, parent, paramSourceDeclaration)
443+
tw.writeParams(id, type.javaResult.id, idx, parent, paramSourceDeclaration)
444+
tw.writeParamsKotlinType(id, type.kotlinResult.id)
444445
tw.writeHasLocation(id, locId)
445446
tw.writeParamName(id, name)
446447
return type

java/ql/consistency-queries/kotlinTypes.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import java
22

33
predicate badKotlinType(Element e, int i) {
44
e = any(Expr expr | count(expr.getKotlinType()) = i) or
5+
e = any(Parameter p | count(p.getKotlinType()) = i) or
56
e = any(Constructor c | count(c.getReturnKotlinType()) = i) or
67
e = any(Method m | count(m.getReturnKotlinType()) = i) or
78
e = any(Field f | count(f.getKotlinType()) = i)

java/ql/lib/config/semmlecode.dbscheme

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,16 @@ methodsKotlinType(
440440
params(
441441
unique int id: @param,
442442
int typeid: @type ref,
443-
int kttypeid: @kt_type ref,
444443
int pos: int ref,
445444
int parentid: @callable ref,
446445
int sourceid: @param ref
447446
);
448447

448+
paramsKotlinType(
449+
unique int id: @param ref,
450+
int kttypeid: @kt_type ref
451+
)
452+
449453
paramName(
450454
unique int id: @param ref,
451455
string nodeName: string ref

java/ql/lib/semmle/code/Location.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ predicate hasName(Element e, string name) {
2929
paramName(e, name)
3030
or
3131
exists(int pos |
32-
params(e, _, _, pos, _, _) and
32+
params(e, _, pos, _, _) and
3333
not paramName(e, _) and
3434
name = "p" + pos
3535
)

java/ql/lib/semmle/code/java/Element.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private predicate hasChildElement(Element parent, Element e) {
6161
or
6262
constrs(e, _, _, _, parent, _)
6363
or
64-
params(e, _, _, _, parent, _)
64+
params(e, _, _, parent, _)
6565
or
6666
fields(e, _, _, parent, _)
6767
or

java/ql/lib/semmle/code/java/Member.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,13 @@ class Callable extends StmtParent, Member, @callable {
186186
Parameter getAParameter() { result.getCallable() = this }
187187

188188
/** Gets the formal parameter at the specified (zero-based) position. */
189-
Parameter getParameter(int n) { params(result, _, _, n, this, _) }
189+
Parameter getParameter(int n) { params(result, _, n, this, _) }
190190

191191
/** Gets the type of the formal parameter at the specified (zero-based) position. */
192-
Type getParameterType(int n) { params(_, result, _, n, this, _) }
192+
Type getParameterType(int n) { params(_, result, n, this, _) }
193193

194194
/** Gets the type of the formal parameter at the specified (zero-based) position. */
195-
KotlinType getParameterKotlinType(int n) { params(_, _, result, n, this, _) }
195+
KotlinType getParameterKotlinType(int n) { paramsKotlinType(this.getParameter(n), result) }
196196

197197
/**
198198
* Gets the signature of this callable, including its name and the types of all

java/ql/lib/semmle/code/java/Variable.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,22 @@ class LocalVariableDecl extends @localvar, LocalScopeVariable {
6666
/** A formal parameter of a callable. */
6767
class Parameter extends Element, @param, LocalScopeVariable {
6868
/** Gets the type of this formal parameter. */
69-
override Type getType() { params(this, result, _, _, _, _) }
69+
override Type getType() { params(this, result, _, _, _) }
7070

7171
/** Gets the Kotlin type of this formal parameter. */
72-
override KotlinType getKotlinType() { params(this, _, result, _, _, _) }
72+
override KotlinType getKotlinType() { paramsKotlinType(this, result) }
7373

7474
/** Holds if the parameter is never assigned a value in the body of the callable. */
7575
predicate isEffectivelyFinal() { not exists(this.getAnAssignedValue()) }
7676

7777
/** Gets the (zero-based) index of this formal parameter. */
78-
int getPosition() { params(this, _, _, result, _, _) }
78+
int getPosition() { params(this, _, result, _, _) }
7979

8080
/** Gets the callable that declares this formal parameter. */
81-
override Callable getCallable() { params(this, _, _, _, result, _) }
81+
override Callable getCallable() { params(this, _, _, result, _) }
8282

8383
/** Gets the source declaration of this formal parameter. */
84-
Parameter getSourceDeclaration() { params(this, _, _, _, _, result) }
84+
Parameter getSourceDeclaration() { params(this, _, _, _, result) }
8585

8686
/** Holds if this formal parameter is the same as its source declaration. */
8787
predicate isSourceDeclaration() { this.getSourceDeclaration() = this }

0 commit comments

Comments
 (0)