PsiExpression (String textWithExpression) { myFixture.configureByText("Foo.java", "import java.util.*;" + "class Foo {" + " void foo(int i) {" + textWithExpression + " }" + "}"); final PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); assertNotNull(elementAtCaret); return PsiTreeUtil.getParentOfType(elementAtCaret, PsiExpression.class); }