void (final PsiElement element, PsiReference reference, final PsiElement referencedElement) { final Project project = element.getProject(); myReferencedElement = referencedElement; if (referencedElement != null) { myReferencedElementPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(referencedElement); } if (reference == null) reference = element.getReference(); PsiFile containingFile = element.getContainingFile(); if (reference == null) { final TextRange textRange = element.getTextRange(); if (textRange != null) { reference = containingFile.findReferenceAt(textRange.getStartOffset()); } } myReference = reference; if (reference != null) { Document document = PsiDocumentManager.getInstance(project).getDocument(containingFile); if (document != null) { final int elementStart = reference.getElement().getTextRange().getStartOffset(); final TextRange rangeInElement = reference.getRangeInElement(); LOG.assertTrue(elementStart + rangeInElement.getEndOffset() <= document.getTextLength(), reference); myReferenceRangeMarker = document.createRangeMarker(elementStart + rangeInElement.getStartOffset(), elementStart + rangeInElement.getEndOffset()); } myDynamicUsage = reference.resolve() == null; } }