Merge pull request #282 from lopekpl/type_mismatch_in_literals3
QuickFixes for TYPE_MISMATCH
This commit is contained in:
@@ -59,9 +59,12 @@ add.semicolon.after.invocation=Add semicolon after invocation of ''{0}''
|
||||
add.semicolon.family=Add Semicolon
|
||||
change.function.return.type=Change ''{0}'' function return type to ''{1}''
|
||||
change.no.name.function.return.type=Change function return type to ''{0}''
|
||||
change.function.literal.return.type=Change function literal return type to ''{0}''
|
||||
remove.function.return.type=Remove explicitly specified return type in ''{0}'' function
|
||||
remove.no.name.function.return.type=Remove explicitly specified function return type
|
||||
change.element.type=Change ''{0}'' type to ''{1}''
|
||||
change.function.parameter.type=Change parameter ''{0}'' type of function ''{1}'' to ''{2}''
|
||||
change.primary.constructor.parameter.type=Change parameter ''{0}'' type of primary constructor of class ''{1}'' to ''{2}''
|
||||
change.type=Change type from ''{0}'' to ''{1}''
|
||||
change.type.family=Change Type
|
||||
add.parameters.to.function=Add parameter{0} to function ''{1}''
|
||||
|
||||
@@ -43,9 +43,8 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||
import org.jetbrains.jet.plugin.quickfix.JetIntentionActionFactory;
|
||||
import org.jetbrains.jet.plugin.quickfix.JetIntentionActionsFactory;
|
||||
import org.jetbrains.jet.plugin.quickfix.QuickFixes;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -217,14 +216,12 @@ public class JetPsiChecker implements Annotator {
|
||||
return null;
|
||||
}
|
||||
|
||||
Collection<JetIntentionActionFactory> intentionActionFactories = QuickFixes.getActionFactories(diagnostic.getFactory());
|
||||
for (JetIntentionActionFactory intentionActionFactory : intentionActionFactories) {
|
||||
IntentionAction action = null;
|
||||
if (intentionActionFactory != null) {
|
||||
action = intentionActionFactory.createAction(diagnostic);
|
||||
}
|
||||
if (action != null) {
|
||||
annotation.registerFix(action);
|
||||
Collection<JetIntentionActionsFactory> intentionActionsFactories = QuickFixes.getActionsFactories(diagnostic.getFactory());
|
||||
for (JetIntentionActionsFactory intentionActionsFactory : intentionActionsFactories) {
|
||||
if (intentionActionsFactory != null) {
|
||||
for (IntentionAction action: intentionActionsFactory.createActions(diagnostic)) {
|
||||
annotation.registerFix(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,8 +67,8 @@ public class AddFunctionBodyFix extends JetIntentionAction<JetFunction> {
|
||||
element.replace(newElement);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JetIntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -158,8 +158,8 @@ public class AddFunctionToSupertypeFix extends JetHintAction<JetNamedFunction> {
|
||||
return new JetAddFunctionToClassifierAction(project, editor, bindingContext, functionsToAdd);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetIntentionActionsFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -164,8 +164,8 @@ public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static <T extends JetModifierListOwner> JetIntentionActionFactory createFactory(final JetKeywordToken modifier, final Class<T> modifierOwnerClass) {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static <T extends JetModifierListOwner> JetSingleIntentionActionFactory createFactory(final JetKeywordToken modifier, final Class<T> modifierOwnerClass) {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
JetModifierListOwner modifierListOwner = QuickFixUtil.getParentElementOfType(diagnostic, modifierOwnerClass);
|
||||
@@ -175,7 +175,7 @@ public class AddModifierFix extends JetIntentionAction<JetModifierListOwner> {
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory(JetKeywordToken modifier) {
|
||||
public static JetSingleIntentionActionFactory createFactory(JetKeywordToken modifier) {
|
||||
return createFactory(modifier, JetModifierListOwner.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -183,8 +183,8 @@ public class AddNameToArgumentFix extends JetIntentionAction<JetValueArgument> {
|
||||
return JetBundle.message("add.name.to.argument.family");
|
||||
}
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetIntentionActionsFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
+2
-2
@@ -81,8 +81,8 @@ public class AddOpenModifierToClassDeclarationFix extends JetIntentionAction<Jet
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -61,8 +61,8 @@ public class AddSemicolonAfterFunctionCallFix extends JetIntentionAction<JetCall
|
||||
editor.getCaretModel().moveToOffset(caretOffset + 1);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JetIntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -68,8 +68,8 @@ public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserTy
|
||||
return true;
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactoryForIsExpression() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactoryForIsExpression() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
assert diagnostic.getFactory() == Errors.NO_TYPE_ARGUMENTS_ON_RHS_OF_IS_EXPRESSION;
|
||||
@@ -84,8 +84,8 @@ public abstract class AddStarProjectionsFix extends JetIntentionAction<JetUserTy
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactoryForJavaClass() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactoryForJavaClass() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
assert diagnostic.getFactory() == Errors.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
|
||||
|
||||
@@ -74,8 +74,8 @@ public class AddWhenElseBranchFix extends JetIntentionAction<JetWhenExpression>
|
||||
editor.getCaretModel().moveToOffset(textRange.getStartOffset() + indexOfOpenBrace + 1);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JetIntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -289,8 +289,8 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JetIntentionAction<JetSimpleNameExpression> createAction(@NotNull Diagnostic diagnostic) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -33,19 +32,22 @@ import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
public class CastExpressionFix extends JetIntentionAction<JetExpression> {
|
||||
private final JetType type;
|
||||
private final String renderedType;
|
||||
|
||||
public CastExpressionFix(@NotNull JetExpression element, @NotNull JetType type) {
|
||||
super(element);
|
||||
this.type = type;
|
||||
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return JetBundle.message("cast.expression.to.type", element.getText(), type.toString());
|
||||
return JetBundle.message("cast.expression.to.type", element.getText(), renderedType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -64,9 +66,9 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
JetBinaryExpressionWithTypeRHS castedExpression =
|
||||
(JetBinaryExpressionWithTypeRHS) JetPsiFactory.createExpression(project, "(" + element.getText() + ") as " + type.toString());
|
||||
(JetBinaryExpressionWithTypeRHS) JetPsiFactory.createExpression(project, "(" + element.getText() + ") as " + renderedType);
|
||||
if (JetPsiUtil.areParenthesesUseless((JetParenthesizedExpression) castedExpression.getLeft())) {
|
||||
castedExpression = (JetBinaryExpressionWithTypeRHS) JetPsiFactory.createExpression(project, element.getText() + " as " + type.toString());
|
||||
castedExpression = (JetBinaryExpressionWithTypeRHS) JetPsiFactory.createExpression(project, element.getText() + " as " + renderedType);
|
||||
}
|
||||
|
||||
JetParenthesizedExpression castedExpressionInParentheses =
|
||||
@@ -78,8 +80,8 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactoryForAutoCastImpossible() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactoryForAutoCastImpossible() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
@@ -91,32 +93,4 @@ public class CastExpressionFix extends JetIntentionAction<JetExpression> {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactoryForTypeMismatch() {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
assert diagnostic.getFactory() == Errors.TYPE_MISMATCH;
|
||||
@SuppressWarnings("unchecked")
|
||||
DiagnosticWithParameters2<JetExpression, JetType, JetType> diagnosticWithParameters =
|
||||
(DiagnosticWithParameters2<JetExpression, JetType, JetType>) diagnostic;
|
||||
JetExpression expression = diagnosticWithParameters.getPsiElement();
|
||||
|
||||
// we don't want to cast a cast:
|
||||
if (expression instanceof JetBinaryExpressionWithTypeRHS) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 'x: Int' - TYPE_MISMATCH might be reported on 'x', and we don't want this quickfix to be available:
|
||||
JetBinaryExpressionWithTypeRHS parentExpressionWithTypeRHS =
|
||||
PsiTreeUtil.getParentOfType(expression, JetBinaryExpressionWithTypeRHS.class, true);
|
||||
if (parentExpressionWithTypeRHS != null && parentExpressionWithTypeRHS.getLeft() == expression) {
|
||||
return null;
|
||||
}
|
||||
return new CastExpressionFix(expression, diagnosticWithParameters.getA());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,38 +23,38 @@ import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccessor> {
|
||||
private String renderedType;
|
||||
|
||||
public ChangeAccessorTypeFix(@NotNull JetPropertyAccessor element) {
|
||||
super(element);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetType getPropertyType() {
|
||||
JetProperty property = PsiTreeUtil.getParentOfType(element, JetProperty.class);
|
||||
if (property == null) return null;
|
||||
return QuickFixUtil.getDeclarationReturnType(property);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
JetType type = getPropertyType();
|
||||
return super.isAvailable(project, editor, file) && type != null && !ErrorUtils.isErrorType(type);
|
||||
JetProperty property = PsiTreeUtil.getParentOfType(element, JetProperty.class);
|
||||
if (property == null) return false;
|
||||
JetType type = QuickFixUtil.getDeclarationReturnType(property);
|
||||
if (super.isAvailable(project, editor, file) && type != null && !ErrorUtils.isErrorType(type)) {
|
||||
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
JetType type = getPropertyType();
|
||||
return element.isGetter()
|
||||
? JetBundle.message("change.getter.type", type)
|
||||
: JetBundle.message("change.setter.type", type);
|
||||
? JetBundle.message("change.getter.type", renderedType)
|
||||
: JetBundle.message("change.setter.type", renderedType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -65,10 +65,8 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
JetType type = getPropertyType();
|
||||
if (type == null) return;
|
||||
JetPropertyAccessor newElement = (JetPropertyAccessor) element.copy();
|
||||
JetTypeReference newTypeReference = JetPsiFactory.createType(project, type.toString());
|
||||
JetTypeReference newTypeReference = JetPsiFactory.createType(project, renderedType);
|
||||
|
||||
if (element.isGetter()) {
|
||||
JetTypeReference returnTypeReference = newElement.getReturnTypeReference();
|
||||
@@ -85,8 +83,8 @@ public class ChangeAccessorTypeFix extends JetIntentionAction<JetPropertyAccesso
|
||||
element.replace(newElement);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetPropertyAccessor> createAction(Diagnostic diagnostic) {
|
||||
JetPropertyAccessor accessor = QuickFixUtil.getParentElementOfType(diagnostic, JetPropertyAccessor.class);
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChangeFunctionLiteralReturnTypeFix extends JetIntentionAction<JetFunctionLiteralExpression> {
|
||||
private final String renderedType;
|
||||
private final JetTypeReference functionLiteralReturnTypeRef;
|
||||
private IntentionAction appropriateQuickFix = null;
|
||||
|
||||
public ChangeFunctionLiteralReturnTypeFix(@NotNull JetFunctionLiteralExpression element, @NotNull JetType type) {
|
||||
super(element);
|
||||
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
|
||||
functionLiteralReturnTypeRef = element.getFunctionLiteral().getReturnTypeRef();
|
||||
|
||||
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext();
|
||||
JetType functionLiteralType = context.get(BindingContext.EXPRESSION_TYPE, element);
|
||||
assert functionLiteralType != null : "Type of function literal not available in binding context";
|
||||
|
||||
ClassDescriptor functionClass = KotlinBuiltIns.getInstance().getFunction(functionLiteralType.getArguments().size() - 1);
|
||||
List<JetType> functionClassTypeParameters = new LinkedList<JetType>();
|
||||
for (TypeProjection typeProjection: functionLiteralType.getArguments()) {
|
||||
functionClassTypeParameters.add(typeProjection.getType());
|
||||
}
|
||||
// Replacing return type:
|
||||
functionClassTypeParameters.remove(functionClassTypeParameters.size() - 1);
|
||||
functionClassTypeParameters.add(type);
|
||||
JetType eventualFunctionLiteralType = TypeUtils.substituteParameters(functionClass, functionClassTypeParameters);
|
||||
|
||||
JetProperty correspondingProperty = PsiTreeUtil.getParentOfType(element, JetProperty.class);
|
||||
if (correspondingProperty != null && QuickFixUtil.canEvaluateTo(correspondingProperty.getInitializer(), element)) {
|
||||
JetTypeReference correspondingPropertyTypeRef = correspondingProperty.getTypeRef();
|
||||
JetType propertyType = context.get(BindingContext.TYPE, correspondingPropertyTypeRef);
|
||||
if (propertyType != null && !JetTypeChecker.INSTANCE.isSubtypeOf(eventualFunctionLiteralType, propertyType)) {
|
||||
appropriateQuickFix = new ChangeVariableTypeFix(correspondingProperty, eventualFunctionLiteralType);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
JetParameter correspondingParameter = QuickFixUtil.getParameterCorrespondingToFunctionLiteralPassedOutsideArgumentList(element);
|
||||
if (correspondingParameter != null) {
|
||||
JetTypeReference correspondingParameterTypeRef = correspondingParameter.getTypeReference();
|
||||
JetType parameterType = context.get(BindingContext.TYPE, correspondingParameterTypeRef);
|
||||
if (parameterType != null && !JetTypeChecker.INSTANCE.isSubtypeOf(eventualFunctionLiteralType, parameterType)) {
|
||||
appropriateQuickFix = new ChangeParameterTypeFix(correspondingParameter, eventualFunctionLiteralType);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
JetFunction parentFunction = PsiTreeUtil.getParentOfType(element, JetFunction.class, true);
|
||||
if (parentFunction != null && QuickFixUtil.canFunctionOrGetterReturnExpression(parentFunction, element)) {
|
||||
JetTypeReference parentFunctionReturnTypeRef = parentFunction.getReturnTypeRef();
|
||||
JetType parentFunctionReturnType = context.get(BindingContext.TYPE, parentFunctionReturnTypeRef);
|
||||
if (parentFunctionReturnType != null && !JetTypeChecker.INSTANCE.isSubtypeOf(eventualFunctionLiteralType, parentFunctionReturnType)) {
|
||||
appropriateQuickFix = new ChangeFunctionReturnTypeFix(parentFunction, eventualFunctionLiteralType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
if (appropriateQuickFix != null) {
|
||||
return appropriateQuickFix.getText();
|
||||
}
|
||||
return JetBundle.message("change.function.literal.return.type", renderedType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return JetBundle.message("change.type.family");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return super.isAvailable(project, editor, file) &&
|
||||
(functionLiteralReturnTypeRef != null || (appropriateQuickFix != null && appropriateQuickFix.isAvailable(project, editor, file)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
if (functionLiteralReturnTypeRef != null) {
|
||||
functionLiteralReturnTypeRef.replace(JetPsiFactory.createType(project, renderedType));
|
||||
}
|
||||
if (appropriateQuickFix != null && appropriateQuickFix.isAvailable(project, editor, file)) {
|
||||
appropriateQuickFix.invoke(project, editor, file);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetSingleIntentionActionFactory createFactoryForExpectedOrAssignmentTypeMismatch() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
JetFunctionLiteralExpression functionLiteralExpression = QuickFixUtil.getParentElementOfType(diagnostic, JetFunctionLiteralExpression.class);
|
||||
assert functionLiteralExpression != null : "ASSIGNMENT/EXPECTED_TYPE_MISMATCH reported outside any function literal";
|
||||
return new ChangeFunctionLiteralReturnTypeFix(functionLiteralExpression, KotlinBuiltIns.getInstance().getUnitType());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,13 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiErrorElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters3;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
@@ -37,24 +39,45 @@ import org.jetbrains.jet.lang.resolve.DescriptorResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.KotlinCacheManagerUtil;
|
||||
import org.jetbrains.jet.plugin.intentions.SpecifyTypeExplicitlyAction;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunction> {
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetFunction> {
|
||||
private final JetType type;
|
||||
private final String renderedType;
|
||||
private final ChangeFunctionLiteralReturnTypeFix changeFunctionLiteralReturnTypeFix;
|
||||
|
||||
public ChangeFunctionReturnTypeFix(@NotNull JetNamedFunction element, @NotNull JetType type) {
|
||||
public ChangeFunctionReturnTypeFix(@NotNull JetFunction element, @NotNull JetType type) {
|
||||
super(element);
|
||||
this.type = type;
|
||||
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
|
||||
if (element instanceof JetFunctionLiteral) {
|
||||
JetFunctionLiteralExpression functionLiteralExpression = PsiTreeUtil.getParentOfType(element, JetFunctionLiteralExpression.class);
|
||||
assert functionLiteralExpression != null : "FunctionLiteral outside any FunctionLiteralExpression";
|
||||
changeFunctionLiteralReturnTypeFix = new ChangeFunctionLiteralReturnTypeFix(functionLiteralExpression, type);
|
||||
}
|
||||
else {
|
||||
changeFunctionLiteralReturnTypeFix = null;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
if (changeFunctionLiteralReturnTypeFix != null) {
|
||||
return changeFunctionLiteralReturnTypeFix.getText();
|
||||
}
|
||||
|
||||
String functionName = element.getName();
|
||||
FqName fqName = JetPsiUtil.getFQName(element);
|
||||
if (fqName != null) functionName = fqName.asString();
|
||||
@@ -65,8 +88,8 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
|
||||
JetBundle.message("remove.function.return.type", functionName);
|
||||
}
|
||||
return functionName == null ?
|
||||
JetBundle.message("change.no.name.function.return.type", type.toString()) :
|
||||
JetBundle.message("change.function.return.type", functionName, type.toString());
|
||||
JetBundle.message("change.no.name.function.return.type", renderedType) :
|
||||
JetBundle.message("change.function.return.type", functionName, renderedType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -76,10 +99,20 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, @Nullable Editor editor, @Nullable PsiFile file) throws IncorrectOperationException {
|
||||
SpecifyTypeExplicitlyAction.removeTypeAnnotation(element);
|
||||
if (!(KotlinBuiltIns.getInstance().isUnit(type) && element.hasBlockBody())) {
|
||||
addReturnTypeAnnotation(project, element, type.toString());
|
||||
public boolean isAvailable(@NotNull Project project, @Nullable Editor editor, @Nullable PsiFile file) {
|
||||
return super.isAvailable(project, editor, file) && !ErrorUtils.containsErrorType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, @Nullable Editor editor, @Nullable JetFile file) throws IncorrectOperationException {
|
||||
if (changeFunctionLiteralReturnTypeFix != null) {
|
||||
changeFunctionLiteralReturnTypeFix.invoke(project, editor, file);
|
||||
}
|
||||
else {
|
||||
SpecifyTypeExplicitlyAction.removeTypeAnnotation(element);
|
||||
if (!(KotlinBuiltIns.getInstance().isUnit(type) && element.hasBlockBody())) {
|
||||
addReturnTypeAnnotation(project, element, renderedType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,6 +130,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
|
||||
|
||||
@NotNull
|
||||
public static JetMultiDeclarationEntry getMultiDeclarationEntryThatTypeMismatchComponentFunction(Diagnostic diagnostic) {
|
||||
@SuppressWarnings("unchecked")
|
||||
String componentName = ((DiagnosticWithParameters3<JetExpression, Name, JetType, JetType>) diagnostic).getA().asString();
|
||||
int componentIndex = Integer.valueOf(componentName.substring(DescriptorResolver.COMPONENT_FUNCTION_NAME_PREFIX.length()));
|
||||
JetMultiDeclaration multiDeclaration = QuickFixUtil.getParentElementOfType(diagnostic, JetMultiDeclaration.class);
|
||||
@@ -105,8 +139,8 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactoryForComponentFunctionReturnTypeMismatch() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactoryForComponentFunctionReturnTypeMismatch() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
@@ -114,7 +148,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
|
||||
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) entry.getContainingFile().getContainingFile()).getBindingContext();
|
||||
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
|
||||
if (resolvedCall == null) return null;
|
||||
JetNamedFunction componentFunction = (JetNamedFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
|
||||
JetFunction componentFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
|
||||
JetType expectedType = context.get(BindingContext.TYPE, entry.getTypeRef());
|
||||
if (componentFunction != null && expectedType != null) {
|
||||
return new ChangeFunctionReturnTypeFix(componentFunction, expectedType);
|
||||
@@ -125,8 +159,8 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactoryForHasNextFunctionTypeMismatch() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactoryForHasNextFunctionTypeMismatch() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
@@ -135,7 +169,7 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
|
||||
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) expression.getContainingFile()).getBindingContext();
|
||||
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.LOOP_RANGE_HAS_NEXT_RESOLVED_CALL, expression);
|
||||
if (resolvedCall == null) return null;
|
||||
JetNamedFunction hasNextFunction = (JetNamedFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
|
||||
JetFunction hasNextFunction = (JetFunction) BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
|
||||
if (hasNextFunction != null) {
|
||||
return new ChangeFunctionReturnTypeFix(hasNextFunction, KotlinBuiltIns.getInstance().getBooleanType());
|
||||
}
|
||||
@@ -145,67 +179,75 @@ public class ChangeFunctionReturnTypeFix extends JetIntentionAction<JetNamedFunc
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactoryForCompareToTypeMismatch() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactoryForCompareToTypeMismatch() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class);
|
||||
assert expression != null : "COMPARE_TO_TYPE_MISMATCH reported on element that is not within any expression";
|
||||
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) expression.getContainingFile()).getBindingContext();
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall = context.get(BindingContext.RESOLVED_CALL, expression.getOperationReference());
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall = context.get(BindingContext.RESOLVED_CALL,
|
||||
expression.getOperationReference());
|
||||
if (resolvedCall == null) return null;
|
||||
PsiElement compareTo = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
|
||||
if (!(compareTo instanceof JetNamedFunction)) return null;
|
||||
return new ChangeFunctionReturnTypeFix((JetNamedFunction) compareTo, KotlinBuiltIns.getInstance().getIntType());
|
||||
if (!(compareTo instanceof JetFunction)) return null;
|
||||
return new ChangeFunctionReturnTypeFix((JetFunction) compareTo, KotlinBuiltIns.getInstance().getIntType());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactoryForReturnTypeMismatchOnOverride() {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Nullable
|
||||
public static JetIntentionActionsFactory createFactoryForReturnTypeMismatchOnOverride() {
|
||||
return new JetIntentionActionsFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
JetNamedFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetNamedFunction.class);
|
||||
if (function == null) return null;
|
||||
BindingContext context = KotlinCacheManagerUtil.getDeclarationsBindingContext(function);
|
||||
JetType matchingReturnType = QuickFixUtil.findLowerBoundOfOverriddenCallablesReturnTypes(context, function);
|
||||
return matchingReturnType == null ? null : new ChangeFunctionReturnTypeFix(function, matchingReturnType);
|
||||
public List<IntentionAction> createActions(Diagnostic diagnostic) {
|
||||
List<IntentionAction> actions = new LinkedList<IntentionAction>();
|
||||
|
||||
JetFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetFunction.class);
|
||||
if (function != null) {
|
||||
BindingContext context = KotlinCacheManagerUtil.getDeclarationsBindingContext(function);
|
||||
JetType matchingReturnType = QuickFixUtil.findLowerBoundOfOverriddenCallablesReturnTypes(context, function);
|
||||
if (matchingReturnType != null) {
|
||||
actions.add(new ChangeFunctionReturnTypeFix(function, matchingReturnType));
|
||||
}
|
||||
|
||||
SimpleFunctionDescriptor descriptor = context.get(BindingContext.FUNCTION, function);
|
||||
if (descriptor == null) return actions;
|
||||
JetType functionType = descriptor.getReturnType();
|
||||
if (functionType == null) return actions;
|
||||
|
||||
List<FunctionDescriptor> overriddenMismatchingFunctions = new LinkedList<FunctionDescriptor>();
|
||||
for (FunctionDescriptor overriddenFunction: descriptor.getOverriddenDescriptors()) {
|
||||
JetType overriddenFunctionType = overriddenFunction.getReturnType();
|
||||
if (overriddenFunctionType == null) continue;
|
||||
if (!JetTypeChecker.INSTANCE.isSubtypeOf(functionType, overriddenFunctionType)) {
|
||||
overriddenMismatchingFunctions.add(overriddenFunction);
|
||||
}
|
||||
}
|
||||
|
||||
if (overriddenMismatchingFunctions.size() == 1) {
|
||||
PsiElement overriddenFunction = BindingContextUtils.descriptorToDeclaration(context, overriddenMismatchingFunctions.get(0));
|
||||
if (overriddenFunction instanceof JetFunction) {
|
||||
actions.add(new ChangeFunctionReturnTypeFix((JetFunction) overriddenFunction, functionType));
|
||||
}
|
||||
}
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactoryForChangingReturnTypeToUnit() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactoryForChangingReturnTypeToUnit() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
JetNamedFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetNamedFunction.class);
|
||||
JetFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetFunction.class);
|
||||
return function == null ? null : new ChangeFunctionReturnTypeFix(function, KotlinBuiltIns.getInstance().getUnitType());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactoryForTypeMismatch() {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
JetExpression expression = (JetExpression) diagnostic.getPsiElement();
|
||||
JetNamedFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetNamedFunction.class);
|
||||
|
||||
if (function != null && (function.getInitializer() == expression || expression.getParent() instanceof JetReturnExpression)) {
|
||||
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) diagnostic.getPsiFile()).getBindingContext();
|
||||
JetType type = context.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||
assert type != null : "Expression type mismatch, but expression has no type";
|
||||
return new ChangeFunctionReturnTypeFix(function, type);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,8 +124,8 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
||||
});
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) {
|
||||
JetCallElement callElement = PsiTreeUtil.getParentOfType(diagnostic.getPsiElement(), JetCallElement.class);
|
||||
@@ -140,8 +140,8 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactoryForParametersNumberMismatch() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactoryForParametersNumberMismatch() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) {
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -159,8 +159,8 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction<PsiE
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactoryForUnusedParameter() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactoryForUnusedParameter() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -253,8 +253,8 @@ public class ChangeMemberFunctionSignatureFix extends JetHintAction<JetNamedFunc
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
public class ChangeParameterTypeFix extends JetIntentionAction<JetParameter> {
|
||||
private final String renderedType;
|
||||
private final String containingDeclarationName;
|
||||
private final boolean isPrimaryConstructorParameter;
|
||||
|
||||
public ChangeParameterTypeFix(@NotNull JetParameter element, @NotNull JetType type) {
|
||||
super(element);
|
||||
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
|
||||
JetNamedDeclaration declaration = PsiTreeUtil.getParentOfType(element, JetNamedDeclaration.class);
|
||||
isPrimaryConstructorParameter = declaration instanceof JetClass;
|
||||
FqName declarationFQName = declaration == null ? null : JetPsiUtil.getFQName(declaration);
|
||||
containingDeclarationName = declarationFQName == null ? null : declarationFQName.asString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return super.isAvailable(project, editor, file) && containingDeclarationName != null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return isPrimaryConstructorParameter ?
|
||||
JetBundle.message("change.primary.constructor.parameter.type", element.getName(), containingDeclarationName, renderedType) :
|
||||
JetBundle.message("change.function.parameter.type", element.getName(), containingDeclarationName, renderedType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return JetBundle.message("change.type.family");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
JetTypeReference typeReference = element.getTypeReference();
|
||||
assert typeReference != null : "Parameter without type annotation cannot cause type mismatch";
|
||||
typeReference.replace(JetPsiFactory.createType(project, renderedType));
|
||||
}
|
||||
}
|
||||
@@ -49,8 +49,8 @@ public class ChangeToBackingFieldFix extends JetIntentionAction<JetSimpleNameExp
|
||||
element.replace(backingField);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetSimpleNameExpression> createAction(Diagnostic diagnostic) {
|
||||
JetSimpleNameExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetSimpleNameExpression.class);
|
||||
|
||||
@@ -84,8 +84,8 @@ public class ChangeToConstructorInvocationFix extends JetIntentionAction<JetDele
|
||||
element.replace(specifier);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetDelegatorToSuperClass> createAction(Diagnostic diagnostic) {
|
||||
if (diagnostic.getPsiElement() instanceof JetDelegatorToSuperClass) {
|
||||
|
||||
@@ -50,8 +50,8 @@ public class ChangeToFunctionInvocationFix extends JetIntentionAction<JetExpress
|
||||
element.replace(JetPsiFactory.createExpression(project, reference.getText() + "()"));
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetExpression> createAction(Diagnostic diagnostic) {
|
||||
if (diagnostic.getPsiElement() instanceof JetExpression) {
|
||||
|
||||
@@ -58,8 +58,8 @@ public class ChangeToPropertyNameFix extends JetIntentionAction<JetSimpleNameExp
|
||||
element.replace(propertyName);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetSimpleNameExpression> createAction(Diagnostic diagnostic) {
|
||||
JetSimpleNameExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetSimpleNameExpression.class);
|
||||
|
||||
@@ -54,8 +54,8 @@ public class ChangeToStarProjectionFix extends JetIntentionAction<JetTypeElement
|
||||
}
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
JetBinaryExpressionWithTypeRHS expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpressionWithTypeRHS.class);
|
||||
|
||||
@@ -19,31 +19,32 @@ package org.jetbrains.jet.plugin.quickfix;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
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.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters1;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetParameter;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
|
||||
private final JetType type;
|
||||
private final String renderedType;
|
||||
|
||||
public ChangeTypeFix(@NotNull JetTypeReference element, JetType type) {
|
||||
super(element);
|
||||
this.type = type;
|
||||
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return JetBundle.message("change.type", element.getText(), type);
|
||||
return JetBundle.message("change.type", element.getText(), renderedType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -53,13 +54,13 @@ public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
element.replace(JetPsiFactory.createType(project, type.toString()));
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
element.replace(JetPsiFactory.createType(project, renderedType));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactoryForExpectedParameterTypeMismatch() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactoryForExpectedParameterTypeMismatch() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
@@ -74,8 +75,8 @@ public class ChangeTypeFix extends JetIntentionAction<JetTypeReference> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactoryForExpectedReturnTypeMismatch() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactoryForExpectedReturnTypeMismatch() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -26,29 +26,43 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.KotlinCacheManagerUtil;
|
||||
import org.jetbrains.jet.plugin.intentions.SpecifyTypeExplicitlyAction;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclaration> {
|
||||
private final String renderedType;
|
||||
private final JetType type;
|
||||
|
||||
public ChangeVariableTypeFix(@NotNull JetVariableDeclaration element, @NotNull JetType type) {
|
||||
super(element);
|
||||
renderedType = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(type);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getText() {
|
||||
return JetBundle.message("change.element.type", element.getName(), type);
|
||||
String propertyName = element.getName();
|
||||
FqName fqName = JetPsiUtil.getFQName(element);
|
||||
if (fqName != null) propertyName = fqName.asString();
|
||||
|
||||
return JetBundle.message("change.element.type", propertyName, renderedType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -58,17 +72,37 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
|
||||
return super.isAvailable(project, editor, file) && !ErrorUtils.containsErrorType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull Project project, Editor editor, JetFile file) throws IncorrectOperationException {
|
||||
SpecifyTypeExplicitlyAction.removeTypeAnnotation(element);
|
||||
PsiElement nameIdentifier = element.getNameIdentifier();
|
||||
assert nameIdentifier != null : "ChangeVariableTypeFix applied to variable without name";
|
||||
Pair<PsiElement, PsiElement> typeWhiteSpaceAndColon = JetPsiFactory.createTypeWhiteSpaceAndColon(project, type.toString());
|
||||
Pair<PsiElement, PsiElement> typeWhiteSpaceAndColon = JetPsiFactory.createTypeWhiteSpaceAndColon(project, renderedType);
|
||||
element.addRangeAfter(typeWhiteSpaceAndColon.first, typeWhiteSpaceAndColon.second, nameIdentifier);
|
||||
|
||||
if (element instanceof JetProperty) {
|
||||
JetPropertyAccessor getter = ((JetProperty) element).getGetter();
|
||||
JetTypeReference getterReturnTypeRef = getter == null ? null : getter.getReturnTypeReference();
|
||||
if (getterReturnTypeRef != null) {
|
||||
getterReturnTypeRef.replace(JetPsiFactory.createType(project, renderedType));
|
||||
}
|
||||
|
||||
JetPropertyAccessor setter = ((JetProperty) element).getSetter();
|
||||
JetParameter setterParameter = setter == null ? null : setter.getParameter();
|
||||
JetTypeReference setterParameterTypeRef = setterParameter == null ? null : setterParameter.getTypeReference();
|
||||
if (setterParameterTypeRef != null) {
|
||||
setterParameterTypeRef.replace(JetPsiFactory.createType(project, renderedType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactoryForComponentFunctionReturnTypeMismatch() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactoryForComponentFunctionReturnTypeMismatch() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
@@ -85,16 +119,53 @@ public class ChangeVariableTypeFix extends JetIntentionAction<JetVariableDeclara
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactoryForPropertyOrReturnTypeMismatchOnOverride() {
|
||||
return new JetIntentionActionFactory() {
|
||||
@Nullable
|
||||
public static JetIntentionActionsFactory createFactoryForPropertyOrReturnTypeMismatchOnOverride() {
|
||||
return new JetIntentionActionsFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
public List<IntentionAction> createActions(Diagnostic diagnostic) {
|
||||
List<IntentionAction> actions = new LinkedList<IntentionAction>();
|
||||
|
||||
JetProperty property = QuickFixUtil.getParentElementOfType(diagnostic, JetProperty.class);
|
||||
if (property == null) return null;
|
||||
BindingContext context = KotlinCacheManagerUtil.getDeclarationsBindingContext(property);
|
||||
JetType type = QuickFixUtil.findLowerBoundOfOverriddenCallablesReturnTypes(context, property);
|
||||
return type == null ? null : new ChangeVariableTypeFix(property, type);
|
||||
if (property != null) {
|
||||
BindingContext context = KotlinCacheManagerUtil.getDeclarationsBindingContext(property);
|
||||
JetType lowerBoundOfOverriddenPropertiesTypes = QuickFixUtil.findLowerBoundOfOverriddenCallablesReturnTypes(context, property);
|
||||
|
||||
PropertyDescriptor descriptor = (PropertyDescriptor) context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, property);
|
||||
assert descriptor != null : "Descriptor of property not available in binding context";
|
||||
JetType propertyType = descriptor.getReturnType();
|
||||
assert propertyType != null : "Property type cannot be null if it mismatch something";
|
||||
|
||||
List<PropertyDescriptor> overriddenMismatchingProperties = new LinkedList<PropertyDescriptor>();
|
||||
boolean canChangeOverriddenPropertyType = true;
|
||||
for (PropertyDescriptor overriddenProperty: descriptor.getOverriddenDescriptors()) {
|
||||
JetType overriddenPropertyType = overriddenProperty.getReturnType();
|
||||
if (overriddenPropertyType != null) {
|
||||
if (!JetTypeChecker.INSTANCE.isSubtypeOf(propertyType, overriddenPropertyType)) {
|
||||
overriddenMismatchingProperties.add(overriddenProperty);
|
||||
}
|
||||
else if (overriddenProperty.isVar() && !JetTypeChecker.INSTANCE.equalTypes(overriddenPropertyType, propertyType)) {
|
||||
canChangeOverriddenPropertyType = false;
|
||||
}
|
||||
if (overriddenProperty.isVar() && lowerBoundOfOverriddenPropertiesTypes != null &&
|
||||
!JetTypeChecker.INSTANCE.equalTypes(lowerBoundOfOverriddenPropertiesTypes, overriddenPropertyType)) {
|
||||
lowerBoundOfOverriddenPropertiesTypes = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (lowerBoundOfOverriddenPropertiesTypes != null) {
|
||||
actions.add(new ChangeVariableTypeFix(property, lowerBoundOfOverriddenPropertiesTypes));
|
||||
}
|
||||
|
||||
if (overriddenMismatchingProperties.size() == 1 && canChangeOverriddenPropertyType) {
|
||||
PsiElement overriddenProperty = BindingContextUtils.descriptorToDeclaration(context, overriddenMismatchingProperties.get(0));
|
||||
if (overriddenProperty instanceof JetProperty) {
|
||||
actions.add(new ChangeVariableTypeFix((JetProperty) overriddenProperty, propertyType));
|
||||
}
|
||||
}
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -103,8 +103,8 @@ public class ChangeVisibilityModifierFix extends JetIntentionAction<JetModifierL
|
||||
return JetRefactoringUtil.getVisibilityToken(maxVisibility);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
|
||||
PsiElement element = diagnostic.getPsiElement();
|
||||
|
||||
+5
-4
@@ -17,12 +17,13 @@
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
|
||||
public interface JetIntentionActionFactory {
|
||||
import java.util.List;
|
||||
|
||||
@Nullable
|
||||
IntentionAction createAction(Diagnostic diagnostic);
|
||||
public interface JetIntentionActionsFactory {
|
||||
|
||||
@NotNull
|
||||
List<IntentionAction> createActions(Diagnostic diagnostic);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.codeInsight.intention.IntentionAction;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class JetSingleIntentionActionFactory implements JetIntentionActionsFactory {
|
||||
|
||||
@Nullable
|
||||
public abstract IntentionAction createAction(Diagnostic diagnostic);
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public final List<IntentionAction> createActions(Diagnostic diagnostic) {
|
||||
List<IntentionAction> intentionActionList = new LinkedList<IntentionAction>();
|
||||
IntentionAction intentionAction = createAction(diagnostic);
|
||||
if (intentionAction != null) {
|
||||
intentionActionList.add(intentionAction);
|
||||
}
|
||||
return intentionActionList;
|
||||
}
|
||||
}
|
||||
@@ -90,8 +90,8 @@ public class MakeClassAnAnnotationClassFix extends JetIntentionAction<JetAnnotat
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -110,8 +110,8 @@ public class MakeOverriddenMemberOpenFix extends JetIntentionAction<JetDeclarati
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -183,8 +183,8 @@ public class MapPlatformClassToKotlinFix extends JetIntentionAction<JetReference
|
||||
return typeExpr;
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -135,8 +135,8 @@ public class MigrateSureInProjectFix extends JetIntentionAction<PsiElement> {
|
||||
}
|
||||
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JetIntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -78,8 +78,8 @@ public class MoveWhenElseBranchFix extends JetIntentionAction<JetWhenExpression>
|
||||
editor.getCaretModel().moveToOffset(insertedWhenEntry.getTextOffset() + cursorOffset);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JetIntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class QuickFixFactoryForTypeMismatchError implements JetIntentionActionsFactory {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<IntentionAction> createActions(Diagnostic diagnostic) {
|
||||
List<IntentionAction> actions = new LinkedList<IntentionAction>();
|
||||
|
||||
assert diagnostic.getFactory() == Errors.TYPE_MISMATCH;
|
||||
@SuppressWarnings("unchecked")
|
||||
DiagnosticWithParameters2<JetExpression, JetType, JetType> diagnosticWithParameters =
|
||||
(DiagnosticWithParameters2<JetExpression, JetType, JetType>) diagnostic;
|
||||
JetExpression expression = diagnosticWithParameters.getPsiElement();
|
||||
JetType expectedType = diagnosticWithParameters.getA();
|
||||
JetType expressionType = diagnosticWithParameters.getB();
|
||||
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) diagnostic.getPsiFile()).getBindingContext();
|
||||
|
||||
// We don't want to cast a cast or type-asserted expression:
|
||||
if (!(expression instanceof JetBinaryExpressionWithTypeRHS) && !(expression.getParent() instanceof JetBinaryExpressionWithTypeRHS)) {
|
||||
actions.add(new CastExpressionFix(expression, expectedType));
|
||||
}
|
||||
|
||||
// Property initializer type mismatch property type:
|
||||
JetProperty property = PsiTreeUtil.getParentOfType(expression, JetProperty.class);
|
||||
if (property != null) {
|
||||
JetPropertyAccessor getter = property.getGetter();
|
||||
if (QuickFixUtil.canEvaluateTo(property.getInitializer(), expression) ||
|
||||
(getter != null && QuickFixUtil.canFunctionOrGetterReturnExpression(property.getGetter(), expression))) {
|
||||
actions.add(new ChangeVariableTypeFix(property, expressionType));
|
||||
}
|
||||
}
|
||||
|
||||
// Mismatch in returned expression:
|
||||
JetFunction function = PsiTreeUtil.getParentOfType(expression, JetFunction.class, true);
|
||||
if (function != null && QuickFixUtil.canFunctionOrGetterReturnExpression(function, expression)) {
|
||||
actions.add(new ChangeFunctionReturnTypeFix(function, expressionType));
|
||||
}
|
||||
|
||||
// Fixing overloaded operators:
|
||||
if (expression instanceof JetOperationExpression) {
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall =
|
||||
context.get(BindingContext.RESOLVED_CALL, ((JetOperationExpression) expression).getOperationReference());
|
||||
if (resolvedCall != null) {
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getResultingDescriptor());
|
||||
if (declaration instanceof JetFunction) {
|
||||
actions.add(new ChangeFunctionReturnTypeFix((JetFunction) declaration, expectedType));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (expression.getParent() instanceof JetBinaryExpression) {
|
||||
JetBinaryExpression parentBinary = (JetBinaryExpression) expression.getParent();
|
||||
if (parentBinary.getRight() == expression) {
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall = context.get(BindingContext.RESOLVED_CALL, parentBinary.getOperationReference());
|
||||
if (resolvedCall != null) {
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getResultingDescriptor());
|
||||
if (declaration instanceof JetFunction) {
|
||||
JetParameter binaryOperatorParameter = ((JetFunction) declaration).getValueParameterList().getParameters().get(0);
|
||||
actions.add(new ChangeParameterTypeFix(binaryOperatorParameter, expressionType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Change function return type when TYPE_MISMATCH is reported on call expression:
|
||||
if (expression instanceof JetCallExpression) {
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall =
|
||||
context.get(BindingContext.RESOLVED_CALL, ((JetCallExpression) expression).getCalleeExpression());
|
||||
if (resolvedCall != null) {
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getResultingDescriptor());
|
||||
if (declaration instanceof JetFunction) {
|
||||
actions.add(new ChangeFunctionReturnTypeFix((JetFunction) declaration, expectedType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Change type of a function parameter in case TYPE_MISMATCH is reported on expression passed as value argument of call.
|
||||
// 1) When an argument is a dangling function literal:
|
||||
JetFunctionLiteralExpression functionLiteralExpression =
|
||||
QuickFixUtil.getParentElementOfType(diagnostic, JetFunctionLiteralExpression.class);
|
||||
if (functionLiteralExpression != null && functionLiteralExpression.getBodyExpression() == expression) {
|
||||
JetParameter correspondingParameter =
|
||||
QuickFixUtil.getParameterCorrespondingToFunctionLiteralPassedOutsideArgumentList(functionLiteralExpression);
|
||||
JetType functionLiteralExpressionType = context.get(BindingContext.EXPRESSION_TYPE, functionLiteralExpression);
|
||||
if (correspondingParameter != null && functionLiteralExpressionType != null) {
|
||||
actions.add(new ChangeParameterTypeFix(correspondingParameter, functionLiteralExpressionType));
|
||||
}
|
||||
}
|
||||
// 2) When an argument is passed inside value argument list:
|
||||
else {
|
||||
JetValueArgument valueArgument = QuickFixUtil.getParentElementOfType(diagnostic, JetValueArgument.class);
|
||||
if (valueArgument != null && QuickFixUtil.canEvaluateTo(valueArgument.getArgumentExpression(), expression)) {
|
||||
JetParameter correspondingParameter = QuickFixUtil.getParameterCorrespondingToValueArgumentPassedInCall(valueArgument);
|
||||
JetType valueArgumentType = context.get(BindingContext.EXPRESSION_TYPE, valueArgument.getArgumentExpression());
|
||||
if (correspondingParameter != null && valueArgumentType != null) {
|
||||
actions.add(new ChangeParameterTypeFix(correspondingParameter, valueArgumentType));
|
||||
}
|
||||
}
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,10 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.types.DeferredType;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
@@ -93,4 +93,103 @@ public class QuickFixUtil {
|
||||
public static boolean canModifyElement(@NotNull PsiElement element) {
|
||||
return element.isWritable() && !BuiltInsReferenceResolver.isFromBuiltIns(element);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetParameterList getParameterListOfCallee(@NotNull JetCallExpression callExpression) {
|
||||
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) callExpression.getContainingFile()).getBindingContext();
|
||||
ResolvedCall<? extends CallableDescriptor> resolvedCall = context.get(BindingContext.RESOLVED_CALL, callExpression.getCalleeExpression());
|
||||
if (resolvedCall == null) return null;
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context, resolvedCall.getCandidateDescriptor());
|
||||
if (declaration instanceof JetFunction) {
|
||||
return ((JetFunction) declaration).getValueParameterList();
|
||||
}
|
||||
if (declaration instanceof JetClass) {
|
||||
return ((JetClass) declaration).getPrimaryConstructorParameterList();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetParameter getParameterCorrespondingToFunctionLiteralPassedOutsideArgumentList(@NotNull JetFunctionLiteralExpression functionLiteralExpression) {
|
||||
if (!(functionLiteralExpression.getParent() instanceof JetCallExpression)) {
|
||||
return null;
|
||||
}
|
||||
JetCallExpression callExpression = (JetCallExpression) functionLiteralExpression.getParent();
|
||||
JetParameterList parameterList = getParameterListOfCallee(callExpression);
|
||||
if (parameterList == null) return null;
|
||||
return parameterList.getParameters().get(parameterList.getParameters().size() - 1);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetParameter getParameterCorrespondingToValueArgumentPassedInCall(@NotNull JetValueArgument valueArgument) {
|
||||
if (!(valueArgument.getParent() instanceof JetValueArgumentList)) {
|
||||
return null;
|
||||
}
|
||||
JetValueArgumentList valueArgumentList = (JetValueArgumentList) valueArgument.getParent();
|
||||
if (!(valueArgumentList.getParent() instanceof JetCallExpression)) {
|
||||
return null;
|
||||
}
|
||||
JetCallExpression callExpression = (JetCallExpression) valueArgumentList.getParent();
|
||||
JetParameterList parameterList = getParameterListOfCallee(callExpression);
|
||||
if (parameterList == null) return null;
|
||||
int position = valueArgumentList.getArguments().indexOf(valueArgument);
|
||||
if (position == -1) return null;
|
||||
|
||||
if (valueArgument.isNamed()) {
|
||||
JetValueArgumentName valueArgumentName = valueArgument.getArgumentName();
|
||||
JetSimpleNameExpression referenceExpression = valueArgumentName == null ? null : valueArgumentName.getReferenceExpression();
|
||||
String valueArgumentNameAsString = referenceExpression == null ? null : referenceExpression.getReferencedName();
|
||||
if (valueArgumentNameAsString == null) return null;
|
||||
|
||||
for (JetParameter parameter: parameterList.getParameters()) {
|
||||
if (valueArgumentNameAsString.equals(parameter.getName())) {
|
||||
return parameter;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
return parameterList.getParameters().get(position);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean equalOrLastInThenOrElse(JetExpression thenOrElse, JetExpression expression) {
|
||||
if (thenOrElse == expression) return true;
|
||||
return thenOrElse instanceof JetBlockExpression && expression.getParent() == thenOrElse &&
|
||||
PsiTreeUtil.getNextSiblingOfType(expression, JetExpression.class) == null;
|
||||
}
|
||||
|
||||
public static boolean canEvaluateTo(JetExpression parent, JetExpression child) {
|
||||
if (parent == null || child == null) {
|
||||
return false;
|
||||
}
|
||||
while (parent != child) {
|
||||
if (child.getParent() instanceof JetParenthesizedExpression) {
|
||||
child = (JetExpression) child.getParent();
|
||||
continue;
|
||||
}
|
||||
JetIfExpression jetIfExpression = PsiTreeUtil.getParentOfType(child, JetIfExpression.class, true);
|
||||
if (jetIfExpression == null) return false;
|
||||
if (!equalOrLastInThenOrElse(jetIfExpression.getThen(), child) && !equalOrLastInThenOrElse(jetIfExpression.getElse(), child)) {
|
||||
return false;
|
||||
}
|
||||
child = jetIfExpression;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean canFunctionOrGetterReturnExpression(@NotNull JetDeclaration functionOrGetter, @NotNull JetExpression expression) {
|
||||
if (functionOrGetter instanceof JetFunctionLiteral) {
|
||||
JetBlockExpression functionLiteralBody = ((JetFunctionLiteral) functionOrGetter).getBodyExpression();
|
||||
PsiElement returnedElement = functionLiteralBody == null ? null : functionLiteralBody.getLastChild();
|
||||
return returnedElement instanceof JetExpression && canEvaluateTo((JetExpression) returnedElement, expression);
|
||||
}
|
||||
else {
|
||||
if (functionOrGetter instanceof JetWithExpressionInitializer && canEvaluateTo(((JetWithExpressionInitializer) functionOrGetter).getInitializer(), expression)) {
|
||||
return true;
|
||||
}
|
||||
JetReturnExpression returnExpression = PsiTreeUtil.getParentOfType(expression, JetReturnExpression.class);
|
||||
return returnExpression != null && canEvaluateTo(returnExpression.getReturnedExpression(), expression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@ import static org.jetbrains.jet.lexer.JetTokens.*;
|
||||
|
||||
public class QuickFixes {
|
||||
|
||||
private static final Multimap<AbstractDiagnosticFactory, JetIntentionActionFactory> factories = HashMultimap.create();
|
||||
private static final Multimap<AbstractDiagnosticFactory, JetIntentionActionsFactory> factories = HashMultimap.create();
|
||||
private static final Multimap<AbstractDiagnosticFactory, IntentionAction> actions = HashMultimap.create();
|
||||
|
||||
public static Collection<JetIntentionActionFactory> getActionFactories(AbstractDiagnosticFactory diagnosticFactory) {
|
||||
public static Collection<JetIntentionActionsFactory> getActionsFactories(AbstractDiagnosticFactory diagnosticFactory) {
|
||||
return factories.get(diagnosticFactory);
|
||||
}
|
||||
|
||||
@@ -44,12 +44,12 @@ public class QuickFixes {
|
||||
private QuickFixes() {}
|
||||
|
||||
static {
|
||||
JetIntentionActionFactory removeAbstractModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(ABSTRACT_KEYWORD);
|
||||
JetIntentionActionFactory addAbstractModifierFactory = AddModifierFix.createFactory(ABSTRACT_KEYWORD);
|
||||
JetSingleIntentionActionFactory removeAbstractModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(ABSTRACT_KEYWORD);
|
||||
JetSingleIntentionActionFactory addAbstractModifierFactory = AddModifierFix.createFactory(ABSTRACT_KEYWORD);
|
||||
|
||||
factories.put(ABSTRACT_PROPERTY_IN_PRIMARY_CONSTRUCTOR_PARAMETERS, removeAbstractModifierFactory);
|
||||
|
||||
JetIntentionActionFactory removePartsFromPropertyFactory = RemovePartsFromPropertyFix.createFactory();
|
||||
JetSingleIntentionActionFactory removePartsFromPropertyFactory = RemovePartsFromPropertyFix.createFactory();
|
||||
factories.put(ABSTRACT_PROPERTY_WITH_INITIALIZER, removeAbstractModifierFactory);
|
||||
factories.put(ABSTRACT_PROPERTY_WITH_INITIALIZER, removePartsFromPropertyFactory);
|
||||
|
||||
@@ -63,13 +63,13 @@ public class QuickFixes {
|
||||
|
||||
factories.put(MUST_BE_INITIALIZED_OR_BE_ABSTRACT, addAbstractModifierFactory);
|
||||
|
||||
JetIntentionActionFactory removeFinalModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(FINAL_KEYWORD);
|
||||
JetSingleIntentionActionFactory removeFinalModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(FINAL_KEYWORD);
|
||||
|
||||
JetIntentionActionFactory addAbstractToClassFactory = AddModifierFix.createFactory(ABSTRACT_KEYWORD, JetClass.class);
|
||||
JetSingleIntentionActionFactory addAbstractToClassFactory = AddModifierFix.createFactory(ABSTRACT_KEYWORD, JetClass.class);
|
||||
factories.put(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
|
||||
factories.put(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
|
||||
|
||||
JetIntentionActionFactory removeFunctionBodyFactory = RemoveFunctionBodyFix.createFactory();
|
||||
JetSingleIntentionActionFactory removeFunctionBodyFactory = RemoveFunctionBodyFix.createFactory();
|
||||
factories.put(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, removeAbstractModifierFactory);
|
||||
factories.put(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, addAbstractToClassFactory);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class QuickFixes {
|
||||
factories.put(FINAL_PROPERTY_IN_TRAIT, removeFinalModifierFactory);
|
||||
factories.put(FINAL_FUNCTION_WITH_NO_BODY, removeFinalModifierFactory);
|
||||
|
||||
JetIntentionActionFactory addFunctionBodyFactory = AddFunctionBodyFix.createFactory();
|
||||
JetSingleIntentionActionFactory addFunctionBodyFactory = AddFunctionBodyFix.createFactory();
|
||||
factories.put(NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addAbstractModifierFactory);
|
||||
factories.put(NON_ABSTRACT_FUNCTION_WITH_NO_BODY, addFunctionBodyFactory);
|
||||
|
||||
@@ -97,13 +97,13 @@ public class QuickFixes {
|
||||
factories.put(USELESS_CAST_STATIC_ASSERT_IS_FINE, ReplaceOperationInBinaryExpressionFix.createChangeCastToStaticAssertFactory());
|
||||
factories.put(USELESS_CAST, RemoveRightPartOfBinaryExpressionFix.createRemoveCastFactory());
|
||||
|
||||
JetIntentionActionFactory changeAccessorTypeFactory = ChangeAccessorTypeFix.createFactory();
|
||||
JetSingleIntentionActionFactory changeAccessorTypeFactory = ChangeAccessorTypeFix.createFactory();
|
||||
factories.put(WRONG_SETTER_PARAMETER_TYPE, changeAccessorTypeFactory);
|
||||
factories.put(WRONG_GETTER_RETURN_TYPE, changeAccessorTypeFactory);
|
||||
|
||||
factories.put(USELESS_ELVIS, RemoveRightPartOfBinaryExpressionFix.createRemoveElvisOperatorFactory());
|
||||
|
||||
JetIntentionActionFactory removeRedundantModifierFactory = RemoveModifierFix.createRemoveModifierFactory(true);
|
||||
JetSingleIntentionActionFactory removeRedundantModifierFactory = RemoveModifierFix.createRemoveModifierFactory(true);
|
||||
factories.put(REDUNDANT_MODIFIER, removeRedundantModifierFactory);
|
||||
factories.put(ABSTRACT_MODIFIER_IN_TRAIT, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(ABSTRACT_KEYWORD, true));
|
||||
factories.put(OPEN_MODIFIER_IN_TRAIT, RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OPEN_KEYWORD, true));
|
||||
@@ -112,28 +112,28 @@ public class QuickFixes {
|
||||
factories.put(INCOMPATIBLE_MODIFIERS, RemoveModifierFix.createRemoveModifierFactory(false));
|
||||
factories.put(VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY, RemoveModifierFix.createRemoveVarianceFactory());
|
||||
|
||||
JetIntentionActionFactory removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OPEN_KEYWORD);
|
||||
JetSingleIntentionActionFactory removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OPEN_KEYWORD);
|
||||
factories.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, AddModifierFix.createFactory(OPEN_KEYWORD, JetClass.class));
|
||||
factories.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, removeOpenModifierFactory);
|
||||
|
||||
JetIntentionActionFactory removeModifierFactory = RemoveModifierFix.createRemoveModifierFactory();
|
||||
JetSingleIntentionActionFactory removeModifierFactory = RemoveModifierFix.createRemoveModifierFactory();
|
||||
factories.put(GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY, removeModifierFactory);
|
||||
factories.put(REDUNDANT_MODIFIER_IN_GETTER, removeRedundantModifierFactory);
|
||||
factories.put(ILLEGAL_MODIFIER, removeModifierFactory);
|
||||
|
||||
JetIntentionActionFactory changeToBackingFieldFactory = ChangeToBackingFieldFix.createFactory();
|
||||
JetSingleIntentionActionFactory changeToBackingFieldFactory = ChangeToBackingFieldFix.createFactory();
|
||||
factories.put(INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER, changeToBackingFieldFactory);
|
||||
factories.put(INITIALIZATION_USING_BACKING_FIELD_OPEN_SETTER, changeToBackingFieldFactory);
|
||||
|
||||
JetIntentionActionFactory changeToPropertyNameFactory = ChangeToPropertyNameFix.createFactory();
|
||||
JetSingleIntentionActionFactory changeToPropertyNameFactory = ChangeToPropertyNameFix.createFactory();
|
||||
factories.put(NO_BACKING_FIELD_ABSTRACT_PROPERTY, changeToPropertyNameFactory);
|
||||
factories.put(NO_BACKING_FIELD_CUSTOM_ACCESSORS, changeToPropertyNameFactory);
|
||||
factories.put(INACCESSIBLE_BACKING_FIELD, changeToPropertyNameFactory);
|
||||
|
||||
JetIntentionActionFactory unresolvedReferenceFactory = AutoImportFix.createFactory();
|
||||
JetSingleIntentionActionFactory unresolvedReferenceFactory = AutoImportFix.createFactory();
|
||||
factories.put(UNRESOLVED_REFERENCE, unresolvedReferenceFactory);
|
||||
|
||||
JetIntentionActionFactory removeImportFixFactory = RemovePsiElementSimpleFix.createRemoveImportFactory();
|
||||
JetSingleIntentionActionFactory removeImportFixFactory = RemovePsiElementSimpleFix.createRemoveImportFactory();
|
||||
factories.put(USELESS_SIMPLE_IMPORT, removeImportFixFactory);
|
||||
factories.put(USELESS_HIDDEN_IMPORT, removeImportFixFactory);
|
||||
|
||||
@@ -173,7 +173,7 @@ public class QuickFixes {
|
||||
actions.put(UNNECESSARY_NOT_NULL_ASSERTION, ExclExclCallFix.removeExclExclCall());
|
||||
factories.put(UNSAFE_INFIX_CALL, ReplaceInfixCallFix.createFactory());
|
||||
|
||||
JetIntentionActionFactory removeProtectedModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(PROTECTED_KEYWORD);
|
||||
JetSingleIntentionActionFactory removeProtectedModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(PROTECTED_KEYWORD);
|
||||
factories.put(PACKAGE_MEMBER_CANNOT_BE_PROTECTED, removeProtectedModifierFactory);
|
||||
|
||||
actions.put(PUBLIC_MEMBER_SHOULD_SPECIFY_TYPE, new SpecifyTypeExplicitlyFix());
|
||||
@@ -187,13 +187,13 @@ public class QuickFixes {
|
||||
|
||||
factories.put(TYPE_ARGUMENTS_REDUNDANT_IN_SUPER_QUALIFIER, RemovePsiElementSimpleFix.createRemoveTypeArgumentsFactory());
|
||||
|
||||
JetIntentionActionFactory changeToStarProjectionFactory = ChangeToStarProjectionFix.createFactory();
|
||||
JetSingleIntentionActionFactory changeToStarProjectionFactory = ChangeToStarProjectionFix.createFactory();
|
||||
factories.put(UNCHECKED_CAST, changeToStarProjectionFactory);
|
||||
factories.put(CANNOT_CHECK_FOR_ERASED, changeToStarProjectionFactory);
|
||||
|
||||
factories.put(INACCESSIBLE_OUTER_CLASS_EXPRESSION, AddModifierFix.createFactory(INNER_KEYWORD, JetClass.class));
|
||||
|
||||
JetIntentionActionFactory addOpenModifierToClassDeclarationFix = AddOpenModifierToClassDeclarationFix.createFactory();
|
||||
JetSingleIntentionActionFactory addOpenModifierToClassDeclarationFix = AddOpenModifierToClassDeclarationFix.createFactory();
|
||||
factories.put(FINAL_SUPERTYPE, addOpenModifierToClassDeclarationFix);
|
||||
factories.put(FINAL_UPPER_BOUND, addOpenModifierToClassDeclarationFix);
|
||||
|
||||
@@ -214,19 +214,18 @@ public class QuickFixes {
|
||||
|
||||
factories.put(DANGLING_FUNCTION_LITERAL_ARGUMENT_SUSPECTED, AddSemicolonAfterFunctionCallFix.createFactory());
|
||||
|
||||
JetIntentionActionFactory changeVariableTypeFix = ChangeVariableTypeFix.createFactoryForPropertyOrReturnTypeMismatchOnOverride();
|
||||
JetIntentionActionsFactory changeVariableTypeFix = ChangeVariableTypeFix.createFactoryForPropertyOrReturnTypeMismatchOnOverride();
|
||||
factories.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, changeVariableTypeFix);
|
||||
factories.put(PROPERTY_TYPE_MISMATCH_ON_OVERRIDE, changeVariableTypeFix);
|
||||
factories.put(COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, ChangeVariableTypeFix.createFactoryForComponentFunctionReturnTypeMismatch());
|
||||
|
||||
JetIntentionActionFactory changeFunctionReturnTypeFix = ChangeFunctionReturnTypeFix.createFactoryForChangingReturnTypeToUnit();
|
||||
JetSingleIntentionActionFactory changeFunctionReturnTypeFix = ChangeFunctionReturnTypeFix.createFactoryForChangingReturnTypeToUnit();
|
||||
factories.put(RETURN_TYPE_MISMATCH, changeFunctionReturnTypeFix);
|
||||
factories.put(NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY, changeFunctionReturnTypeFix);
|
||||
factories.put(RETURN_TYPE_MISMATCH_ON_OVERRIDE, ChangeFunctionReturnTypeFix.createFactoryForReturnTypeMismatchOnOverride());
|
||||
factories.put(COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH, ChangeFunctionReturnTypeFix.createFactoryForComponentFunctionReturnTypeMismatch());
|
||||
factories.put(HAS_NEXT_FUNCTION_TYPE_MISMATCH, ChangeFunctionReturnTypeFix.createFactoryForHasNextFunctionTypeMismatch());
|
||||
factories.put(COMPARE_TO_TYPE_MISMATCH, ChangeFunctionReturnTypeFix.createFactoryForCompareToTypeMismatch());
|
||||
factories.put(TYPE_MISMATCH, ChangeFunctionReturnTypeFix.createFactoryForTypeMismatch());
|
||||
|
||||
factories.put(TOO_MANY_ARGUMENTS, ChangeFunctionSignatureFix.createFactory());
|
||||
factories.put(NO_VALUE_FOR_PARAMETER, ChangeFunctionSignatureFix.createFactory());
|
||||
@@ -235,9 +234,14 @@ public class QuickFixes {
|
||||
|
||||
factories.put(EXPECTED_PARAMETER_TYPE_MISMATCH, ChangeTypeFix.createFactoryForExpectedParameterTypeMismatch());
|
||||
factories.put(EXPECTED_RETURN_TYPE_MISMATCH, ChangeTypeFix.createFactoryForExpectedReturnTypeMismatch());
|
||||
|
||||
|
||||
JetSingleIntentionActionFactory changeFunctionLiteralReturnTypeFix = ChangeFunctionLiteralReturnTypeFix.createFactoryForExpectedOrAssignmentTypeMismatch();
|
||||
factories.put(EXPECTED_TYPE_MISMATCH, changeFunctionLiteralReturnTypeFix);
|
||||
factories.put(ASSIGNMENT_TYPE_MISMATCH, changeFunctionLiteralReturnTypeFix);
|
||||
|
||||
factories.put(TYPE_MISMATCH, new QuickFixFactoryForTypeMismatchError());
|
||||
|
||||
factories.put(AUTOCAST_IMPOSSIBLE, CastExpressionFix.createFactoryForAutoCastImpossible());
|
||||
factories.put(TYPE_MISMATCH, CastExpressionFix.createFactoryForTypeMismatch());
|
||||
|
||||
factories.put(PLATFORM_CLASS_MAPPED_TO_KOTLIN, MapPlatformClassToKotlinFix.createFactory());
|
||||
|
||||
|
||||
@@ -87,8 +87,8 @@ public class RemoveFunctionBodyFix extends JetIntentionAction<JetFunction> {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetFunction> createAction(Diagnostic diagnostic) {
|
||||
JetFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetFunction.class);
|
||||
|
||||
@@ -103,12 +103,12 @@ public class RemoveModifierFix extends JetIntentionAction<JetModifierListOwner>
|
||||
}
|
||||
|
||||
|
||||
public static JetIntentionActionFactory createRemoveModifierFromListOwnerFactory(JetKeywordToken modifier) {
|
||||
public static JetSingleIntentionActionFactory createRemoveModifierFromListOwnerFactory(JetKeywordToken modifier) {
|
||||
return createRemoveModifierFromListOwnerFactory(modifier, false);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveModifierFromListOwnerFactory(final JetKeywordToken modifier, final boolean isRedundant) {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createRemoveModifierFromListOwnerFactory(final JetKeywordToken modifier, final boolean isRedundant) {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
|
||||
@@ -119,12 +119,12 @@ public class RemoveModifierFix extends JetIntentionAction<JetModifierListOwner>
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveModifierFactory() {
|
||||
public static JetSingleIntentionActionFactory createRemoveModifierFactory() {
|
||||
return createRemoveModifierFactory(false);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveModifierFactory(final boolean isRedundant) {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createRemoveModifierFactory(final boolean isRedundant) {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
|
||||
@@ -139,8 +139,8 @@ public class RemoveModifierFix extends JetIntentionAction<JetModifierListOwner>
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveProjectionFactory(final boolean isRedundant) {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createRemoveProjectionFactory(final boolean isRedundant) {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
|
||||
@@ -156,8 +156,8 @@ public class RemoveModifierFix extends JetIntentionAction<JetModifierListOwner>
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveVarianceFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createRemoveVarianceFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JetIntentionAction<JetModifierListOwner> createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -62,8 +62,8 @@ public class RemoveNullableFix extends JetIntentionAction<JetNullableType> {
|
||||
super.element.replace(type);
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory(final NullableKind typeOfError) {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory(final NullableKind typeOfError) {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetNullableType> createAction(Diagnostic diagnostic) {
|
||||
JetNullableType nullType = QuickFixUtil.getParentElementOfType(diagnostic, JetNullableType.class);
|
||||
|
||||
@@ -121,8 +121,8 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction<JetProperty>
|
||||
}
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetProperty> createAction(Diagnostic diagnostic) {
|
||||
PsiElement element = diagnostic.getPsiElement();
|
||||
|
||||
@@ -60,8 +60,8 @@ public class RemovePsiElementSimpleFix extends JetIntentionAction<PsiElement> {
|
||||
element.delete();
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveImportFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createRemoveImportFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<PsiElement> createAction(Diagnostic diagnostic) {
|
||||
JetImportDirective directive = QuickFixUtil.getParentElementOfType(diagnostic, JetImportDirective.class);
|
||||
@@ -79,8 +79,8 @@ public class RemovePsiElementSimpleFix extends JetIntentionAction<PsiElement> {
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveSpreadFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createRemoveSpreadFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<PsiElement> createAction(Diagnostic diagnostic) {
|
||||
PsiElement element = diagnostic.getPsiElement();
|
||||
@@ -92,8 +92,8 @@ public class RemovePsiElementSimpleFix extends JetIntentionAction<PsiElement> {
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveTypeArgumentsFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createRemoveTypeArgumentsFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<PsiElement> createAction(Diagnostic diagnostic) {
|
||||
JetTypeArgumentList element = QuickFixUtil.getParentElementOfType(diagnostic, JetTypeArgumentList.class);
|
||||
@@ -104,8 +104,8 @@ public class RemovePsiElementSimpleFix extends JetIntentionAction<PsiElement> {
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveVariableFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createRemoveVariableFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<PsiElement> createAction(Diagnostic diagnostic) {
|
||||
final JetProperty expression = QuickFixUtil.getParentElementOfType(diagnostic, JetProperty.class);
|
||||
|
||||
+4
-4
@@ -57,8 +57,8 @@ public class RemoveRightPartOfBinaryExpressionFix<T extends JetExpression> exten
|
||||
}
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveCastFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createRemoveCastFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(Diagnostic diagnostic) {
|
||||
JetBinaryExpressionWithTypeRHS expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpressionWithTypeRHS.class);
|
||||
@@ -68,8 +68,8 @@ public class RemoveRightPartOfBinaryExpressionFix<T extends JetExpression> exten
|
||||
};
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createRemoveElvisOperatorFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createRemoveElvisOperatorFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetBinaryExpression> createAction(Diagnostic diagnostic) {
|
||||
JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class);
|
||||
|
||||
@@ -63,8 +63,8 @@ public class RemoveSupertypeFix extends JetIntentionAction<JetDelegationSpecifie
|
||||
superClass.delete();
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetDelegationSpecifier> createAction(Diagnostic diagnostic) {
|
||||
JetDelegationSpecifier superClass = QuickFixUtil.getParentElementOfType(diagnostic, JetDelegationSpecifier.class);
|
||||
|
||||
+2
-2
@@ -82,8 +82,8 @@ public class RenameParameterToMatchOverriddenMethodFix extends JetIntentionActio
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Nullable
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
|
||||
@@ -59,8 +59,8 @@ public class ReplaceInfixCallFix extends JetIntentionAction<JetBinaryExpression>
|
||||
return true;
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public IntentionAction createAction(Diagnostic diagnostic) {
|
||||
JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class);
|
||||
|
||||
+2
-3
@@ -18,7 +18,6 @@ package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -55,8 +54,8 @@ public abstract class ReplaceOperationInBinaryExpressionFix<T extends JetExpress
|
||||
}
|
||||
}
|
||||
|
||||
public static JetIntentionActionFactory createChangeCastToStaticAssertFactory() {
|
||||
return new JetIntentionActionFactory() {
|
||||
public static JetSingleIntentionActionFactory createChangeCastToStaticAssertFactory() {
|
||||
return new JetSingleIntentionActionFactory() {
|
||||
@Override
|
||||
public JetIntentionAction<JetBinaryExpressionWithTypeRHS> createAction(Diagnostic diagnostic) {
|
||||
JetBinaryExpressionWithTypeRHS expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpressionWithTypeRHS.class);
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Change 'B.x' type to '(Int) -> Int'" "true"
|
||||
trait A {
|
||||
val x: (Int) -> Int
|
||||
}
|
||||
|
||||
trait B {
|
||||
val x: (Int) -> Int
|
||||
}
|
||||
|
||||
trait C : A, B {
|
||||
override val x: (Int) -> Int<caret>
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Change 'A.x' type to 'String'" "true"
|
||||
trait A {
|
||||
var x: String
|
||||
}
|
||||
|
||||
trait B {
|
||||
var x: String
|
||||
}
|
||||
|
||||
trait C : A, B {
|
||||
override var x: String<caret>
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Change 'B.x' type to '(String) -> Int'" "true"
|
||||
trait A {
|
||||
var x: (String) -> Int
|
||||
}
|
||||
trait B : A {
|
||||
override var x: (String) -> Int
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Change 'A.foo' function return type to 'Long'" "true"
|
||||
trait A {
|
||||
fun foo(): Long
|
||||
}
|
||||
|
||||
trait B {
|
||||
fun foo(): Number
|
||||
}
|
||||
|
||||
trait C : A, B {
|
||||
override fun foo(): Long<caret>
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change 'x' type to 'Int'" "true"
|
||||
// "Change 'A.x' type to 'Int'" "true"
|
||||
trait X {
|
||||
val x: Int
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change 'x' type to 'Int'" "true"
|
||||
// "Change 'B.x' type to 'Int'" "true"
|
||||
abstract class A {
|
||||
abstract var x : Int
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change 'x' type to 'Int'" "true"
|
||||
// "Change 'B.x' type to 'Int'" "true"
|
||||
abstract class A {
|
||||
abstract var x : Int
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
// "Change 'A.x' type to '(Int) -> Int'" "false"
|
||||
// ACTION: Change 'C.x' type to '(String) -> Int'
|
||||
// ERROR: <html>Return type is '(jet.Int) → jet.Int', which is not a subtype of overridden<br/><b>internal</b> <b>abstract</b> <b>val</b> x: (jet.String) → jet.Int <i>defined in</i> A</html>
|
||||
trait A {
|
||||
val x: (String) -> Int
|
||||
}
|
||||
|
||||
trait B {
|
||||
val x: (String) -> Any
|
||||
}
|
||||
|
||||
trait C : A, B {
|
||||
override val x: (Int) -> Int<caret>
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Change 'A.x' type to 'String'" "false"
|
||||
// ERROR: <html>Var-property type is 'jet.String', which is not a type of overridden<br/><b>internal</b> <b>abstract</b> <b>var</b> x: jet.Int <i>defined in</i> A</html>
|
||||
trait A {
|
||||
var x: Int
|
||||
}
|
||||
|
||||
trait B {
|
||||
var x: Any
|
||||
}
|
||||
|
||||
trait C : A, B {
|
||||
override var x: String<caret>
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Change 'C.x' type to 'String'" "false"
|
||||
// ERROR: <html>Var-property type is 'jet.Int', which is not a type of overridden<br/><b>internal</b> <b>abstract</b> <b>var</b> x: jet.String <i>defined in</i> A</html>
|
||||
trait A {
|
||||
var x: String
|
||||
}
|
||||
|
||||
trait B {
|
||||
var x: Any
|
||||
}
|
||||
|
||||
trait C : A, B {
|
||||
override var x: Int<caret>
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Change 'A.foo' function return type to 'Long'" "false"
|
||||
// ERROR: <html>Return type is 'jet.Long', which is not a subtype of overridden<br/><b>internal</b> <b>abstract</b> <b>fun</b> foo(): jet.Int <i>defined in</i> A</html>
|
||||
trait A {
|
||||
fun foo(): Int
|
||||
}
|
||||
|
||||
trait B {
|
||||
fun foo(): String
|
||||
}
|
||||
|
||||
trait C : A, B {
|
||||
override fun foo(): Long
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Change 'B.x' type to '(Int) -> Int'" "true"
|
||||
trait A {
|
||||
val x: (Int) -> Int
|
||||
}
|
||||
|
||||
trait B {
|
||||
val x: (String) -> Any
|
||||
}
|
||||
|
||||
trait C : A, B {
|
||||
override val x: (Int) -> Int<caret>
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Change 'A.x' type to 'String'" "true"
|
||||
trait A {
|
||||
var x: Int
|
||||
}
|
||||
|
||||
trait B {
|
||||
var x: String
|
||||
}
|
||||
|
||||
trait C : A, B {
|
||||
override var x: String<caret>
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Change 'B.x' type to '(String) -> Int'" "true"
|
||||
trait A {
|
||||
var x: (String) -> Int
|
||||
}
|
||||
trait B : A {
|
||||
override var x: (Int) -> String<caret>
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// "Change 'A.foo' function return type to 'Long'" "true"
|
||||
trait A {
|
||||
fun foo(): Int
|
||||
}
|
||||
|
||||
trait B {
|
||||
fun foo(): Number
|
||||
}
|
||||
|
||||
trait C : A, B {
|
||||
override fun foo(): Long<caret>
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change 'x' type to 'Int'" "true"
|
||||
// "Change 'A.x' type to 'Int'" "true"
|
||||
trait X {
|
||||
val x: Int
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change 'x' type to 'Int'" "true"
|
||||
// "Change 'B.x' type to 'Int'" "true"
|
||||
abstract class A {
|
||||
abstract var x : Int
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change 'x' type to 'Int'" "true"
|
||||
// "Change 'B.x' type to 'Int'" "true"
|
||||
abstract class A {
|
||||
abstract var x : Int
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Change getter type to (String) -> Int" "true"
|
||||
class A {
|
||||
val x: (String) -> Int
|
||||
get(): (String) -> Int<caret> = {42}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// "Change getter type to (String) -> Int" "true"
|
||||
class A {
|
||||
val x: (String) -> Int
|
||||
get(): Int<caret> = {42}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Change type from 'String' to '(Int) -> String'" "true"
|
||||
fun foo(f: ((Int) -> String) -> String) {
|
||||
foo {
|
||||
(f: (Int) -> String<caret>) -> f(42)
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// "Change 'bar' function return type to 'String'" "true"
|
||||
fun bar(): String = ""
|
||||
fun foo(): String = bar(<caret>)
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Change 'f' type to '(Long) -> Unit'" "true"
|
||||
fun foo() {
|
||||
var f: (Long) -> Unit = if (true) { (x: Long) -> }<caret> else { (x: Long) -> }
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Change type from 'String' to '(Int) -> String'" "true"
|
||||
fun foo(f: ((Int) -> String) -> String) {
|
||||
foo {
|
||||
(f: String<caret>) -> f(42)
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
// "Change 'bar' function return type to 'String'" "true"
|
||||
fun bar(): Any = ""
|
||||
fun foo(): String = bar(<caret>)
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Change 'B.x' type to '(String) -> [ERROR : Ay]'" "false"
|
||||
// ACTION: Change 'A.x' type to '(Int) -> Int'
|
||||
// ERROR: <html>Return type is '(jet.Int) → jet.Int', which is not a subtype of overridden<br/><b>internal</b> <b>abstract</b> <b>val</b> x: (jet.String) → [ERROR : Ay] <i>defined in</i> A</html>
|
||||
// ERROR: Unresolved reference: Ay
|
||||
trait A {
|
||||
val x: (String) -> Ay
|
||||
}
|
||||
trait B : A {
|
||||
override val x: (Int) -> Int<caret>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Change 'f' type to '(Long) -> Unit'" "true"
|
||||
fun foo() {
|
||||
var f: Int = if (true) { (x: Long) -> }<caret> else { (x: Long) -> }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Cast expression 'x' to '() -> Int'" "true"
|
||||
fun foo(x: Any): () -> Int {
|
||||
return x as () -> Int<caret>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// "Cast expression 'x' to '() -> Int'" "true"
|
||||
fun foo(x: Any): () -> Int {
|
||||
return x<caret>
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Change 'A.not' function return type to 'A'" "true"
|
||||
trait A {
|
||||
fun not(): A
|
||||
fun times(a: A): A
|
||||
}
|
||||
|
||||
fun foo(a: A): A = a * <caret>!(if (true) a else a)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Change 'A.plus' function return type to '() -> Int'" "true"
|
||||
trait A {
|
||||
fun plus(a: A): () -> Int
|
||||
}
|
||||
|
||||
fun foo(a: A): () -> Int {
|
||||
return a + a<caret>
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Change parameter 'a' type of function 'A.times' to 'String'" "true"
|
||||
trait A {
|
||||
fun times(a: String): A
|
||||
}
|
||||
|
||||
fun foo(a: A): A = a * <caret>""
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// "Change 'A.not' function return type to 'A'" "true"
|
||||
trait A {
|
||||
fun not(): String
|
||||
fun times(a: A): A
|
||||
}
|
||||
|
||||
fun foo(a: A): A = a * <caret>!(if (true) a else a)
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Change 'A.plus' function return type to '() -> Int'" "true"
|
||||
trait A {
|
||||
fun plus(a: A): String
|
||||
}
|
||||
|
||||
fun foo(a: A): () -> Int {
|
||||
return a + a<caret>
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// "Change parameter 'a' type of function 'A.times' to 'String'" "true"
|
||||
trait A {
|
||||
fun times(a: A): A
|
||||
}
|
||||
|
||||
fun foo(a: A): A = a * <caret>""
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// "Change parameter 'x' type of function 'bar.foo' to '(String) -> Int'" "true"
|
||||
package bar
|
||||
fun foo(w: Int = 0, x: (String) -> Int, y: Int = 0, z: (Int) -> Int = {42}) {
|
||||
foo(1, {(a: String) -> 42}<caret>, 1)
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Change parameter 'y' type of function 'foo' to 'String'" "true"
|
||||
fun foo(v: Int, w: Int = 0, x: Int = 0, y: String, z: (Int) -> Int = {42}) {
|
||||
foo(0, 1, y = ""<caret>)
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Change parameter 'z' type of function 'foo' to '(Int) -> Unit'" "true"
|
||||
fun foo(w: Int = 0, x: Int, y: Int = 0, z: (Int) -> Unit) {
|
||||
foo(0, 1) {<caret>}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// "Change parameter 'a' type of primary constructor of class 'B' to 'String'" "true"
|
||||
class B(val a: String)
|
||||
fun foo() {
|
||||
B(if (true) ""<caret> else "")
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// "Change parameter 'x' type of function 'bar.foo' to '(String) -> Int'" "true"
|
||||
package bar
|
||||
fun foo(w: Int = 0, x: Int, y: Int = 0, z: (Int) -> Int = {42}) {
|
||||
foo(1, {(a: String) -> 42}<caret>, 1)
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Change parameter 'y' type of function 'foo' to 'String'" "true"
|
||||
fun foo(v: Int, w: Int = 0, x: Int = 0, y: Int, z: (Int) -> Int = {42}) {
|
||||
foo(0, 1, y = ""<caret>)
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
// "Change parameter 'z' type of function 'foo' to '(Int) -> Unit'" "true"
|
||||
fun foo(w: Int = 0, x: Int, y: Int = 0, z: (Int) -> String) {
|
||||
foo(0, 1) {<caret>}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Change parameter 'z' type of function 'foo' to '(Int) -> String'" "false"
|
||||
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>jet.Int</td></tr><tr><td>Found:</td><td>jet.String</td></tr></table></html>
|
||||
fun foo(y: Int = 0, z: (Int) -> String = {""}) {
|
||||
foo {
|
||||
""<caret>: Int
|
||||
""
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// "Change parameter 'y' type of function 'foo' to 'Int'" "false"
|
||||
// ERROR: <html>Type mismatch.<table><tr><td>Required:</td><td>jet.Int</td></tr><tr><td>Found:</td><td>jet.String</td></tr></table></html>
|
||||
fun foo(y: Int = 0, z: (Int) -> String = {""}) {
|
||||
foo(""<caret>: Int)
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user