void () { String text = """ class XXX{ void foo() {\s <caret>foo(); }}"""; PsiJavaFile file = (PsiJavaFile)configureByText(JavaFileType.INSTANCE, text); PsiClass aClass = file.getClasses()[0]; assertNotNull(aClass); PsiReferenceExpression ref1 = PsiTreeUtil.getParentOfType(PsiUtilBase.getElementAtCaret(getEditor()), PsiReferenceExpression.class); SmartPsiElementPointer pointer1 = createPointer(ref1); ctrlD(); PsiDocumentManager.getInstance(myProject).commitAllDocuments(); Set<PsiReferenceExpression> refs = new HashSet<>(); int offset=0; while (true) { offset = getEditor().getDocument().getText().indexOf("foo();", offset+1); if (offset == -1) break; PsiReferenceExpression ref2 = PsiTreeUtil.getParentOfType(getFile().findElementAt(offset), PsiReferenceExpression.class); refs.add(ref2); } refs.remove(ref1); assertEquals(1, refs.size()); PsiReferenceExpression ref2 = refs.iterator().next(); assertNotSame(ref1, ref2); SmartPsiElementPointer pointer2 = createPointer(ref2); assertNotSame(pointer1, pointer2); PsiElement element1 = pointer1.getElement(); PsiElement element2 = pointer2.getElement(); assertNotNull(element1); assertNotNull(element2); assertNotSame(element1, element2); assertFalse(getPointerManager().pointToTheSameElement(pointer1, pointer2)); }