use of com.intellij.refactoring.RefactoringActionHandler in project intellij-community by JetBrains.
the class PyExtractMethodTest method doTest.
private void doTest(String newName) {
final String testName = getTestName(false);
final String beforeName = testName + ".before.py";
final String afterName = testName + ".after.py";
final String dir = "refactoring/extractmethod/";
myFixture.configureByFile(dir + beforeName);
final RefactoringSupportProvider provider = LanguageRefactoringSupport.INSTANCE.forLanguage(PythonLanguage.getInstance());
assertNotNull(provider);
final RefactoringActionHandler handler = provider.getExtractMethodHandler();
assertNotNull(handler);
System.setProperty(PyExtractMethodUtil.NAME, newName);
try {
refactorUsingHandler(handler);
} finally {
System.clearProperty(PyExtractMethodUtil.NAME);
}
myFixture.checkResultByFile(dir + afterName);
}
use of com.intellij.refactoring.RefactoringActionHandler in project intellij-community by JetBrains.
the class BaseRefactoringAction method hasAvailableHandler.
protected boolean hasAvailableHandler(@NotNull DataContext dataContext) {
final RefactoringActionHandler handler = getHandler(dataContext);
if (handler != null) {
if (handler instanceof ContextAwareActionHandler) {
final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
if (editor != null && file != null && !((ContextAwareActionHandler) handler).isAvailableForQuickList(editor, file, dataContext)) {
return false;
}
}
return true;
}
return false;
}
use of com.intellij.refactoring.RefactoringActionHandler in project intellij-community by JetBrains.
the class RefactoringQuickFix method doFix.
default default void doFix(@NotNull PsiElement element) {
final PsiElement elementToRefactor = getElementToRefactor(element);
if (elementToRefactor == null) {
return;
}
final Consumer<DataContext> consumer = dataContext -> {
dataContext = enhanceDataContext(dataContext);
final RefactoringActionHandler handler = getHandler();
handler.invoke(element.getProject(), new PsiElement[] { elementToRefactor }, dataContext);
};
DataManager.getInstance().getDataContextFromFocus().doWhenDone(consumer);
}
use of com.intellij.refactoring.RefactoringActionHandler in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoRenameQuickFix method invoke.
@Override
public void invoke(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement) {
if (!FileModificationService.getInstance().preparePsiElementsForWrite(startElement))
return;
Runnable runnable = () -> {
AsyncResult<DataContext> dataContextContainer = DataManager.getInstance().getDataContextFromFocus();
dataContextContainer.doWhenDone(new Consumer<DataContext>() {
@Override
public void consume(DataContext dataContext) {
RenameHandler renameHandler = RenameHandlerRegistry.getInstance().getRenameHandler(dataContext);
if (renameHandler != null) {
renameHandler.invoke(project, new PsiElement[] { startElement }, dataContext);
} else {
RefactoringActionHandler renameRefactoringHandler = RefactoringActionHandlerFactory.getInstance().createRenameHandler();
renameRefactoringHandler.invoke(project, new PsiElement[] { startElement }, dataContext);
}
}
});
};
if (ApplicationManager.getApplication().isUnitTestMode()) {
runnable.run();
} else {
ApplicationManager.getApplication().invokeLater(runnable, project.getDisposed());
}
}
use of com.intellij.refactoring.RefactoringActionHandler in project intellij-community by JetBrains.
the class MoveClassToModuleFix method moveClass.
private void moveClass(Project project, Editor editor, PsiFile file, PsiClass aClass) {
RefactoringActionHandler moveHandler = RefactoringActionHandlerFactory.getInstance().createMoveHandler();
DataManager dataManager = DataManager.getInstance();
DataContext dataContext = dataManager.getDataContext();
final String fqName = aClass.getQualifiedName();
LOG.assertTrue(fqName != null);
PsiDirectory directory = PackageUtil.findOrCreateDirectoryForPackage(myCurrentModule, StringUtil.getPackageName(fqName), mySourceRoot, true);
DataContext context = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT.getName(), directory, dataContext);
moveHandler.invoke(project, new PsiElement[] { aClass }, context);
PsiReference reference = file.findReferenceAt(editor.getCaretModel().getOffset());
PsiClass newClass = JavaPsiFacade.getInstance(project).findClass(fqName, GlobalSearchScope.moduleScope(myCurrentModule));
if (reference != null && newClass != null) {
final QuestionAction action = new AddImportAction(project, reference, editor, newClass);
action.execute();
}
}
Aggregations