Java to Kotlin annotation retention mapping + new test + JvmLoader test adaptation

This commit is contained in:
Mikhail Glukhikh
2015-07-20 16:09:43 +03:00
parent c3c02e49c9
commit c2480d1183
13 changed files with 316 additions and 39 deletions
@@ -21,10 +21,7 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotated;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationArgumentVisitor;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationTarget;
import org.jetbrains.kotlin.descriptors.annotations.*;
import org.jetbrains.kotlin.load.java.JvmAnnotationNames;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.resolve.AnnotationTargetChecker;
@@ -371,16 +368,13 @@ public abstract class AnnotationCodegen {
value.accept(argumentVisitor, null);
}
private enum KotlinRetention {
SOURCE(RetentionPolicy.SOURCE),
BINARY(RetentionPolicy.CLASS),
RUNTIME(RetentionPolicy.RUNTIME);
private static final Map<AnnotationRetention, RetentionPolicy> annotationRetentionMap =
new EnumMap<AnnotationRetention, RetentionPolicy>(AnnotationRetention.class);
final RetentionPolicy mapped;
KotlinRetention(RetentionPolicy mapped) {
this.mapped = mapped;
}
static {
annotationRetentionMap.put(AnnotationRetention.SOURCE, RetentionPolicy.SOURCE);
annotationRetentionMap.put(AnnotationRetention.BINARY, RetentionPolicy.CLASS);
annotationRetentionMap.put(AnnotationRetention.RUNTIME, RetentionPolicy.RUNTIME);
}
@Nullable
@@ -421,10 +415,8 @@ public abstract class AnnotationCodegen {
JetType classObjectType = getClassObjectType(enumEntry);
if (classObjectType != null) {
if ("kotlin/annotation/AnnotationRetention".equals(typeMapper.mapType(classObjectType).getInternalName())) {
String entryName = enumEntry.getName().asString();
for (KotlinRetention retention : KotlinRetention.values()) {
if (retention.name().equals(entryName)) return retention.mapped;
}
AnnotationRetention retention = AnnotationRetention.valueOf(enumEntry.getName().asString());
return annotationRetentionMap.get(retention);
}
}
}
@@ -1,8 +1,8 @@
import java.lang.annotation.*
@java.lang.annotation.Retention(RetentionPolicy.CLASS)
<!DEPRECATED_JAVA_ANNOTATION!>@java.lang.annotation.Retention(RetentionPolicy.CLASS)<!>
annotation class my
Retention(RetentionPolicy.RUNTIME)
<!DEPRECATED_JAVA_ANNOTATION!>Retention(RetentionPolicy.RUNTIME)<!>
<!DEPRECATED_JAVA_ANNOTATION!>Target(ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR)<!>
annotation class my1
@@ -0,0 +1,35 @@
// FILE: AnnotationRetentions.java
import java.lang.annotation.*;
public class AnnotationRetentions {
public @interface BaseAnnotation {
}
@Retention(RetentionPolicy.SOURCE)
public @interface SourceAnnotation {
}
@Retention(RetentionPolicy.CLASS)
public @interface BinaryAnnotation {
}
@Retention(RetentionPolicy.RUNTIME)
public @interface RuntimeAnnotation {
}
}
// FILE: AnnotationRetentions.kt
AnnotationRetentions.BaseAnnotation class BaseClass
AnnotationRetentions.SourceAnnotation class SourceClass
AnnotationRetentions.BinaryAnnotation class BinaryClass
AnnotationRetentions.RuntimeAnnotation class RuntimeClass
@@ -0,0 +1,64 @@
package
public open class AnnotationRetentions {
public constructor AnnotationRetentions()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final class BaseAnnotation : kotlin.Annotation {
public constructor BaseAnnotation()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
kotlin.annotation.annotation(retention = AnnotationRetention.BINARY) public final class BinaryAnnotation : kotlin.Annotation {
public constructor BinaryAnnotation()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
kotlin.annotation.annotation(retention = AnnotationRetention.RUNTIME) public final class RuntimeAnnotation : kotlin.Annotation {
public constructor RuntimeAnnotation()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
kotlin.annotation.annotation(retention = AnnotationRetention.SOURCE) public final class SourceAnnotation : kotlin.Annotation {
public constructor SourceAnnotation()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
AnnotationRetentions.BaseAnnotation() internal final class BaseClass {
public constructor BaseClass()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
AnnotationRetentions.BinaryAnnotation() internal final class BinaryClass {
public constructor BinaryClass()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
AnnotationRetentions.RuntimeAnnotation() internal final class RuntimeClass {
public constructor RuntimeClass()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
AnnotationRetentions.SourceAnnotation() internal final class SourceClass {
public constructor SourceClass()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,43 @@
// SKIP_IN_RUNTIME_TEST
package test;
import java.lang.annotation.*;
public class AnnotationRetentions {
public @interface BaseAnnotation {
}
@Retention(RetentionPolicy.SOURCE)
public @interface SourceAnnotation {
}
@Retention(RetentionPolicy.CLASS)
public @interface BinaryAnnotation {
}
@Retention(RetentionPolicy.RUNTIME)
public @interface RuntimeAnnotation {
}
@BaseAnnotation class BaseClass {
}
@SourceAnnotation class SourceClass {
}
@BinaryAnnotation class BinaryClass {
}
@RuntimeAnnotation class RuntimeClass {
}
}
@@ -0,0 +1,37 @@
package test
public open class AnnotationRetentions {
public constructor AnnotationRetentions()
public final class BaseAnnotation : kotlin.Annotation {
public constructor BaseAnnotation()
}
test.AnnotationRetentions.BaseAnnotation() public/*package*/ open inner class BaseClass {
public/*package*/ constructor BaseClass()
}
kotlin.annotation.annotation(retention = AnnotationRetention.BINARY) public final class BinaryAnnotation : kotlin.Annotation {
public constructor BinaryAnnotation()
}
test.AnnotationRetentions.BinaryAnnotation() public/*package*/ open inner class BinaryClass {
public/*package*/ constructor BinaryClass()
}
kotlin.annotation.annotation(retention = AnnotationRetention.RUNTIME) public final class RuntimeAnnotation : kotlin.Annotation {
public constructor RuntimeAnnotation()
}
test.AnnotationRetentions.RuntimeAnnotation() public/*package*/ open inner class RuntimeClass {
public/*package*/ constructor RuntimeClass()
}
kotlin.annotation.annotation(retention = AnnotationRetention.SOURCE) public final class SourceAnnotation : kotlin.Annotation {
public constructor SourceAnnotation()
}
public/*package*/ open inner class SourceClass {
public/*package*/ constructor SourceClass()
}
}
@@ -1016,6 +1016,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("javaretention.kt")
public void testJavaretention() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/javaretention.kt");
doTest(fileName);
}
@TestMetadata("repeatable.kt")
public void testRepeatable() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/repeatable.kt");
@@ -327,6 +327,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTestCompiledJava(fileName);
}
@TestMetadata("AnnotationRetentions.java")
public void testAnnotationRetentions() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledJava/annotations/AnnotationRetentions.java");
doTestCompiledJava(fileName);
}
@TestMetadata("AnnotationTargets.java")
public void testAnnotationTargets() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledJava/annotations/AnnotationTargets.java");
@@ -3378,6 +3378,12 @@ public class JvmRuntimeDescriptorLoaderTestGenerated extends AbstractJvmRuntimeD
doTest(fileName);
}
@TestMetadata("AnnotationRetentions.java")
public void testAnnotationRetentions() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledJava/annotations/AnnotationRetentions.java");
doTest(fileName);
}
@TestMetadata("AnnotationTargets.java")
public void testAnnotationTargets() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/loadJava/compiledJava/annotations/AnnotationTargets.java");