use of com.intellij.refactoring.RefactoringActionHandler in project intellij-community by JetBrains.
the class BasePlatformRefactoringAction method getHandler.
@Override
protected final RefactoringActionHandler getHandler(@NotNull DataContext dataContext) {
PsiElement element = null;
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
if (editor != null && file != null) {
element = getElementAtCaret(editor, file);
if (element != null) {
RefactoringActionHandler handler = getHandler(element.getLanguage(), element);
if (handler != null) {
return handler;
}
}
}
PsiElement referenced = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
if (referenced != null) {
RefactoringActionHandler handler = getHandler(referenced.getLanguage(), referenced);
if (handler != null) {
return handler;
}
}
PsiElement[] psiElements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(dataContext);
if (psiElements != null && psiElements.length > 1) {
RefactoringActionHandler handler = getHandler(psiElements[0].getLanguage(), psiElements[0]);
if (handler != null && isEnabledOnElements(psiElements)) {
return handler;
}
}
if (element == null) {
element = referenced;
}
final Language[] languages = LangDataKeys.CONTEXT_LANGUAGES.getData(dataContext);
if (languages != null) {
for (Language language : languages) {
RefactoringActionHandler handler = getHandler(language, element);
if (handler != null) {
return handler;
}
}
}
return null;
}
use of com.intellij.refactoring.RefactoringActionHandler in project intellij-community by JetBrains.
the class BasePlatformRefactoringAction method isEnabledOnElements.
@Override
protected boolean isEnabledOnElements(@NotNull PsiElement[] elements) {
if (elements.length > 0) {
Language language = elements[0].getLanguage();
RefactoringActionHandler handler = getHandler(language, elements[0]);
return handler instanceof ElementsHandler && ((ElementsHandler) handler).isEnabledOnElements(elements);
}
return false;
}
use of com.intellij.refactoring.RefactoringActionHandler in project intellij-community by JetBrains.
the class BaseRefactoringAction method actionPerformed.
@Override
public final void actionPerformed(@NotNull AnActionEvent e) {
DataContext dataContext = e.getDataContext();
Project project = e.getProject();
if (project == null)
return;
PsiDocumentManager.getInstance(project).commitAllDocuments();
final Editor editor = e.getData(CommonDataKeys.EDITOR);
final PsiElement[] elements = getPsiElementArray(dataContext);
int eventCount = IdeEventQueue.getInstance().getEventCount();
RefactoringActionHandler handler;
try {
handler = getHandler(dataContext);
} catch (ProcessCanceledException ignored) {
return;
}
if (handler == null) {
String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("error.wrong.caret.position.symbol.to.refactor"));
CommonRefactoringUtil.showErrorHint(project, editor, message, RefactoringBundle.getCannotRefactorMessage(null), null);
return;
}
InplaceRefactoring activeInplaceRenamer = InplaceRefactoring.getActiveInplaceRenamer(editor);
if (!InplaceRefactoring.canStartAnotherRefactoring(editor, project, handler, elements) && activeInplaceRenamer != null) {
InplaceRefactoring.unableToStartWarning(project, editor);
return;
}
if (activeInplaceRenamer == null) {
final LookupEx lookup = LookupManager.getActiveLookup(editor);
if (lookup instanceof LookupImpl) {
Runnable command = () -> ((LookupImpl) lookup).finishLookup(Lookup.NORMAL_SELECT_CHAR);
Document doc = editor.getDocument();
DocCommandGroupId group = DocCommandGroupId.noneGroupId(doc);
CommandProcessor.getInstance().executeCommand(editor.getProject(), command, "Completion", group, UndoConfirmationPolicy.DEFAULT, doc);
}
}
IdeEventQueue.getInstance().setEventCount(eventCount);
if (editor != null) {
final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
if (file == null)
return;
DaemonCodeAnalyzer.getInstance(project).autoImportReferenceAtCursor(editor, file);
handler.invoke(project, editor, file, dataContext);
} else {
handler.invoke(project, elements, dataContext);
}
}
use of com.intellij.refactoring.RefactoringActionHandler in project intellij-community by JetBrains.
the class ChangeSignatureAction method getRefactoringHandler.
@Nullable
@Override
protected RefactoringActionHandler getRefactoringHandler(@NotNull RefactoringSupportProvider provider, final PsiElement element) {
abstract class ContextAwareChangeSignatureHandler implements RefactoringActionHandler, ContextAwareActionHandler {
}
return new ContextAwareChangeSignatureHandler() {
@Override
public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
return findTargetMember(element) != null;
}
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
final PsiElement targetMember = findTargetMember(element);
if (targetMember == null) {
final ChangeSignatureHandler handler = getChangeSignatureHandler(file.getLanguage());
if (handler != null) {
final String notFoundMessage = handler.getTargetNotFoundMessage();
if (notFoundMessage != null) {
CommonRefactoringUtil.showErrorHint(project, editor, notFoundMessage, ChangeSignatureHandler.REFACTORING_NAME, null);
}
}
return;
}
final ChangeSignatureHandler handler = getChangeSignatureHandler(targetMember.getLanguage());
if (handler == null)
return;
handler.invoke(project, new PsiElement[] { targetMember }, dataContext);
}
@Override
public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
if (elements.length != 1)
return;
final PsiElement targetMember = findTargetMember(elements[0]);
if (targetMember == null)
return;
final ChangeSignatureHandler handler = getChangeSignatureHandler(targetMember.getLanguage());
if (handler == null)
return;
handler.invoke(project, new PsiElement[] { targetMember }, dataContext);
}
};
}
use of com.intellij.refactoring.RefactoringActionHandler in project intellij-community by JetBrains.
the class ExtractIncludeAction method update.
@Override
public void update(final AnActionEvent e) {
super.update(e);
final RefactoringActionHandler handler = getHandler(e.getDataContext());
if (handler instanceof TitledHandler) {
e.getPresentation().setText(((TitledHandler) handler).getActionTitle());
} else {
e.getPresentation().setText("Include File...");
}
}
Aggregations