PsiVariable () { PsiElement anchor = myChosenAnchor.getElement(); if (anchor == null) return null; PsiVariable variable = VariableExtractor.introduce(myProject, myExpr, myEditor, anchor, getOccurrences(), mySettings); SmartPointerManager smartPointerManager = SmartPointerManager.getInstance(myProject); if (variable instanceof PsiField || variable instanceof PsiResourceVariable) { myPointer = smartPointerManager.createSmartPsiElementPointer(variable); } else if (variable instanceof PsiPatternVariable) { PsiElement parent = ((PsiPatternVariable)variable).getPattern().getParent(); LOG.assertTrue(parent instanceof PsiInstanceOfExpression); myPointer = smartPointerManager.createSmartPsiElementPointer(parent); } else { final PsiDeclarationStatement declarationStatement = PsiTreeUtil.getParentOfType(variable, PsiDeclarationStatement.class); if (declarationStatement != null) { SmartPsiElementPointer<PsiDeclarationStatement> pointer = smartPointerManager.createSmartPsiElementPointer(declarationStatement); myPointer = pointer; myEditor.putUserData(ReassignVariableUtil.DECLARATION_KEY, pointer); PsiType variableType = variable.getType(); ReadAction.nonBlocking(() -> { PsiDeclarationStatement element = pointer.getElement(); return element != null && variableType.isValid() ? getAdvertisementText(element, variableType, myHasTypeSuggestion) : null; }) .finishOnUiThread(ModalityState.nonModal(), (@NlsContexts.PopupAdvertisement String text) -> setAdvertisementText(text)) .submit(NonUrgentExecutor.getInstance()); } } SmartPsiElementPointer<PsiVariable> pointer = variable == null ? null : smartPointerManager.createSmartPsiElementPointer(variable); PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(myEditor.getDocument()); return pointer == null ? null : pointer.getElement(); }