Prohibit explicit usage of kotlin.Metadata as annotation
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 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.resolve.jvm.checkers
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.annotations.KotlinTarget
|
||||||
|
import org.jetbrains.kotlin.name.FqName
|
||||||
|
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||||
|
import org.jetbrains.kotlin.resolve.AdditionalAnnotationChecker
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||||
|
|
||||||
|
object ExplicitMetadataChecker : AdditionalAnnotationChecker {
|
||||||
|
private val METADATA_FQ_NAME = FqName("kotlin.Metadata")
|
||||||
|
|
||||||
|
override fun checkEntries(entries: List<KtAnnotationEntry>, actualTargets: List<KotlinTarget>, trace: BindingTrace) {
|
||||||
|
for (entry in entries) {
|
||||||
|
val descriptor = trace.get(BindingContext.ANNOTATION, entry) ?: continue
|
||||||
|
if (descriptor.fqName == METADATA_FQ_NAME) {
|
||||||
|
trace.report(ErrorsJvm.EXPLICIT_METADATA_IS_DISALLOWED.on(entry))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -141,6 +141,7 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
|||||||
MAP.put(JVM_DEFAULT_THROUGH_INHERITANCE, "Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option");
|
MAP.put(JVM_DEFAULT_THROUGH_INHERITANCE, "Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option");
|
||||||
MAP.put(USAGE_OF_JVM_DEFAULT_THROUGH_SUPER_CALL, "Super calls of '@JvmDefault' members are only allowed with -Xjvm-default option");
|
MAP.put(USAGE_OF_JVM_DEFAULT_THROUGH_SUPER_CALL, "Super calls of '@JvmDefault' members are only allowed with -Xjvm-default option");
|
||||||
MAP.put(NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT, "Non-@JvmDefault interface method cannot override default Java method. Please annotate this method with @JvmDefault");
|
MAP.put(NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT, "Non-@JvmDefault interface method cannot override default Java method. Please annotate this method with @JvmDefault");
|
||||||
|
MAP.put(EXPLICIT_METADATA_IS_DISALLOWED, "Explicit @Metadata is disallowed");
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -123,6 +123,8 @@ public interface ErrorsJvm {
|
|||||||
|
|
||||||
DiagnosticFactory0<KtDeclaration> NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
|
DiagnosticFactory0<KtDeclaration> NON_JVM_DEFAULT_OVERRIDES_JAVA_DEFAULT = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
|
||||||
|
|
||||||
|
DiagnosticFactory0<KtAnnotationEntry> EXPLICIT_METADATA_IS_DISALLOWED = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
enum NullabilityInformationSource {
|
enum NullabilityInformationSource {
|
||||||
KOTLIN {
|
KOTLIN {
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+2
-1
@@ -71,7 +71,8 @@ object JvmPlatformConfigurator : PlatformConfigurator(
|
|||||||
|
|
||||||
additionalAnnotationCheckers = listOf(
|
additionalAnnotationCheckers = listOf(
|
||||||
RepeatableAnnotationChecker,
|
RepeatableAnnotationChecker,
|
||||||
FileClassAnnotationsChecker
|
FileClassAnnotationsChecker,
|
||||||
|
ExplicitMetadataChecker
|
||||||
),
|
),
|
||||||
|
|
||||||
identifierChecker = JvmSimpleNameBacktickChecker,
|
identifierChecker = JvmSimpleNameBacktickChecker,
|
||||||
|
|||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
// !DIAGNOSTICS: -INVISIBLE_MEMBER -INVISIBLE_REFERENCE -EXPOSED_PARAMETER_TYPE
|
||||||
|
|
||||||
|
<!EXPLICIT_METADATA_IS_DISALLOWED!>@Metadata<!>
|
||||||
|
class A
|
||||||
|
|
||||||
|
<!EXPLICIT_METADATA_IS_DISALLOWED!>@Metadata(xs = "_")<!>
|
||||||
|
annotation class B(val m: Metadata)
|
||||||
|
|
||||||
|
<!WRONG_ANNOTATION_TARGET, EXPLICIT_METADATA_IS_DISALLOWED!>@Metadata(xi = 0)<!>
|
||||||
|
@B(Metadata())
|
||||||
|
fun f() {}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
@kotlin.Metadata(xi = 0) @B(m = kotlin.Metadata) public fun f(): kotlin.Unit
|
||||||
|
|
||||||
|
@kotlin.Metadata public final class A {
|
||||||
|
public constructor A()
|
||||||
|
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.Metadata(xs = "_") public final annotation class B : kotlin.Annotation {
|
||||||
|
public constructor B(/*0*/ m: kotlin.Metadata)
|
||||||
|
public final val m: kotlin.Metadata
|
||||||
|
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
|
||||||
|
}
|
||||||
+5
@@ -171,6 +171,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("explicitMetadata.kt")
|
||||||
|
public void testExplicitMetadata() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/explicitMetadata.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("JvmSyntheticOnDelegate.kt")
|
@TestMetadata("JvmSyntheticOnDelegate.kt")
|
||||||
public void testJvmSyntheticOnDelegate() throws Exception {
|
public void testJvmSyntheticOnDelegate() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt");
|
||||||
|
|||||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+5
@@ -171,6 +171,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/defaultValueMustBeConstant.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("explicitMetadata.kt")
|
||||||
|
public void testExplicitMetadata() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/explicitMetadata.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("JvmSyntheticOnDelegate.kt")
|
@TestMetadata("JvmSyntheticOnDelegate.kt")
|
||||||
public void testJvmSyntheticOnDelegate() throws Exception {
|
public void testJvmSyntheticOnDelegate() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user