More quickfixes to use API for setting type ref
This commit is contained in:
@@ -20,7 +20,6 @@ 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 com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiErrorElement;
|
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import com.intellij.util.IncorrectOperationException;
|
import com.intellij.util.IncorrectOperationException;
|
||||||
@@ -108,26 +107,15 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction>
|
|||||||
changeFunctionLiteralReturnTypeFix.invoke(project, editor, file);
|
changeFunctionLiteralReturnTypeFix.invoke(project, editor, file);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
element.setReturnTypeRef(null);
|
|
||||||
if (!(KotlinBuiltIns.getInstance().isUnit(type) && element.hasBlockBody())) {
|
if (!(KotlinBuiltIns.getInstance().isUnit(type) && element.hasBlockBody())) {
|
||||||
addReturnTypeAnnotation(element, renderedType);
|
element.setReturnTypeRef(JetPsiFactory(project).createType(renderedType));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
element.setReturnTypeRef(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addReturnTypeAnnotation(JetFunction function, String typeText) {
|
|
||||||
PsiElement elementToPrecedeType = function.getValueParameterList();
|
|
||||||
if (elementToPrecedeType == null) elementToPrecedeType = function.getNameIdentifier();
|
|
||||||
assert elementToPrecedeType != null : "Return type of function without name can't mismatch anything";
|
|
||||||
if (elementToPrecedeType.getNextSibling() instanceof PsiErrorElement) {
|
|
||||||
// if a function doesn't have a value parameter list, a syntax error is raised, and it should follow the function name
|
|
||||||
elementToPrecedeType = elementToPrecedeType.getNextSibling();
|
|
||||||
}
|
|
||||||
JetPsiFactory psiFactory = JetPsiFactory(function);
|
|
||||||
function.addAfter(psiFactory.createType(typeText), elementToPrecedeType);
|
|
||||||
function.addAfter(psiFactory.createColon(), elementToPrecedeType);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetMultiDeclarationEntry getMultiDeclarationEntryThatTypeMismatchComponentFunction(Diagnostic diagnostic) {
|
public static JetMultiDeclarationEntry getMultiDeclarationEntryThatTypeMismatchComponentFunction(Diagnostic diagnostic) {
|
||||||
Name componentName = COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH.cast(diagnostic).getA();
|
Name componentName = COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH.cast(diagnostic).getA();
|
||||||
|
|||||||
@@ -65,8 +65,6 @@ public class ChangeParameterTypeFix extends JetIntentionAction<JetParameter> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||||
JetTypeReference typeReference = element.getTypeReference();
|
element.setTypeRef(JetPsiFactory(file).createType(renderedType));
|
||||||
assert typeReference != null : "Parameter without type annotation cannot cause type mismatch";
|
|
||||||
typeReference.replace(JetPsiFactory(file).createType(renderedType));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-8
@@ -24,7 +24,6 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
|||||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
import org.jetbrains.jet.plugin.quickfix.AddModifierFix;
|
import org.jetbrains.jet.plugin.quickfix.AddModifierFix;
|
||||||
import org.jetbrains.jet.plugin.quickfix.ChangeFunctionReturnTypeFix;
|
|
||||||
import org.jetbrains.jet.plugin.quickfix.ChangeVisibilityModifierFix;
|
import org.jetbrains.jet.plugin.quickfix.ChangeVisibilityModifierFix;
|
||||||
import org.jetbrains.jet.plugin.refactoring.JetRefactoringUtil;
|
import org.jetbrains.jet.plugin.refactoring.JetRefactoringUtil;
|
||||||
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetChangeInfo;
|
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetChangeInfo;
|
||||||
@@ -62,8 +61,9 @@ public class JetFunctionDefinitionUsage extends JetUsageInfo<PsiElement> {
|
|||||||
String returnTypeText = changeInfo.getNewReturnTypeText();
|
String returnTypeText = changeInfo.getNewReturnTypeText();
|
||||||
|
|
||||||
//TODO use ChangeFunctionReturnTypeFix.invoke when JetTypeCodeFragment.getType() is ready
|
//TODO use ChangeFunctionReturnTypeFix.invoke when JetTypeCodeFragment.getType() is ready
|
||||||
if (!KotlinBuiltIns.getInstance().getUnitType().toString().equals(returnTypeText))
|
if (!KotlinBuiltIns.getInstance().getUnitType().toString().equals(returnTypeText)) {
|
||||||
ChangeFunctionReturnTypeFix.addReturnTypeAnnotation(function, returnTypeText);
|
function.setReturnTypeRef(JetPsiFactory(function).createType(returnTypeText));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -138,11 +138,8 @@ public class JetFunctionDefinitionUsage extends JetUsageInfo<PsiElement> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (parameterInfo.isTypeChanged()) {
|
if (parameterInfo.isTypeChanged()) {
|
||||||
JetTypeReference newType = psiFactory.createType(parameterInfo.getTypeText());
|
JetTypeReference newTypeRef = psiFactory.createType(parameterInfo.getTypeText());
|
||||||
JetTypeReference typeReference = parameter.getTypeReference();
|
parameter.setTypeRef(newTypeRef);
|
||||||
|
|
||||||
if (typeReference != null)
|
|
||||||
typeReference.replace(newType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PsiElement identifier = parameter.getNameIdentifier();
|
PsiElement identifier = parameter.getNameIdentifier();
|
||||||
|
|||||||
Reference in New Issue
Block a user