Deprecate and don't write KotlinClass$Kind, to be removed later

This commit is contained in:
Alexander Udalov
2015-10-01 19:12:07 +03:00
parent 056bb3f833
commit 041af28166
17 changed files with 101 additions and 158 deletions
@@ -185,7 +185,7 @@ public object InlineTestUtil {
}
private fun isClassOrPackagePartKind(header: KotlinClassHeader): Boolean {
return header.classKind == JvmAnnotationNames.KotlinClass.Kind.CLASS || header.isInterfaceDefaultImpls
return (header.kind == KotlinClassHeader.Kind.CLASS && !header.isLocalClass) || header.isInterfaceDefaultImpls
}
private fun getClassHeader(file: OutputFile): KotlinClassHeader {
@@ -19,14 +19,12 @@ package org.jetbrains.kotlin.codegen;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.backend.common.output.OutputFile;
import org.jetbrains.kotlin.load.java.AbiVersionUtil;
import org.jetbrains.kotlin.load.java.JvmAbi;
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinClass;
import org.jetbrains.kotlin.load.java.JvmAnnotationNames;
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
import org.jetbrains.kotlin.serialization.deserialization.BinaryVersion;
import org.jetbrains.kotlin.test.ConfigurationKind;
@@ -34,9 +32,6 @@ import java.lang.annotation.Annotation;
import java.util.Collection;
import java.util.List;
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KIND_FIELD_NAME;
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinClass.Kind.ANONYMOUS_OBJECT;
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinClass.Kind.LOCAL_CLASS;
import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.VERSION_FIELD_NAME;
public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
@@ -93,8 +88,7 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
public void testLocalClass() {
doTestKotlinClass(
"fun foo() { class Local }",
"Local",
LOCAL_CLASS
"Local"
);
}
@@ -108,24 +102,21 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
public void testLocalTraitInterface() {
doTestKotlinClass(
"fun foo() { interface Local { fun bar() = 42 } }",
"Local.class",
LOCAL_CLASS
"Local.class"
);
}
public void testInnerClassOfLocalClass() {
doTestKotlinClass(
"fun foo() { class Local { inner class Inner } }",
"Inner",
LOCAL_CLASS
"Inner"
);
}
public void testAnonymousObject() {
doTestKotlinClass(
"val o = object {}",
"$1",
ANONYMOUS_OBJECT
"$1"
);
}
@@ -138,22 +129,17 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
}
private void doTestKotlinSyntheticClass(@NotNull String code, @NotNull String classFilePart) {
doTest(code, classFilePart, KotlinSyntheticClass.CLASS_NAME, null);
doTest(code, classFilePart, KotlinSyntheticClass.CLASS_NAME.getFqNameForClassNameWithoutDollars());
}
private void doTestKotlinClass(
@NotNull String code,
@NotNull String classFilePart,
@NotNull KotlinClass.Kind expectedKind
) {
doTest(code, classFilePart, KotlinClass.CLASS_NAME, expectedKind.toString());
private void doTestKotlinClass(@NotNull String code, @NotNull String classFilePart) {
doTest(code, classFilePart, JvmAnnotationNames.KOTLIN_CLASS, JvmAnnotationNames.KOTLIN_LOCAL_CLASS);
}
private void doTest(
@NotNull String code,
@NotNull final String classFilePart,
@NotNull JvmClassName annotationName,
@Nullable String expectedKind
@NotNull FqName... annotationFqNames
) {
loadText("package " + PACKAGE_NAME + "\n\n" + code);
List<OutputFile> output = generateClassesInFile().asList();
@@ -169,14 +155,12 @@ 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);
assertAnnotatedWithKind(aClass, annotationName.getFqNameForClassNameWithoutDollars().asString(), expectedKind);
for (FqName annotationFqName : annotationFqNames) {
assertAnnotatedWith(aClass, annotationFqName.asString());
}
}
private void assertAnnotatedWithKind(
@NotNull Class<?> aClass,
@NotNull String annotationFqName,
@Nullable String expectedKind
) {
private void assertAnnotatedWith(@NotNull Class<?> aClass, @NotNull String annotationFqName) {
Class<? extends Annotation> annotationClass = loadAnnotationClassQuietly(annotationFqName);
assertTrue("No annotation " + annotationFqName + " found in " + aClass, aClass.isAnnotationPresent(annotationClass));
@@ -186,9 +170,5 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
assertNotNull(version);
assertTrue("Annotation " + annotationFqName + " is written with an unsupported format",
AbiVersionUtil.isAbiVersionCompatible(BinaryVersion.create(version)));
Object actualKind = CodegenTestUtil.getAnnotationAttribute(annotation, KIND_FIELD_NAME);
assertNotNull(actualKind);
assertEquals("Annotation " + annotationFqName + " has the wrong kind", expectedKind, actualKind.toString());
}
}
@@ -150,11 +150,10 @@ public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdi
val packageView = module.getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME)
packageScopes.add(packageView.memberScope)
}
else if (header == null ||
(header.kind == KotlinClassHeader.Kind.CLASS && header.classKind == JvmAnnotationNames.KotlinClass.Kind.CLASS)) {
else if (header == null || (header.kind == KotlinClassHeader.Kind.CLASS && !header.isLocalClass)) {
// Either a normal Kotlin class or a Java class
val classId = klass.classId
if (!classId.isLocal()) {
if (!classId.isLocal) {
val classDescriptor = module.findClassAcrossModuleDependencies(classId).sure { "Couldn't resolve class $className" }
if (DescriptorUtils.isTopLevelDeclaration(classDescriptor)) {
classes.add(classDescriptor)
@@ -76,17 +76,13 @@ public abstract class AbstractLocalClassProtoTest : TestCaseWithTmpdir() {
)
}
@Suppress("UNCHECKED_CAST")
private fun assertHasAnnotationData(clazz: Class<*>) {
@Suppress("UNCHECKED_CAST")
val annotation = clazz.getAnnotation(
checkNotNull(clazz.getAnnotation(
clazz.classLoader.loadClass(JvmAnnotationNames.KOTLIN_CLASS.asString()) as Class<Annotation>
)
assert(annotation != null) { "KotlinClass annotation is not found for class $clazz" }
val kindMethod = annotation.annotationType().getDeclaredMethod("kind")
val kind = kindMethod(annotation)
assert(kind.toString() != JvmAnnotationNames.KotlinClass.Kind.CLASS.toString()) {
"'kind' should not be CLASS: $clazz (was $kind)"
}
)) { "KotlinClass annotation is not found for class $clazz" }
checkNotNull(clazz.getAnnotation(
clazz.classLoader.loadClass(JvmAnnotationNames.KOTLIN_LOCAL_CLASS.asString()) as Class<Annotation>
)) { "KotlinLocalClass annotation is not found for class $clazz" }
}
}