diff --git a/java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java b/java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java index 67b4397f8577..3b41f40e8fa0 100644 --- a/java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java +++ b/java/java-impl/src/com/intellij/lang/java/JavaRefactoringSupportProvider.java @@ -23,6 +23,7 @@ import com.intellij.psi.search.PsiSearchHelper; import com.intellij.psi.search.SearchScope; import com.intellij.psi.util.PsiTreeUtil; import com.intellij.refactoring.RefactoringActionHandler; +import com.intellij.refactoring.actions.IntroduceFunctionalParameterHandler; import com.intellij.refactoring.changeSignature.ChangeSignatureHandler; import com.intellij.refactoring.changeSignature.JavaChangeSignatureHandler; import com.intellij.refactoring.extractInterface.ExtractInterfaceHandler; @@ -85,6 +86,12 @@ public class JavaRefactoringSupportProvider extends RefactoringSupportProvider { return new IntroduceParameterHandler(); } + @Nullable + @Override + public RefactoringActionHandler getIntroduceFunctionalParameterHandler() { + return new IntroduceFunctionalParameterHandler(); + } + @Override public RefactoringActionHandler getPullUpHandler() { return new JavaPullUpHandler(); diff --git a/java/java-impl/src/com/intellij/refactoring/actions/IntroduceFunctionalParameterAction.java b/java/java-impl/src/com/intellij/refactoring/actions/IntroduceFunctionalParameterAction.java deleted file mode 100644 index 734d27dbc767..000000000000 --- a/java/java-impl/src/com/intellij/refactoring/actions/IntroduceFunctionalParameterAction.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2000-2015 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. - */ - -/* - * Created by IntelliJ IDEA. - * User: dsl - * Date: 06.05.2002 - * Time: 14:03:43 - * To change template for new class use - * Code Style | Class Templates options (Tools | IDE Options). - */ -package com.intellij.refactoring.actions; - -import com.intellij.lang.refactoring.RefactoringSupportProvider; -import com.intellij.openapi.actionSystem.CommonDataKeys; -import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Pass; -import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; -import com.intellij.refactoring.HelpID; -import com.intellij.refactoring.RefactoringActionHandler; -import com.intellij.refactoring.RefactoringBundle; -import com.intellij.refactoring.extractMethod.ExtractMethodHandler; -import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; -import com.intellij.refactoring.util.CommonRefactoringUtil; -import org.jetbrains.annotations.NotNull; - -public class IntroduceFunctionalParameterAction extends BasePlatformRefactoringAction { - private static final String REFACTORING_NAME = RefactoringBundle.message("introduce.functional.parameter.title"); - - @Override - protected boolean isAvailableInEditorOnly() { - return true; - } - - @Override - protected boolean isEnabledOnElements(@NotNull PsiElement[] elements) { - return false; - } - - @Override - protected RefactoringActionHandler getRefactoringHandler(@NotNull RefactoringSupportProvider provider) { - return new IntroduceParameterHandler() { - @Override - public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) { - if (dataContext != null) { - final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext); - final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); - if (file != null && editor != null && !introduceStrategy(project, editor, file, elements)) { - showErrorMessage(project, editor); - } - } - } - - @Override - public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, DataContext dataContext) { - ExtractMethodHandler.selectAndPass(project, editor, file, new Pass() { - @Override - public void pass(PsiElement[] elements) { - if (!introduceStrategy(project, editor, file, elements)) { - showErrorMessage(project, editor); - } - } - }); - } - - private void showErrorMessage(@NotNull Project project, Editor editor) { - String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("is.not.supported.in.the.current.context", REFACTORING_NAME)); - CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INTRODUCE_PARAMETER); - } - }; - } -} diff --git a/java/java-impl/src/com/intellij/refactoring/actions/IntroduceFunctionalParameterHandler.java b/java/java-impl/src/com/intellij/refactoring/actions/IntroduceFunctionalParameterHandler.java new file mode 100644 index 000000000000..a841f6d75a78 --- /dev/null +++ b/java/java-impl/src/com/intellij/refactoring/actions/IntroduceFunctionalParameterHandler.java @@ -0,0 +1,61 @@ +/* + * Copyright 2000-2015 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 com.intellij.refactoring.actions; + +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Pass; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiFile; +import com.intellij.refactoring.HelpID; +import com.intellij.refactoring.RefactoringBundle; +import com.intellij.refactoring.extractMethod.ExtractMethodHandler; +import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler; +import com.intellij.refactoring.util.CommonRefactoringUtil; +import org.jetbrains.annotations.NotNull; + +public class IntroduceFunctionalParameterHandler extends IntroduceParameterHandler { + @Override + public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) { + if (dataContext != null) { + final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext); + final Editor editor = CommonDataKeys.EDITOR.getData(dataContext); + if (file != null && editor != null && !introduceStrategy(project, editor, file, elements)) { + showErrorMessage(project, editor); + } + } + } + + @Override + public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file, DataContext dataContext) { + ExtractMethodHandler.selectAndPass(project, editor, file, new Pass() { + @Override + public void pass(PsiElement[] elements) { + if (!introduceStrategy(project, editor, file, elements)) { + showErrorMessage(project, editor); + } + } + }); + } + + private static void showErrorMessage(@NotNull Project project, Editor editor) { + final String message = RefactoringBundle + .getCannotRefactorMessage(RefactoringBundle.message("is.not.supported.in.the.current.context", IntroduceFunctionalParameterAction.REFACTORING_NAME)); + CommonRefactoringUtil.showErrorHint(project, editor, message, IntroduceFunctionalParameterAction.REFACTORING_NAME, HelpID.INTRODUCE_PARAMETER); + } +} diff --git a/platform/lang-api/src/com/intellij/lang/refactoring/RefactoringSupportProvider.java b/platform/lang-api/src/com/intellij/lang/refactoring/RefactoringSupportProvider.java index 14aea4ce295c..449a62555746 100644 --- a/platform/lang-api/src/com/intellij/lang/refactoring/RefactoringSupportProvider.java +++ b/platform/lang-api/src/com/intellij/lang/refactoring/RefactoringSupportProvider.java @@ -15,6 +15,7 @@ */ package com.intellij.lang.refactoring; +import com.intellij.lang.ContextAwareActionHandler; import com.intellij.psi.PsiElement; import com.intellij.refactoring.RefactoringActionHandler; import com.intellij.refactoring.changeSignature.ChangeSignatureHandler; @@ -90,6 +91,16 @@ public abstract class RefactoringSupportProvider { @Nullable public RefactoringActionHandler getIntroduceParameterHandler() { return null; } + /** + * @return handler for introducing functional parameters/closures in this language + * @see ContextAwareActionHandler + * @see RefactoringActionHandler + */ + @Nullable + public RefactoringActionHandler getIntroduceFunctionalParameterHandler() { + return null; + } + /** * @return handler for pulling up members in this language * @see com.intellij.refactoring.RefactoringActionHandler diff --git a/platform/lang-impl/src/com/intellij/refactoring/actions/IntroduceFunctionalParameterAction.java b/platform/lang-impl/src/com/intellij/refactoring/actions/IntroduceFunctionalParameterAction.java new file mode 100644 index 000000000000..0c820ce19968 --- /dev/null +++ b/platform/lang-impl/src/com/intellij/refactoring/actions/IntroduceFunctionalParameterAction.java @@ -0,0 +1,50 @@ +/* + * Copyright 2000-2015 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. + */ + +/* + * Created by IntelliJ IDEA. + * User: dsl + * Date: 06.05.2002 + * Time: 14:03:43 + * To change template for new class use + * Code Style | Class Templates options (Tools | IDE Options). + */ +package com.intellij.refactoring.actions; + +import com.intellij.lang.refactoring.RefactoringSupportProvider; +import com.intellij.psi.PsiElement; +import com.intellij.refactoring.RefactoringActionHandler; +import com.intellij.refactoring.RefactoringBundle; +import org.jetbrains.annotations.NotNull; + +public class IntroduceFunctionalParameterAction extends BasePlatformRefactoringAction { + public static final String REFACTORING_NAME = RefactoringBundle.message("introduce.functional.parameter.title"); + + @Override + protected boolean isAvailableInEditorOnly() { + return true; + } + + @Override + protected boolean isEnabledOnElements(@NotNull PsiElement[] elements) { + return false; + } + + @Override + protected RefactoringActionHandler getRefactoringHandler(@NotNull RefactoringSupportProvider provider) { + return provider.getIntroduceFunctionalParameterHandler(); + } +}