Adjust testData: don't use java.lang.Class in annotations
This commit is contained in:
+4
-2
@@ -1,5 +1,7 @@
|
||||
import java.lang.annotation.Retention
|
||||
import java.lang.annotation.RetentionPolicy
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.jvm.java
|
||||
|
||||
Retention(RetentionPolicy.RUNTIME)
|
||||
annotation class Ann(
|
||||
@@ -7,7 +9,7 @@ annotation class Ann(
|
||||
val s: String = "a",
|
||||
val a: Ann2 = Ann2(),
|
||||
val e: MyEnum = MyEnum.A,
|
||||
val c: Class<*> = javaClass<A>(),
|
||||
val c: KClass<*> = A::class,
|
||||
val ia: IntArray = intArray(1, 2),
|
||||
val sa: Array<String> = array("a", "b")
|
||||
)
|
||||
@@ -20,7 +22,7 @@ fun box(): String {
|
||||
val annSimpleName = ann.a.annotationType().getSimpleName()
|
||||
if (annSimpleName != "Ann2") return "fail: annotation parameter a should be of class Ann2, but was $annSimpleName"
|
||||
if (ann.e != MyEnum.A) return "fail: annotation parameter e should be MyEnum.A, but was ${ann.e}"
|
||||
if (ann.c != javaClass<A>()) return "fail: annotation parameter c should be of class A, but was ${ann.c}"
|
||||
if (ann.c.java != javaClass<A>()) return "fail: annotation parameter c should be of class A, but was ${ann.c}"
|
||||
if (ann.ia[0] != 1 || ann.ia[1] != 2) return "fail: annotation parameter ia should be [1, 2], but was ${ann.ia}"
|
||||
if (ann.sa[0] != "a" || ann.sa[1] != "b") return "fail: annotation parameter ia should be [\"a\", \"b\"], but was ${ann.sa}"
|
||||
return "OK"
|
||||
|
||||
+2
-1
@@ -3,6 +3,7 @@
|
||||
package test
|
||||
|
||||
import test.MyEnum.*
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
ANNOTATION class MyClass @ANNOTATION constructor(@ANNOTATION param: Int, @ANNOTATION val consProp: Int) {
|
||||
ANNOTATION companion object {
|
||||
@@ -48,7 +49,7 @@ annotation class AnnStringVararg(vararg a: String)
|
||||
annotation class AnnStringArray(a: Array<String>)
|
||||
annotation class AnnArrayOfEnum(a: Array<MyEnum>)
|
||||
annotation class AnnAnn(a: AnnInt)
|
||||
annotation class AnnClass(a: Class<*>)
|
||||
annotation class AnnClass(a: KClass<*>)
|
||||
|
||||
enum class MyEnum {
|
||||
A
|
||||
|
||||
@@ -307,39 +307,6 @@ public class AnnotationGenTest extends CodegenTestCase {
|
||||
assertEquals("239", cClass.getDeclaredMethod("c").invoke(invoke));
|
||||
}
|
||||
|
||||
public void testAnnotationClassWithClassProperty()
|
||||
throws
|
||||
NoSuchFieldException,
|
||||
NoSuchMethodException,
|
||||
ClassNotFoundException,
|
||||
IllegalAccessException,
|
||||
InstantiationException,
|
||||
InvocationTargetException {
|
||||
loadText("import java.lang.annotation.*\n" +
|
||||
"" +
|
||||
"Retention(RetentionPolicy.RUNTIME) annotation class A(val a: java.lang.Class<*>)\n" +
|
||||
"" +
|
||||
"A(javaClass<String>()) class B()");
|
||||
Class aClass = generateClass("A");
|
||||
|
||||
Retention annotation = (Retention)aClass.getAnnotation(Retention.class);
|
||||
RetentionPolicy value = annotation.value();
|
||||
assertEquals(RetentionPolicy.RUNTIME, value);
|
||||
|
||||
Method[] methods = aClass.getDeclaredMethods();
|
||||
assertEquals(1, methods.length);
|
||||
assertEquals("a", methods[0].getName());
|
||||
assertEquals(Class.class, methods[0].getReturnType());
|
||||
assertEquals(0, methods[0].getParameterTypes().length);
|
||||
assertTrue(aClass.isAnnotation());
|
||||
|
||||
Class<?> bClass = aClass.getClassLoader().loadClass("B");
|
||||
Annotation bClassAnnotation = bClass.getAnnotation(aClass);
|
||||
assertNotNull(bClassAnnotation);
|
||||
|
||||
assertEquals(String.class, methods[0].invoke(bClassAnnotation));
|
||||
}
|
||||
|
||||
public void testAnnotationClassWithStringArrayProperty()
|
||||
throws
|
||||
NoSuchFieldException,
|
||||
|
||||
+2
-2
@@ -86,8 +86,8 @@ public class AnnotationDescriptorResolveTest extends AbstractAnnotationDescripto
|
||||
}
|
||||
|
||||
public void testJavaClassAnnotation() throws Exception {
|
||||
String content = getContent("AnnClass(javaClass<MyClass>())");
|
||||
String expectedAnnotation = "AnnClass(a = javaClass<MyClass>(): Class<MyClass>)";
|
||||
String content = getContent("AnnClass(MyClass::class)");
|
||||
String expectedAnnotation = "AnnClass(a = MyClass::class: KClass<MyClass>)";
|
||||
doTest(content, expectedAnnotation);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user