Jinseong Jeon | ee5edba | 2018-12-17 23:49:40 -0800 | [diff] [blame] | 1 | // Copyright (c) 2018, the R8 project authors. Please see the AUTHORS file |
| 2 | // for details. All rights reserved. Use of this source code is governed by a |
| 3 | // BSD-style license that can be found in the LICENSE file. |
| 4 | package internal_annotation |
| 5 | |
| 6 | @Target(AnnotationTarget.CLASS) |
| 7 | internal annotation class Annotation( |
| 8 | @get:JvmName("f1") |
| 9 | val field1: Int = 0, |
| 10 | @get:JvmName("f2") |
| 11 | val field2: String = "", |
| 12 | @get:JvmName("f3") |
| 13 | val field3: IntArray = [], |
| 14 | @get:JvmName("f4") |
| 15 | val field4: Array<String> = [] |
| 16 | ) |
| 17 | |
| 18 | @JvmName("foo") |
| 19 | internal fun Base.foo(): StackTraceElement? { |
| 20 | val anno = getMyAnnotation() ?: return null |
| 21 | // Note that only Annotation.f(1|2) will be live. |
| 22 | return StackTraceElement(anno.field2, anno.field2, anno.field2, anno.field1) |
| 23 | } |
| 24 | |
| 25 | // To prevent Annotation.f(3|4) from being stripped out by kotlinc |
| 26 | internal fun Base.getUnusedFields(): Array<String>? { |
| 27 | val anno = getMyAnnotation() ?: return null |
| 28 | val res = arrayListOf<String>() |
| 29 | for ((i, idx) in anno.field3.withIndex()) { |
| 30 | if (idx == i % 8) { |
| 31 | res.add(anno.field4[i]) |
| 32 | } |
| 33 | } |
| 34 | return res.toTypedArray() |
| 35 | } |
| 36 | |
| 37 | private fun Base.getMyAnnotation(): Annotation? = |
| 38 | javaClass.getAnnotation(Annotation::class.java) |