|
| 1 | +/** KDoc for the file's package. */ |
| 2 | +package com.example.torture |
| 3 | + |
| 4 | +import com.example.other.OtherClass |
| 5 | +import com.example.util.helper |
| 6 | +import com.example.wild.* |
| 7 | +import com.example.alias.LongName as Short |
| 8 | + |
| 9 | +// line comment run 1 |
| 10 | +// line comment run 2 |
| 11 | +fun topLevel(x: Int, s: String): WidgetK { |
| 12 | + val local = x + 1 |
| 13 | + return WidgetK(local) |
| 14 | +} |
| 15 | + |
| 16 | +/** KDoc on extension fn. */ |
| 17 | +fun WidgetK.extend(n: Int): Int { |
| 18 | + render() |
| 19 | + return n |
| 20 | +} |
| 21 | + |
| 22 | +fun <T> List<T>.genericExt(): T = first() |
| 23 | + |
| 24 | +fun com.example.Qualified.qext() {} |
| 25 | + |
| 26 | +suspend fun suspender(): Unit { helper() } |
| 27 | + |
| 28 | +private internal fun visFn() {} |
| 29 | + |
| 30 | +fun inferred() = helper() |
| 31 | + |
| 32 | +fun nullableRet(): WidgetK? = null |
| 33 | + |
| 34 | +fun lambdaRet(): (Int) -> Unit = { } |
| 35 | + |
| 36 | +expect fun platformThing(): Int |
| 37 | + |
| 38 | +actual fun actualThing(): Int = 1 |
| 39 | + |
| 40 | +tailrec fun tailer(n: Int): Int = if (n <= 0) 0 else tailer(n - 1) |
| 41 | + |
| 42 | +infix fun Int.pow(e: Int): Int = this |
| 43 | + |
| 44 | +operator fun WidgetK.plus(o: WidgetK): WidgetK = this |
| 45 | + |
| 46 | +val topVal: Int = 3 |
| 47 | +var topVar = "s" |
| 48 | +const val TOP_CONST = 99 |
| 49 | +val topDelegated by lazy { WidgetK(1) } |
| 50 | +val (destA, destB) = makePair() |
| 51 | +val withGetter: Int |
| 52 | + get() = 42 |
| 53 | + |
| 54 | +class WidgetK(val size: Int, private var name: String = defaultName()) { |
| 55 | + val area: Int = size * size |
| 56 | + var label: String? = null |
| 57 | + val computed: Int |
| 58 | + get() = size * 2 |
| 59 | + |
| 60 | + init { |
| 61 | + val initLocal = 5 |
| 62 | + register(initLocal) |
| 63 | + } |
| 64 | + |
| 65 | + constructor(s: String) : this(s.length) { |
| 66 | + log(s) |
| 67 | + } |
| 68 | + |
| 69 | + fun render(): Unit { |
| 70 | + draw(size) |
| 71 | + } |
| 72 | + |
| 73 | + fun chainInner(): WidgetK = this |
| 74 | + |
| 75 | + companion object { |
| 76 | + val SHARED = WidgetK(0) |
| 77 | + const val COMPANION_CONST = 7 |
| 78 | + fun create(): WidgetK = WidgetK(1) |
| 79 | + } |
| 80 | + |
| 81 | + companion object Named { } |
| 82 | +} |
| 83 | + |
| 84 | +data class DataK(val a: Int, val b: String) |
| 85 | + |
| 86 | +abstract class AbstractK { |
| 87 | + abstract fun impl(): Int |
| 88 | +} |
| 89 | + |
| 90 | +open class OpenBase(n: Int) { |
| 91 | + open fun over() {} |
| 92 | +} |
| 93 | + |
| 94 | +class SubK(n: Int) : OpenBase(n), Drawable, Comparable<SubK> { |
| 95 | + override fun over() {} |
| 96 | + override fun compareTo(other: SubK): Int = 0 |
| 97 | + override fun draw() {} |
| 98 | +} |
| 99 | + |
| 100 | +class QualifiedSuper : com.example.deep.RemoteBase() { } |
| 101 | + |
| 102 | +class DelegatedImpl(d: Drawable) : Drawable by d |
| 103 | + |
| 104 | +interface Drawable { |
| 105 | + fun draw() |
| 106 | + fun outline(): Int = 1 |
| 107 | + val prop: Int get() = 2 |
| 108 | +} |
| 109 | + |
| 110 | +sealed class SealedOp { |
| 111 | + object Add : SealedOp() |
| 112 | + data class Mul(val f: Int) : SealedOp() |
| 113 | +} |
| 114 | + |
| 115 | +sealed interface SealedIface |
| 116 | + |
| 117 | +enum class Color { |
| 118 | + RED, GREEN, BLUE |
| 119 | +} |
| 120 | + |
| 121 | +enum class Http(val code: Int) { |
| 122 | + OK(200) { |
| 123 | + override fun label(): String = "ok" |
| 124 | + }, |
| 125 | + ERR(500) { |
| 126 | + override fun label(): String = "err" |
| 127 | + }; |
| 128 | + |
| 129 | + abstract fun label(): String |
| 130 | + fun common(): Int = code |
| 131 | + companion object { |
| 132 | + fun of(c: Int): Http = OK |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +object Registry { |
| 137 | + val instances = mutableListOf<WidgetK>() |
| 138 | + var count = 0 |
| 139 | + const val REG_CONST = 1 |
| 140 | + fun register(w: WidgetK) { instances.add(w) } |
| 141 | +} |
| 142 | + |
| 143 | +annotation class MyMarker(val why: String = "") |
| 144 | + |
| 145 | +@MyMarker |
| 146 | +class Annotated { |
| 147 | + @JvmStatic |
| 148 | + fun jvmStatic() {} |
| 149 | + |
| 150 | + @Deprecated("gone", ReplaceWith("new")) |
| 151 | + fun old() {} |
| 152 | + |
| 153 | + @field:JvmField |
| 154 | + val fielded: Int = 1 |
| 155 | + |
| 156 | + @get:MyMarker |
| 157 | + val got: Int = 2 |
| 158 | +} |
| 159 | + |
| 160 | +typealias Handler = (Int) -> Unit |
| 161 | +typealias WidgetList = List<WidgetK> |
| 162 | + |
| 163 | +expect class PlatformFile { |
| 164 | + fun path(): String |
| 165 | +} |
| 166 | + |
| 167 | +actual class ActualFile { |
| 168 | + actual fun path(): String = "/" |
| 169 | +} |
| 170 | + |
| 171 | +actual typealias PlatformClock = java.time.Clock |
| 172 | + |
| 173 | +fun caller() { |
| 174 | + val w = WidgetK(1) |
| 175 | + w.render() |
| 176 | + this.toString() |
| 177 | + super.hashCode() |
| 178 | + Registry.register(w) |
| 179 | + Registry.count |
| 180 | + Color.RED |
| 181 | + com.example.Fq.CONST_READ |
| 182 | + WidgetK.create().render() |
| 183 | + Foo.getInstance().bar() |
| 184 | + lowerFactory().chain() |
| 185 | + w.chainInner().render() |
| 186 | + "literal".uppercase() |
| 187 | + 5.toString() |
| 188 | + listOf(1, 2).size |
| 189 | + w.label?.length |
| 190 | + w.label!!.length |
| 191 | + helper() |
| 192 | + Short.static() |
| 193 | + val fn: Handler = { i -> println(i) } |
| 194 | + fn(3) |
| 195 | + (fn)(4) |
| 196 | + run { helper() } |
| 197 | + listOf(1).forEach { it + 1 } |
| 198 | + w.let { it.render() } |
| 199 | + generic<Int>(1) |
| 200 | + register(::topLevel) |
| 201 | + register(OtherClass::handle) |
| 202 | + register(w::render) |
| 203 | + register(this::caller) |
| 204 | + obtain(String::class) |
| 205 | + val m = ::caller |
| 206 | + val bound = w::render |
| 207 | + val s = "interp $topVal and ${w.render()} end" |
| 208 | + val multi = """raw $topVal""" |
| 209 | + when (w.size) { |
| 210 | + 1 -> helper() |
| 211 | + else -> draw(0) |
| 212 | + } |
| 213 | + if (topVal > 1) { helper() } |
| 214 | + for (i in 1..3) { draw(i) } |
| 215 | + fun localFn(): Int = 5 |
| 216 | + localFn() |
| 217 | + class LocalClass { |
| 218 | + fun lm() {} |
| 219 | + } |
| 220 | + object LocalObj { |
| 221 | + fun om() {} |
| 222 | + } |
| 223 | + val anon = object : Drawable { |
| 224 | + override fun draw() { helper() } |
| 225 | + } |
| 226 | + anon.draw() |
| 227 | + label@ for (i in 1..2) { break@label } |
| 228 | + val backtick = `weird name`() |
| 229 | +} |
| 230 | + |
| 231 | +fun `weird name`(): Int = 1 |
| 232 | + |
| 233 | +fun trailing(block: (Int) -> Int): Int = block(1) |
| 234 | + |
| 235 | +fun useTrailing() { |
| 236 | + trailing { it * 2 } |
| 237 | + trailing() { it * 3 } |
| 238 | +} |
| 239 | + |
| 240 | +fun defaults(a: Int = compute(), b: String = "x") {} |
| 241 | + |
| 242 | +fun varargFn(vararg xs: Int) {} |
| 243 | + |
| 244 | +fun destructuringBody(p: Pair<Int, Int>) { |
| 245 | + val (x, y) = p |
| 246 | + draw(x + y) |
| 247 | +} |
| 248 | + |
| 249 | +fun assignRefs() { |
| 250 | + Registry.count = 5 |
| 251 | + Registry.count += 1 |
| 252 | +} |
| 253 | + |
| 254 | +fun nullish(x: WidgetK?) { |
| 255 | + x?.render() |
| 256 | + val l = x ?: WidgetK(0) |
| 257 | +} |
| 258 | + |
| 259 | +fun stringsEdge() { |
| 260 | + val a = "quote \" and dollar ${'$'} done" |
| 261 | +} |
| 262 | + |
| 263 | +fun labeledLambda() { |
| 264 | + listOf(1).forEach loop@{ if (it == 0) return@loop } |
| 265 | +} |
| 266 | + |
| 267 | +fun whereClause(): Int where Int : Comparable<Int> = 1 |
0 commit comments