mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Don't suggest using property access syntax in super. calls
KTIJ-31647 K2: False positive "property access syntax" on `super` setters and getters (cherry picked from commit e0bc11426631dab4fc5f30e5cbff5fbdba3fe395) IJ-CR-148581 GitOrigin-RevId: 4059ff4377fd11be056ee63c8cafea6d39e0af79
This commit is contained in:
committed by
intellij-monorepo-bot
parent
027605bb9b
commit
4dc92cf3fa
+7
-1
@@ -165,6 +165,12 @@ class UsePropertyAccessSyntaxInspection : LocalInspectionTool(), CleanupLocalIns
|
||||
return
|
||||
}
|
||||
|
||||
if (expressionParent is KtDotQualifiedExpression) {
|
||||
if (expressionParent.receiverExpression is KtSuperExpression) {
|
||||
return // Shouldn't suggest property accessors on "super"
|
||||
}
|
||||
}
|
||||
|
||||
if (propertyAccessorKind is PropertyAccessorKind.Setter) {
|
||||
if (expressionParent is KtDotQualifiedExpression) {
|
||||
if (expressionParent.parent is KtDotQualifiedExpression) {
|
||||
@@ -194,7 +200,7 @@ class UsePropertyAccessSyntaxInspection : LocalInspectionTool(), CleanupLocalIns
|
||||
|
||||
val returnType = successfulFunctionCallSymbol.returnType.lowerBoundIfFlexible()
|
||||
|
||||
// For extension functions, receiver type taken such way is is null
|
||||
// For extension functions, receiver type taken such way is null
|
||||
val receiverType = resolvedFunctionCall.partiallyAppliedSymbol.dispatchReceiver?.type?.lowerBoundIfFlexible() ?: return
|
||||
|
||||
val syntheticProperty = getSyntheticProperty(propertyNames, receiverType) ?: return
|
||||
|
||||
+10
-5
@@ -6350,6 +6350,11 @@ public abstract class K2LocalInspectionTestGenerated extends AbstractK2LocalInsp
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/dontReplaceFirstSetterInChain.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontReplaceGetterAfterSuperCall.kt")
|
||||
public void testDontReplaceGetterAfterSuperCall() throws Exception {
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/dontReplaceGetterAfterSuperCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontReplaceGetterFromKotlinFile.kt")
|
||||
public void testDontReplaceGetterFromKotlinFile() throws Exception {
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/dontReplaceGetterFromKotlinFile.kt");
|
||||
@@ -6460,6 +6465,11 @@ public abstract class K2LocalInspectionTestGenerated extends AbstractK2LocalInsp
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/dontReplaceSetterWithReservedWord2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontReplaceWhenReceiverIsSuper.kt")
|
||||
public void testDontReplaceWhenReceiverIsSuper() throws Exception {
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/dontReplaceWhenReceiverIsSuper.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("get.kt")
|
||||
public void testGet() throws Exception {
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/get.kt");
|
||||
@@ -6485,11 +6495,6 @@ public abstract class K2LocalInspectionTestGenerated extends AbstractK2LocalInsp
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/replaceGetterAfterSafeCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("replaceGetterAfterSuperCall.kt")
|
||||
public void testReplaceGetterAfterSuperCall() throws Exception {
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/replaceGetterAfterSuperCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("replaceGetterFromGenericClassMethod.kt")
|
||||
public void testReplaceGetterFromGenericClassMethod() throws Exception {
|
||||
runTest("../../../idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/replaceGetterFromGenericClassMethod.kt");
|
||||
|
||||
+10
-5
@@ -19272,6 +19272,11 @@ public abstract class LocalInspectionTestGenerated extends AbstractLocalInspecti
|
||||
runTest("testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/dontReplaceFirstSetterInChain.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontReplaceGetterAfterSuperCall.kt")
|
||||
public void testDontReplaceGetterAfterSuperCall() throws Exception {
|
||||
runTest("testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/dontReplaceGetterAfterSuperCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontReplaceGetterFromKotlinFile.kt")
|
||||
public void testDontReplaceGetterFromKotlinFile() throws Exception {
|
||||
runTest("testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/dontReplaceGetterFromKotlinFile.kt");
|
||||
@@ -19382,6 +19387,11 @@ public abstract class LocalInspectionTestGenerated extends AbstractLocalInspecti
|
||||
runTest("testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/dontReplaceSetterWithReservedWord2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("dontReplaceWhenReceiverIsSuper.kt")
|
||||
public void testDontReplaceWhenReceiverIsSuper() throws Exception {
|
||||
runTest("testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/dontReplaceWhenReceiverIsSuper.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("get.kt")
|
||||
public void testGet() throws Exception {
|
||||
runTest("testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/get.kt");
|
||||
@@ -19407,11 +19417,6 @@ public abstract class LocalInspectionTestGenerated extends AbstractLocalInspecti
|
||||
runTest("testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/replaceGetterAfterSafeCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("replaceGetterAfterSuperCall.kt")
|
||||
public void testReplaceGetterAfterSuperCall() throws Exception {
|
||||
runTest("testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/replaceGetterAfterSuperCall.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("replaceGetterFromGenericClassMethod.kt")
|
||||
public void testReplaceGetterFromGenericClassMethod() throws Exception {
|
||||
runTest("testData/inspectionsLocal/usePropertyAccessSyntax/dotQualifiedExpressions/replaceGetterFromGenericClassMethod.kt");
|
||||
|
||||
+1
-3
@@ -1,7 +1,5 @@
|
||||
// WITH_STDLIB
|
||||
// FIX: Use property access syntax
|
||||
// IGNORE_K1
|
||||
// PROBLEM: "Use of getter method instead of property access syntax"
|
||||
// PROBLEM: none
|
||||
import java.io.File
|
||||
|
||||
class MyFile : File("file") {
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
public class Foo {
|
||||
|
||||
public void setFoo(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
private int x = 0;
|
||||
|
||||
public int getFoo(){
|
||||
return x;
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// PROBLEM: none
|
||||
|
||||
class KotlinInheritor: Foo() {
|
||||
|
||||
override fun setFoo(x: Int) {
|
||||
super.<caret>setFoo(x)
|
||||
}
|
||||
}
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
// WITH_STDLIB
|
||||
// FIX: Use property access syntax
|
||||
// IGNORE_K1
|
||||
// PROBLEM: "Use of getter method instead of property access syntax"
|
||||
import java.io.File
|
||||
|
||||
class MyFile : File("file") {
|
||||
override fun getCanonicalFile(): File {
|
||||
return super.canonicalFile
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user