Extract type parameter bounds

This commit is contained in:
Chris Smowton
2022-01-31 16:13:15 +00:00
committed by Ian Lynagh
parent ec5bc8dad5
commit 8bb23651ae
4 changed files with 31 additions and 1 deletions

View File

@@ -151,7 +151,13 @@ open class KotlinFileExtractor(
val locId = tw.getLocation(tp)
tw.writeHasLocation(id, locId)
// todo: add type bounds
tp.superTypes.forEachIndexed { boundIdx, bound ->
if(!(bound.isAny() || bound.isNullableAny())) {
tw.getLabelFor<DbTypebound>("@\"bound;$boundIdx;{$id}\"") {
tw.writeTypeBounds(it, useType(bound).javaResult.id as Label<out DbReftype>, boundIdx, id)
}
}
}
return id
}

View File

@@ -0,0 +1,8 @@
classTVs
| test.kt:1:12:1:21 | T | test.kt:1:1:5:1 | Test | Number |
| test.kt:1:24:1:28 | S | test.kt:1:1:5:1 | Test | T |
| test.kt:1:31:1:31 | R | test.kt:1:1:5:1 | Test | Object |
| test.kt:7:22:7:22 | P | test.kt:7:1:7:67 | MultipleBounds | List<String> |
| test.kt:7:22:7:22 | P | test.kt:7:1:7:67 | MultipleBounds | Set<String> |
functionTVs
| test.kt:3:8:3:17 | Q | test.kt:3:3:3:26 | f | Number |

View File

@@ -0,0 +1,7 @@
class Test<T : Number, S : T, R> {
fun <Q : Number> f() { }
}
class MultipleBounds<P> where P : List<String>, P : Set<String> { }

View File

@@ -0,0 +1,9 @@
import java
query predicate classTVs(TypeVariable tv, GenericType declType, string bound) {
tv.getGenericType() = declType and tv.getUpperBoundType().toString() = bound and declType.fromSource()
}
query predicate functionTVs(TypeVariable tv, GenericCallable callable, string bound) {
tv.getGenericCallable() = callable and tv.getUpperBoundType().toString() = bound and callable.fromSource()
}