RefactoringElementListener (final PsiElement element) { UElement uElement = UastContextKt.toUElement(element); JUnitConfiguration configuration = getConfiguration(); if (uElement instanceof PsiMethod method) { if (!method.getName().equals(configuration.getPersistentData().getMethodName())) return null; //noinspection ConstantConditions if (!method.getContainingClass().equals(configuration.myClass.getPsiElement())) return null; class Listener extends RefactoringElementAdapter implements UndoRefactoringElementListener { @Override public void elementRenamedOrMoved(@NotNull final PsiElement newElement) { final boolean generatedName = configuration.isGeneratedName(); configuration.getPersistentData().setTestMethod(PsiLocation.fromPsiElement((PsiMethod)UastContextKt.toUElement(newElement))); if (generatedName) configuration.setGeneratedName(); } @Override public void undoElementMovedOrRenamed(@NotNull PsiElement newElement, @NotNull String oldQualifiedName) { final int methodIdx = oldQualifiedName.indexOf("#") + 1; if (methodIdx <= 0 || methodIdx >= oldQualifiedName.length()) return; final boolean generatedName = configuration.isGeneratedName(); configuration.getPersistentData().METHOD_NAME = oldQualifiedName.substring(methodIdx); if (generatedName) configuration.setGeneratedName(); } } return new Listener(); } else { return RefactoringListeners.getClassOrPackageListener(element, configuration.myClass); } }