Show warnings for Java methods with external annotations when they called from Kotlin code

This commit is contained in:
Ilya Kirillov
2019-02-22 15:36:19 +03:00
parent ba9b3397d0
commit f1f6740ec9
17 changed files with 193 additions and 8 deletions
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.KotlinRetention
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
import org.jetbrains.kotlin.load.java.descriptors.PossiblyExternalAnnotationDescriptor
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaAnnotationDescriptor
import org.jetbrains.kotlin.load.java.structure.*
@@ -103,7 +104,7 @@ open class JavaAnnotationDescriptor(
c: LazyJavaResolverContext,
annotation: JavaAnnotation?,
override val fqName: FqName
) : AnnotationDescriptor {
) : AnnotationDescriptor, PossiblyExternalAnnotationDescriptor {
override val source: SourceElement = annotation?.let { c.components.sourceElementFactory.source(it) } ?: SourceElement.NO_SOURCE
override val type: SimpleType by c.storageManager.createLazyValue { c.module.builtIns.getBuiltInClassByFqName(fqName).defaultType }
@@ -111,6 +112,8 @@ open class JavaAnnotationDescriptor(
protected val firstArgument: JavaAnnotationArgument? = annotation?.arguments?.firstOrNull()
override val allValueArguments: Map<Name, ConstantValue<*>> get() = emptyMap()
override val isIdeExternalAnnotation: Boolean = annotation?.isIdeExternalAnnotation == true
}
class JavaDeprecatedAnnotationDescriptor(
@@ -0,0 +1,12 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.load.java.descriptors
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
interface PossiblyExternalAnnotationDescriptor : AnnotationDescriptor {
val isIdeExternalAnnotation: Boolean
}
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.findNonGenericClassAcrossDependencies
import org.jetbrains.kotlin.load.java.JvmAnnotationNames.DEFAULT_ANNOTATION_MEMBER_NAME
import org.jetbrains.kotlin.load.java.components.DescriptorResolverUtils
import org.jetbrains.kotlin.load.java.components.TypeUsage
import org.jetbrains.kotlin.load.java.descriptors.PossiblyExternalAnnotationDescriptor
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
import org.jetbrains.kotlin.load.java.structure.*
@@ -39,7 +40,7 @@ import org.jetbrains.kotlin.types.isError
class LazyJavaAnnotationDescriptor(
private val c: LazyJavaResolverContext,
private val javaAnnotation: JavaAnnotation
) : AnnotationDescriptor {
) : AnnotationDescriptor, PossiblyExternalAnnotationDescriptor {
override val fqName by c.storageManager.createNullableLazyValue {
javaAnnotation.classId?.asSingleFqName()
}
@@ -112,4 +113,6 @@ class LazyJavaAnnotationDescriptor(
ClassId.topLevel(fqName),
c.components.deserializedDescriptorResolver.components.notFoundClasses
)
override val isIdeExternalAnnotation: Boolean = javaAnnotation.isIdeExternalAnnotation
}
@@ -48,6 +48,8 @@ interface JavaTypeParameterListOwner : JavaElement {
interface JavaAnnotation : JavaElement {
val arguments: Collection<JavaAnnotationArgument>
val classId: ClassId?
val isIdeExternalAnnotation: Boolean
get() = false
fun resolve(): JavaClass?
}
@@ -18,10 +18,7 @@ package org.jetbrains.kotlin.load.java.typeEnhancement
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotated
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.annotations.composeAnnotations
import org.jetbrains.kotlin.descriptors.annotations.*
import org.jetbrains.kotlin.load.java.*
import org.jetbrains.kotlin.load.java.descriptors.*
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
@@ -34,6 +31,7 @@ import org.jetbrains.kotlin.resolve.constants.EnumValue
import org.jetbrains.kotlin.resolve.deprecation.DEPRECATED_FUNCTION_KEY
import org.jetbrains.kotlin.resolve.descriptorUtil.firstArgument
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
import org.jetbrains.kotlin.resolve.descriptorUtil.isSourceAnnotation
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.typeUtil.isTypeParameter
@@ -103,6 +101,12 @@ class SignatureEnhancement(
isForWarningOnly = true
)
else -> null
}?.let { migrationStatus ->
if (!migrationStatus.isForWarningOnly
&& annotationDescriptor is PossiblyExternalAnnotationDescriptor
&& annotationDescriptor.isIdeExternalAnnotation)
migrationStatus.copy(isForWarningOnly = true)
else migrationStatus
}
}