void () { String text = "if(x&y);"; PsiFile file = createFile("A.java", "class C{{\n" + text + "\n}}"); PsiElement element = file.findElementAt(file.getText().indexOf(text)); PsiIfStatement statement = PsiTreeUtil.getParentOfType(element, PsiIfStatement.class); assertNotNull(statement); Ref<PsiElement> result = Ref.create(); CommandProcessor.getInstance().executeCommand(getProject(), () -> WriteAction.run( () -> result.set(CodeStyleManager.getInstance(getProject()).reformat(statement)) ), "", null); PsiExpression expr = ((PsiIfStatement)result.get()).getCondition(); assertEquals(""" PsiBinaryExpression:x & y PsiReferenceExpression:x PsiReferenceParameterList <empty list> PsiIdentifier:x('x') PsiWhiteSpace(' ') PsiJavaToken:AND('&') PsiWhiteSpace(' ') PsiReferenceExpression:y PsiReferenceParameterList <empty list> PsiIdentifier:y('y') """, DebugUtil.psiToString(expr, true)); }