Files
kotlin/compiler/testData/codegen/boxWithStdlib/annotations/packageFacadeMethodsAnnotation.kt
Dmitry Petrov 5cdbdfc2cc - Annotate package facades with java.lang.Deprecated.
- Provide KotlinDelegatedMethod annotation on package facade members.
2015-09-23 17:41:12 +03:00

47 lines
1.8 KiB
Kotlin
Vendored

package test
import kotlin.jvm.internal.KotlinDelegatedMethod
fun findClassOrFail(className: String): Class<*> =
try {
Class.forName(className)
}
catch (e: Exception) {
throw AssertionError("Class $className not found")
}
fun box(): String {
val testPackage = findClassOrFail("test.TestPackage")
val kotlinDelegatedMethod = findClassOrFail("kotlin.jvm.internal.KotlinDelegatedMethod") as Class<Annotation>
assert(testPackage.declaredMethods.size() > 0) { "Class ${testPackage.name} has no declared methods" }
for (method in testPackage.declaredMethods) {
val ann = method.getAnnotation(kotlinDelegatedMethod) as? KotlinDelegatedMethod
if (ann == null) {
throw AssertionError("Method ${method.name} has no ${kotlinDelegatedMethod.simpleName} annotation.")
}
val implementationClassName = ann.implementationClassName()
val implementationClass = try {
Class.forName(implementationClassName)
}
catch (e: Exception) {
throw AssertionError("Implementation class $implementationClassName for method ${method.name} not found.")
}
val implementationMethod = try {
implementationClass.getMethod(method.name, *method.parameterTypes)
}
catch (e: Exception) {
throw AssertionError("Implementation class $implementationClassName for method ${method.name} has no corresponding implementation method.")
}
assert(implementationMethod.modifiers == method.modifiers) {
"Implementation method for ${method.name} in $implementationClassName: " +
"expected modifiers: ${method.modifiers}; actual modifiers: ${implementationMethod.modifiers}"
}
}
return "OK"
}