Reformat: CreateLocalVariableActionFactory
This commit is contained in:
+7
-7
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.psi.psiUtil.parents
|
|||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
object CreateLocalVariableActionFactory: KotlinSingleIntentionActionFactory() {
|
object CreateLocalVariableActionFactory : KotlinSingleIntentionActionFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
val refExpr = QuickFixUtil.getParentElementOfType(diagnostic, KtNameReferenceExpression::class.java) ?: return null
|
val refExpr = QuickFixUtil.getParentElementOfType(diagnostic, KtNameReferenceExpression::class.java) ?: return null
|
||||||
if (refExpr.getQualifiedElement() != refExpr) return null
|
if (refExpr.getQualifiedElement() != refExpr) return null
|
||||||
@@ -44,10 +44,10 @@ object CreateLocalVariableActionFactory: KotlinSingleIntentionActionFactory() {
|
|||||||
val propertyName = refExpr.getReferencedName()
|
val propertyName = refExpr.getReferencedName()
|
||||||
|
|
||||||
val container = refExpr.parents
|
val container = refExpr.parents
|
||||||
.filter { it is KtBlockExpression || it is KtDeclarationWithBody }
|
.filter { it is KtBlockExpression || it is KtDeclarationWithBody }
|
||||||
.firstOrNull() as? KtElement ?: return null
|
.firstOrNull() as? KtElement ?: return null
|
||||||
|
|
||||||
return object: CreateFromUsageFixBase<KtSimpleNameExpression>(refExpr) {
|
return object : CreateFromUsageFixBase<KtSimpleNameExpression>(refExpr) {
|
||||||
override fun getText(): String = KotlinBundle.message("create.local.variable.from.usage", propertyName)
|
override fun getText(): String = KotlinBundle.message("create.local.variable.from.usage", propertyName)
|
||||||
|
|
||||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||||
@@ -66,12 +66,12 @@ object CreateLocalVariableActionFactory: KotlinSingleIntentionActionFactory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val typeInfo = TypeInfo(
|
val typeInfo = TypeInfo(
|
||||||
originalElement.getExpressionForTypeGuess(),
|
originalElement.getExpressionForTypeGuess(),
|
||||||
if (varExpected) Variance.INVARIANT else Variance.OUT_VARIANCE
|
if (varExpected) Variance.INVARIANT else Variance.OUT_VARIANCE
|
||||||
)
|
)
|
||||||
val propertyInfo = PropertyInfo(propertyName, TypeInfo.Empty, typeInfo, varExpected, Collections.singletonList(actualContainer))
|
val propertyInfo = PropertyInfo(propertyName, TypeInfo.Empty, typeInfo, varExpected, Collections.singletonList(actualContainer))
|
||||||
|
|
||||||
with (CallableBuilderConfiguration(listOfNotNull(propertyInfo), originalElement, file, editor).createBuilder()) {
|
with(CallableBuilderConfiguration(listOfNotNull(propertyInfo), originalElement, file, editor).createBuilder()) {
|
||||||
placement = CallablePlacement.NoReceiver(actualContainer)
|
placement = CallablePlacement.NoReceiver(actualContainer)
|
||||||
project.executeCommand(text) { build() }
|
project.executeCommand(text) { build() }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user