void () { myFixture.configureByText("Test.java", """ class Demo { static void process(String s, Object date, boolean b) { String conditional = String.format(b ? "myFormat: num = %1$d, date = %2$s" : "<caret>myFormat: date = %2$s; num = %1$d", 123, date); } }"""); PsiLiteralExpression str = PsiTreeUtil.getParentOfType(myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset()), PsiLiteralExpression.class); assertNotNull(str); Collection<? extends @NotNull PsiSymbolReference> refs = PsiSymbolReferenceService.getService().getReferences(str); assertEquals(2, refs.size()); Map<String, String> expected = Map.of("%2$s", "date", "%1$d", "123"); for (PsiSymbolReference ref : refs) { assertEquals(str, ref.getElement()); String formatSpecifier = ref.getRangeInElement().substring(ref.getElement().getText()); Collection<? extends Symbol> symbols = ref.resolveReference(); assertEquals(1, symbols.size()); Symbol symbol = CollectionUtils.getOnlyElement(symbols); assertTrue(symbol instanceof JavaFormatArgumentSymbol); JavaFormatArgumentSymbol formatSymbol = (JavaFormatArgumentSymbol)symbol; assertTrue(formatSymbol.getFormatString() instanceof PsiConditionalExpression); String expressionText = formatSymbol.getExpression().getText(); assertEquals(expected.get(formatSpecifier), expressionText); } }