Java Deprecated is mapped in accordance with Java Target / Retention, some diagnostic changed
This commit is contained in:
+1
-1
@@ -2,4 +2,4 @@ import java.util.ArrayList
|
||||
|
||||
<!NONE_APPLICABLE!>ArrayList<!><Int>(1, 1) fun b() {}
|
||||
<!UNRESOLVED_REFERENCE!>Xoo<!>(<!UNRESOLVED_REFERENCE!>x<!>) fun c() {}
|
||||
<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Deprecated<!>(<!UNRESOLVED_REFERENCE, TOO_MANY_ARGUMENTS!>x<!>) fun a() {}
|
||||
<!DEPRECATED_JAVA_ANNOTATION!>Deprecated(<!UNRESOLVED_REFERENCE, TOO_MANY_ARGUMENTS!>x<!>)<!> fun a() {}
|
||||
+4
-4
@@ -1,15 +1,15 @@
|
||||
package a
|
||||
|
||||
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Deprecated<!> as deprecated
|
||||
import java.lang.Deprecated as deprecated
|
||||
import java.lang.SuppressWarnings as suppresswarnings
|
||||
|
||||
|
||||
<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>deprecated<!> suppresswarnings val s: String = "";
|
||||
<!DEPRECATED_JAVA_ANNOTATION!>deprecated<!> suppresswarnings val s: String = "";
|
||||
|
||||
<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>deprecated<!> suppresswarnings fun main(args : Array<String>) {
|
||||
<!DEPRECATED_JAVA_ANNOTATION!>deprecated<!> suppresswarnings fun main(args : Array<String>) {
|
||||
System.out.println("Hello, world!")
|
||||
}
|
||||
|
||||
class Test(<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>deprecated<!> val s: String,
|
||||
class Test(<!DEPRECATED_JAVA_ANNOTATION!>deprecated<!> val s: String,
|
||||
suppresswarnings val x : Int) {}
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
annotation @<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Deprecated<!> class my
|
||||
annotation <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Deprecated<!> class my1
|
||||
annotation <!DEPRECATED_JAVA_ANNOTATION!>@java.lang.Deprecated<!> class my
|
||||
annotation <!DEPRECATED_JAVA_ANNOTATION!>Deprecated<!> class my1
|
||||
@@ -1,5 +1,5 @@
|
||||
import <!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>java.lang.Deprecated<!> as deprecated
|
||||
import java.lang.Deprecated as deprecated
|
||||
|
||||
<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>Deprecated<!> fun foo() {}
|
||||
<!DEPRECATED_JAVA_ANNOTATION!>Deprecated<!> fun foo() {}
|
||||
|
||||
<!PLATFORM_CLASS_MAPPED_TO_KOTLIN!>deprecated<!> fun foo1() {}
|
||||
<!DEPRECATED_JAVA_ANNOTATION!>deprecated<!> fun foo1() {}
|
||||
+22
-2
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention
|
||||
import org.jetbrains.kotlin.resolve.constants.ConstantValueFactory
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import java.lang.annotation.Retention
|
||||
import java.lang.annotation.Target
|
||||
@@ -47,21 +48,25 @@ public object JavaAnnotationMapper {
|
||||
|
||||
private val javaTargetFqName = FqName(javaClass<Target>().canonicalName)
|
||||
private val javaRetentionFqName = FqName(javaClass<Retention>().canonicalName)
|
||||
private val javaDeprecatedFqName = FqName(javaClass<Deprecated>().canonicalName)
|
||||
|
||||
public fun mapJavaAnnotation(annotation: JavaAnnotation, c: LazyJavaResolverContext): AnnotationDescriptor? =
|
||||
when (annotation.classId) {
|
||||
ClassId.topLevel(javaTargetFqName) -> JavaTargetAnnotationDescriptor(annotation, c)
|
||||
ClassId.topLevel(javaRetentionFqName) -> JavaRetentionAnnotationDescriptor(annotation, c)
|
||||
ClassId.topLevel(javaDeprecatedFqName) -> JavaDeprecatedAnnotationDescriptor(annotation, c)
|
||||
else -> null
|
||||
}
|
||||
|
||||
public val kotlinToJavaNameMap: Map<FqName, FqName> =
|
||||
mapOf(KotlinBuiltIns.FQ_NAMES.target to javaTargetFqName,
|
||||
KotlinBuiltIns.FQ_NAMES.annotation to javaRetentionFqName)
|
||||
KotlinBuiltIns.FQ_NAMES.annotation to javaRetentionFqName,
|
||||
KotlinBuiltIns.FQ_NAMES.deprecated to javaDeprecatedFqName)
|
||||
|
||||
public val javaToKotlinNameMap: Map<FqName, FqName> =
|
||||
mapOf(javaTargetFqName to KotlinBuiltIns.FQ_NAMES.target,
|
||||
javaRetentionFqName to KotlinBuiltIns.FQ_NAMES.annotation)
|
||||
javaRetentionFqName to KotlinBuiltIns.FQ_NAMES.annotation,
|
||||
javaDeprecatedFqName to KotlinBuiltIns.FQ_NAMES.deprecated)
|
||||
}
|
||||
|
||||
abstract class AbstractJavaAnnotationDescriptor(
|
||||
@@ -76,6 +81,21 @@ abstract class AbstractJavaAnnotationDescriptor(
|
||||
protected val firstArgument: JavaAnnotationArgument? = annotation.arguments.firstOrNull()
|
||||
}
|
||||
|
||||
class JavaDeprecatedAnnotationDescriptor(
|
||||
annotation: JavaAnnotation,
|
||||
c: LazyJavaResolverContext
|
||||
): AbstractJavaAnnotationDescriptor(annotation, c.module.builtIns.deprecatedAnnotation) {
|
||||
|
||||
private val valueArguments = c.storageManager.createLazyValue {
|
||||
val parameterDescriptor = valueParameters.firstOrNull {
|
||||
it.name == JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME
|
||||
}
|
||||
parameterDescriptor?.let { mapOf(it to ConstantValueFactory(c.module.builtIns).createConstantValue("Deprecated in Java")) } ?: emptyMap()
|
||||
}
|
||||
|
||||
override fun getAllValueArguments() = valueArguments()
|
||||
}
|
||||
|
||||
class JavaRetentionAnnotationDescriptor(
|
||||
annotation: JavaAnnotation,
|
||||
c: LazyJavaResolverContext
|
||||
|
||||
+1
-14
@@ -38,11 +38,6 @@ import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.utils.keysToMapExceptNulls
|
||||
import org.jetbrains.kotlin.utils.valuesToMap
|
||||
|
||||
private object DEPRECATED_IN_JAVA : JavaLiteralAnnotationArgument {
|
||||
override val name: Name? = null
|
||||
override val value: Any? = "Deprecated in Java"
|
||||
}
|
||||
|
||||
fun LazyJavaResolverContext.resolveAnnotation(annotation: JavaAnnotation): LazyJavaAnnotationDescriptor? {
|
||||
val classId = annotation.getClassId()
|
||||
if (classId == null || isSpecialAnnotation(classId, !PLATFORM_TYPES)) return null
|
||||
@@ -79,7 +74,7 @@ class LazyJavaAnnotationDescriptor(
|
||||
val constructors = getAnnotationClass().getConstructors()
|
||||
if (constructors.isEmpty()) return mapOf()
|
||||
|
||||
val nameToArg = nameToArgument()
|
||||
val nameToArg = javaAnnotation.getArguments().valuesToMap { it.name }
|
||||
|
||||
return constructors.first().getValueParameters().keysToMapExceptNulls { valueParameter ->
|
||||
var javaAnnotationArgument = nameToArg[valueParameter.getName()]
|
||||
@@ -91,14 +86,6 @@ class LazyJavaAnnotationDescriptor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun nameToArgument(): Map<Name?, JavaAnnotationArgument> {
|
||||
var arguments = javaAnnotation.getArguments()
|
||||
if (arguments.isEmpty() && fqName()?.asString() == "java.lang.Deprecated") {
|
||||
arguments = listOf(DEPRECATED_IN_JAVA)
|
||||
}
|
||||
return arguments.valuesToMap { it.name }
|
||||
}
|
||||
|
||||
private fun getAnnotationClass() = getType().getConstructor().getDeclarationDescriptor() as ClassDescriptor
|
||||
|
||||
private fun resolveAnnotationArgument(argument: JavaAnnotationArgument?): ConstantValue<*>? {
|
||||
|
||||
-3
@@ -85,15 +85,12 @@ public class JavaToKotlinClassMap implements PlatformToKotlinClassMap {
|
||||
addKotlinToJava(new FqNameUnsafe(kFun + i), ClassId.topLevel(new FqName(kFun)));
|
||||
}
|
||||
|
||||
addJavaToKotlin(classId(Deprecated.class), builtIns.getDeprecatedAnnotation());
|
||||
|
||||
addKotlinToJava(builtIns.getNothing(), classId(Void.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* E.g.
|
||||
* java.lang.String -> kotlin.String
|
||||
* java.lang.Deprecated -> kotlin.deprecated
|
||||
* java.lang.Integer -> kotlin.Int
|
||||
* kotlin.jvm.internal.IntCompanionObject -> kotlin.Int.Companion
|
||||
* java.util.List -> kotlin.List
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
import java.lang.Deprecated;
|
||||
import java.lang.SuppressWarnings;
|
||||
|
||||
class C {
|
||||
|
||||
Reference in New Issue
Block a user