void () { Project project = getProject(); PsiCodeFragment fragment = JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment("AAA.foo()", null, null, false); JavaPsiFacadeEx javaPsiFacade = JavaPsiFacadeEx.getInstanceEx(project); PsiClass arrayListClass = javaPsiFacade.findClass("java.util.ArrayList", GlobalSearchScope.allScope(project)); PsiReference ref = fragment.findReferenceAt(0); ApplicationManager.getApplication().runWriteAction(() -> { ref.bindToElement(arrayListClass); }); assertEquals("ArrayList.foo()", fragment.getText()); }