extract introduce functional parameter handler api (^kotlin)

This commit is contained in:
Anna Kozlova
2015-11-24 11:28:50 +01:00
parent 46aa85a55f
commit d89a6497ef
5 changed files with 129 additions and 88 deletions
@@ -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();
@@ -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<PsiElement[]>() {
@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);
}
};
}
}
@@ -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<PsiElement[]>() {
@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);
}
}