diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index c640470d94b..a68d3edbb91 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -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}'' diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java index 21d32d41fa7..21b4a2a6729 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetPsiChecker.java @@ -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 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 intentionActionsFactories = QuickFixes.getActionsFactories(diagnostic.getFactory()); + for (JetIntentionActionsFactory intentionActionsFactory : intentionActionsFactories) { + if (intentionActionsFactory != null) { + for (IntentionAction action: intentionActionsFactory.createActions(diagnostic)) { + annotation.registerFix(action); + } } } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionBodyFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionBodyFix.java index 2654f228e78..b0819791d25 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionBodyFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionBodyFix.java @@ -67,8 +67,8 @@ public class AddFunctionBodyFix extends JetIntentionAction { element.replace(newElement); } - public static JetIntentionActionFactory createFactory() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createFactory() { + return new JetSingleIntentionActionFactory() { @Nullable @Override public JetIntentionAction createAction(Diagnostic diagnostic) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionToSupertypeFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionToSupertypeFix.java index 05844b5f937..f565679cb6d 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionToSupertypeFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionToSupertypeFix.java @@ -158,8 +158,8 @@ public class AddFunctionToSupertypeFix extends JetHintAction { 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) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AddModifierFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AddModifierFix.java index 162dc6b7aa3..d3bdd9b985e 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/AddModifierFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AddModifierFix.java @@ -164,8 +164,8 @@ public class AddModifierFix extends JetIntentionAction { return true; } - public static JetIntentionActionFactory createFactory(final JetKeywordToken modifier, final Class modifierOwnerClass) { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createFactory(final JetKeywordToken modifier, final Class 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 { }; } - public static JetIntentionActionFactory createFactory(JetKeywordToken modifier) { + public static JetSingleIntentionActionFactory createFactory(JetKeywordToken modifier) { return createFactory(modifier, JetModifierListOwner.class); } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AddNameToArgumentFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AddNameToArgumentFix.java index cc53c6ad0e3..93c03343de2 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/AddNameToArgumentFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AddNameToArgumentFix.java @@ -183,8 +183,8 @@ public class AddNameToArgumentFix extends JetIntentionAction { 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) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AddOpenModifierToClassDeclarationFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AddOpenModifierToClassDeclarationFix.java index 8fa3b39a8c6..13509245a17 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/AddOpenModifierToClassDeclarationFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AddOpenModifierToClassDeclarationFix.java @@ -81,8 +81,8 @@ public class AddOpenModifierToClassDeclarationFix extends JetIntentionAction 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) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AutoImportFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AutoImportFix.java index c4cdd8d9533..68b66bfa623 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/AutoImportFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AutoImportFix.java @@ -289,8 +289,8 @@ public class AutoImportFix extends JetHintAction implem } @Nullable - public static JetIntentionActionFactory createFactory() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createFactory() { + return new JetSingleIntentionActionFactory() { @Nullable @Override public JetIntentionAction createAction(@NotNull Diagnostic diagnostic) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/CastExpressionFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/CastExpressionFix.java index 1b4cc20a134..d58f92e6ebd 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/CastExpressionFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/CastExpressionFix.java @@ -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 { 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 { @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 { } @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 { } }; } - - @NotNull - public static JetIntentionActionFactory createFactoryForTypeMismatch() { - return new JetIntentionActionFactory() { - @Nullable - @Override - public IntentionAction createAction(Diagnostic diagnostic) { - assert diagnostic.getFactory() == Errors.TYPE_MISMATCH; - @SuppressWarnings("unchecked") - DiagnosticWithParameters2 diagnosticWithParameters = - (DiagnosticWithParameters2) 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()); - } - }; - } } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeAccessorTypeFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeAccessorTypeFix.java index 102874d7f83..59dee5775e8 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeAccessorTypeFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeAccessorTypeFix.java @@ -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 { + 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 createAction(Diagnostic diagnostic) { JetPropertyAccessor accessor = QuickFixUtil.getParentElementOfType(diagnostic, JetPropertyAccessor.class); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionLiteralReturnTypeFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionLiteralReturnTypeFix.java new file mode 100644 index 00000000000..3027cba79c4 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionLiteralReturnTypeFix.java @@ -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 { + 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 functionClassTypeParameters = new LinkedList(); + 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()); + } + }; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java index e8368c9a771..cf22d69bf9c 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionReturnTypeFix.java @@ -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 { +import java.util.LinkedList; +import java.util.List; + +public class ChangeFunctionReturnTypeFix extends JetIntentionAction { 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) 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 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 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 resolvedCall = context.get(BindingContext.RESOLVED_CALL, expression.getOperationReference()); + ResolvedCall 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 createActions(Diagnostic diagnostic) { + List actions = new LinkedList(); + + 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 overriddenMismatchingFunctions = new LinkedList(); + 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; - } - }; - } } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionSignatureFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionSignatureFix.java index 62449021494..0412b7191e4 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionSignatureFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionSignatureFix.java @@ -124,8 +124,8 @@ public abstract class ChangeFunctionSignatureFix extends JetIntentionAction { + 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)); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToBackingFieldFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToBackingFieldFix.java index 4f524d4d9a0..52b672da595 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToBackingFieldFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToBackingFieldFix.java @@ -49,8 +49,8 @@ public class ChangeToBackingFieldFix extends JetIntentionAction createAction(Diagnostic diagnostic) { JetSimpleNameExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetSimpleNameExpression.class); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToConstructorInvocationFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToConstructorInvocationFix.java index 7890d0a49da..3cb0532bf48 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToConstructorInvocationFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToConstructorInvocationFix.java @@ -84,8 +84,8 @@ public class ChangeToConstructorInvocationFix extends JetIntentionAction createAction(Diagnostic diagnostic) { if (diagnostic.getPsiElement() instanceof JetDelegatorToSuperClass) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToFunctionInvocationFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToFunctionInvocationFix.java index acbdc338f17..b96a01b3155 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToFunctionInvocationFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToFunctionInvocationFix.java @@ -50,8 +50,8 @@ public class ChangeToFunctionInvocationFix extends JetIntentionAction createAction(Diagnostic diagnostic) { if (diagnostic.getPsiElement() instanceof JetExpression) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToPropertyNameFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToPropertyNameFix.java index 96ecda49d7e..9d832492d35 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToPropertyNameFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToPropertyNameFix.java @@ -58,8 +58,8 @@ public class ChangeToPropertyNameFix extends JetIntentionAction createAction(Diagnostic diagnostic) { JetSimpleNameExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetSimpleNameExpression.class); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToStarProjectionFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToStarProjectionFix.java index 18c050c42d3..ac083e375bd 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToStarProjectionFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeToStarProjectionFix.java @@ -54,8 +54,8 @@ public class ChangeToStarProjectionFix extends JetIntentionAction { - 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 { } @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 { } @NotNull - public static JetIntentionActionFactory createFactoryForExpectedReturnTypeMismatch() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createFactoryForExpectedReturnTypeMismatch() { + return new JetSingleIntentionActionFactory() { @Nullable @Override public IntentionAction createAction(Diagnostic diagnostic) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVariableTypeFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVariableTypeFix.java index c3423fa6b28..bcb408900ba 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVariableTypeFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVariableTypeFix.java @@ -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 { + 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 typeWhiteSpaceAndColon = JetPsiFactory.createTypeWhiteSpaceAndColon(project, type.toString()); + Pair 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 createActions(Diagnostic diagnostic) { + List actions = new LinkedList(); + 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 overriddenMismatchingProperties = new LinkedList(); + 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; } }; } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVisibilityModifierFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVisibilityModifierFix.java index 0bcc32fbdd9..b3adc058a84 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVisibilityModifierFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeVisibilityModifierFix.java @@ -103,8 +103,8 @@ public class ChangeVisibilityModifierFix extends JetIntentionAction createAction(Diagnostic diagnostic) { PsiElement element = diagnostic.getPsiElement(); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/JetIntentionActionFactory.java b/idea/src/org/jetbrains/jet/plugin/quickfix/JetIntentionActionsFactory.java similarity index 80% rename from idea/src/org/jetbrains/jet/plugin/quickfix/JetIntentionActionFactory.java rename to idea/src/org/jetbrains/jet/plugin/quickfix/JetIntentionActionsFactory.java index 3301507e6ac..953acf3469b 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/JetIntentionActionFactory.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/JetIntentionActionsFactory.java @@ -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 createActions(Diagnostic diagnostic); } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/JetSingleIntentionActionFactory.java b/idea/src/org/jetbrains/jet/plugin/quickfix/JetSingleIntentionActionFactory.java new file mode 100644 index 00000000000..1ecbd890a63 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/JetSingleIntentionActionFactory.java @@ -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 createActions(Diagnostic diagnostic) { + List intentionActionList = new LinkedList(); + IntentionAction intentionAction = createAction(diagnostic); + if (intentionAction != null) { + intentionActionList.add(intentionAction); + } + return intentionActionList; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/MakeClassAnAnnotationClassFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/MakeClassAnAnnotationClassFix.java index 4f5191179a3..6f2712cc75d 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/MakeClassAnAnnotationClassFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/MakeClassAnAnnotationClassFix.java @@ -90,8 +90,8 @@ public class MakeClassAnAnnotationClassFix extends JetIntentionAction { } - public static JetIntentionActionFactory createFactory() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createFactory() { + return new JetSingleIntentionActionFactory() { @Nullable @Override public JetIntentionAction createAction(Diagnostic diagnostic) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/MoveWhenElseBranchFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/MoveWhenElseBranchFix.java index 132d8989c9d..95e503a6eab 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/MoveWhenElseBranchFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/MoveWhenElseBranchFix.java @@ -78,8 +78,8 @@ public class MoveWhenElseBranchFix extends JetIntentionAction 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) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixFactoryForTypeMismatchError.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixFactoryForTypeMismatchError.java new file mode 100644 index 00000000000..9eb2dd5314b --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixFactoryForTypeMismatchError.java @@ -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 createActions(Diagnostic diagnostic) { + List actions = new LinkedList(); + + assert diagnostic.getFactory() == Errors.TYPE_MISMATCH; + @SuppressWarnings("unchecked") + DiagnosticWithParameters2 diagnosticWithParameters = + (DiagnosticWithParameters2) 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 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 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 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; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java index a1d9aa40425..11380a56cc4 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixUtil.java @@ -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 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); + } + } } diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java index be8f7fb5b30..63f87c80c17 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java @@ -30,10 +30,10 @@ import static org.jetbrains.jet.lexer.JetTokens.*; public class QuickFixes { - private static final Multimap factories = HashMultimap.create(); + private static final Multimap factories = HashMultimap.create(); private static final Multimap actions = HashMultimap.create(); - public static Collection getActionFactories(AbstractDiagnosticFactory diagnosticFactory) { + public static Collection 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()); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveFunctionBodyFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveFunctionBodyFix.java index f93954651f4..19e77848cd5 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveFunctionBodyFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveFunctionBodyFix.java @@ -87,8 +87,8 @@ public class RemoveFunctionBodyFix extends JetIntentionAction { return false; } - public static JetIntentionActionFactory createFactory() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createFactory() { + return new JetSingleIntentionActionFactory() { @Override public JetIntentionAction createAction(Diagnostic diagnostic) { JetFunction function = QuickFixUtil.getParentElementOfType(diagnostic, JetFunction.class); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveModifierFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveModifierFix.java index 6dfe9a14c17..03d61b2998a 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveModifierFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveModifierFix.java @@ -103,12 +103,12 @@ public class RemoveModifierFix extends JetIntentionAction } - 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 createAction(Diagnostic diagnostic) { @@ -119,12 +119,12 @@ public class RemoveModifierFix extends JetIntentionAction }; } - 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 createAction(Diagnostic diagnostic) { @@ -139,8 +139,8 @@ public class RemoveModifierFix extends JetIntentionAction }; } - public static JetIntentionActionFactory createRemoveProjectionFactory(final boolean isRedundant) { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createRemoveProjectionFactory(final boolean isRedundant) { + return new JetSingleIntentionActionFactory() { @Nullable @Override public JetIntentionAction createAction(Diagnostic diagnostic) { @@ -156,8 +156,8 @@ public class RemoveModifierFix extends JetIntentionAction }; } - public static JetIntentionActionFactory createRemoveVarianceFactory() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createRemoveVarianceFactory() { + return new JetSingleIntentionActionFactory() { @Nullable @Override public JetIntentionAction createAction(Diagnostic diagnostic) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveNullableFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveNullableFix.java index fdabcc18e73..a1f0e08fd8b 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveNullableFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveNullableFix.java @@ -62,8 +62,8 @@ public class RemoveNullableFix extends JetIntentionAction { 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 createAction(Diagnostic diagnostic) { JetNullableType nullType = QuickFixUtil.getParentElementOfType(diagnostic, JetNullableType.class); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemovePartsFromPropertyFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemovePartsFromPropertyFix.java index 6854ba50f3c..6778eec9646 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemovePartsFromPropertyFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemovePartsFromPropertyFix.java @@ -121,8 +121,8 @@ public class RemovePartsFromPropertyFix extends JetIntentionAction } } - public static JetIntentionActionFactory createFactory() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createFactory() { + return new JetSingleIntentionActionFactory() { @Override public JetIntentionAction createAction(Diagnostic diagnostic) { PsiElement element = diagnostic.getPsiElement(); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemovePsiElementSimpleFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemovePsiElementSimpleFix.java index 43388a24bb5..40f46346cf6 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemovePsiElementSimpleFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemovePsiElementSimpleFix.java @@ -60,8 +60,8 @@ public class RemovePsiElementSimpleFix extends JetIntentionAction { element.delete(); } - public static JetIntentionActionFactory createRemoveImportFactory() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createRemoveImportFactory() { + return new JetSingleIntentionActionFactory() { @Override public JetIntentionAction createAction(Diagnostic diagnostic) { JetImportDirective directive = QuickFixUtil.getParentElementOfType(diagnostic, JetImportDirective.class); @@ -79,8 +79,8 @@ public class RemovePsiElementSimpleFix extends JetIntentionAction { }; } - public static JetIntentionActionFactory createRemoveSpreadFactory() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createRemoveSpreadFactory() { + return new JetSingleIntentionActionFactory() { @Override public JetIntentionAction createAction(Diagnostic diagnostic) { PsiElement element = diagnostic.getPsiElement(); @@ -92,8 +92,8 @@ public class RemovePsiElementSimpleFix extends JetIntentionAction { }; } - public static JetIntentionActionFactory createRemoveTypeArgumentsFactory() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createRemoveTypeArgumentsFactory() { + return new JetSingleIntentionActionFactory() { @Override public JetIntentionAction createAction(Diagnostic diagnostic) { JetTypeArgumentList element = QuickFixUtil.getParentElementOfType(diagnostic, JetTypeArgumentList.class); @@ -104,8 +104,8 @@ public class RemovePsiElementSimpleFix extends JetIntentionAction { }; } - public static JetIntentionActionFactory createRemoveVariableFactory() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createRemoveVariableFactory() { + return new JetSingleIntentionActionFactory() { @Override public JetIntentionAction createAction(Diagnostic diagnostic) { final JetProperty expression = QuickFixUtil.getParentElementOfType(diagnostic, JetProperty.class); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveRightPartOfBinaryExpressionFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveRightPartOfBinaryExpressionFix.java index 3ad449a3bc4..a2918726a83 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveRightPartOfBinaryExpressionFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveRightPartOfBinaryExpressionFix.java @@ -57,8 +57,8 @@ public class RemoveRightPartOfBinaryExpressionFix exten } } - public static JetIntentionActionFactory createRemoveCastFactory() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createRemoveCastFactory() { + return new JetSingleIntentionActionFactory() { @Override public JetIntentionAction createAction(Diagnostic diagnostic) { JetBinaryExpressionWithTypeRHS expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpressionWithTypeRHS.class); @@ -68,8 +68,8 @@ public class RemoveRightPartOfBinaryExpressionFix exten }; } - public static JetIntentionActionFactory createRemoveElvisOperatorFactory() { - return new JetIntentionActionFactory() { + public static JetSingleIntentionActionFactory createRemoveElvisOperatorFactory() { + return new JetSingleIntentionActionFactory() { @Override public JetIntentionAction createAction(Diagnostic diagnostic) { JetBinaryExpression expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpression.class); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveSupertypeFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveSupertypeFix.java index e6374d65aa4..fd7983caa1e 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveSupertypeFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveSupertypeFix.java @@ -63,8 +63,8 @@ public class RemoveSupertypeFix extends JetIntentionAction createAction(Diagnostic diagnostic) { JetDelegationSpecifier superClass = QuickFixUtil.getParentElementOfType(diagnostic, JetDelegationSpecifier.class); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RenameParameterToMatchOverriddenMethodFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RenameParameterToMatchOverriddenMethodFix.java index 59c7b6fa088..2c41571125c 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/RenameParameterToMatchOverriddenMethodFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RenameParameterToMatchOverriddenMethodFix.java @@ -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) { diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceInfixCallFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceInfixCallFix.java index b4c93eb5b5c..7f31feeac9e 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceInfixCallFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceInfixCallFix.java @@ -59,8 +59,8 @@ public class ReplaceInfixCallFix extends JetIntentionAction 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); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceOperationInBinaryExpressionFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceOperationInBinaryExpressionFix.java index 317a2c3cd9d..2bb7c65bfdb 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceOperationInBinaryExpressionFix.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceOperationInBinaryExpressionFix.java @@ -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 createAction(Diagnostic diagnostic) { JetBinaryExpressionWithTypeRHS expression = QuickFixUtil.getParentElementOfType(diagnostic, JetBinaryExpressionWithTypeRHS.class); diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/afterChangeOverriddenPropertyType1.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/afterChangeOverriddenPropertyType1.kt new file mode 100644 index 00000000000..6a3586ed492 --- /dev/null +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/afterChangeOverriddenPropertyType1.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/afterChangeOverriddenPropertyType2.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/afterChangeOverriddenPropertyType2.kt new file mode 100644 index 00000000000..fd1e09a06ce --- /dev/null +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/afterChangeOverriddenPropertyType2.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/afterChangeOverridingPropertyTypeToFunctionType.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/afterChangeOverridingPropertyTypeToFunctionType.kt new file mode 100644 index 00000000000..8bd2d6f38b3 --- /dev/null +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/afterChangeOverridingPropertyTypeToFunctionType.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/afterChangeReturnTypeOfOverriddenFunction.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/afterChangeReturnTypeOfOverriddenFunction.kt new file mode 100644 index 00000000000..0efefb16139 --- /dev/null +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/afterChangeReturnTypeOfOverriddenFunction.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/afterPropertyReturnTypeMismatchOnOverride.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/afterPropertyReturnTypeMismatchOnOverride.kt index 9dbb3cbe563..0f79cd40f9d 100644 --- a/idea/testData/quickfix/override/typeMismatchOnOverride/afterPropertyReturnTypeMismatchOnOverride.kt +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/afterPropertyReturnTypeMismatchOnOverride.kt @@ -1,4 +1,4 @@ -// "Change 'x' type to 'Int'" "true" +// "Change 'A.x' type to 'Int'" "true" trait X { val x: Int } diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/afterPropertyTypeMismatchOnOverrideIntLong.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/afterPropertyTypeMismatchOnOverrideIntLong.kt index e810c22a1ee..80d3b2e6a05 100644 --- a/idea/testData/quickfix/override/typeMismatchOnOverride/afterPropertyTypeMismatchOnOverrideIntLong.kt +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/afterPropertyTypeMismatchOnOverrideIntLong.kt @@ -1,4 +1,4 @@ -// "Change 'x' type to 'Int'" "true" +// "Change 'B.x' type to 'Int'" "true" abstract class A { abstract var x : Int } diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/afterPropertyTypeMismatchOnOverrideIntUnit.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/afterPropertyTypeMismatchOnOverrideIntUnit.kt index 8296b837504..f37ab4f9ff0 100644 --- a/idea/testData/quickfix/override/typeMismatchOnOverride/afterPropertyTypeMismatchOnOverrideIntUnit.kt +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/afterPropertyTypeMismatchOnOverrideIntUnit.kt @@ -1,4 +1,4 @@ -// "Change 'x' type to 'Int'" "true" +// "Change 'B.x' type to 'Int'" "true" abstract class A { abstract var x : Int } diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangeMultipleOverriddenPropertiesTypes.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangeMultipleOverriddenPropertiesTypes.kt new file mode 100644 index 00000000000..9fe0b5a6264 --- /dev/null +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangeMultipleOverriddenPropertiesTypes.kt @@ -0,0 +1,14 @@ +// "Change 'A.x' type to '(Int) -> Int'" "false" +// ACTION: Change 'C.x' type to '(String) -> Int' +// ERROR: Return type is '(jet.Int) → jet.Int', which is not a subtype of overridden
internal abstract val x: (jet.String) → jet.Int defined in A +trait A { + val x: (String) -> Int +} + +trait B { + val x: (String) -> Any +} + +trait C : A, B { + override val x: (Int) -> Int +} \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangeOverriddenPropertyTypeToMatchOverridingProperty.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangeOverriddenPropertyTypeToMatchOverridingProperty.kt new file mode 100644 index 00000000000..1a7149f1ca8 --- /dev/null +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangeOverriddenPropertyTypeToMatchOverridingProperty.kt @@ -0,0 +1,13 @@ +// "Change 'A.x' type to 'String'" "false" +// ERROR: Var-property type is 'jet.String', which is not a type of overridden
internal abstract var x: jet.Int defined in A +trait A { + var x: Int +} + +trait B { + var x: Any +} + +trait C : A, B { + override var x: String +} \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangePropertyTypeToMatchOverridenProperties.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangePropertyTypeToMatchOverridenProperties.kt new file mode 100644 index 00000000000..c47babf6e69 --- /dev/null +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangePropertyTypeToMatchOverridenProperties.kt @@ -0,0 +1,13 @@ +// "Change 'C.x' type to 'String'" "false" +// ERROR: Var-property type is 'jet.Int', which is not a type of overridden
internal abstract var x: jet.String defined in A +trait A { + var x: String +} + +trait B { + var x: Any +} + +trait C : A, B { + override var x: Int +} \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangeReturnTypeOfOverriddenFunction.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangeReturnTypeOfOverriddenFunction.kt new file mode 100644 index 00000000000..302ed8d5be4 --- /dev/null +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangeReturnTypeOfOverriddenFunction.kt @@ -0,0 +1,13 @@ +// "Change 'A.foo' function return type to 'Long'" "false" +// ERROR: Return type is 'jet.Long', which is not a subtype of overridden
internal abstract fun foo(): jet.Int defined in A +trait A { + fun foo(): Int +} + +trait B { + fun foo(): String +} + +trait C : A, B { + override fun foo(): Long +} \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeOverriddenPropertyType1.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeOverriddenPropertyType1.kt new file mode 100644 index 00000000000..9216f429193 --- /dev/null +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeOverriddenPropertyType1.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeOverriddenPropertyType2.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeOverriddenPropertyType2.kt new file mode 100644 index 00000000000..df144be7ce6 --- /dev/null +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeOverriddenPropertyType2.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeOverridingPropertyTypeToFunctionType.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeOverridingPropertyTypeToFunctionType.kt new file mode 100644 index 00000000000..6a6b1155d01 --- /dev/null +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeOverridingPropertyTypeToFunctionType.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeReturnTypeOfOverriddenFunction.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeReturnTypeOfOverriddenFunction.kt new file mode 100644 index 00000000000..a8ccbc2551c --- /dev/null +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeReturnTypeOfOverriddenFunction.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyReturnTypeMismatchOnOverride.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyReturnTypeMismatchOnOverride.kt index afd321e5cfa..4378d809f4a 100644 --- a/idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyReturnTypeMismatchOnOverride.kt +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyReturnTypeMismatchOnOverride.kt @@ -1,4 +1,4 @@ -// "Change 'x' type to 'Int'" "true" +// "Change 'A.x' type to 'Int'" "true" trait X { val x: Int } diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyTypeMismatchOnOverrideIntLong.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyTypeMismatchOnOverrideIntLong.kt index db0eabb5856..a70d8d74a05 100644 --- a/idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyTypeMismatchOnOverrideIntLong.kt +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyTypeMismatchOnOverrideIntLong.kt @@ -1,4 +1,4 @@ -// "Change 'x' type to 'Int'" "true" +// "Change 'B.x' type to 'Int'" "true" abstract class A { abstract var x : Int } diff --git a/idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyTypeMismatchOnOverrideIntUnit.kt b/idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyTypeMismatchOnOverrideIntUnit.kt index 39289180da2..469a62099b0 100644 --- a/idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyTypeMismatchOnOverrideIntUnit.kt +++ b/idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyTypeMismatchOnOverrideIntUnit.kt @@ -1,4 +1,4 @@ -// "Change 'x' type to 'Int'" "true" +// "Change 'B.x' type to 'Int'" "true" abstract class A { abstract var x : Int } diff --git a/idea/testData/quickfix/typeAddition/afterChangeAccessorTypeToFunctionType.kt b/idea/testData/quickfix/typeAddition/afterChangeAccessorTypeToFunctionType.kt new file mode 100644 index 00000000000..642223733a3 --- /dev/null +++ b/idea/testData/quickfix/typeAddition/afterChangeAccessorTypeToFunctionType.kt @@ -0,0 +1,5 @@ +// "Change getter type to (String) -> Int" "true" +class A { + val x: (String) -> Int + get(): (String) -> Int = {42} +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeAddition/beforeChangeAccessorTypeToFunctionType.kt b/idea/testData/quickfix/typeAddition/beforeChangeAccessorTypeToFunctionType.kt new file mode 100644 index 00000000000..2a070579945 --- /dev/null +++ b/idea/testData/quickfix/typeAddition/beforeChangeAccessorTypeToFunctionType.kt @@ -0,0 +1,5 @@ +// "Change getter type to (String) -> Int" "true" +class A { + val x: (String) -> Int + get(): Int = {42} +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/afterChangeFunctionLiteralParameterTypeToFunctionType.kt b/idea/testData/quickfix/typeMismatch/afterChangeFunctionLiteralParameterTypeToFunctionType.kt new file mode 100644 index 00000000000..89a07f91281 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/afterChangeFunctionLiteralParameterTypeToFunctionType.kt @@ -0,0 +1,6 @@ +// "Change type from 'String' to '(Int) -> String'" "true" +fun foo(f: ((Int) -> String) -> String) { + foo { + (f: (Int) -> String) -> f(42) + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/afterChangeFunctionReturnTypeToMatchExpectedTypeOfCall.kt b/idea/testData/quickfix/typeMismatch/afterChangeFunctionReturnTypeToMatchExpectedTypeOfCall.kt new file mode 100644 index 00000000000..e043c28dd7b --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/afterChangeFunctionReturnTypeToMatchExpectedTypeOfCall.kt @@ -0,0 +1,3 @@ +// "Change 'bar' function return type to 'String'" "true" +fun bar(): String = "" +fun foo(): String = bar() \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/afterPropertyTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/afterPropertyTypeMismatch.kt new file mode 100644 index 00000000000..4302b75770c --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/afterPropertyTypeMismatch.kt @@ -0,0 +1,4 @@ +// "Change 'f' type to '(Long) -> Unit'" "true" +fun foo() { + var f: (Long) -> Unit = if (true) { (x: Long) -> } else { (x: Long) -> } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/beforeChangeFunctionLiteralParameterTypeToFunctionType.kt b/idea/testData/quickfix/typeMismatch/beforeChangeFunctionLiteralParameterTypeToFunctionType.kt new file mode 100644 index 00000000000..c8897d3a65e --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/beforeChangeFunctionLiteralParameterTypeToFunctionType.kt @@ -0,0 +1,6 @@ +// "Change type from 'String' to '(Int) -> String'" "true" +fun foo(f: ((Int) -> String) -> String) { + foo { + (f: String) -> f(42) + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/beforeChangeFunctionReturnTypeToMatchExpectedTypeOfCall.kt b/idea/testData/quickfix/typeMismatch/beforeChangeFunctionReturnTypeToMatchExpectedTypeOfCall.kt new file mode 100644 index 00000000000..dcd7a090c5b --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/beforeChangeFunctionReturnTypeToMatchExpectedTypeOfCall.kt @@ -0,0 +1,3 @@ +// "Change 'bar' function return type to 'String'" "true" +fun bar(): Any = "" +fun foo(): String = bar() \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/beforeDontChangeOverriddenPropertyTypeToErrorType.kt b/idea/testData/quickfix/typeMismatch/beforeDontChangeOverriddenPropertyTypeToErrorType.kt new file mode 100644 index 00000000000..b291b9499cf --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/beforeDontChangeOverriddenPropertyTypeToErrorType.kt @@ -0,0 +1,10 @@ +// "Change 'B.x' type to '(String) -> [ERROR : Ay]'" "false" +// ACTION: Change 'A.x' type to '(Int) -> Int' +// ERROR: Return type is '(jet.Int) → jet.Int', which is not a subtype of overridden
internal abstract val x: (jet.String) → [ERROR : Ay] defined in A +// ERROR: Unresolved reference: Ay +trait A { + val x: (String) -> Ay +} +trait B : A { + override val x: (Int) -> Int +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/beforePropertyTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/beforePropertyTypeMismatch.kt new file mode 100644 index 00000000000..a1ffc07759c --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/beforePropertyTypeMismatch.kt @@ -0,0 +1,4 @@ +// "Change 'f' type to '(Long) -> Unit'" "true" +fun foo() { + var f: Int = if (true) { (x: Long) -> } else { (x: Long) -> } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/casts/afterCastToFunctionType.kt b/idea/testData/quickfix/typeMismatch/casts/afterCastToFunctionType.kt new file mode 100644 index 00000000000..989e55304cf --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/casts/afterCastToFunctionType.kt @@ -0,0 +1,4 @@ +// "Cast expression 'x' to '() -> Int'" "true" +fun foo(x: Any): () -> Int { + return x as () -> Int +} diff --git a/idea/testData/quickfix/typeMismatch/casts/beforeCastToFunctionType.kt b/idea/testData/quickfix/typeMismatch/casts/beforeCastToFunctionType.kt new file mode 100644 index 00000000000..eb0f35b50c3 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/casts/beforeCastToFunctionType.kt @@ -0,0 +1,4 @@ +// "Cast expression 'x' to '() -> Int'" "true" +fun foo(x: Any): () -> Int { + return x +} diff --git a/idea/testData/quickfix/typeMismatch/afterComponentFunctionReturnTypeMismatch1.kt b/idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/afterComponentFunctionReturnTypeMismatch1.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/afterComponentFunctionReturnTypeMismatch1.kt rename to idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/afterComponentFunctionReturnTypeMismatch1.kt diff --git a/idea/testData/quickfix/typeMismatch/afterComponentFunctionReturnTypeMismatch2.kt b/idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/afterComponentFunctionReturnTypeMismatch2.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/afterComponentFunctionReturnTypeMismatch2.kt rename to idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/afterComponentFunctionReturnTypeMismatch2.kt diff --git a/idea/testData/quickfix/typeMismatch/afterComponentFunctionReturnTypeMismatch3.kt b/idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/afterComponentFunctionReturnTypeMismatch3.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/afterComponentFunctionReturnTypeMismatch3.kt rename to idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/afterComponentFunctionReturnTypeMismatch3.kt diff --git a/idea/testData/quickfix/typeMismatch/afterComponentFunctionReturnTypeMismatch4.kt b/idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/afterComponentFunctionReturnTypeMismatch4.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/afterComponentFunctionReturnTypeMismatch4.kt rename to idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/afterComponentFunctionReturnTypeMismatch4.kt diff --git a/idea/testData/quickfix/typeMismatch/afterComponentFunctionReturnTypeMismatch5.kt b/idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/afterComponentFunctionReturnTypeMismatch5.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/afterComponentFunctionReturnTypeMismatch5.kt rename to idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/afterComponentFunctionReturnTypeMismatch5.kt diff --git a/idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch1.kt b/idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch1.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch1.kt rename to idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch1.kt diff --git a/idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch2.kt b/idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch2.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch2.kt rename to idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch2.kt diff --git a/idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch3.kt b/idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch3.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch3.kt rename to idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch3.kt diff --git a/idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch4.kt b/idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch4.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch4.kt rename to idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch4.kt diff --git a/idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch5.kt b/idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch5.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch5.kt rename to idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch5.kt diff --git a/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/afterChangeNotFunctionReturnType.kt b/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/afterChangeNotFunctionReturnType.kt new file mode 100644 index 00000000000..2e02e549264 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/afterChangeNotFunctionReturnType.kt @@ -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 * !(if (true) a else a) \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/afterChangePlusFunctionReturnType.kt b/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/afterChangePlusFunctionReturnType.kt new file mode 100644 index 00000000000..5f841fe38b4 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/afterChangePlusFunctionReturnType.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/afterChangeTimesFunctionParameterType.kt b/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/afterChangeTimesFunctionParameterType.kt new file mode 100644 index 00000000000..a0178c297d5 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/afterChangeTimesFunctionParameterType.kt @@ -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 * "" \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/beforeChangeNotFunctionReturnType.kt b/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/beforeChangeNotFunctionReturnType.kt new file mode 100644 index 00000000000..3fcbddff06c --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/beforeChangeNotFunctionReturnType.kt @@ -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 * !(if (true) a else a) \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/beforeChangePlusFunctionReturnType.kt b/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/beforeChangePlusFunctionReturnType.kt new file mode 100644 index 00000000000..c83d83f0c41 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/beforeChangePlusFunctionReturnType.kt @@ -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 +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/beforeChangeTimesFunctionParameterType.kt b/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/beforeChangeTimesFunctionParameterType.kt new file mode 100644 index 00000000000..837fc7af446 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/fixOverloadedOperator/beforeChangeTimesFunctionParameterType.kt @@ -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 * "" \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/afterChangeFunctionParameterType1.kt b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/afterChangeFunctionParameterType1.kt new file mode 100644 index 00000000000..b253e8b1782 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/afterChangeFunctionParameterType1.kt @@ -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}, 1) +} diff --git a/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/afterChangeFunctionParameterType2.kt b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/afterChangeFunctionParameterType2.kt new file mode 100644 index 00000000000..c1b3343642c --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/afterChangeFunctionParameterType2.kt @@ -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 = "") +} diff --git a/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/afterChangeFunctionParameterType3.kt b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/afterChangeFunctionParameterType3.kt new file mode 100644 index 00000000000..30b490ba5ed --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/afterChangeFunctionParameterType3.kt @@ -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) {} +} diff --git a/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/afterChangePrimaryConstructorParameterType.kt b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/afterChangePrimaryConstructorParameterType.kt new file mode 100644 index 00000000000..9acd1ad0389 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/afterChangePrimaryConstructorParameterType.kt @@ -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) "" else "") +} diff --git a/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType1.kt b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType1.kt new file mode 100644 index 00000000000..deb5313f041 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType1.kt @@ -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}, 1) +} diff --git a/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType2.kt b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType2.kt new file mode 100644 index 00000000000..c5e45b514be --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType2.kt @@ -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 = "") +} diff --git a/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType3.kt b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType3.kt new file mode 100644 index 00000000000..9d5f48d961d --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType3.kt @@ -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) {} +} diff --git a/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType4.kt b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType4.kt new file mode 100644 index 00000000000..a4c9f02baaf --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType4.kt @@ -0,0 +1,8 @@ +// "Change parameter 'z' type of function 'foo' to '(Int) -> String'" "false" +// ERROR: Type mismatch.
Required:jet.Int
Found:jet.String
+fun foo(y: Int = 0, z: (Int) -> String = {""}) { + foo { + "": Int + "" + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType5.kt b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType5.kt new file mode 100644 index 00000000000..80f37c15a85 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType5.kt @@ -0,0 +1,5 @@ +// "Change parameter 'y' type of function 'foo' to 'Int'" "false" +// ERROR: Type mismatch.
Required:jet.Int
Found:jet.String
+fun foo(y: Int = 0, z: (Int) -> String = {""}) { + foo("": Int) +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangePrimaryConstructorParameterType.kt b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangePrimaryConstructorParameterType.kt new file mode 100644 index 00000000000..7e39c54a4a1 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangePrimaryConstructorParameterType.kt @@ -0,0 +1,5 @@ +// "Change parameter 'a' type of primary constructor of class 'B' to 'String'" "true" +class B(val a: Int) +fun foo() { + B(if (true) "" else "") +} diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterAssignmentTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterAssignmentTypeMismatch.kt new file mode 100644 index 00000000000..ac73a6453e9 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterAssignmentTypeMismatch.kt @@ -0,0 +1,7 @@ +// "Change 'f' type to '() -> Unit'" "true" +fun foo() { + val f: () -> Unit = { + var x = 1 + x += 21 + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterChangeFunctionLiteralTypeWithoutChangingFunctionParameterType.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterChangeFunctionLiteralTypeWithoutChangingFunctionParameterType.kt new file mode 100644 index 00000000000..b2b6552068c --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterChangeFunctionLiteralTypeWithoutChangingFunctionParameterType.kt @@ -0,0 +1,7 @@ +// "Change function literal return type to 'String'" "true" +fun foo(f: (String) -> Any) { + foo { + (s: String): String -> + s + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterChangeFunctionLiteralTypeWithoutChangingPropertyType.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterChangeFunctionLiteralTypeWithoutChangingPropertyType.kt new file mode 100644 index 00000000000..35be90c1bea --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterChangeFunctionLiteralTypeWithoutChangingPropertyType.kt @@ -0,0 +1,7 @@ +// "Change function literal return type to 'String'" "true" +fun foo() { + val f: (String) -> String = { + (s: Any): String -> + "" + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterChangeFunctionReturnTypeToFunctionType.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterChangeFunctionReturnTypeToFunctionType.kt new file mode 100644 index 00000000000..4d6e718b946 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterChangeFunctionReturnTypeToFunctionType.kt @@ -0,0 +1,4 @@ +// "Change 'foo' function return type to '(Long) -> Int'" "true" +fun foo(x: Any): (Long) -> Int { + return {(x: Long) -> 42} +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterChangeFunctionReturnTypeToMatchReturnTypeOfReturnedLiteral.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterChangeFunctionReturnTypeToMatchReturnTypeOfReturnedLiteral.kt new file mode 100644 index 00000000000..5c7182093c5 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterChangeFunctionReturnTypeToMatchReturnTypeOfReturnedLiteral.kt @@ -0,0 +1,4 @@ +// "Change 'foo' function return type to '() -> Any'" "true" +fun foo(x: Any): () -> Any { + return {x} +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterExpectedTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterExpectedTypeMismatch.kt new file mode 100644 index 00000000000..d51e2648772 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterExpectedTypeMismatch.kt @@ -0,0 +1,7 @@ +// "Change 'bar' type to '(() -> Long) -> Unit'" "true" +fun foo() { + val bar: (() -> Long) -> Unit = { + (f: () -> Long): Unit -> + var x = 5 + } +} diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterPropertyGetterInitializerTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterPropertyGetterInitializerTypeMismatch.kt new file mode 100644 index 00000000000..e22fc7027ef --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterPropertyGetterInitializerTypeMismatch.kt @@ -0,0 +1,6 @@ +// "Change 'A.x' type to '() -> Int'" "true" +class A { + var x: () -> Int + get(): () -> Int = if (true) { {42} } else { {24} } + set(i: () -> Int) {} +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterReturnedExpressionTypeMismatchFunctionParameterType.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterReturnedExpressionTypeMismatchFunctionParameterType.kt new file mode 100644 index 00000000000..16a4b270648 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterReturnedExpressionTypeMismatchFunctionParameterType.kt @@ -0,0 +1,6 @@ +// "Change parameter 'f' type of function 'foo' to '() -> String'" "true" +fun foo(f: () -> String) { + foo { + "" + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterTypeMismatchInIfStatementReturnedByFunction.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterTypeMismatchInIfStatementReturnedByFunction.kt new file mode 100644 index 00000000000..031dded208b --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterTypeMismatchInIfStatementReturnedByFunction.kt @@ -0,0 +1,7 @@ +// "Change 'boo' function return type to 'String'" "true" +fun boo(): String { + return ((if (true) { + val a = "" + a + } else "")) +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterTypeMismatchInIfStatementReturnedByLiteral.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterTypeMismatchInIfStatementReturnedByLiteral.kt new file mode 100644 index 00000000000..19f21d70c71 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterTypeMismatchInIfStatementReturnedByLiteral.kt @@ -0,0 +1,12 @@ +// "Change 'f' type to '(Int, Int) -> (String) -> Int'" "true" +fun foo() { + val f: (Int, Int) -> (String) -> Int = { + (a: Int, b: Int): (String) -> Int -> + val x = {(s: String) -> 42} + if (true) x + else if (true) x else { + var y = 42 + if (true) x else x + } + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/afterTypeMismatchInInitializer.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterTypeMismatchInInitializer.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/afterTypeMismatchInInitializer.kt rename to idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterTypeMismatchInInitializer.kt diff --git a/idea/testData/quickfix/typeMismatch/afterTypeMismatchInReturnStatement.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterTypeMismatchInReturnStatement.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/afterTypeMismatchInReturnStatement.kt rename to idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/afterTypeMismatchInReturnStatement.kt diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeAssignmentTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeAssignmentTypeMismatch.kt new file mode 100644 index 00000000000..ad45d53e8c7 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeAssignmentTypeMismatch.kt @@ -0,0 +1,7 @@ +// "Change 'f' type to '() -> Unit'" "true" +fun foo() { + val f: () -> Int = { + var x = 1 + x += 21 + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionLiteralTypeWithoutChangingFunctionParameterType.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionLiteralTypeWithoutChangingFunctionParameterType.kt new file mode 100644 index 00000000000..0a04b9f473b --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionLiteralTypeWithoutChangingFunctionParameterType.kt @@ -0,0 +1,7 @@ +// "Change function literal return type to 'String'" "true" +fun foo(f: (String) -> Any) { + foo { + (s: String): Int -> + s + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionLiteralTypeWithoutChangingPropertyType.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionLiteralTypeWithoutChangingPropertyType.kt new file mode 100644 index 00000000000..dbec7994ac1 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionLiteralTypeWithoutChangingPropertyType.kt @@ -0,0 +1,7 @@ +// "Change function literal return type to 'String'" "true" +fun foo() { + val f: (String) -> String = { + (s: Any): Int -> + "" + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionReturnTypeToFunctionType.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionReturnTypeToFunctionType.kt new file mode 100644 index 00000000000..2f90f8ee5e5 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionReturnTypeToFunctionType.kt @@ -0,0 +1,4 @@ +// "Change 'foo' function return type to '(Long) -> Int'" "true" +fun foo(x: Any): Int { + return {(x: Long) -> 42} +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionReturnTypeToMatchReturnTypeOfReturnedLiteral.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionReturnTypeToMatchReturnTypeOfReturnedLiteral.kt new file mode 100644 index 00000000000..44c4c565685 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionReturnTypeToMatchReturnTypeOfReturnedLiteral.kt @@ -0,0 +1,4 @@ +// "Change 'foo' function return type to '() -> Any'" "true" +fun foo(x: Any): () -> Int { + return {x} +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeDontChangeFunctionReturnTypeToErrorType.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeDontChangeFunctionReturnTypeToErrorType.kt new file mode 100644 index 00000000000..ff1d6c75cf7 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeDontChangeFunctionReturnTypeToErrorType.kt @@ -0,0 +1,6 @@ +// "Change 'foo' function return type to '([ERROR : NoSuchType]) -> Int'" "false" +// ERROR: Type mismatch.
Required:jet.Int
Found:([ERROR : NoSuchType]) → jet.Int
+// ERROR: Unresolved reference: NoSuchType +fun foo(): Int { + return { (x: NoSuchType) -> 42 } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeExpectedTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeExpectedTypeMismatch.kt new file mode 100644 index 00000000000..379a397ab85 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeExpectedTypeMismatch.kt @@ -0,0 +1,7 @@ +// "Change 'bar' type to '(() -> Long) -> Unit'" "true" +fun foo() { + val bar: () -> Double = { + (f: () -> Long): String -> + var x = 5 + } +} diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforePropertyGetterInitializerTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforePropertyGetterInitializerTypeMismatch.kt new file mode 100644 index 00000000000..c9196877276 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforePropertyGetterInitializerTypeMismatch.kt @@ -0,0 +1,6 @@ +// "Change 'A.x' type to '() -> Int'" "true" +class A { + var x: Int + get(): Int = if (true) { {42} } else { {24} } + set(i: Int) {} +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeReturnedExpresionCantEvaluateToExpresionThatTypeMismatch.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeReturnedExpresionCantEvaluateToExpresionThatTypeMismatch.kt new file mode 100644 index 00000000000..8161c29c287 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeReturnedExpresionCantEvaluateToExpresionThatTypeMismatch.kt @@ -0,0 +1,6 @@ +// "Change function 'foo' return type to 'String'" "false" +// ERROR: Type mismatch.
Required:jet.Int
Found:jet.String
+// ACTION: Disable 'Replace 'if' with 'when'' +// ACTION: Edit intention settings +// ACTION: Replace 'if' with 'when' +fun foo(): Int = if (true) "": Int else 4 \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeReturnedExpressionTypeMismatchFunctionParameterType.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeReturnedExpressionTypeMismatchFunctionParameterType.kt new file mode 100644 index 00000000000..cb39787a072 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeReturnedExpressionTypeMismatchFunctionParameterType.kt @@ -0,0 +1,6 @@ +// "Change parameter 'f' type of function 'foo' to '() -> String'" "true" +fun foo(f: () -> Int) { + foo { + "" + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInIfStatementReturnedByFunction.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInIfStatementReturnedByFunction.kt new file mode 100644 index 00000000000..8a4869a7439 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInIfStatementReturnedByFunction.kt @@ -0,0 +1,7 @@ +// "Change 'boo' function return type to 'String'" "true" +fun boo(): Int { + return ((if (true) { + val a = "" + a + } else "")) +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInIfStatementReturnedByLiteral.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInIfStatementReturnedByLiteral.kt new file mode 100644 index 00000000000..ae1c5c6a142 --- /dev/null +++ b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInIfStatementReturnedByLiteral.kt @@ -0,0 +1,12 @@ +// "Change 'f' type to '(Int, Int) -> (String) -> Int'" "true" +fun foo() { + val f: () -> Long = { + (a: Int, b: Int): Long -> + val x = {(s: String) -> 42} + if (true) x + else if (true) x else { + var y = 42 + if (true) x else x + } + } +} \ No newline at end of file diff --git a/idea/testData/quickfix/typeMismatch/beforeTypeMismatchInInitializer.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInInitializer.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/beforeTypeMismatchInInitializer.kt rename to idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInInitializer.kt diff --git a/idea/testData/quickfix/typeMismatch/beforeTypeMismatchInReturnStatement.kt b/idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInReturnStatement.kt similarity index 100% rename from idea/testData/quickfix/typeMismatch/beforeTypeMismatchInReturnStatement.kt rename to idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInReturnStatement.kt diff --git a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java index 350eaa4bd87..f4226698736 100644 --- a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java @@ -1018,6 +1018,46 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/override/typeMismatchOnOverride"), Pattern.compile("^before(\\w+)\\.kt$"), true); } + @TestMetadata("beforeCantChangeMultipleOverriddenPropertiesTypes.kt") + public void testCantChangeMultipleOverriddenPropertiesTypes() throws Exception { + doTest("idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangeMultipleOverriddenPropertiesTypes.kt"); + } + + @TestMetadata("beforeCantChangeOverriddenPropertyTypeToMatchOverridingProperty.kt") + public void testCantChangeOverriddenPropertyTypeToMatchOverridingProperty() throws Exception { + doTest("idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangeOverriddenPropertyTypeToMatchOverridingProperty.kt"); + } + + @TestMetadata("beforeCantChangePropertyTypeToMatchOverridenProperties.kt") + public void testCantChangePropertyTypeToMatchOverridenProperties() throws Exception { + doTest("idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangePropertyTypeToMatchOverridenProperties.kt"); + } + + @TestMetadata("beforeCantChangeReturnTypeOfOverriddenFunction.kt") + public void testCantChangeReturnTypeOfOverriddenFunction() throws Exception { + doTest("idea/testData/quickfix/override/typeMismatchOnOverride/beforeCantChangeReturnTypeOfOverriddenFunction.kt"); + } + + @TestMetadata("beforeChangeOverriddenPropertyType1.kt") + public void testChangeOverriddenPropertyType1() throws Exception { + doTest("idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeOverriddenPropertyType1.kt"); + } + + @TestMetadata("beforeChangeOverriddenPropertyType2.kt") + public void testChangeOverriddenPropertyType2() throws Exception { + doTest("idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeOverriddenPropertyType2.kt"); + } + + @TestMetadata("beforeChangeOverridingPropertyTypeToFunctionType.kt") + public void testChangeOverridingPropertyTypeToFunctionType() throws Exception { + doTest("idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeOverridingPropertyTypeToFunctionType.kt"); + } + + @TestMetadata("beforeChangeReturnTypeOfOverriddenFunction.kt") + public void testChangeReturnTypeOfOverriddenFunction() throws Exception { + doTest("idea/testData/quickfix/override/typeMismatchOnOverride/beforeChangeReturnTypeOfOverriddenFunction.kt"); + } + @TestMetadata("beforePropertyReturnTypeMismatchOnOverride.kt") public void testPropertyReturnTypeMismatchOnOverride() throws Exception { doTest("idea/testData/quickfix/override/typeMismatchOnOverride/beforePropertyReturnTypeMismatchOnOverride.kt"); @@ -1149,6 +1189,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest("idea/testData/quickfix/typeAddition/beforeAmbiguousPropertyReturnType.kt"); } + @TestMetadata("beforeChangeAccessorTypeToFunctionType.kt") + public void testChangeAccessorTypeToFunctionType() throws Exception { + doTest("idea/testData/quickfix/typeAddition/beforeChangeAccessorTypeToFunctionType.kt"); + } + @TestMetadata("beforeNoAddErrorType.kt") public void testNoAddErrorType() throws Exception { doTest("idea/testData/quickfix/typeAddition/beforeNoAddErrorType.kt"); @@ -1230,12 +1275,22 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } @TestMetadata("idea/testData/quickfix/typeMismatch") - @InnerTestClasses({TypeMismatch.Casts.class}) + @InnerTestClasses({TypeMismatch.Casts.class, TypeMismatch.ComponentFunctionReturnTypeMismatch.class, TypeMismatch.FixOverloadedOperator.class, TypeMismatch.ParameterTypeMismatch.class, TypeMismatch.TypeMismatchOnReturnedExpression.class}) public static class TypeMismatch extends AbstractQuickFixTest { public void testAllFilesPresentInTypeMismatch() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/typeMismatch"), Pattern.compile("^before(\\w+)\\.kt$"), true); } + @TestMetadata("beforeChangeFunctionLiteralParameterTypeToFunctionType.kt") + public void testChangeFunctionLiteralParameterTypeToFunctionType() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/beforeChangeFunctionLiteralParameterTypeToFunctionType.kt"); + } + + @TestMetadata("beforeChangeFunctionReturnTypeToMatchExpectedTypeOfCall.kt") + public void testChangeFunctionReturnTypeToMatchExpectedTypeOfCall() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/beforeChangeFunctionReturnTypeToMatchExpectedTypeOfCall.kt"); + } + @TestMetadata("beforeChangeReturnTypeWhenFunctionNameIsMissing.kt") public void testChangeReturnTypeWhenFunctionNameIsMissing() throws Exception { doTest("idea/testData/quickfix/typeMismatch/beforeChangeReturnTypeWhenFunctionNameIsMissing.kt"); @@ -1251,29 +1306,9 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest("idea/testData/quickfix/typeMismatch/beforeCompareToTypeMismatch.kt"); } - @TestMetadata("beforeComponentFunctionReturnTypeMismatch1.kt") - public void testComponentFunctionReturnTypeMismatch1() throws Exception { - doTest("idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch1.kt"); - } - - @TestMetadata("beforeComponentFunctionReturnTypeMismatch2.kt") - public void testComponentFunctionReturnTypeMismatch2() throws Exception { - doTest("idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch2.kt"); - } - - @TestMetadata("beforeComponentFunctionReturnTypeMismatch3.kt") - public void testComponentFunctionReturnTypeMismatch3() throws Exception { - doTest("idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch3.kt"); - } - - @TestMetadata("beforeComponentFunctionReturnTypeMismatch4.kt") - public void testComponentFunctionReturnTypeMismatch4() throws Exception { - doTest("idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch4.kt"); - } - - @TestMetadata("beforeComponentFunctionReturnTypeMismatch5.kt") - public void testComponentFunctionReturnTypeMismatch5() throws Exception { - doTest("idea/testData/quickfix/typeMismatch/beforeComponentFunctionReturnTypeMismatch5.kt"); + @TestMetadata("beforeDontChangeOverriddenPropertyTypeToErrorType.kt") + public void testDontChangeOverriddenPropertyTypeToErrorType() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/beforeDontChangeOverriddenPropertyTypeToErrorType.kt"); } @TestMetadata("beforeExpectedParameterTypeMismatch.kt") @@ -1296,21 +1331,16 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest("idea/testData/quickfix/typeMismatch/beforeNoReturnInFunctionWithBlockBody.kt"); } + @TestMetadata("beforePropertyTypeMismatch.kt") + public void testPropertyTypeMismatch() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/beforePropertyTypeMismatch.kt"); + } + @TestMetadata("beforeReturnTypeMismatch.kt") public void testReturnTypeMismatch() throws Exception { doTest("idea/testData/quickfix/typeMismatch/beforeReturnTypeMismatch.kt"); } - @TestMetadata("beforeTypeMismatchInInitializer.kt") - public void testTypeMismatchInInitializer() throws Exception { - doTest("idea/testData/quickfix/typeMismatch/beforeTypeMismatchInInitializer.kt"); - } - - @TestMetadata("beforeTypeMismatchInReturnStatement.kt") - public void testTypeMismatchInReturnStatement() throws Exception { - doTest("idea/testData/quickfix/typeMismatch/beforeTypeMismatchInReturnStatement.kt"); - } - @TestMetadata("idea/testData/quickfix/typeMismatch/casts") public static class Casts extends AbstractQuickFixTest { public void testAllFilesPresentInCasts() throws Exception { @@ -1332,6 +1362,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { doTest("idea/testData/quickfix/typeMismatch/casts/beforeAutocastImpossible3.kt"); } + @TestMetadata("beforeCastToFunctionType.kt") + public void testCastToFunctionType() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/casts/beforeCastToFunctionType.kt"); + } + @TestMetadata("beforeTypeMismatch1.kt") public void testTypeMismatch1() throws Exception { doTest("idea/testData/quickfix/typeMismatch/casts/beforeTypeMismatch1.kt"); @@ -1359,10 +1394,186 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } + @TestMetadata("idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch") + public static class ComponentFunctionReturnTypeMismatch extends AbstractQuickFixTest { + public void testAllFilesPresentInComponentFunctionReturnTypeMismatch() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch"), Pattern.compile("^before(\\w+)\\.kt$"), true); + } + + @TestMetadata("beforeComponentFunctionReturnTypeMismatch1.kt") + public void testComponentFunctionReturnTypeMismatch1() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch1.kt"); + } + + @TestMetadata("beforeComponentFunctionReturnTypeMismatch2.kt") + public void testComponentFunctionReturnTypeMismatch2() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch2.kt"); + } + + @TestMetadata("beforeComponentFunctionReturnTypeMismatch3.kt") + public void testComponentFunctionReturnTypeMismatch3() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch3.kt"); + } + + @TestMetadata("beforeComponentFunctionReturnTypeMismatch4.kt") + public void testComponentFunctionReturnTypeMismatch4() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch4.kt"); + } + + @TestMetadata("beforeComponentFunctionReturnTypeMismatch5.kt") + public void testComponentFunctionReturnTypeMismatch5() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/componentFunctionReturnTypeMismatch/beforeComponentFunctionReturnTypeMismatch5.kt"); + } + + } + + @TestMetadata("idea/testData/quickfix/typeMismatch/fixOverloadedOperator") + public static class FixOverloadedOperator extends AbstractQuickFixTest { + public void testAllFilesPresentInFixOverloadedOperator() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/typeMismatch/fixOverloadedOperator"), Pattern.compile("^before(\\w+)\\.kt$"), true); + } + + @TestMetadata("beforeChangeNotFunctionReturnType.kt") + public void testChangeNotFunctionReturnType() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/fixOverloadedOperator/beforeChangeNotFunctionReturnType.kt"); + } + + @TestMetadata("beforeChangePlusFunctionReturnType.kt") + public void testChangePlusFunctionReturnType() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/fixOverloadedOperator/beforeChangePlusFunctionReturnType.kt"); + } + + @TestMetadata("beforeChangeTimesFunctionParameterType.kt") + public void testChangeTimesFunctionParameterType() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/fixOverloadedOperator/beforeChangeTimesFunctionParameterType.kt"); + } + + } + + @TestMetadata("idea/testData/quickfix/typeMismatch/parameterTypeMismatch") + public static class ParameterTypeMismatch extends AbstractQuickFixTest { + public void testAllFilesPresentInParameterTypeMismatch() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/typeMismatch/parameterTypeMismatch"), Pattern.compile("^before(\\w+)\\.kt$"), true); + } + + @TestMetadata("beforeChangeFunctionParameterType1.kt") + public void testChangeFunctionParameterType1() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType1.kt"); + } + + @TestMetadata("beforeChangeFunctionParameterType2.kt") + public void testChangeFunctionParameterType2() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType2.kt"); + } + + @TestMetadata("beforeChangeFunctionParameterType3.kt") + public void testChangeFunctionParameterType3() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType3.kt"); + } + + @TestMetadata("beforeChangeFunctionParameterType4.kt") + public void testChangeFunctionParameterType4() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType4.kt"); + } + + @TestMetadata("beforeChangeFunctionParameterType5.kt") + public void testChangeFunctionParameterType5() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangeFunctionParameterType5.kt"); + } + + @TestMetadata("beforeChangePrimaryConstructorParameterType.kt") + public void testChangePrimaryConstructorParameterType() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/parameterTypeMismatch/beforeChangePrimaryConstructorParameterType.kt"); + } + + } + + @TestMetadata("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression") + public static class TypeMismatchOnReturnedExpression extends AbstractQuickFixTest { + public void testAllFilesPresentInTypeMismatchOnReturnedExpression() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression"), Pattern.compile("^before(\\w+)\\.kt$"), true); + } + + @TestMetadata("beforeAssignmentTypeMismatch.kt") + public void testAssignmentTypeMismatch() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeAssignmentTypeMismatch.kt"); + } + + @TestMetadata("beforeChangeFunctionLiteralTypeWithoutChangingFunctionParameterType.kt") + public void testChangeFunctionLiteralTypeWithoutChangingFunctionParameterType() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionLiteralTypeWithoutChangingFunctionParameterType.kt"); + } + + @TestMetadata("beforeChangeFunctionLiteralTypeWithoutChangingPropertyType.kt") + public void testChangeFunctionLiteralTypeWithoutChangingPropertyType() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionLiteralTypeWithoutChangingPropertyType.kt"); + } + + @TestMetadata("beforeChangeFunctionReturnTypeToFunctionType.kt") + public void testChangeFunctionReturnTypeToFunctionType() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionReturnTypeToFunctionType.kt"); + } + + @TestMetadata("beforeChangeFunctionReturnTypeToMatchReturnTypeOfReturnedLiteral.kt") + public void testChangeFunctionReturnTypeToMatchReturnTypeOfReturnedLiteral() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeChangeFunctionReturnTypeToMatchReturnTypeOfReturnedLiteral.kt"); + } + + @TestMetadata("beforeDontChangeFunctionReturnTypeToErrorType.kt") + public void testDontChangeFunctionReturnTypeToErrorType() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeDontChangeFunctionReturnTypeToErrorType.kt"); + } + + @TestMetadata("beforeExpectedTypeMismatch.kt") + public void testExpectedTypeMismatch() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeExpectedTypeMismatch.kt"); + } + + @TestMetadata("beforePropertyGetterInitializerTypeMismatch.kt") + public void testPropertyGetterInitializerTypeMismatch() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforePropertyGetterInitializerTypeMismatch.kt"); + } + + @TestMetadata("beforeReturnedExpresionCantEvaluateToExpresionThatTypeMismatch.kt") + public void testReturnedExpresionCantEvaluateToExpresionThatTypeMismatch() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeReturnedExpresionCantEvaluateToExpresionThatTypeMismatch.kt"); + } + + @TestMetadata("beforeReturnedExpressionTypeMismatchFunctionParameterType.kt") + public void testReturnedExpressionTypeMismatchFunctionParameterType() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeReturnedExpressionTypeMismatchFunctionParameterType.kt"); + } + + @TestMetadata("beforeTypeMismatchInIfStatementReturnedByFunction.kt") + public void testTypeMismatchInIfStatementReturnedByFunction() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInIfStatementReturnedByFunction.kt"); + } + + @TestMetadata("beforeTypeMismatchInIfStatementReturnedByLiteral.kt") + public void testTypeMismatchInIfStatementReturnedByLiteral() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInIfStatementReturnedByLiteral.kt"); + } + + @TestMetadata("beforeTypeMismatchInInitializer.kt") + public void testTypeMismatchInInitializer() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInInitializer.kt"); + } + + @TestMetadata("beforeTypeMismatchInReturnStatement.kt") + public void testTypeMismatchInReturnStatement() throws Exception { + doTest("idea/testData/quickfix/typeMismatch/typeMismatchOnReturnedExpression/beforeTypeMismatchInReturnStatement.kt"); + } + + } + public static Test innerSuite() { TestSuite suite = new TestSuite("TypeMismatch"); suite.addTestSuite(TypeMismatch.class); suite.addTestSuite(Casts.class); + suite.addTestSuite(ComponentFunctionReturnTypeMismatch.class); + suite.addTestSuite(FixOverloadedOperator.class); + suite.addTestSuite(ParameterTypeMismatch.class); + suite.addTestSuite(TypeMismatchOnReturnedExpression.class); return suite; } }