Use kotlin.Metadata instead of old annotations in IDE, reflection and tests
This commit is contained in:
@@ -30,8 +30,7 @@ import org.jetbrains.org.objectweb.asm.tree.MethodNode
|
||||
import java.util.*
|
||||
|
||||
object InlineTestUtil {
|
||||
private val KOTLIN_MULTIFILE_CLASS_DESC =
|
||||
AsmUtil.asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_MULTIFILE_CLASS)
|
||||
private val KOTLIN_METADATA_DESC = AsmUtil.asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.METADATA)
|
||||
|
||||
fun checkNoCallsToInline(files: Iterable<OutputFile>, sourceFiles: List<KtFile>) {
|
||||
val inlineInfo = obtainInlineInfo(files)
|
||||
@@ -87,14 +86,20 @@ object InlineTestUtil {
|
||||
val notInlined = ArrayList<NotInlinedCall>()
|
||||
|
||||
files.forEach { file ->
|
||||
val cr = ClassReader(file.asByteArray())
|
||||
cr.accept(object : ClassVisitorWithName() {
|
||||
ClassReader(file.asByteArray()).accept(object : ClassVisitorWithName() {
|
||||
private var skipMethodsOfThisClass = false
|
||||
|
||||
override fun visitAnnotation(desc: String, visible: Boolean): AnnotationVisitor? {
|
||||
if (desc == KOTLIN_MULTIFILE_CLASS_DESC) {
|
||||
skipMethodsOfThisClass = true
|
||||
if (desc == KOTLIN_METADATA_DESC) {
|
||||
return object : AnnotationVisitor(Opcodes.ASM5) {
|
||||
override fun visit(name: String?, value: Any) {
|
||||
if (name == JvmAnnotationNames.KIND_FIELD_NAME && value == KotlinClassHeader.Kind.MULTIFILE_CLASS.id) {
|
||||
skipMethodsOfThisClass = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ import java.lang.annotation.Annotation;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.*;
|
||||
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.METADATA;
|
||||
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.METADATA_VERSION_FIELD_NAME;
|
||||
|
||||
public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
|
||||
public static final FqName PACKAGE_NAME = new FqName("test");
|
||||
@@ -112,14 +113,14 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
|
||||
}
|
||||
|
||||
private void doTestKotlinSyntheticClass(@NotNull String code, @NotNull String classFilePart) {
|
||||
doTest(code, classFilePart, KOTLIN_SYNTHETIC_CLASS);
|
||||
doTest(code, classFilePart);
|
||||
}
|
||||
|
||||
private void doTestKotlinClass(@NotNull String code, @NotNull String classFilePart) {
|
||||
doTest(code, classFilePart, KOTLIN_CLASS);
|
||||
doTest(code, classFilePart);
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String code, @NotNull final String classFilePart, @NotNull FqName annotationFqName) {
|
||||
private void doTest(@NotNull String code, @NotNull final String classFilePart) {
|
||||
loadText("package " + PACKAGE_NAME + "\n\n" + code);
|
||||
List<OutputFile> output = generateClassesInFile().asList();
|
||||
Collection<OutputFile> files = Collections2.filter(output, new Predicate<OutputFile>() {
|
||||
@@ -134,16 +135,17 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
|
||||
String path = files.iterator().next().getRelativePath();
|
||||
String fqName = path.substring(0, path.length() - ".class".length()).replace('/', '.');
|
||||
Class<?> aClass = generateClass(fqName);
|
||||
assertAnnotatedWith(aClass, annotationFqName.asString());
|
||||
assertAnnotatedWithMetadata(aClass);
|
||||
}
|
||||
|
||||
private void assertAnnotatedWith(@NotNull Class<?> aClass, @NotNull String annotationFqName) {
|
||||
private void assertAnnotatedWithMetadata(@NotNull Class<?> aClass) {
|
||||
String annotationFqName = METADATA.asString();
|
||||
Class<? extends Annotation> annotationClass = loadAnnotationClassQuietly(annotationFqName);
|
||||
assertTrue("No annotation " + annotationFqName + " found in " + aClass, aClass.isAnnotationPresent(annotationClass));
|
||||
|
||||
Annotation annotation = aClass.getAnnotation(annotationClass);
|
||||
|
||||
int[] version = (int[]) CodegenTestUtil.getAnnotationAttribute(annotation, VERSION_FIELD_NAME);
|
||||
int[] version = (int[]) CodegenTestUtil.getAnnotationAttribute(annotation, METADATA_VERSION_FIELD_NAME);
|
||||
assertNotNull(version);
|
||||
assertTrue("Annotation " + annotationFqName + " is written with an unsupported format",
|
||||
new JvmMetadataVersion(version).isCompatible());
|
||||
|
||||
@@ -79,7 +79,7 @@ abstract class AbstractLocalClassProtoTest : TestCaseWithTmpdir() {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
private fun assertHasAnnotationData(clazz: Class<*>) {
|
||||
checkNotNull(clazz.getAnnotation(
|
||||
clazz.classLoader.loadClass(JvmAnnotationNames.KOTLIN_CLASS.asString()) as Class<Annotation>
|
||||
)) { "KotlinClass annotation is not found for class $clazz" }
|
||||
clazz.classLoader.loadClass(JvmAnnotationNames.METADATA.asString()) as Class<Annotation>
|
||||
)) { "Metadata annotation is not found for class $clazz" }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user