"Change to function invocation" fix added
This commit is contained in:
@@ -86,3 +86,4 @@ options.jet.attribute.descriptor.extension.fun.call=Extension function call
|
||||
options.jet.attribute.descriptor.constructor.call=Constructor call
|
||||
options.jet.attribute.descriptor.auto.casted=Smart-cast value
|
||||
options.jet.attribute.descriptor.label=Label
|
||||
change.to.function.invocation=Change to function invocation
|
||||
|
||||
+3
-3
@@ -33,9 +33,9 @@ import java.util.List;
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class ChangeToInvocationFix extends JetIntentionAction<JetDelegatorToSuperClass> {
|
||||
public class ChangeToConstructorInvocationFix extends JetIntentionAction<JetDelegatorToSuperClass> {
|
||||
|
||||
public ChangeToInvocationFix(@NotNull JetDelegatorToSuperClass element) {
|
||||
public ChangeToConstructorInvocationFix(@NotNull JetDelegatorToSuperClass element) {
|
||||
super(element);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ public class ChangeToInvocationFix extends JetIntentionAction<JetDelegatorToSupe
|
||||
@Override
|
||||
public JetIntentionAction<JetDelegatorToSuperClass> createAction(Diagnostic diagnostic) {
|
||||
if (diagnostic.getPsiElement() instanceof JetDelegatorToSuperClass) {
|
||||
return new ChangeToInvocationFix((JetDelegatorToSuperClass) diagnostic.getPsiElement());
|
||||
return new ChangeToConstructorInvocationFix((JetDelegatorToSuperClass) diagnostic.getPsiElement());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class ChangeToFunctionInvocationFix extends JetIntentionAction<JetReferenceExpression> {
|
||||
|
||||
public ChangeToFunctionInvocationFix(@NotNull JetReferenceExpression element) {
|
||||
super(element);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return JetBundle.message("change.to.function.invocation");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return JetBundle.message("change.to.function.invocation");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
JetReferenceExpression reference = (JetReferenceExpression) element.copy();
|
||||
element.replace(JetPsiFactory.createExpression(project, reference.getText() + "()"));
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetReferenceExpression> createAction(Diagnostic diagnostic) {
|
||||
if (diagnostic.getPsiElement() instanceof JetReferenceExpression) {
|
||||
return new ChangeToFunctionInvocationFix((JetReferenceExpression) diagnostic.getPsiElement());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -119,7 +119,8 @@ public class QuickFixes {
|
||||
JetIntentionActionFactory unresolvedReferenceFactory = ImportClassAndFunFix.createFactory();
|
||||
factories.put(UNRESOLVED_REFERENCE, unresolvedReferenceFactory);
|
||||
|
||||
factories.put(SUPERTYPE_NOT_INITIALIZED_DEFAULT, ChangeToInvocationFix.createFactory());
|
||||
factories.put(SUPERTYPE_NOT_INITIALIZED_DEFAULT, ChangeToConstructorInvocationFix.createFactory());
|
||||
factories.put(FUNCTION_CALL_EXPECTED, ChangeToFunctionInvocationFix.createFactory());
|
||||
|
||||
factories.put(CANNOT_CHANGE_ACCESS_PRIVILEGE, ChangeVisibilityModifierFix.createFactory());
|
||||
factories.put(CANNOT_WEAKEN_ACCESS_PRIVILEGE, ChangeVisibilityModifierFix.createFactory());
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Change to function invocation" "true"
|
||||
package a
|
||||
|
||||
fun foo() {}
|
||||
|
||||
fun test() {
|
||||
foo()
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Change to function invocation" "true"
|
||||
package a
|
||||
|
||||
fun foo() {}
|
||||
|
||||
fun test() {
|
||||
foo<caret>
|
||||
}
|
||||
Reference in New Issue
Block a user