mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
common introduce parameter object action
This commit is contained in:
+12
@@ -22,7 +22,9 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.MoveDestination;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.changeSignature.*;
|
||||
import com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectClassDescriptor;
|
||||
import com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectDelegate;
|
||||
@@ -44,6 +46,16 @@ import java.util.List;
|
||||
public class JavaIntroduceParameterObjectDelegate
|
||||
extends IntroduceParameterObjectDelegate<PsiMethod, ParameterInfoImpl, JavaIntroduceParameterObjectClassDescriptor> {
|
||||
|
||||
@Override
|
||||
public boolean isEnabledOn(PsiElement element) {
|
||||
return PsiTreeUtil.getParentOfType(element, PsiMethod.class, false) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringActionHandler getHandler(PsiElement element) {
|
||||
return new IntroduceParameterObjectHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParameterInfoImpl createMergedParameterInfo(JavaIntroduceParameterObjectClassDescriptor descriptor,
|
||||
PsiMethod method,
|
||||
|
||||
+20
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 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.
|
||||
@@ -15,12 +15,14 @@
|
||||
*/
|
||||
package com.intellij.refactoring.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.introduceparameterobject.IntroduceParameterObjectHandler;
|
||||
import com.intellij.refactoring.changeSignature.ParameterInfo;
|
||||
import com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectClassDescriptor;
|
||||
import com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectDelegate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class IntroduceParameterObjectAction extends BaseRefactoringAction {
|
||||
@@ -30,10 +32,22 @@ public class IntroduceParameterObjectAction extends BaseRefactoringAction {
|
||||
}
|
||||
|
||||
protected boolean isEnabledOnElements(@NotNull final PsiElement[] elements) {
|
||||
return elements.length == 1 && PsiTreeUtil.getParentOfType(elements[0], PsiMethod.class, false) != null;
|
||||
if (elements.length == 1) {
|
||||
final IntroduceParameterObjectDelegate delegate = IntroduceParameterObjectDelegate.findDelegate(elements[0]);
|
||||
if (delegate != null && delegate.isEnabledOn(elements[0])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected RefactoringActionHandler getHandler(@NotNull DataContext context) {
|
||||
return new IntroduceParameterObjectHandler();
|
||||
final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
|
||||
if (element == null) {
|
||||
return null;
|
||||
}
|
||||
final IntroduceParameterObjectDelegate<PsiNamedElement, ParameterInfo, IntroduceParameterObjectClassDescriptor<PsiNamedElement, ParameterInfo>>
|
||||
delegate = IntroduceParameterObjectDelegate.findDelegate(element);
|
||||
return delegate != null ? delegate.getHandler(element) : null;
|
||||
}
|
||||
}
|
||||
+7
@@ -19,12 +19,14 @@ import com.intellij.lang.Language;
|
||||
import com.intellij.lang.LanguageExtension;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.changeSignature.ChangeInfo;
|
||||
import com.intellij.refactoring.changeSignature.ParameterInfo;
|
||||
import com.intellij.refactoring.util.FixableUsageInfo;
|
||||
import com.intellij.usageView.UsageInfo;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -47,6 +49,11 @@ public abstract class IntroduceParameterObjectDelegate<M extends PsiNamedElement
|
||||
return EP_NAME.forLanguage(language);
|
||||
}
|
||||
|
||||
public abstract boolean isEnabledOn(PsiElement element);
|
||||
|
||||
@Nullable
|
||||
public abstract RefactoringActionHandler getHandler(PsiElement element);
|
||||
|
||||
public abstract P createMergedParameterInfo(C descriptor,
|
||||
M method,
|
||||
List<P> oldMethodParameters);
|
||||
|
||||
@@ -324,6 +324,7 @@
|
||||
<action id="ExtractInterface" class="com.intellij.refactoring.actions.ExtractInterfaceAction"/>
|
||||
<action id="ExtractSuperclass" class="com.intellij.refactoring.actions.ExtractSuperclassAction"/>
|
||||
<action id="ExtractModule" class="com.intellij.refactoring.actions.ExtractModuleAction"/>
|
||||
<action id="IntroduceParameterObject" class="com.intellij.refactoring.actions.IntroduceParameterObjectAction"/>
|
||||
</group>
|
||||
|
||||
<action id="Inline" class="com.intellij.refactoring.actions.InlineAction"/>
|
||||
|
||||
+11
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.search.LocalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.refactoring.RefactoringActionHandler;
|
||||
import com.intellij.refactoring.changeSignature.ChangeInfo;
|
||||
import com.intellij.refactoring.changeSignature.ParameterInfo;
|
||||
import com.intellij.refactoring.introduceParameterObject.IntroduceParameterObjectClassDescriptor;
|
||||
@@ -49,6 +50,16 @@ import java.util.List;
|
||||
|
||||
public class GroovyIntroduceParameterObjectDelegate
|
||||
extends IntroduceParameterObjectDelegate<GrMethod, GrParameterInfo, GroovyIntroduceObjectClassDescriptor> {
|
||||
@Override
|
||||
public boolean isEnabledOn(PsiElement element) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RefactoringActionHandler getHandler(PsiElement element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GrParameterInfo createMergedParameterInfo(GroovyIntroduceObjectClassDescriptor descriptor,
|
||||
GrMethod method,
|
||||
|
||||
@@ -92,10 +92,6 @@
|
||||
<keyboard-shortcut first-keystroke="control shift alt P" keymap="$default"/>
|
||||
</action>
|
||||
|
||||
<action id="IntroduceParameterObject" class="com.intellij.refactoring.actions.IntroduceParameterObjectAction">
|
||||
<add-to-group group-id="IntroduceActionsGroup" anchor="after" relative-to-action="IntroduceFunctionalParameter"/>
|
||||
</action>
|
||||
|
||||
<action id="RenameFile" class="com.intellij.refactoring.actions.RenameFileAction">
|
||||
<add-to-group group-id="RefactoringMenu" anchor="after" relative-to-action="RenameElement"/>
|
||||
<add-to-group group-id="EditorTabPopupMenuEx" anchor="after" relative-to-action="AddAllToFavorites"/>
|
||||
|
||||
Reference in New Issue
Block a user