Extract Function: Create separate action for extraction to arbitrary code block
This commit is contained in:
@@ -96,6 +96,12 @@
|
|||||||
text="Configure Kotlin (JavaScript) in Project">
|
text="Configure Kotlin (JavaScript) in Project">
|
||||||
<add-to-group group-id="KotlinToolsGroup"/>
|
<add-to-group group-id="KotlinToolsGroup"/>
|
||||||
</action>
|
</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>
|
</actions>
|
||||||
|
|
||||||
<extensions defaultExtensionNs="com.intellij">
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ public class JetRefactoringSupportProvider extends RefactoringSupportProvider {
|
|||||||
return new ExtractKotlinFunctionHandler();
|
return new ExtractKotlinFunctionHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public RefactoringActionHandler getExtractFunctionToScopeHandler() {
|
||||||
|
return new ExtractKotlinFunctionHandler(true);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInplaceRenameAvailable(@NotNull PsiElement element, PsiElement context) {
|
public boolean isInplaceRenameAvailable(@NotNull PsiElement element, PsiElement context) {
|
||||||
if (element instanceof JetProperty) {
|
if (element instanceof JetProperty) {
|
||||||
|
|||||||
+42
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user