Use property access: suppress for reserved words #KT-23775 Fixed

This commit is contained in:
Toshiaki Kameyama
2018-05-07 17:48:36 +03:00
committed by Mikhail Glukhikh
parent 240b9fd97a
commit 4ee9db7a6c
10 changed files with 87 additions and 0 deletions
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
import org.jetbrains.kotlin.idea.resolve.frontendService
import org.jetbrains.kotlin.idea.util.getResolutionScope
import org.jetbrains.kotlin.idea.util.shouldNotConvertToProperty
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.FqNameUnsafe
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
@@ -144,6 +145,8 @@ class UsePropertyAccessSyntaxIntention :
val resolutionScope = callExpression.getResolutionScope(bindingContext, resolutionFacade)
val property = findSyntheticProperty(function, resolutionFacade.getFrontendService(SyntheticScopes::class.java)) ?: return null
if (KtTokens.KEYWORDS.types.any { it.toString() == property.name.asString() }) return null
val dataFlowInfo = bindingContext.getDataFlowInfoBefore(callee)
val qualifiedExpression = callExpression.getQualifiedExpressionForSelectorOrThis()
val expectedType = bindingContext[BindingContext.EXPECTED_EXPRESSION_TYPE, qualifiedExpression] ?: TypeUtils.NO_EXPECTED_TYPE
@@ -0,0 +1,11 @@
public class Foo {
private String object;
public String getObject() {
return object;
}
public void setObject(String object) {
this.object = object;
}
}
@@ -0,0 +1,5 @@
// IS_APPLICABLE: false
fun test() {
Foo().<caret>getObject()
}
@@ -0,0 +1,11 @@
public class Foo {
private String typeof;
public String getTypeof() {
return typeof;
}
public void setTypeof(String typeof) {
this.typeof = typeof;
}
}
@@ -0,0 +1,5 @@
// IS_APPLICABLE: false
fun test() {
Foo().<caret>getTypeof()
}
@@ -0,0 +1,11 @@
public class Foo {
private String object;
public String getObject() {
return object;
}
public void setObject(String object) {
this.object = object;
}
}
@@ -0,0 +1,5 @@
// IS_APPLICABLE: false
fun test() {
Foo().<caret>setObject("")
}
@@ -0,0 +1,11 @@
public class Foo {
private String typeof;
public String getTypeof() {
return typeof;
}
public void setTypeof(String typeof) {
this.typeof = typeof;
}
}
@@ -0,0 +1,5 @@
// IS_APPLICABLE: false
fun test() {
Foo().<caret>setTypeof("")
}
@@ -15336,6 +15336,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/usePropertyAccessSyntax/getImplicitReceiver.kt");
}
@TestMetadata("getReservedWord1.kt")
public void testGetReservedWord1() throws Exception {
runTest("idea/testData/intentions/usePropertyAccessSyntax/getReservedWord1.kt");
}
@TestMetadata("getReservedWord2.kt")
public void testGetReservedWord2() throws Exception {
runTest("idea/testData/intentions/usePropertyAccessSyntax/getReservedWord2.kt");
}
@TestMetadata("getSafeCall.kt")
public void testGetSafeCall() throws Exception {
runTest("idea/testData/intentions/usePropertyAccessSyntax/getSafeCall.kt");
@@ -15396,6 +15406,16 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
runTest("idea/testData/intentions/usePropertyAccessSyntax/setImplicitReceiver.kt");
}
@TestMetadata("setReservedWord1.kt")
public void testSetReservedWord1() throws Exception {
runTest("idea/testData/intentions/usePropertyAccessSyntax/setReservedWord1.kt");
}
@TestMetadata("setReservedWord2.kt")
public void testSetReservedWord2() throws Exception {
runTest("idea/testData/intentions/usePropertyAccessSyntax/setReservedWord2.kt");
}
@TestMetadata("setSafeCall.kt")
public void testSetSafeCall() throws Exception {
runTest("idea/testData/intentions/usePropertyAccessSyntax/setSafeCall.kt");