- Annotate package facades with java.lang.Deprecated.

- Provide KotlinDelegatedMethod annotation on package facade members.
This commit is contained in:
Dmitry Petrov
2015-09-22 12:32:06 +03:00
parent c4fb6d48c5
commit 5cdbdfc2cc
12 changed files with 170 additions and 16 deletions
@@ -0,0 +1,18 @@
package test
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 deprecated = findClassOrFail("java.lang.Deprecated") as Class<Annotation>
val ann = testPackage.getAnnotation(deprecated)
assert(ann != null) { "Package facade ${testPackage.name} is not deprecated" }
return "OK"
}
@@ -0,0 +1,47 @@
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"
}