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
@@ -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());
}
}