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

Skip to content

Commit 46add88

Browse files
committed
Kotlin: Add more types
1 parent 1c39f00 commit 46add88

4 files changed

Lines changed: 69 additions & 20 deletions

File tree

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -156,28 +156,28 @@ class KotlinFileExtractor(val tw: TrapWriter) {
156156

157157
@Suppress("UNUSED_PARAMETER")
158158
fun useSimpleType(s: IrSimpleType): Label<out DbType> {
159+
fun primitiveType(name: String): Label<DbPrimitive> {
160+
return tw.getLabelFor("@\"type;$name\"", {
161+
tw.writePrimitives(it, name)
162+
})
163+
}
159164
when {
160-
s.isInt() -> {
161-
val label = "@\"type;int\""
162-
val id: Label<DbPrimitive> = tw.getLabelFor(label, {
163-
tw.writePrimitives(it, "int")
164-
})
165-
return id
166-
}
167-
s.isBoolean() -> {
168-
val label = "@\"type;boolean\""
169-
val id: Label<DbPrimitive> = tw.getLabelFor(label, {
170-
tw.writePrimitives(it, "boolean")
171-
})
172-
return id
173-
}
174-
s.isString() -> {
175-
val label = "@\"type;string\""
176-
val id: Label<DbPrimitive> = tw.getLabelFor(label, {
177-
tw.writePrimitives(it, "string")
178-
})
179-
return id
165+
s.isByte() -> return primitiveType("byte")
166+
s.isShort() -> return primitiveType("short")
167+
s.isInt() -> return primitiveType("int")
168+
s.isLong() -> return primitiveType("long")
169+
s.isUByte() || s.isUShort() || s.isUInt() || s.isULong() -> {
170+
extractorBug("Unhandled unsigned type")
171+
return Label(0)
180172
}
173+
174+
s.isDouble() -> return primitiveType("double")
175+
s.isFloat() -> return primitiveType("float")
176+
177+
s.isBoolean() -> return primitiveType("boolean")
178+
179+
s.isChar() -> return primitiveType("char")
180+
s.isString() -> return primitiveType("string") // TODO: Wrong
181181
s.classifier.owner is IrClass -> {
182182
val classifier: IrClassifierSymbol = s.classifier
183183
val cls: IrClass = classifier.owner as IrClass
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
| file://:0:0:0:0 | boolean | PrimitiveType |
2+
| file://:0:0:0:0 | byte | PrimitiveType |
3+
| file://:0:0:0:0 | char | PrimitiveType |
4+
| file://:0:0:0:0 | double | PrimitiveType |
5+
| file://:0:0:0:0 | float | PrimitiveType |
6+
| file://:0:0:0:0 | int | PrimitiveType |
7+
| file://:0:0:0:0 | long | PrimitiveType |
8+
| file://:0:0:0:0 | short | PrimitiveType |
9+
| file://:0:0:0:0 | string | ??? |
10+
| types.kt:2:1:33:1 | Foo | Class |
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
class Foo {
3+
val propByte: Byte = 1
4+
val propShort: Short = 1
5+
val propInt: Int = 1
6+
val propLong: Long = 1
7+
8+
/*
9+
TODO
10+
val propUByte: UByte = 1u
11+
val propUShort: UShort = 1u
12+
val propUInt: UInt = 1u
13+
val propULong: ULong = 1u
14+
*/
15+
16+
val propFloat: Float = 1.0f
17+
val propDouble: Double = 1.0
18+
19+
val propBoolean: Boolean = true
20+
21+
val propChar: Char = 'c'
22+
val propString: String = "str"
23+
24+
/*
25+
TODO
26+
val propArray: Array<Int> = arrayOf(1, 2, 3)
27+
28+
val propByteArray: ByteArray = byteArrayOf(1, 2, 3)
29+
val propShortArray: ShortArray = shortArrayOf(1, 2, 3)
30+
val propIntArray: IntArray = intArrayOf(1, 2, 3)
31+
val propLongArray: LongArray = longArrayOf(1, 2, 3)
32+
*/
33+
}
34+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import java
2+
3+
from Type t
4+
select t, concat(t.getAPrimaryQlClass(), ", ")
5+

0 commit comments

Comments
 (0)