diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index acc5d5bd7f3..40bbf21ec63 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -64,6 +64,13 @@ remove.no.name.function.return.type=Remove explicitly specified function return change.element.type=Change ''{0}'' type to ''{1}'' change.type=Change type from ''{0}'' to ''{1}'' change.type.family=Change Type +add.parameters.to.function=Add parameter{0} to function ''{1}'' +add.parameters.to.constructor=Add parameter{0} to constructor ''{1}'' +change.function.signature=Change the signature of function ''{0}'' +change.constructor.signature=Change the signature of constructor ''{0}'' +change.function.literal.signature=Change the signature of function literal +remove.parameter=Remove parameter ''{0}'' +change.signature.family=Change signature of function/constructor cast.expression.to.type=Cast expression ''{0}'' to ''{1}'' cast.expression.family=Cast Expression @@ -144,15 +151,11 @@ surround.with.function.template={ } surround.with.cannot.perform.action=Cannot perform Surround With action to the current contextsurround.with.function.template={ } remove.variable.family.name=Remove variable remove.variable.action=Remove variable ''{0}'' + kotlin.code.transformations=Kotlin Code Transformations transform.if.statement.with.assignments.to.expression=Transform 'if' statement with assignments to expression transform.assignment.with.if.expression.to.statement=Transform assignment with 'if' expression to statement transform.if.statement.with.assignments.to.expression.family=Transform 'if' Statement with Assignments to Expression transform.assignment.with.if.expression.to.statement.family=Transform Assignment with 'if' Expression to Statement -change.function.signature.action.single=Change function signature to ''{0}'' -change.function.signature.action.multiple=Change function signature... -change.function.signature.family=Change function signature -change.function.signature.chooser.title=Choose signature -change.function.signature.action=Change function signature remove.unnecessary.parentheses=Remove unnecessary parentheses remove.unnecessary.parentheses.family=Remove Unnecessary Parentheses \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionParametersFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionParametersFix.java new file mode 100644 index 00000000000..bb05a682110 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/AddFunctionParametersFix.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.openapi.application.ApplicationManager; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiReference; +import com.intellij.psi.search.searches.ReferencesSearch; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor; +import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; +import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; +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.checker.JetTypeChecker; +import org.jetbrains.jet.plugin.JetBundle; +import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache; +import org.jetbrains.jet.plugin.refactoring.JetNameValidator; +import org.jetbrains.jet.plugin.refactoring.changeSignature.JetChangeSignatureDialog; +import org.jetbrains.jet.plugin.refactoring.changeSignature.JetFunctionPlatformDescriptorImpl; +import org.jetbrains.jet.plugin.refactoring.changeSignature.JetParameterInfo; +import org.jetbrains.jet.renderer.DescriptorRenderer; + +import java.util.List; + +public class AddFunctionParametersFix extends ChangeFunctionSignatureFix { + private final JetCallElement callElement; + private final boolean hasTypeMismatches; + + public AddFunctionParametersFix( + @NotNull PsiElement declaration, + @NotNull JetCallElement callElement, + @NotNull FunctionDescriptor functionDescriptor, + boolean hasTypeMismatches + ) { + super(declaration, callElement, functionDescriptor); + this.callElement = callElement; + this.hasTypeMismatches = hasTypeMismatches; + } + + @NotNull + @Override + public String getText() { + List parameters = functionDescriptor.getValueParameters(); + List arguments = callElement.getValueArguments(); + int newParametersCnt = arguments.size() - parameters.size(); + assert newParametersCnt > 0; + String subjectSuffix = newParametersCnt > 1 ? "s" : ""; + + if (functionDescriptor instanceof ConstructorDescriptor) { + String className = functionDescriptor.getContainingDeclaration().getName().getName(); + + if (hasTypeMismatches) + return JetBundle.message("change.constructor.signature", className); + else + return JetBundle.message("add.parameters.to.constructor", subjectSuffix, className); + } + else { + String functionName = functionDescriptor.getName().getName(); + + if (hasTypeMismatches) + return JetBundle.message("change.function.signature", functionName); + else + return JetBundle.message("add.parameters.to.function", subjectSuffix, functionName); + } + } + + @Override + protected void invoke(@NotNull Project project, Editor editor, JetFile file) { + BindingContext bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) callElement.getContainingFile()).getBindingContext(); + JetFunctionPlatformDescriptorImpl platformDescriptor = new JetFunctionPlatformDescriptorImpl(functionDescriptor, element); + final List parameters = functionDescriptor.getValueParameters(); + List arguments = callElement.getValueArguments(); + JetNameValidator validator = JetNameValidator.getCollectingValidator(callElement.getProject()); + + for (int i = 0; i < arguments.size(); i ++) { + ValueArgument argument = arguments.get(i); + JetExpression expression = argument.getArgumentExpression(); + + if (i < parameters.size()) { + validator.validateName(parameters.get(i).getName().getName()); + JetType argumentType = expression != null ? bindingContext.get(BindingContext.EXPRESSION_TYPE, expression) : null; + JetType parameterType = parameters.get(i).getType(); + + if (argumentType != null && !JetTypeChecker.INSTANCE.isSubtypeOf(argumentType, parameterType)) + platformDescriptor.getParameters().get(i).setTypeText(DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(argumentType)); + } + else { + JetParameterInfo parameterInfo = getNewParameterInfo(bindingContext, argument, validator); + + if (expression != null) + parameterInfo.setDefaultValueText(expression.getText()); + + platformDescriptor.addParameter(parameterInfo); + } + } + + JetChangeSignatureDialog dialog = new JetChangeSignatureDialog(project, platformDescriptor, callElement, getText()) { + @Override + protected int getSelectedIdx() { + return parameters.size(); + } + }; + + if (ApplicationManager.getApplication().isUnitTestMode() || + !hasTypeMismatches && !(functionDescriptor instanceof ConstructorDescriptor) && !hasOtherUsages()) + performRefactoringSilently(dialog); + else + dialog.show(); + } + + private boolean hasOtherUsages() { + for (PsiReference reference : ReferencesSearch.search(element)) { + PsiElement referenceElement = reference.getElement(); + + if (referenceElement != null && referenceElement.getParent() instanceof JetReferenceExpression && + !callElement.equals(referenceElement.getParent().getParent())) + return true; + } + + return false; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionLiteralSignatureFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionLiteralSignatureFix.java new file mode 100644 index 00000000000..ace4c72e126 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionLiteralSignatureFix.java @@ -0,0 +1,64 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.quickfix; + +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; +import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.jet.lang.psi.JetFunctionLiteral; +import org.jetbrains.jet.lang.types.JetType; +import org.jetbrains.jet.plugin.JetBundle; +import org.jetbrains.jet.plugin.refactoring.JetNameSuggester; +import org.jetbrains.jet.plugin.refactoring.JetNameValidator; +import org.jetbrains.jet.plugin.refactoring.changeSignature.JetFunctionPlatformDescriptorImpl; +import org.jetbrains.jet.plugin.refactoring.changeSignature.JetParameterInfo; + +import java.util.List; + +public class ChangeFunctionLiteralSignatureFix extends ChangeFunctionSignatureFix { + private final List parameterTypes; + + public ChangeFunctionLiteralSignatureFix( + @NotNull JetFunctionLiteral functionLiteral, + @NotNull FunctionDescriptor functionDescriptor, + @NotNull List parameterTypes) { + super(functionLiteral, functionLiteral, functionDescriptor); + this.parameterTypes = parameterTypes; + } + + @NotNull + @Override + public String getText() { + return JetBundle.message("change.function.literal.signature"); + } + + @Override + protected void invoke(@NotNull Project project, Editor editor, JetFile file) { + JetFunctionPlatformDescriptorImpl platformDescriptor = new JetFunctionPlatformDescriptorImpl(functionDescriptor, element); + JetNameValidator validator = JetNameValidator.getCollectingValidator(project); + platformDescriptor.clearParameters(); + + for (JetType type : parameterTypes) { + String name = JetNameSuggester.suggestNames(type, validator, "param")[0]; + platformDescriptor.addParameter(new JetParameterInfo(name, type)); + } + + showDialog(project, platformDescriptor); + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionSignatureFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionSignatureFix.java new file mode 100644 index 00000000000..62449021494 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ChangeFunctionSignatureFix.java @@ -0,0 +1,206 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.quickfix; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiNameIdentifierOwner; +import com.intellij.psi.util.PsiTreeUtil; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lang.descriptors.CallableDescriptor; +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor; +import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; +import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; +import org.jetbrains.jet.lang.diagnostics.Diagnostic; +import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters1; +import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters2; +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.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.project.AnalyzerFacadeWithCache; +import org.jetbrains.jet.plugin.refactoring.JetNameSuggester; +import org.jetbrains.jet.plugin.refactoring.JetNameValidator; +import org.jetbrains.jet.plugin.refactoring.changeSignature.*; + +import java.util.List; + +public abstract class ChangeFunctionSignatureFix extends JetIntentionAction { + private final PsiElement context; + protected final FunctionDescriptor functionDescriptor; + + public ChangeFunctionSignatureFix( + @NotNull PsiElement element, + @NotNull PsiElement context, + @NotNull FunctionDescriptor functionDescriptor + ) { + super(element); + this.context = context; + this.functionDescriptor = functionDescriptor; + } + + @NotNull + @Override + public String getFamilyName() { + return JetBundle.message("change.signature.family"); + } + + @Override + public boolean startInWriteAction() { + return false; + } + + protected void showDialog(Project project, JetFunctionPlatformDescriptorImpl platformDescriptor) { + JetChangeSignatureDialog dialog = new JetChangeSignatureDialog(project, platformDescriptor, context, getText()); + + if (ApplicationManager.getApplication().isUnitTestMode()) + performRefactoringSilently(dialog); + else + dialog.show(); + } + + protected static String getNewArgumentName(ValueArgument argument, JetNameValidator validator) { + JetValueArgumentName argumentName = argument.getArgumentName(); + JetExpression expression = argument.getArgumentExpression(); + + if (argumentName != null) + return validator.validateName(argumentName.getName()); + else if (expression != null) { + return JetNameSuggester.suggestNames(expression, validator, "param")[0]; + } + + return validator.validateName("param"); + } + + protected static JetParameterInfo getNewParameterInfo(BindingContext bindingContext, ValueArgument argument, JetNameValidator validator) { + String name = getNewArgumentName(argument, validator); + JetExpression expression = argument.getArgumentExpression(); + JetType type = expression != null ? bindingContext.get(BindingContext.EXPRESSION_TYPE, expression) : null; + type = type != null ? type : KotlinBuiltIns.getInstance().getNullableAnyType(); + return new JetParameterInfo(name, type); + } + + private static boolean hasTypeMismatches(List parameters, List arguments, BindingContext bindingContext) { + for (int i = 0; i < parameters.size(); i++) { + assert i < arguments.size(); // number of parameters must not be greater than the number of arguments (it's called only for TOO_MANY_ARGUMENTS error) + JetExpression argumentExpression = arguments.get(i).getArgumentExpression(); + JetType argumentType = argumentExpression != null ? bindingContext.get(BindingContext.EXPRESSION_TYPE, argumentExpression) : null; + JetType parameterType = parameters.get(i).getType(); + + if (argumentType == null || !JetTypeChecker.INSTANCE.isSubtypeOf(argumentType, parameterType)) + return true; + } + + return false; + } + + protected void performRefactoringSilently(final JetChangeSignatureDialog dialog) { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + JetChangeInfo changeInfo = dialog.evaluateChangeInfo(); + JetChangeSignatureProcessor processor = new JetChangeSignatureProcessor(element.getProject(), changeInfo, getText()); + processor.run(); + } + }); + } + + public static JetIntentionActionFactory createFactory() { + return new JetIntentionActionFactory() { + @Override + public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) { + JetCallElement callElement = PsiTreeUtil.getParentOfType(diagnostic.getPsiElement(), JetCallElement.class); + @SuppressWarnings("unchecked") + CallableDescriptor descriptor = ((DiagnosticWithParameters1) diagnostic).getA(); + + if (callElement != null) + return createFix(callElement, callElement, descriptor); + + return null; + } + }; + } + + public static JetIntentionActionFactory createFactoryForParametersNumberMismatch() { + return new JetIntentionActionFactory() { + @Override + public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) { + @SuppressWarnings("unchecked") + DiagnosticWithParameters2> diagnosticWithParameters = + (DiagnosticWithParameters2>) diagnostic; + JetFunctionLiteral functionLiteral = diagnosticWithParameters.getPsiElement(); + BindingContext bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) functionLiteral.getContainingFile()).getBindingContext(); + DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, functionLiteral); + + if (descriptor instanceof FunctionDescriptor) + return new ChangeFunctionLiteralSignatureFix(functionLiteral, (FunctionDescriptor) descriptor, diagnosticWithParameters.getB()); + else + return null; + } + }; + } + + public static JetIntentionActionFactory createFactoryForUnusedParameter() { + return new JetIntentionActionFactory() { + @Override + public ChangeFunctionSignatureFix createAction(Diagnostic diagnostic) { + @SuppressWarnings("unchecked") + Object descriptor = ((DiagnosticWithParameters1) diagnostic).getA(); + + if (descriptor instanceof ValueParameterDescriptor) + return createFix(null, diagnostic.getPsiElement(), (CallableDescriptor) descriptor); + else + return null; + } + }; + } + + @Nullable + private static ChangeFunctionSignatureFix createFix(JetCallElement callElement, PsiElement context, CallableDescriptor descriptor) { + FunctionDescriptor functionDescriptor = null; + + if (descriptor instanceof FunctionDescriptor) + functionDescriptor = (FunctionDescriptor) descriptor; + else if (descriptor instanceof ValueParameterDescriptor) { + DeclarationDescriptor containingDescriptor = descriptor.getContainingDeclaration(); + + if (containingDescriptor instanceof FunctionDescriptor) + functionDescriptor = (FunctionDescriptor) containingDescriptor; + } + + if (functionDescriptor != null) { + BindingContext bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) context.getContainingFile()).getBindingContext(); + PsiElement declaration = BindingContextUtils.descriptorToDeclaration(bindingContext, functionDescriptor); + + if (declaration != null) { + if (descriptor instanceof ValueParameterDescriptor) + return new RemoveFunctionParametersFix(declaration, context, functionDescriptor, (ValueParameterDescriptor) descriptor); + else { + boolean hasTypeMismatches = hasTypeMismatches(functionDescriptor.getValueParameters(), callElement.getValueArguments(), bindingContext); + return new AddFunctionParametersFix(declaration, callElement, functionDescriptor, hasTypeMismatches); + } + } + } + + return null; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java index 697388a2102..756b883bfee 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/QuickFixes.java @@ -225,6 +225,11 @@ public class QuickFixes { 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()); + factories.put(UNUSED_PARAMETER, ChangeFunctionSignatureFix.createFactoryForUnusedParameter()); + factories.put(EXPECTED_PARAMETERS_NUMBER_MISMATCH, ChangeFunctionSignatureFix.createFactoryForParametersNumberMismatch()); + factories.put(EXPECTED_PARAMETER_TYPE_MISMATCH, ChangeTypeFix.createFactoryForExpectedParameterTypeMismatch()); factories.put(EXPECTED_RETURN_TYPE_MISMATCH, ChangeTypeFix.createFactoryForExpectedReturnTypeMismatch()); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveFunctionParametersFix.java b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveFunctionParametersFix.java new file mode 100644 index 00000000000..da0681e3e1d --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/RemoveFunctionParametersFix.java @@ -0,0 +1,57 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.quickfix; + +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; +import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; +import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.jet.plugin.JetBundle; +import org.jetbrains.jet.plugin.refactoring.changeSignature.JetFunctionPlatformDescriptorImpl; + +import java.util.List; + +public class RemoveFunctionParametersFix extends ChangeFunctionSignatureFix { + private final ValueParameterDescriptor parameterToRemove; + + public RemoveFunctionParametersFix( + @NotNull PsiElement element, + @NotNull PsiElement context, + @NotNull FunctionDescriptor functionDescriptor, + @NotNull ValueParameterDescriptor parameterToRemove + ) { + super(element, context, functionDescriptor); + this.parameterToRemove = parameterToRemove; + } + + @NotNull + @Override + public String getText() { + return JetBundle.message("remove.parameter", parameterToRemove.getName().getName()); + } + + @Override + protected void invoke(@NotNull Project project, Editor editor, JetFile file) { + JetFunctionPlatformDescriptorImpl platformDescriptor = new JetFunctionPlatformDescriptorImpl(functionDescriptor, element); + List parameters = functionDescriptor.getValueParameters(); + platformDescriptor.removeParameter(parameters.indexOf(parameterToRemove)); + showDialog(project, platformDescriptor); + } +} diff --git a/idea/testData/quickfix/changeSignature/afterAddConstructorParameter.kt b/idea/testData/quickfix/changeSignature/afterAddConstructorParameter.kt new file mode 100644 index 00000000000..b37f87989d8 --- /dev/null +++ b/idea/testData/quickfix/changeSignature/afterAddConstructorParameter.kt @@ -0,0 +1,13 @@ +// "Add parameter to constructor 'Base'" "true" +// DISABLE-ERRORS + +open class Base(var x: Int, + d: Double) { + val y = Base(1, 2.5); + + fun f() { + val base = Base(1, 2.5); + } +} + +open class Inherited(x: Int) : Base(1, 2.5) {} diff --git a/idea/testData/quickfix/changeSignature/afterAddFunctionParameter.kt b/idea/testData/quickfix/changeSignature/afterAddFunctionParameter.kt new file mode 100644 index 00000000000..a359dab3cf0 --- /dev/null +++ b/idea/testData/quickfix/changeSignature/afterAddFunctionParameter.kt @@ -0,0 +1,10 @@ +// "Add parameter to function 'foo'" "true" +// DISABLE-ERRORS + +fun foo(x: Int, + i: Int) { + foo(, 4); + foo(1, 4); + foo(1, 4); + foo(2, 4); +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeSignature/afterAddFunctionParameterAndChangeTypes.kt b/idea/testData/quickfix/changeSignature/afterAddFunctionParameterAndChangeTypes.kt new file mode 100644 index 00000000000..7709e69eb10 --- /dev/null +++ b/idea/testData/quickfix/changeSignature/afterAddFunctionParameterAndChangeTypes.kt @@ -0,0 +1,13 @@ +// "Change the signature of function 'foo'" "true" +// DISABLE-ERRORS + +fun foo(x: Double, + i: Int, + i1: Int, + i2: Int) { + foo(,, 5, 6); + foo(1,, 5, 6); + foo(1, 2.5, 5, 6); + foo(1.5, 4, 5, 6); + foo(2, 3, 5, 6); +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeSignature/afterChangeFunctionLiteralParameters1.kt b/idea/testData/quickfix/changeSignature/afterChangeFunctionLiteralParameters1.kt new file mode 100644 index 00000000000..1723a00db1a --- /dev/null +++ b/idea/testData/quickfix/changeSignature/afterChangeFunctionLiteralParameters1.kt @@ -0,0 +1,6 @@ +// "Change the signature of function literal" "true" +// DISABLE-ERRORS + +fun f(x: Int, y: Int, z : () -> Int) { + f(1, 2, {() -> x}); +} diff --git a/idea/testData/quickfix/changeSignature/afterChangeFunctionLiteralParameters2.kt b/idea/testData/quickfix/changeSignature/afterChangeFunctionLiteralParameters2.kt new file mode 100644 index 00000000000..325cedab369 --- /dev/null +++ b/idea/testData/quickfix/changeSignature/afterChangeFunctionLiteralParameters2.kt @@ -0,0 +1,8 @@ +// "Change the signature of function literal" "true" +// DISABLE-ERRORS + +fun f(x: Int, y: Int, z : (Int, Int?, Any) -> Int) { + f(1, 2, {(i: Int, + i1: Int?, + any: Any) -> x}); +} diff --git a/idea/testData/quickfix/changeSignature/afterRemoveConstructorParameter.kt b/idea/testData/quickfix/changeSignature/afterRemoveConstructorParameter.kt new file mode 100644 index 00000000000..69b96d13914 --- /dev/null +++ b/idea/testData/quickfix/changeSignature/afterRemoveConstructorParameter.kt @@ -0,0 +1,12 @@ +// "Remove parameter 'x'" "true" +// DISABLE-ERRORS + +open class Base() { + val y = Base(); + + fun f() { + val base = Base(); + } +} + +open class Inherited(x: Int) : Base() {} diff --git a/idea/testData/quickfix/changeSignature/afterRemoveFunctionFirstParameter.kt b/idea/testData/quickfix/changeSignature/afterRemoveFunctionFirstParameter.kt new file mode 100644 index 00000000000..b59b76f88e3 --- /dev/null +++ b/idea/testData/quickfix/changeSignature/afterRemoveFunctionFirstParameter.kt @@ -0,0 +1,9 @@ +// "Remove parameter 'x'" "true" +// DISABLE-ERRORS + +fun foo(y: Int) { + foo(); + foo(); + foo(2); + foo(3); +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeSignature/afterRemoveFunctionSecondParameter1.kt b/idea/testData/quickfix/changeSignature/afterRemoveFunctionSecondParameter1.kt new file mode 100644 index 00000000000..baa5fc9cdab --- /dev/null +++ b/idea/testData/quickfix/changeSignature/afterRemoveFunctionSecondParameter1.kt @@ -0,0 +1,9 @@ +// "Remove parameter 'y'" "true" +// DISABLE-ERRORS + +fun foo(x: Int) { + foo(); + foo(1); + foo(1); + foo(2); +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeSignature/afterRemoveFunctionSecondParameter2.kt b/idea/testData/quickfix/changeSignature/afterRemoveFunctionSecondParameter2.kt new file mode 100644 index 00000000000..75434347a0f --- /dev/null +++ b/idea/testData/quickfix/changeSignature/afterRemoveFunctionSecondParameter2.kt @@ -0,0 +1,9 @@ +// "Remove parameter 'y'" "true" +// DISABLE-ERRORS + +fun foo(x: Int) { + foo(); + foo(1); + foo(1); + foo(2); +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeSignature/afterRemoveNamedParameter.kt b/idea/testData/quickfix/changeSignature/afterRemoveNamedParameter.kt new file mode 100644 index 00000000000..a57cce2079b --- /dev/null +++ b/idea/testData/quickfix/changeSignature/afterRemoveNamedParameter.kt @@ -0,0 +1,9 @@ +// "Remove parameter 'x'" "true" +// DISABLE-ERRORS + +fun foo(y: Int) { + foo(); + foo(y = 1); + foo(2); + foo(3); +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeSignature/afterRemoveUnusedParameter.kt b/idea/testData/quickfix/changeSignature/afterRemoveUnusedParameter.kt new file mode 100644 index 00000000000..4be8e0a5009 --- /dev/null +++ b/idea/testData/quickfix/changeSignature/afterRemoveUnusedParameter.kt @@ -0,0 +1,10 @@ +// "Remove parameter 'x'" "true" +// DISABLE-ERRORS + +fun f(y: Int) { + f(2); +} + +fun g(x: Int, y: Int) { + f(y); +} diff --git a/idea/testData/quickfix/changeSignature/beforeAddConstructorParameter.kt b/idea/testData/quickfix/changeSignature/beforeAddConstructorParameter.kt new file mode 100644 index 00000000000..9e648afa50d --- /dev/null +++ b/idea/testData/quickfix/changeSignature/beforeAddConstructorParameter.kt @@ -0,0 +1,12 @@ +// "Add parameter to constructor 'Base'" "true" +// DISABLE-ERRORS + +open class Base(var x: Int) { + val y = Base(1, 2); + + fun f() { + val base = Base(1); + } +} + +open class Inherited(x: Int) : Base(1, 2.5) {} diff --git a/idea/testData/quickfix/changeSignature/beforeAddFunctionParameter.kt b/idea/testData/quickfix/changeSignature/beforeAddFunctionParameter.kt new file mode 100644 index 00000000000..7c6018598db --- /dev/null +++ b/idea/testData/quickfix/changeSignature/beforeAddFunctionParameter.kt @@ -0,0 +1,9 @@ +// "Add parameter to function 'foo'" "true" +// DISABLE-ERRORS + +fun foo(x: Int) { + foo(); + foo(1); + foo(1, 4); + foo(2, 3, sdsd); +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeSignature/beforeAddFunctionParameterAndChangeTypes.kt b/idea/testData/quickfix/changeSignature/beforeAddFunctionParameterAndChangeTypes.kt new file mode 100644 index 00000000000..af26c7c7b5b --- /dev/null +++ b/idea/testData/quickfix/changeSignature/beforeAddFunctionParameterAndChangeTypes.kt @@ -0,0 +1,10 @@ +// "Change the signature of function 'foo'" "true" +// DISABLE-ERRORS + +fun foo(x: Int, i: Double) { + foo(); + foo(1); + foo(1, 2.5); + foo(1.5, 4, 5, 6); + foo(2, 3, sdsd); +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeSignature/beforeChangeFunctionLiteralParameters1.kt b/idea/testData/quickfix/changeSignature/beforeChangeFunctionLiteralParameters1.kt new file mode 100644 index 00000000000..c21d427282d --- /dev/null +++ b/idea/testData/quickfix/changeSignature/beforeChangeFunctionLiteralParameters1.kt @@ -0,0 +1,6 @@ +// "Change the signature of function literal" "true" +// DISABLE-ERRORS + +fun f(x: Int, y: Int, z : () -> Int) { + f(1, 2, {(x: Int, y: Int) -> x}); +} diff --git a/idea/testData/quickfix/changeSignature/beforeChangeFunctionLiteralParameters2.kt b/idea/testData/quickfix/changeSignature/beforeChangeFunctionLiteralParameters2.kt new file mode 100644 index 00000000000..38b814edd96 --- /dev/null +++ b/idea/testData/quickfix/changeSignature/beforeChangeFunctionLiteralParameters2.kt @@ -0,0 +1,6 @@ +// "Change the signature of function literal" "true" +// DISABLE-ERRORS + +fun f(x: Int, y: Int, z : (Int, Int?, Any) -> Int) { + f(1, 2, {(x: Int) -> x}); +} diff --git a/idea/testData/quickfix/changeSignature/beforeRemoveConstructorParameter.kt b/idea/testData/quickfix/changeSignature/beforeRemoveConstructorParameter.kt new file mode 100644 index 00000000000..8d205f303cf --- /dev/null +++ b/idea/testData/quickfix/changeSignature/beforeRemoveConstructorParameter.kt @@ -0,0 +1,12 @@ +// "Remove parameter 'x'" "true" +// DISABLE-ERRORS + +open class Base(var x: Int) { + val y = Base(1); + + fun f() { + val base = Base(1, 2); + } +} + +open class Inherited(x: Int) : Base() {} diff --git a/idea/testData/quickfix/changeSignature/beforeRemoveFunctionFirstParameter.kt b/idea/testData/quickfix/changeSignature/beforeRemoveFunctionFirstParameter.kt new file mode 100644 index 00000000000..9c604b54b79 --- /dev/null +++ b/idea/testData/quickfix/changeSignature/beforeRemoveFunctionFirstParameter.kt @@ -0,0 +1,9 @@ +// "Remove parameter 'x'" "true" +// DISABLE-ERRORS + +fun foo(x: Int, y: Int) { + foo(); + foo(1); + foo(1, 2); + foo(2, 3, sdsd); +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeSignature/beforeRemoveFunctionSecondParameter1.kt b/idea/testData/quickfix/changeSignature/beforeRemoveFunctionSecondParameter1.kt new file mode 100644 index 00000000000..491563b5fcf --- /dev/null +++ b/idea/testData/quickfix/changeSignature/beforeRemoveFunctionSecondParameter1.kt @@ -0,0 +1,9 @@ +// "Remove parameter 'y'" "true" +// DISABLE-ERRORS + +fun foo(x: Int, y: Int) { + foo(); + foo(1); + foo(1, 2); + foo(2, 3, sdsd); +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeSignature/beforeRemoveFunctionSecondParameter2.kt b/idea/testData/quickfix/changeSignature/beforeRemoveFunctionSecondParameter2.kt new file mode 100644 index 00000000000..2acbed4239a --- /dev/null +++ b/idea/testData/quickfix/changeSignature/beforeRemoveFunctionSecondParameter2.kt @@ -0,0 +1,9 @@ +// "Remove parameter 'y'" "true" +// DISABLE-ERRORS + +fun foo(x: Int, y: Int) { + foo(); + foo(1); + foo(1, 2); + foo(2, 3, sdsd); +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeSignature/beforeRemoveNamedParameter.kt b/idea/testData/quickfix/changeSignature/beforeRemoveNamedParameter.kt new file mode 100644 index 00000000000..1336b8d32a0 --- /dev/null +++ b/idea/testData/quickfix/changeSignature/beforeRemoveNamedParameter.kt @@ -0,0 +1,9 @@ +// "Remove parameter 'x'" "true" +// DISABLE-ERRORS + +fun foo(x: Int, y: Int) { + foo(); + foo(y = 1); + foo(1, 2); + foo(2, 3, sdsd); +} \ No newline at end of file diff --git a/idea/testData/quickfix/changeSignature/beforeRemoveUnusedParameter.kt b/idea/testData/quickfix/changeSignature/beforeRemoveUnusedParameter.kt new file mode 100644 index 00000000000..f059da16602 --- /dev/null +++ b/idea/testData/quickfix/changeSignature/beforeRemoveUnusedParameter.kt @@ -0,0 +1,10 @@ +// "Remove parameter 'x'" "true" +// DISABLE-ERRORS + +fun f(x: Int, y: Int) { + f(1, 2); +} + +fun g(x: Int, y: Int) { + f(x, y); +} diff --git a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java index 636fb8264d6..9697cd550b8 100644 --- a/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/plugin/quickfix/QuickFixTestGenerated.java @@ -16,22 +16,19 @@ package org.jetbrains.jet.plugin.quickfix; -import junit.framework.Assert; import junit.framework.Test; import junit.framework.TestSuite; - -import java.io.File; -import java.util.regex.Pattern; import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.test.InnerTestClasses; import org.jetbrains.jet.test.TestMetadata; -import org.jetbrains.jet.plugin.quickfix.AbstractQuickFixTest; +import java.io.File; +import java.util.regex.Pattern; /** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("idea/testData/quickfix") -@InnerTestClasses({QuickFixTestGenerated.Abstract.class, QuickFixTestGenerated.AddStarProjections.class, QuickFixTestGenerated.AutoImports.class, QuickFixTestGenerated.CheckArguments.class, QuickFixTestGenerated.Expressions.class, QuickFixTestGenerated.Migration.class, QuickFixTestGenerated.Modifiers.class, QuickFixTestGenerated.Nullables.class, QuickFixTestGenerated.Override.class, QuickFixTestGenerated.PlatformClasses.class, QuickFixTestGenerated.Supercalls.class, QuickFixTestGenerated.SupertypeInitialization.class, QuickFixTestGenerated.TypeAddition.class, QuickFixTestGenerated.TypeImports.class, QuickFixTestGenerated.TypeMismatch.class, QuickFixTestGenerated.TypeProjection.class, QuickFixTestGenerated.UselessImports.class, QuickFixTestGenerated.Variables.class, QuickFixTestGenerated.When.class}) +@InnerTestClasses({QuickFixTestGenerated.Abstract.class, QuickFixTestGenerated.AddStarProjections.class, QuickFixTestGenerated.AutoImports.class, QuickFixTestGenerated.ChangeSignature.class, QuickFixTestGenerated.CheckArguments.class, QuickFixTestGenerated.Expressions.class, QuickFixTestGenerated.Migration.class, QuickFixTestGenerated.Modifiers.class, QuickFixTestGenerated.Nullables.class, QuickFixTestGenerated.Override.class, QuickFixTestGenerated.PlatformClasses.class, QuickFixTestGenerated.Supercalls.class, QuickFixTestGenerated.SupertypeInitialization.class, QuickFixTestGenerated.TypeAddition.class, QuickFixTestGenerated.TypeImports.class, QuickFixTestGenerated.TypeMismatch.class, QuickFixTestGenerated.TypeProjection.class, QuickFixTestGenerated.UselessImports.class, QuickFixTestGenerated.Variables.class, QuickFixTestGenerated.When.class}) public class QuickFixTestGenerated extends AbstractQuickFixTest { public void testAllFilesPresentInQuickfix() throws Exception { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix"), Pattern.compile("^before(\\w+)\\.kt$"), true); @@ -353,6 +350,69 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { } + @TestMetadata("idea/testData/quickfix/changeSignature") + public static class ChangeSignature extends AbstractQuickFixTest { + @TestMetadata("beforeAddConstructorParameter.kt") + public void testAddConstructorParameter() throws Exception { + doTest("idea/testData/quickfix/changeSignature/beforeAddConstructorParameter.kt"); + } + + @TestMetadata("beforeAddFunctionParameter.kt") + public void testAddFunctionParameter() throws Exception { + doTest("idea/testData/quickfix/changeSignature/beforeAddFunctionParameter.kt"); + } + + @TestMetadata("beforeAddFunctionParameterAndChangeTypes.kt") + public void testAddFunctionParameterAndChangeTypes() throws Exception { + doTest("idea/testData/quickfix/changeSignature/beforeAddFunctionParameterAndChangeTypes.kt"); + } + + public void testAllFilesPresentInChangeSignature() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/changeSignature"), Pattern.compile("^before(\\w+)\\.kt$"), true); + } + + @TestMetadata("beforeChangeFunctionLiteralParameters1.kt") + public void testChangeFunctionLiteralParameters1() throws Exception { + doTest("idea/testData/quickfix/changeSignature/beforeChangeFunctionLiteralParameters1.kt"); + } + + @TestMetadata("beforeChangeFunctionLiteralParameters2.kt") + public void testChangeFunctionLiteralParameters2() throws Exception { + doTest("idea/testData/quickfix/changeSignature/beforeChangeFunctionLiteralParameters2.kt"); + } + + @TestMetadata("beforeRemoveConstructorParameter.kt") + public void testRemoveConstructorParameter() throws Exception { + doTest("idea/testData/quickfix/changeSignature/beforeRemoveConstructorParameter.kt"); + } + + @TestMetadata("beforeRemoveFunctionFirstParameter.kt") + public void testRemoveFunctionFirstParameter() throws Exception { + doTest("idea/testData/quickfix/changeSignature/beforeRemoveFunctionFirstParameter.kt"); + } + + @TestMetadata("beforeRemoveFunctionSecondParameter1.kt") + public void testRemoveFunctionSecondParameter1() throws Exception { + doTest("idea/testData/quickfix/changeSignature/beforeRemoveFunctionSecondParameter1.kt"); + } + + @TestMetadata("beforeRemoveFunctionSecondParameter2.kt") + public void testRemoveFunctionSecondParameter2() throws Exception { + doTest("idea/testData/quickfix/changeSignature/beforeRemoveFunctionSecondParameter2.kt"); + } + + @TestMetadata("beforeRemoveNamedParameter.kt") + public void testRemoveNamedParameter() throws Exception { + doTest("idea/testData/quickfix/changeSignature/beforeRemoveNamedParameter.kt"); + } + + @TestMetadata("beforeRemoveUnusedParameter.kt") + public void testRemoveUnusedParameter() throws Exception { + doTest("idea/testData/quickfix/changeSignature/beforeRemoveUnusedParameter.kt"); + } + + } + @TestMetadata("idea/testData/quickfix/checkArguments") public static class CheckArguments extends AbstractQuickFixTest { public void testAllFilesPresentInCheckArguments() throws Exception { @@ -1439,6 +1499,7 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { suite.addTestSuite(Abstract.class); suite.addTest(AddStarProjections.innerSuite()); suite.addTestSuite(AutoImports.class); + suite.addTestSuite(ChangeSignature.class); suite.addTestSuite(CheckArguments.class); suite.addTestSuite(Expressions.class); suite.addTestSuite(Migration.class);