mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +07:00
[java] StringFormatSymbolReferenceProvider: restore support of .formatted() (IDEA-372694)
Was broken during MessageFormat implementation (5bfb87b4 [java] IDEA-358431 Support MessageFormat specifier-to-argument navigation, similar to String.format) when moving away from FormatDecode.FormatArgument.extract. Was not covered by a test. (cherry picked from commit b7fdecc6c70508608c9157090272b6b4140af0ba) IJ-CR-163911 GitOrigin-RevId: a34b6822d6b250cb4e7fc1f1378e6f3c7856f70c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
23f25ec112
commit
dec7ad081b
@@ -205,6 +205,10 @@ public final class StringFormatSymbolReferenceProvider implements PsiSymbolRefer
|
||||
!(list.getParent() instanceof PsiCallExpression call)) {
|
||||
return null;
|
||||
}
|
||||
if (myFormatStringIndex == -1) {
|
||||
if (!(call instanceof PsiMethodCallExpression methodCall)) return null;
|
||||
return PsiUtil.skipParenthesizedExprDown(methodCall.getMethodExpression().getQualifierExpression());
|
||||
}
|
||||
PsiExpressionList argumentList = call.getArgumentList();
|
||||
if (argumentList == null) return null;
|
||||
PsiExpression[] expressions = argumentList.getExpressions();
|
||||
|
||||
@@ -36,6 +36,20 @@ public class StringFormatSymbolReferenceProviderTest extends LightJavaCodeInsigh
|
||||
checkRefs(refs, str, str.getParent(), Map.of("%2$s", "date", "%1$d", "123"));
|
||||
}
|
||||
|
||||
public void testResolveFormatSpecifiersFormatted() {
|
||||
myFixture.configureByText("Test.java", """
|
||||
final class Demo {
|
||||
static void process(String s, Object date, boolean b) {
|
||||
String conditional = (b ? "myFormat: num = %1$d, date = %2$s" :
|
||||
"<caret>myFormat: date = %2$s; num = %1$d").formatted(123, date);
|
||||
}
|
||||
}""");
|
||||
PsiLiteralExpression str = getLiteral();
|
||||
Collection<? extends @NotNull PsiSymbolReference> refs = PsiSymbolReferenceService.getService().getReferences(str);
|
||||
assertEquals(2, refs.size());
|
||||
checkRefs(refs, str, str.getParent(), Map.of("%2$s", "date", "%1$d", "123"));
|
||||
}
|
||||
|
||||
public void testResolveFromLocalVar() {
|
||||
myFixture.configureByText("Test.java", """
|
||||
final class Demo {
|
||||
|
||||
Reference in New Issue
Block a user