Don't highlight 'this' references as deprecated
#KT-17613 Fixed
This commit is contained in:
+2
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.checkers
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtThisExpression
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.createDeprecationDiagnostic
|
||||
import org.jetbrains.kotlin.resolve.getDeprecations
|
||||
@@ -30,6 +31,7 @@ class DeprecatedClassifierUsageChecker : ClassifierUsageChecker {
|
||||
element: PsiElement,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
) {
|
||||
if (element.parent is KtThisExpression) return
|
||||
for (deprecation in targetDescriptor.getDeprecations(languageVersionSettings)) {
|
||||
trace.report(createDeprecationDiagnostic(element, deprecation, languageVersionSettings))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
@Deprecated("Use A instead") open class MyClass {
|
||||
fun foo() {
|
||||
val test = this
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package
|
||||
|
||||
@kotlin.Deprecated(message = "Use A instead") public open class MyClass {
|
||||
public constructor MyClass()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -6589,6 +6589,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("thisUsage.kt")
|
||||
public void testThisUsage() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/thisUsage.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("typeUsage.kt")
|
||||
public void testTypeUsage() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/typeUsage.kt");
|
||||
|
||||
+3
-1
@@ -2,7 +2,9 @@ package test
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
@Deprecated("Use A instead") open class MyClass {}
|
||||
@Deprecated("Use A instead") open class MyClass {
|
||||
val test = this
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val a : <warning descr="[DEPRECATION] 'MyClass' is deprecated. Use A instead">MyClass</warning>? = null
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package test
|
||||
|
||||
class A {
|
||||
constructor(x: Int) : <warning descr="[DEPRECATION] 'constructor A(Int, Int)' is deprecated. use one-arg overload">this</warning>(x, 0) {
|
||||
}
|
||||
|
||||
@Deprecated("use one-arg overload")
|
||||
constructor(x: Int, y: Int) {
|
||||
x + y
|
||||
}
|
||||
}
|
||||
|
||||
// NO_CHECK_INFOS
|
||||
// NO_CHECK_WEAK_WARNINGS
|
||||
@@ -158,6 +158,12 @@ public class HighlightingTestGenerated extends AbstractHighlightingTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("Constructor.kt")
|
||||
public void testConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/highlighter/deprecated/Constructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ExtensionFunction.kt")
|
||||
public void testExtensionFunction() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/highlighter/deprecated/ExtensionFunction.kt");
|
||||
|
||||
Reference in New Issue
Block a user