Create from Usage: Forbid for parameters/local variables when reference is not an identifier
#KT-9305 Fixed
This commit is contained in:
+3
-1
@@ -27,18 +27,20 @@ import org.jetbrains.kotlin.idea.quickfix.JetSingleIntentionActionFactory
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.CreateFromUsageFixBase
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.*
|
||||
import org.jetbrains.kotlin.idea.util.application.executeCommand
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getAssignmentByLHS
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList
|
||||
import java.util.Collections
|
||||
import java.util.*
|
||||
|
||||
object CreateLocalVariableActionFactory: JetSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||
val refExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetSimpleNameExpression>()) ?: return null
|
||||
if (refExpr.getQualifiedElement() != refExpr) return null
|
||||
if (refExpr.getReferencedNameElementType() != JetTokens.IDENTIFIER) return null
|
||||
|
||||
val propertyName = refExpr.getReferencedName()
|
||||
|
||||
|
||||
+2
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.guessT
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetParameterInfo
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.JetValVar
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getAssignmentByLHS
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement
|
||||
@@ -47,6 +48,7 @@ object CreateParameterByRefActionFactory : CreateParameterFromUsageFactory<JetSi
|
||||
override fun getElementOfInterest(diagnostic: Diagnostic): JetSimpleNameExpression? {
|
||||
val refExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass<JetSimpleNameExpression>()) ?: return null
|
||||
if (refExpr.getQualifiedElement() != refExpr) return null
|
||||
if (refExpr.getReferencedNameElementType() != JetTokens.IDENTIFIER) return null
|
||||
return refExpr
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// "Import" "false"
|
||||
// ACTION: Create extension function 'inc'
|
||||
// ACTION: Create member function 'inc'
|
||||
// ACTION: Create local variable '++'
|
||||
// ACTION: Create parameter '++'
|
||||
// ACTION: Replace overloaded operator with function call
|
||||
// ERROR: Unresolved reference: ++
|
||||
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Create local variable '-'" "false"
|
||||
// ACTION: Create extension function 'minus'
|
||||
// ACTION: Create member function 'minus'
|
||||
// ACTION: Replace overloaded operator with function call
|
||||
// ERROR: Unresolved reference: -
|
||||
class A
|
||||
|
||||
fun bar() {
|
||||
val a = A()
|
||||
return a <caret>- a
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Create parameter '-'" "false"
|
||||
// ACTION: Create extension function 'minus'
|
||||
// ACTION: Create member function 'minus'
|
||||
// ACTION: Replace overloaded operator with function call
|
||||
// ERROR: Unresolved reference: -
|
||||
class A
|
||||
|
||||
fun bar() {
|
||||
val a = A()
|
||||
return a <caret>- a
|
||||
}
|
||||
@@ -2465,6 +2465,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nonIdentifier.kt")
|
||||
public void testNonIdentifier() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/localVariable/nonIdentifier.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nullableType.kt")
|
||||
public void testNullableType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/localVariable/nullableType.kt");
|
||||
@@ -2714,6 +2720,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nonIdentifier.kt")
|
||||
public void testNonIdentifier() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/nonIdentifier.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nullableType.kt")
|
||||
public void testNullableType() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/createFromUsage/createVariable/parameter/nullableType.kt");
|
||||
|
||||
Reference in New Issue
Block a user