Check annotations on default property getter/setter
This commit is contained in:
+7
-3
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtProperty
|
||||
@@ -28,11 +29,14 @@ import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||
|
||||
class JvmSyntheticApplicabilityChecker : DeclarationChecker {
|
||||
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor,
|
||||
diagnosticHolder: DiagnosticSink, bindingContext: BindingContext
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext
|
||||
) {
|
||||
val annotation = descriptor.findJvmSyntheticAnnotation() ?: return
|
||||
if (declaration is KtProperty && declaration.hasDelegate()) {
|
||||
if (declaration is KtProperty && descriptor is VariableDescriptor && declaration.hasDelegate()) {
|
||||
val annotationEntry = DescriptorToSourceUtils.getSourceFromAnnotation(annotation) ?: return
|
||||
diagnosticHolder.report(ErrorsJvm.JVM_SYNTHETIC_ON_DELEGATE.on(annotationEntry))
|
||||
}
|
||||
|
||||
+6
-1
@@ -99,7 +99,12 @@ class PlatformStaticAnnotationChecker : DeclarationChecker {
|
||||
}
|
||||
|
||||
class JvmNameAnnotationChecker : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, diagnosticHolder: DiagnosticSink, bindingContext: BindingContext) {
|
||||
override fun check(
|
||||
declaration: KtDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext
|
||||
) {
|
||||
val platformNameAnnotation = DescriptorUtils.getJvmNameAnnotation(descriptor)
|
||||
if (platformNameAnnotation != null) {
|
||||
checkDeclaration(descriptor, platformNameAnnotation, diagnosticHolder)
|
||||
|
||||
@@ -727,12 +727,16 @@ class DeclarationsChecker(
|
||||
}
|
||||
|
||||
private fun checkAccessors(property: KtProperty, propertyDescriptor: PropertyDescriptor) {
|
||||
for (accessor in property.accessors) {
|
||||
val propertyAccessorDescriptor = (if (accessor.isGetter) propertyDescriptor.getter else propertyDescriptor.setter)
|
||||
?: throw AssertionError("No property accessor descriptor for ${property.text}")
|
||||
accessor.checkTypeReferences()
|
||||
modifiersChecker.checkModifiersForDeclaration(accessor, propertyAccessorDescriptor)
|
||||
identifierChecker.checkDeclaration(accessor, trace)
|
||||
for (accessorDescriptor in propertyDescriptor.accessors) {
|
||||
val accessor = if (accessorDescriptor is PropertyGetterDescriptor) property.getter else property.setter
|
||||
if (accessor != null) {
|
||||
accessor.checkTypeReferences()
|
||||
modifiersChecker.checkModifiersForDeclaration(accessor, accessorDescriptor)
|
||||
identifierChecker.checkDeclaration(accessor, trace)
|
||||
}
|
||||
else {
|
||||
modifiersChecker.runDeclarationCheckers(property, accessorDescriptor)
|
||||
}
|
||||
}
|
||||
checkAccessor(propertyDescriptor, property.getter, propertyDescriptor.getter)
|
||||
checkAccessor(propertyDescriptor, property.setter, propertyDescriptor.setter)
|
||||
|
||||
@@ -228,7 +228,10 @@ public class ModifiersChecker {
|
||||
}
|
||||
|
||||
|
||||
private void runDeclarationCheckers(@NotNull KtDeclaration declaration, @NotNull DeclarationDescriptor descriptor) {
|
||||
public void runDeclarationCheckers(
|
||||
@NotNull KtDeclaration declaration,
|
||||
@NotNull DeclarationDescriptor descriptor
|
||||
) {
|
||||
for (DeclarationChecker checker : declarationCheckers) {
|
||||
checker.check(declaration, descriptor, trace, trace.getBindingContext());
|
||||
}
|
||||
|
||||
@@ -18,12 +18,10 @@ package org.jetbrains.kotlin.resolve
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtTypeParameterListOwner
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
|
||||
object UnderscoreChecker : DeclarationChecker {
|
||||
|
||||
@@ -44,6 +42,7 @@ object UnderscoreChecker : DeclarationChecker {
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext
|
||||
) {
|
||||
if (declaration is KtProperty && descriptor !is VariableDescriptor) return
|
||||
if (declaration is KtCallableDeclaration) {
|
||||
for (parameter in declaration.valueParameters) {
|
||||
checkNamed(parameter, diagnosticHolder)
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
interface Test {
|
||||
@get:JvmStatic
|
||||
val a: Int
|
||||
|
||||
<!INAPPLICABLE_JVM_NAME!>@get:JvmName("1")<!>
|
||||
val b: Int
|
||||
|
||||
<!SYNCHRONIZED_ON_ABSTRACT!>@get:Synchronized<!>
|
||||
val c: Int
|
||||
|
||||
<!WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET!>@get:JvmOverloads<!>
|
||||
val d: Int
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public interface Test {
|
||||
public abstract val a: kotlin.Int
|
||||
public abstract val b: kotlin.Int
|
||||
public abstract val c: kotlin.Int
|
||||
public abstract val d: kotlin.Int
|
||||
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
|
||||
}
|
||||
Vendored
+6
@@ -86,4 +86,10 @@ class D: AB() {
|
||||
|
||||
@JvmName("D_finalFun")
|
||||
fun finalFun() {}
|
||||
}
|
||||
|
||||
interface Intf {
|
||||
<!INAPPLICABLE_JVM_NAME!>@get:JvmName("getBar")<!> // no error in IDE
|
||||
<!INAPPLICABLE_JVM_NAME!>@set:JvmName("setBar")<!> // no error in IDE
|
||||
var foo: Int
|
||||
}
|
||||
Vendored
+7
@@ -43,3 +43,10 @@ public final class D : AB {
|
||||
@kotlin.jvm.JvmName(name = "D_openFun") public final override /*1*/ fun openFun(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface Intf {
|
||||
public abstract var foo: kotlin.Int
|
||||
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
|
||||
}
|
||||
|
||||
@@ -207,6 +207,12 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("annotationsOnUseSiteTargets.kt")
|
||||
public void testAnnotationsOnUseSiteTargets() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/annotationsOnUseSiteTargets.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("illegalPlatformName.kt")
|
||||
public void testIllegalPlatformName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/annotationApplicability/illegalPlatformName.kt");
|
||||
|
||||
Reference in New Issue
Block a user