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

Skip to content

Commit 4ba13d3

Browse files
committed
Kotlin: Extract parameters
1 parent 799cf64 commit 4ba13d3

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,12 @@ class KotlinFileExtractor(val tw: TrapWriter) {
206206
}
207207

208208
fun useClass(c: IrClass): Label<out DbClass> {
209-
if(c.name.asString() == "Unit" && tw.getExistingLabelFor<DbClass>(getClassLabel(c)) == null) {
210-
return extractClass(c)
211-
} else {
212-
return addClassLabel(c)
209+
if(c.name.asString() == "Any" || c.name.asString() == "Unit") {
210+
if(tw.getExistingLabelFor<DbClass>(getClassLabel(c)) == null) {
211+
return extractClass(c)
212+
}
213213
}
214+
return addClassLabel(c)
214215
}
215216

216217
fun extractClass(c: IrClass): Label<out DbClass> {
@@ -256,6 +257,15 @@ class KotlinFileExtractor(val tw: TrapWriter) {
256257
return id
257258
}
258259

260+
fun extractValueParameter(vp: IrValueParameter, parent: Label<out DbMethod>, idx: Int) {
261+
val id = tw.getFreshIdLabel<DbParam>()
262+
val typeId = useType(vp.type)
263+
val locId = tw.getLocation(vp.startOffset, vp.endOffset)
264+
tw.writeParams(id, typeId, idx, parent, id)
265+
tw.writeHasLocation(id, locId)
266+
tw.writeParamName(id, vp.name.asString())
267+
}
268+
259269
fun extractFunction(f: IrFunction, parentid: Label<out DbPackage_or_reftype>) {
260270
val id = useFunction(f)
261271
val locId = tw.getLocation(f.startOffset, f.endOffset)
@@ -267,6 +277,9 @@ class KotlinFileExtractor(val tw: TrapWriter) {
267277
if(body != null) {
268278
extractBody(body, id)
269279
}
280+
f.valueParameters.forEachIndexed { i, vp ->
281+
extractValueParameter(vp, id, i)
282+
}
270283
}
271284

272285
fun useProperty(p: IrProperty): Label<out DbField> {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
| variables.kt:0:0:0:0 | other | variables.kt:0:0:0:0 | Any |
2+
| variables.kt:0:0:0:0 | other | variables.kt:0:0:0:0 | Any |
3+
| variables.kt:2:1:8:1 | other | variables.kt:0:0:0:0 | Any |
14
| variables.kt:3:5:3:21 | prop | file://:0:0:0:0 | int |
5+
| variables.kt:5:20:5:29 | param | file://:0:0:0:0 | int |
26
| variables.kt:6:9:6:21 | int local | file://:0:0:0:0 | int |

0 commit comments

Comments
 (0)