void (@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) { editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); final int offset = TargetElementUtil.adjustOffset(file, editor.getDocument(), editor.getCaretModel().getOffset()); final PsiElement element = file.findElementAt(offset); if (element instanceof PsiIdentifier) { PsiElement parent = element.getParent(); if (parent instanceof PsiVariable variable) { if (invoke(project, editor, variable.getTypeElement(), variable)) { return; } } else if (parent instanceof PsiMethod method && !method.isConstructor()) { if (invoke(project, editor, method.getReturnTypeElement(), method)) { return; } } } PsiTypeElement typeElement = PsiTreeUtil.getParentOfType(element, PsiTypeElement.class); while (typeElement != null) { final PsiElement parent = typeElement.getParent(); if (invoke(project, editor, typeElement, parent)) return; typeElement = PsiTreeUtil.getParentOfType(parent, PsiTypeElement.class, false); } CommonRefactoringUtil.showErrorHint(project, editor, JavaRefactoringBundle.message("caret.position.warning.message"), JavaRefactoringBundle.message("type.migration.error.hint.title"), "refactoring.migrateType"); }