Change to Function Invocation Quick-Fix: Convert to Kotlin & refactor
This commit is contained in:
@@ -128,7 +128,6 @@ options.kotlin.attribute.descriptor.smart.constant=Smart constant
|
|||||||
options.kotlin.attribute.descriptor.smart.cast.receiver=Smart-cast implicit receiver
|
options.kotlin.attribute.descriptor.smart.cast.receiver=Smart-cast implicit receiver
|
||||||
options.kotlin.attribute.descriptor.implicit.exhaustive.when=Implicitly exhaustive when
|
options.kotlin.attribute.descriptor.implicit.exhaustive.when=Implicitly exhaustive when
|
||||||
options.kotlin.attribute.descriptor.label=Label
|
options.kotlin.attribute.descriptor.label=Label
|
||||||
change.to.function.invocation=Change to function invocation
|
|
||||||
migrate.sure=Replace sure() calls by !! in project
|
migrate.sure=Replace sure() calls by !! in project
|
||||||
migrate.class.object.to.companion=Replace 'class' keyword with 'companion' modifier
|
migrate.class.object.to.companion=Replace 'class' keyword with 'companion' modifier
|
||||||
migrate.class.object.to.companion.family=Replace 'class' Keyword with 'companion' Modifier
|
migrate.class.object.to.companion.family=Replace 'class' Keyword with 'companion' Modifier
|
||||||
|
|||||||
@@ -14,51 +14,29 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.idea.quickfix;
|
package org.jetbrains.kotlin.idea.quickfix
|
||||||
|
|
||||||
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 com.intellij.util.IncorrectOperationException;
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic;
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.idea.KotlinBundle;
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
import org.jetbrains.kotlin.psi.KtExpression;
|
import org.jetbrains.kotlin.psi.createExpressionByPattern
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
|
||||||
import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
|
|
||||||
|
|
||||||
public class ChangeToFunctionInvocationFix extends KotlinQuickFixAction<KtExpression> {
|
class ChangeToFunctionInvocationFix(element: KtExpression) : KotlinQuickFixAction<KtExpression>(element) {
|
||||||
|
override fun getFamilyName() = "Change to function invocation"
|
||||||
|
|
||||||
public ChangeToFunctionInvocationFix(@NotNull KtExpression element) {
|
override fun getText() = familyName
|
||||||
super(element);
|
|
||||||
|
public override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||||
|
element.replace(KtPsiFactory(file).createExpressionByPattern("$0()", element))
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
companion object : KotlinSingleIntentionActionFactory() {
|
||||||
@Override
|
override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction<KtExpression>? {
|
||||||
public String getText() {
|
val expression = diagnostic.psiElement as? KtExpression ?: return null
|
||||||
return KotlinBundle.message("change.to.function.invocation");
|
return ChangeToFunctionInvocationFix(expression)
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getFamilyName() {
|
|
||||||
return KotlinBundle.message("change.to.function.invocation");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException {
|
|
||||||
KtExpression reference = (KtExpression) getElement().copy();
|
|
||||||
getElement().replace(KtPsiFactoryKt.KtPsiFactory(file).createExpression(reference.getText() + "()"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static KotlinSingleIntentionActionFactory createFactory() {
|
|
||||||
return new KotlinSingleIntentionActionFactory() {
|
|
||||||
@Override
|
|
||||||
public KotlinQuickFixAction<KtExpression> createAction(@NotNull Diagnostic diagnostic) {
|
|
||||||
if (diagnostic.getPsiElement() instanceof KtExpression) {
|
|
||||||
return new ChangeToFunctionInvocationFix((KtExpression) diagnostic.getPsiElement());
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ class QuickFixRegistrar : QuickFixContributor {
|
|||||||
CONFLICTING_IMPORT.registerFactory(removeImportFixFactory)
|
CONFLICTING_IMPORT.registerFactory(removeImportFixFactory)
|
||||||
|
|
||||||
SUPERTYPE_NOT_INITIALIZED.registerFactory(SuperClassNotInitialized)
|
SUPERTYPE_NOT_INITIALIZED.registerFactory(SuperClassNotInitialized)
|
||||||
FUNCTION_CALL_EXPECTED.registerFactory(ChangeToFunctionInvocationFix.createFactory())
|
FUNCTION_CALL_EXPECTED.registerFactory(ChangeToFunctionInvocationFix)
|
||||||
|
|
||||||
CANNOT_CHANGE_ACCESS_PRIVILEGE.registerFactory(ChangeVisibilityModifierFix.createFactory())
|
CANNOT_CHANGE_ACCESS_PRIVILEGE.registerFactory(ChangeVisibilityModifierFix.createFactory())
|
||||||
CANNOT_WEAKEN_ACCESS_PRIVILEGE.registerFactory(ChangeVisibilityModifierFix.createFactory())
|
CANNOT_WEAKEN_ACCESS_PRIVILEGE.registerFactory(ChangeVisibilityModifierFix.createFactory())
|
||||||
|
|||||||
Reference in New Issue
Block a user