void (final Document document, final PsiClass aClass, final int start, final int end) { final Project project = aClass.getProject(); PsiDocumentManager.getInstance(project).commitAllDocuments(); if (!aClass.isValid() || aClass.getQualifiedName() == null) return; JavaPsiFacade manager = JavaPsiFacade.getInstance(project); PsiResolveHelper helper = manager.getResolveHelper(); final PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document); CharSequence chars = document.getCharsSequence(); PsiElement element = file.findElementAt(start); String refText = chars.subSequence(start, end).toString(); PsiClass refClass = helper.resolveReferencedClass(refText, element); if (aClass.equals(refClass)) return; if (element instanceof PsiIdentifier) { PsiElement parent = element.getParent(); while (parent != null) { PsiElement tmp = parent.getParent(); if (!(tmp instanceof PsiJavaCodeReferenceElement) || tmp.getTextRange().getEndOffset() > end) break; parent = tmp; } if (parent instanceof PsiJavaCodeReferenceElement ref && !ref.isQualified()) { ApplicationManager.getApplication().runWriteAction(() -> { try { ref.bindToElement(aClass); } catch (IncorrectOperationException e) { LOG.error(e); } }); } } }