mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
InlineMethodHandler: extract static method to allow reuse from plugins
GitOrigin-RevId: 30293c32981b09da7753cce3484148c52b2636c3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c6d7083c35
commit
356b90a3ce
@@ -19,7 +19,7 @@ import com.intellij.refactoring.util.RefactoringUtil;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
class InlineMethodHandler extends JavaInlineActionHandler {
|
||||
public class InlineMethodHandler extends JavaInlineActionHandler {
|
||||
private static final String REFACTORING_NAME = RefactoringBundle.message("inline.method.title");
|
||||
|
||||
private InlineMethodHandler() {
|
||||
@@ -32,17 +32,27 @@ class InlineMethodHandler extends JavaInlineActionHandler {
|
||||
|
||||
@Override
|
||||
public void inlineElement(final Project project, Editor editor, PsiElement element) {
|
||||
PsiMethod method = (PsiMethod)element.getNavigationElement();
|
||||
performInline(project, editor, (PsiMethod)element.getNavigationElement(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to inline method, displaying UI or error message if necessary
|
||||
* @param project project where method is declared
|
||||
* @param editor active editor where cursor might point to the call site
|
||||
* @param method method to be inlined
|
||||
* @param allowInlineThisOnly if true, only call-site at cursor will be suggested
|
||||
* (in this case caller must check that cursor points to the valid reference)
|
||||
*/
|
||||
public static void performInline(Project project, Editor editor, PsiMethod method, boolean allowInlineThisOnly) {
|
||||
PsiReference reference = editor != null ? TargetElementUtil.findReference(editor, editor.getCaretModel().getOffset()) : null;
|
||||
|
||||
boolean allowInlineThisOnly = false;
|
||||
PsiCodeBlock methodBody = method.getBody();
|
||||
Supplier<PsiCodeBlock> specialization = InlineMethodSpecialization.forReference(reference);
|
||||
if (specialization != null) {
|
||||
allowInlineThisOnly = true;
|
||||
methodBody = specialization.get();
|
||||
}
|
||||
|
||||
|
||||
if (methodBody == null){
|
||||
String message;
|
||||
if (method.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
@@ -60,7 +70,7 @@ class InlineMethodHandler extends JavaInlineActionHandler {
|
||||
|
||||
if (reference != null) {
|
||||
final PsiElement refElement = reference.getElement();
|
||||
if (!isEnabledForLanguage(refElement.getLanguage())) {
|
||||
if (!isJavaLanguage(refElement.getLanguage())) {
|
||||
String message = RefactoringBundle
|
||||
.message("refactoring.is.not.supported.for.language", "Inline of Java method", refElement.getLanguage().getDisplayName());
|
||||
CommonRefactoringUtil.showErrorHint(project, editor, message, REFACTORING_NAME, HelpID.INLINE_METHOD);
|
||||
|
||||
@@ -19,11 +19,6 @@ import com.intellij.lang.Language;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.lang.refactoring.InlineActionHandler;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.refactoring.ui.ConflictsDialog;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -31,6 +26,10 @@ import org.jetbrains.annotations.NotNull;
|
||||
public abstract class JavaInlineActionHandler extends InlineActionHandler {
|
||||
@Override
|
||||
public boolean isEnabledForLanguage(Language l) {
|
||||
return isJavaLanguage(l);
|
||||
}
|
||||
|
||||
protected static boolean isJavaLanguage(Language l) {
|
||||
return l instanceof JavaLanguage ||
|
||||
l.equals(StdFileTypes.JSPX.getLanguage()) ||
|
||||
l.equals(StdFileTypes.JSP.getLanguage());
|
||||
|
||||
Reference in New Issue
Block a user