void () { final PsiReference iRef = configure(); PsiElement context = PsiTreeUtil.getParentOfType(iRef.getElement(), PsiCodeBlock.class); JavaCodeFragment codeFragment = JavaCodeFragmentFactory.getInstance(getProject()) .createExpressionCodeFragment(iRef.getElement().getText(), context, null, true); codeFragment.setVisibilityChecker(JavaCodeFragment.VisibilityChecker.EVERYTHING_VISIBLE); PsiElement[] fileContent = codeFragment.getChildren(); assertEquals(1, fileContent.length); assertTrue(fileContent[0] instanceof PsiExpression); PsiExpression expr = (PsiExpression) fileContent[0]; expr.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { assertEquals(iRef.resolve(), expression.resolve()); } }); }