From 95a8db458bfc3ab799652e30468113edaa8f5019 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 2 Apr 2015 17:50:04 +0300 Subject: [PATCH] Minor: Generify KotlinInplaceVariableIntroducer --- .../KotlinInplacePropertyIntroducer.kt | 18 +++++--- .../KotlinInplaceVariableIntroducer.java | 41 ++++++++++--------- .../KotlinIntroduceVariableHandler.java | 4 +- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceProperty/KotlinInplacePropertyIntroducer.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceProperty/KotlinInplacePropertyIntroducer.kt index 852e9339bb0..f5a754a06a4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceProperty/KotlinInplacePropertyIntroducer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceProperty/KotlinInplacePropertyIntroducer.kt @@ -42,7 +42,7 @@ public class KotlinInplacePropertyIntroducer( exprType: JetType?, extractionResult: ExtractionResult, private val availableTargets: List -): KotlinInplaceVariableIntroducer( +): KotlinInplaceVariableIntroducer( property, editor, project, title, JetExpression.EMPTY_ARRAY, null, false, property, false, doNotChangeVar, exprType, false ) { init { @@ -58,9 +58,9 @@ public class KotlinInplacePropertyIntroducer( $currentTarget = value runWriteActionAndRestartRefactoring { with (extractionResult.config) { - extractionResult = copy(generatorOptions = generatorOptions.copy(target = currentTarget)).generateDeclaration(myProperty) - myProperty = extractionResult.declaration as JetProperty - myElementToRename = myProperty + extractionResult = copy(generatorOptions = generatorOptions.copy(target = currentTarget)).generateDeclaration(property) + property = extractionResult.declaration as JetProperty + myElementToRename = property } } updatePanelControls() @@ -68,6 +68,12 @@ public class KotlinInplacePropertyIntroducer( private var replaceAll: Boolean = true + protected var property: JetProperty + get() = myDeclaration + set(value: JetProperty) { + myDeclaration = value + } + private fun isInitializer(): Boolean = currentTarget == ExtractionTarget.PROPERTY_WITH_INITIALIZER override fun initPanelControls() { @@ -109,7 +115,7 @@ public class KotlinInplacePropertyIntroducer( getCreateVarCheckBox()?.let { val initializer = object: Pass() { override fun pass(t: JComponent) { - (t as JCheckBox).setSelected(myProperty.isVar()) + (t as JCheckBox).setSelected(property.isVar()) } } addPanelControl(ControlWrapper(it, condition, initializer)) @@ -117,7 +123,7 @@ public class KotlinInplacePropertyIntroducer( getCreateExplicitTypeCheckBox()?.let { val initializer = object: Pass() { override fun pass(t: JComponent) { - (t as JCheckBox).setSelected(myProperty.getTypeReference() != null) + (t as JCheckBox).setSelected(property.getTypeReference() != null) } } addPanelControl(ControlWrapper(it, condition, initializer)) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinInplaceVariableIntroducer.java b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinInplaceVariableIntroducer.java index 50d66389cc8..5bdd5f2357a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinInplaceVariableIntroducer.java +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/introduce/introduceVariable/KotlinInplaceVariableIntroducer.java @@ -43,10 +43,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyAction; import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers; import org.jetbrains.kotlin.lexer.JetTokens; -import org.jetbrains.kotlin.psi.JetExpression; -import org.jetbrains.kotlin.psi.JetProperty; -import org.jetbrains.kotlin.psi.JetPsiFactory; -import org.jetbrains.kotlin.psi.JetTypeReference; +import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.types.JetType; import javax.swing.*; @@ -58,7 +55,7 @@ import java.util.Collection; import java.util.LinkedHashSet; import java.util.List; -public class KotlinInplaceVariableIntroducer extends InplaceVariableIntroducer { +public class KotlinInplaceVariableIntroducer extends InplaceVariableIntroducer { private static final Function0 TRUE = new Function0() { @Override public Boolean invoke() { @@ -113,7 +110,7 @@ public class KotlinInplaceVariableIntroducer extends InplaceVariableIntroducer getSuggestionsForNextRun() { LinkedHashSet nameSuggestions; - String currentName = myProperty.getName(); + String currentName = myDeclaration.getName(); if (myNameSuggestions.contains(currentName)) { nameSuggestions = myNameSuggestions; } @@ -329,7 +330,7 @@ public class KotlinInplaceVariableIntroducer extends InplaceVariableIntroducer variableIntroducer = + new KotlinInplaceVariableIntroducer(property, editor, project, INTRODUCE_VARIABLE, references.toArray(new JetExpression[references.size()]), reference.get(), finalReplaceOccurrence, property, /*todo*/false, /*todo*/false,