Do not suggest "create local variable" inside primary constructor

#KT-26158 Fixed
EA-99300 Fixed
This commit is contained in:
Mikhail Glukhikh
2018-08-15 15:57:07 +03:00
parent 34be9ccbbe
commit 04675b4446
3 changed files with 19 additions and 1 deletions
@@ -44,7 +44,7 @@ object CreateLocalVariableActionFactory : KotlinSingleIntentionActionFactory() {
val propertyName = refExpr.getReferencedName()
val container = refExpr.parents
.filter { it is KtBlockExpression || it is KtDeclarationWithBody }
.filter { it is KtBlockExpression || it is KtDeclarationWithBody && it.bodyExpression != null }
.firstOrNull() as? KtElement ?: return null
return object : CreateFromUsageFixBase<KtSimpleNameExpression>(refExpr) {
@@ -0,0 +1,13 @@
// "Create local variable 'defaultPreferencesName'" "false"
// ACTION: Create abstract property 'defaultPreferencesName'
// ACTION: Create parameter 'defaultPreferencesName'
// ACTION: Create property 'defaultPreferencesName'
// ACTION: Rename reference
// ERROR: Unresolved reference: defaultPreferencesName
// ERROR: Default value of annotation parameter must be a compile-time constant
class AppModule {
val defaultPreferencesName = "defaultPreferences"
annotation class Preferences(val type: String = <caret>defaultPreferencesName)
}
@@ -4204,6 +4204,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
runTest("idea/testData/quickfix/createFromUsage/createVariable/localVariable/inAccessorWithExpressionBody.kt");
}
@TestMetadata("inAnnotation.kt")
public void testInAnnotation() throws Exception {
runTest("idea/testData/quickfix/createFromUsage/createVariable/localVariable/inAnnotation.kt");
}
@TestMetadata("inBinaryOperation.kt")
public void testInBinaryOperation() throws Exception {
runTest("idea/testData/quickfix/createFromUsage/createVariable/localVariable/inBinaryOperation.kt");