use of com.intellij.refactoring.listeners.UndoRefactoringElementListener in project intellij-community by JetBrains.
the class TestNGConfiguration method getRefactoringElementListener.
@Nullable
public RefactoringElementListener getRefactoringElementListener(final PsiElement element) {
if (data.TEST_OBJECT.equals(TestType.PACKAGE.getType())) {
if (!(element instanceof PsiPackage))
return null;
final RefactoringElementListener listener = RefactoringListeners.getListener((PsiPackage) element, myPackage);
return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener);
} else if (data.TEST_OBJECT.equals(TestType.CLASS.getType())) {
if (!(element instanceof PsiClass) && !(element instanceof PsiPackage))
return null;
final RefactoringElementListener listener = RefactoringListeners.getClassOrPackageListener(element, myClass);
return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener);
} else if (data.TEST_OBJECT.equals(TestType.METHOD.getType())) {
if (!(element instanceof PsiMethod)) {
final RefactoringElementListener listener = RefactoringListeners.getClassOrPackageListener(element, myClass);
return RunConfigurationExtension.wrapRefactoringElementListener(element, this, listener);
}
final PsiMethod method = (PsiMethod) element;
if (!method.getName().equals(data.getMethodName()))
return null;
if (!method.getContainingClass().equals(myClass.getPsiElement()))
return null;
class Listener extends RefactoringElementAdapter implements UndoRefactoringElementListener {
public void elementRenamedOrMoved(@NotNull final PsiElement newElement) {
data.setTestMethod(PsiLocation.fromPsiElement((PsiMethod) newElement));
}
@Override
public void undoElementMovedOrRenamed(@NotNull PsiElement newElement, @NotNull String oldQualifiedName) {
final int methodIdx = oldQualifiedName.indexOf("#") + 1;
if (methodIdx <= 0 || methodIdx >= oldQualifiedName.length())
return;
data.METHOD_NAME = oldQualifiedName.substring(methodIdx);
}
}
return RunConfigurationExtension.wrapRefactoringElementListener(element, this, new Listener());
}
return null;
}
use of com.intellij.refactoring.listeners.UndoRefactoringElementListener in project intellij-community by JetBrains.
the class RenameUtil method doRename.
public static void doRename(final PsiElement element, String newName, UsageInfo[] usages, final Project project, @Nullable final RefactoringElementListener listener) throws IncorrectOperationException {
final RenamePsiElementProcessor processor = RenamePsiElementProcessor.forElement(element);
final String fqn = element instanceof PsiFile ? ((PsiFile) element).getVirtualFile().getPath() : CopyReferenceAction.elementToFqn(element);
if (fqn != null) {
UndoableAction action = new BasicUndoableAction() {
@Override
public void undo() throws UnexpectedUndoException {
if (listener instanceof UndoRefactoringElementListener) {
((UndoRefactoringElementListener) listener).undoElementMovedOrRenamed(element, fqn);
}
}
@Override
public void redo() throws UnexpectedUndoException {
}
};
UndoManager.getInstance(project).undoableActionPerformed(action);
}
processor.renameElement(element, newName, usages, listener);
}
use of com.intellij.refactoring.listeners.UndoRefactoringElementListener in project intellij-community by JetBrains.
the class ChangeSignatureProcessorBase method performRefactoring.
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
RefactoringTransaction transaction = getTransaction();
final ChangeInfo changeInfo = myChangeInfo;
final RefactoringElementListener elementListener = transaction == null ? null : transaction.getElementListener(changeInfo.getMethod());
final String fqn = CopyReferenceAction.elementToFqn(changeInfo.getMethod());
if (fqn != null) {
UndoableAction action = new BasicUndoableAction() {
@Override
public void undo() {
if (elementListener instanceof UndoRefactoringElementListener) {
((UndoRefactoringElementListener) elementListener).undoElementMovedOrRenamed(changeInfo.getMethod(), fqn);
}
}
@Override
public void redo() {
}
};
UndoManager.getInstance(myProject).undoableActionPerformed(action);
}
try {
doChangeSignature(changeInfo, usages);
final PsiElement method = changeInfo.getMethod();
LOG.assertTrue(method.isValid());
if (elementListener != null && changeInfo.isNameChanged()) {
elementListener.elementRenamed(method);
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
Aggregations