Extract Function: Create separate action for extraction to arbitrary code block

This commit is contained in:
Alexey Sedunov
2014-06-02 14:20:41 +04:00
parent ee52073488
commit 07c19b1c9b
3 changed files with 53 additions and 0 deletions
+6
View File
@@ -96,6 +96,12 @@
text="Configure Kotlin (JavaScript) in Project">
<add-to-group group-id="KotlinToolsGroup"/>
</action>
<action id="ExtractFunctionToScope" class="org.jetbrains.jet.plugin.refactoring.extractFunction.ExtractFunctionToScopeAction"
text="Extract Function to _Scope...">
<keyboard-shortcut keymap="$default" first-keystroke="control alt shift M"/>
<add-to-group group-id="IntroduceActionsGroup" anchor="after" relative-to-action="ExtractMethod"/>
</action>
</actions>
<extensions defaultExtensionNs="com.intellij">
@@ -44,6 +44,11 @@ public class JetRefactoringSupportProvider extends RefactoringSupportProvider {
return new ExtractKotlinFunctionHandler();
}
@NotNull
public RefactoringActionHandler getExtractFunctionToScopeHandler() {
return new ExtractKotlinFunctionHandler(true);
}
@Override
public boolean isInplaceRenameAvailable(@NotNull PsiElement element, PsiElement context) {
if (element instanceof JetProperty) {
@@ -0,0 +1,42 @@
/*
* Copyright 2010-2014 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.refactoring.extractFunction
import com.intellij.refactoring.actions.BasePlatformRefactoringAction
import com.intellij.psi.PsiElement
import com.intellij.refactoring.RefactoringActionHandler
import com.intellij.lang.refactoring.RefactoringSupportProvider
import org.jetbrains.jet.lang.psi.JetElement
import org.jetbrains.jet.plugin.refactoring.JetRefactoringSupportProvider
public class ExtractFunctionToScopeAction: BasePlatformRefactoringAction() {
{
setInjectedContext(true)
}
override fun isAvailableInEditorOnly(): Boolean {
return true
}
protected override fun isEnabledOnElements(elements: Array<out PsiElement>): Boolean {
return elements.all { it is JetElement }
}
override fun getRefactoringHandler(provider: RefactoringSupportProvider): RefactoringActionHandler? {
return (provider as? JetRefactoringSupportProvider)?.getExtractFunctionToScopeHandler()
}
}