Remove 'val'/'var' from Parameter Quick-Fix: Convert to Kotlin & refactor
This commit is contained in:
@@ -128,7 +128,6 @@ migrate.class.object.to.companion.in.whole.project.modal.title=Replacing 'class'
|
|||||||
migrate.class.object.to.companion.in.whole.project.family=Replace 'class' Keyword with 'companion' Modifier in Whole Project
|
migrate.class.object.to.companion.in.whole.project.family=Replace 'class' Keyword with 'companion' Modifier in Whole Project
|
||||||
migrate.lambda.syntax=Migrate lambda syntax
|
migrate.lambda.syntax=Migrate lambda syntax
|
||||||
migrate.lambda.syntax.family=Migrate lambda syntax
|
migrate.lambda.syntax.family=Migrate lambda syntax
|
||||||
remove.val.var.from.parameter=Remove ''{0}'' from parameter
|
|
||||||
change.to.property.name.family.name=Change to property name
|
change.to.property.name.family.name=Change to property name
|
||||||
change.to.property.name.action=Change ''{0}'' to ''{1}''
|
change.to.property.name.action=Change ''{0}'' to ''{1}''
|
||||||
create.from.usage.family=Create from usage
|
create.from.usage.family=Create from usage
|
||||||
|
|||||||
@@ -165,12 +165,11 @@ class QuickFixRegistrar : QuickFixContributor {
|
|||||||
VAL_REASSIGNMENT.registerFactory(ChangeVariableMutabilityFix.VAL_REASSIGNMENT_FACTORY)
|
VAL_REASSIGNMENT.registerFactory(ChangeVariableMutabilityFix.VAL_REASSIGNMENT_FACTORY)
|
||||||
VAR_OVERRIDDEN_BY_VAL.registerFactory(ChangeVariableMutabilityFix.VAR_OVERRIDDEN_BY_VAL_FACTORY)
|
VAR_OVERRIDDEN_BY_VAL.registerFactory(ChangeVariableMutabilityFix.VAR_OVERRIDDEN_BY_VAL_FACTORY)
|
||||||
|
|
||||||
val removeValVarFromParameterFixFactory = RemoveValVarFromParameterFix.createFactory()
|
VAL_OR_VAR_ON_FUN_PARAMETER.registerFactory(RemoveValVarFromParameterFix)
|
||||||
VAL_OR_VAR_ON_FUN_PARAMETER.registerFactory(removeValVarFromParameterFixFactory)
|
VAL_OR_VAR_ON_LOOP_PARAMETER.registerFactory(RemoveValVarFromParameterFix)
|
||||||
VAL_OR_VAR_ON_LOOP_PARAMETER.registerFactory(removeValVarFromParameterFixFactory)
|
VAL_OR_VAR_ON_LOOP_MULTI_PARAMETER.registerFactory(RemoveValVarFromParameterFix)
|
||||||
VAL_OR_VAR_ON_LOOP_MULTI_PARAMETER.registerFactory(removeValVarFromParameterFixFactory)
|
VAL_OR_VAR_ON_CATCH_PARAMETER.registerFactory(RemoveValVarFromParameterFix)
|
||||||
VAL_OR_VAR_ON_CATCH_PARAMETER.registerFactory(removeValVarFromParameterFixFactory)
|
VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER.registerFactory(RemoveValVarFromParameterFix)
|
||||||
VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER.registerFactory(removeValVarFromParameterFixFactory)
|
|
||||||
|
|
||||||
VIRTUAL_MEMBER_HIDDEN.registerFactory(AddOverrideToEqualsHashCodeToStringActionFactory)
|
VIRTUAL_MEMBER_HIDDEN.registerFactory(AddOverrideToEqualsHashCodeToStringActionFactory)
|
||||||
|
|
||||||
|
|||||||
@@ -14,58 +14,37 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix;
|
package org.jetbrains.kotlin.idea.quickfix
|
||||||
|
|
||||||
import com.intellij.codeInsight.intention.IntentionAction;
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.editor.Editor;
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.project.Project;
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import com.intellij.psi.PsiElement;
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import com.intellij.util.IncorrectOperationException;
|
import org.jetbrains.kotlin.psi.KtValVarKeywordOwner
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinBundle;
|
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
|
||||||
import org.jetbrains.kotlin.psi.KtValVarKeywordOwner;
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt;
|
|
||||||
|
|
||||||
public class RemoveValVarFromParameterFix extends KotlinQuickFixAction<KtValVarKeywordOwner> {
|
class RemoveValVarFromParameterFix(element: KtValVarKeywordOwner) : KotlinQuickFixAction<KtValVarKeywordOwner>(element) {
|
||||||
private final String varOrVal;
|
private val varOrVal: String
|
||||||
|
|
||||||
public RemoveValVarFromParameterFix(@NotNull KtValVarKeywordOwner element) {
|
init {
|
||||||
super(element);
|
val valOrVarNode = element.valOrVarKeyword
|
||||||
PsiElement valOrVarNode = element.getValOrVarKeyword();
|
assert(valOrVarNode != null) { "Val or var node not found for " + element.getElementTextWithContext() }
|
||||||
assert valOrVarNode != null : "Val or var node not found for " + PsiUtilsKt.getElementTextWithContext(element);
|
varOrVal = valOrVarNode!!.text
|
||||||
varOrVal = valOrVarNode.getText();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getFamilyName() = "Remove 'val/var' from parameter"
|
||||||
@Override
|
|
||||||
public String getText() {
|
override fun getText(): String {
|
||||||
return KotlinBundle.message("remove.val.var.from.parameter", varOrVal);
|
val varOrVal = element.valOrVarKeyword?.text ?: return familyName
|
||||||
|
return "Remove '$varOrVal' from parameter"
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||||
@Override
|
element.valOrVarKeyword?.delete()
|
||||||
public String getFamilyName() {
|
|
||||||
return KotlinBundle.message("remove.val.var.from.parameter", "val/var");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
companion object : KotlinSingleIntentionActionFactory() {
|
||||||
protected void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException {
|
override fun createAction(diagnostic: Diagnostic) =
|
||||||
PsiElement keyword = getElement().getValOrVarKeyword();
|
RemoveValVarFromParameterFix(diagnostic.psiElement.parent as KtValVarKeywordOwner)
|
||||||
if (keyword == null) return;
|
|
||||||
keyword.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static KotlinSingleIntentionActionFactory createFactory() {
|
|
||||||
return new KotlinSingleIntentionActionFactory() {
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public IntentionAction createAction(@NotNull Diagnostic diagnostic) {
|
|
||||||
return new RemoveValVarFromParameterFix((KtValVarKeywordOwner) diagnostic.getPsiElement().getParent());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user