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

Skip to content

Commit b91660a

Browse files
committed
Kotlin: Extract properties
1 parent 97722fa commit b91660a

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
1616
import org.jetbrains.kotlin.ir.declarations.IrFile
1717
import org.jetbrains.kotlin.ir.declarations.IrFunction
1818
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
19+
import org.jetbrains.kotlin.ir.declarations.IrProperty
1920
import org.jetbrains.kotlin.ir.util.dump
2021
import org.jetbrains.kotlin.ir.util.IdSignature
2122
import org.jetbrains.kotlin.ir.util.packageFqName
@@ -148,6 +149,7 @@ class KotlinFileExtractor(val tw: TrapWriter) {
148149
when (declaration) {
149150
is IrClass -> extractClass(declaration)
150151
is IrFunction -> extractFunction(declaration, parentid)
152+
is IrProperty -> extractProperty(declaration, parentid)
151153
else -> extractorBug("Unrecognised IrDeclaration: " + declaration.javaClass)
152154
}
153155
}
@@ -266,6 +268,26 @@ class KotlinFileExtractor(val tw: TrapWriter) {
266268
}
267269
}
268270

271+
fun useProperty(p: IrProperty): Label<out DbField> {
272+
val parentId = useDeclarationParent(p.parent)
273+
val label = "@\"field;{$parentId};${p.name.asString()}\""
274+
val id: Label<DbField> = tw.getLabelFor(label)
275+
return id
276+
}
277+
278+
fun extractProperty(p: IrProperty, parentid: Label<out DbPackage_or_reftype>) {
279+
val bf = p.backingField
280+
if(bf == null) {
281+
extractorBug("IrProperty without backing field")
282+
} else {
283+
val id = useProperty(p)
284+
val locId = tw.getLocation(p.startOffset, p.endOffset)
285+
val typeId = useType(bf.type)
286+
tw.writeFields(id, p.name.asString(), typeId, parentid, id)
287+
tw.writeHasLocation(id, locId)
288+
}
289+
}
290+
269291
fun extractBody(b: IrBody, callable: Label<out DbCallable>) {
270292
when(b) {
271293
is IrBlockBody -> extractBlockBody(b, callable, callable, 0)

java/ql/lib/config/semmlecode.dbscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ fields(
319319
unique int id: @field,
320320
string nodeName: string ref,
321321
int typeid: @type ref,
322-
int parentid: @reftype ref,
322+
int parentid: @package_or_reftype ref,
323323
int sourceid: @field ref
324324
);
325325

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| stmts.kt:2:41:13:1 | { ... } |
1+
| stmts.kt:2:41:16:1 | { ... } |
22
| stmts.kt:3:8:3:12 | if (...) |
33
| stmts.kt:3:15:4:5 | { ... } |
44
| stmts.kt:4:15:4:19 | if (...) |
@@ -8,4 +8,6 @@
88
| stmts.kt:9:5:11:5 | while (...) |
99
| stmts.kt:9:18:11:5 | { ... } |
1010
| stmts.kt:10:9:10:16 | return ... |
11-
| stmts.kt:12:5:12:16 | return ... |
11+
| stmts.kt:12:5:14:18 | do ... while (...) |
12+
| stmts.kt:12:5:14:18 | { ... } |
13+
| stmts.kt:15:5:15:16 | return ... |

0 commit comments

Comments
 (0)