Skip to content

Localizing ClassPresentationUtil - #312

Merged
VISTALL merged 1 commit into
consulo:masterfrom
unv-unv:localizing-class-presentation-util
Oct 10, 2026
Merged

VISTALL merged 1 commit into
consulo:masterfrom
unv-unv:localizing-class-presentation-util

Conversation

@unv-unv

@unv-unv unv-unv commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@unv-unv

unv-unv commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@claude review pr with inline comments

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @unv-unv's task in 1m 54s —— View job


PR review: Localizing ClassPresentationUtil

  • Gather context
  • Review diff (17 files)
  • Post inline comments (review)
  • Final summary

Moving getNameForClass and getFunctionalExpressionPresentation over to LocalizeValue looks correct. I compared getContextName with the old code: it skips null or empty names the same way as before.

I posted 6 inline comments. Most include one-click suggestions.

Should fix

  • Two call sites still pass the new LocalizeValue where a String is expected, so the text depends on LocalizeValue.toString(). Every other call site uses .get().
    • JavaMethodNode.java:82: buffer.append(getNameForClass(...))
    • StaticImportMethodQuestionAction.java:250: getNameForClass(...) + "." + .... This line is outside the diff, so I couldn't attach a suggestion to it; the fix is written in the comment on line 247.

Nits

  • ClassPresentationUtil.java:94: after isNotEmpty(), getNullIfEmpty() adds nothing; get() is enough.
  • ClassPresentationUtil.java:105: the localizeTODO text has the context name baked in. When a real key is added, it should take the context as an argument. The text still shows "... in null" when there is no context, as it did before this PR.
  • PsiFieldFavoriteNodeProvider.java:121: this still uses ModuleUtilCore, while the Class and Method providers were switched to getModule() in this PR.
  • ClassPresentationProvider.java:56: packageName.length() == 0 could be isEmpty().

I didn't build the project, so I haven't confirmed that the LanguageLocalize keys used here (enumConstantContext, anonymousClassContextDisplay, classContextDisplay, methodContextDisplay) exist in the platform version this branch depends on.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by Claude — see inline comments. Overall the migration to LocalizeValue looks good; two call sites were missed and still rely on implicit LocalizeValue.toString().

StringBuilder buffer = new StringBuilder(128);
PsiClass containingClass = myMethod.getContainingClass();
if (containingClass != null) {
buffer.append(ClassPresentationUtil.getNameForClass(containingClass, false));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getNameForClass now returns LocalizeValue, so this compiles via StringBuilder.append(Object) and depends on LocalizeValue.toString(). Every other call site in this PR uses .get() explicitly. It's safer and more consistent to do the same here:

Suggested change
buffer.append(ClassPresentationUtil.getNameForClass(containingClass, false));
buffer.append(ClassPresentationUtil.getNameForClass(containingClass, false).get());

}

@RequiredReadAction
private String getElementPresentableName(T element) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue at line 250, which is just outside the diff so I can't attach a suggestion to it. return ClassPresentationUtil.getNameForClass(aClass, false) + "." + element.getName(); now concatenates a LocalizeValue and so depends on its implicit toString(). Use .get() explicitly, like the other call sites:

        return ClassPresentationUtil.getNameForClass(aClass, false).get() + "." + element.getName();

}
LocalizeValue name = getNameForElement(parent, qualified);
if (name.isNotEmpty()) {
return name.getNullIfEmpty();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the isNotEmpty() check already passed, so getNullIfEmpty() can't return null here. get() is clearer:

Suggested change
return name.getNullIfEmpty();
return name.get();

}
@RequiredReadAction
public static LocalizeValue getFunctionalExpressionPresentation(PsiFunctionalExpression functionalExpression, boolean qualified) {
return LocalizeValue.localizeTODO("Functional expression in " + getContextName(functionalExpression, qualified));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: localizeTODO with a concatenated string bakes the context name into the untranslated text. Leaving this as a TODO is fine. When a key is added, it should take the context name as an argument (e.g. functional.expression.in.context, with getContextName passed through StringUtil.notNullize) so translators get one stable template. A small related point: if getContextName returns null, this still renders "Functional expression in null". That's how it behaved before this PR too.

Comment on lines +121 to +122
if (element instanceof PsiField) {
Module module = ModuleUtilCore.findModuleForPsiElement((PsiField) element);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency: PsiClassFavoriteNodeProvider and PsiMethodFavoriteNodeProvider were switched to getModule() in this PR, but this one still uses ModuleUtilCore. Suggest aligning them (the ModuleUtilCore import can then be dropped):

Suggested change
if (element instanceof PsiField) {
Module module = ModuleUtilCore.findModuleForPsiElement((PsiField) element);
if (element instanceof PsiField field) {
Module module = field.getModule();

PsiFile file = psiClass.getContainingFile();
if (file instanceof PsiClassOwner classOwner) {
String packageName = classOwner.getPackageName();
if (packageName.length() == 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: since this block is being reformatted anyway, use isEmpty(). PsiClassListCellRenderer.getContainerTextStatic does the same thing and already uses it:

Suggested change
if (packageName.length() == 0) {
if (packageName.isEmpty()) {

@unv-unv
unv-unv force-pushed the localizing-class-presentation-util branch from a79253d to 513d146 Compare October 9, 2026 23:13
@unv-unv

unv-unv commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@claude review pr with inline comments

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @unv-unv's task in 58s —— View job


PR review: Localizing ClassPresentationUtil

  • Gather context
  • Check the current head (513d146) against the 6 inline comments from the earlier review
  • Re-review the full diff (17 files) for anything new
  • Final summary

The earlier inline comments no longer match the code. The current head already contains five of the six fixes, so I didn't post them again:

Earlier comment Status at 513d146
JavaMethodNode.java:82 was missing .get() ✅ It already calls .get()
StaticImportMethodQuestionAction.java:250 was missing .get() ✅ It already calls .get()
ClassPresentationUtil.getContextName used getNullIfEmpty() ✅ It returns name.get() and is annotated @Nullable
PsiFieldFavoriteNodeProvider used ModuleUtilCore ✅ It uses field.getModule(), like the Class and Method providers
ClassPresentationProvider used length() == 0 ✅ It uses isEmpty()
getFunctionalExpressionPresentation uses localizeTODO ⏳ Still open, see below

Those five threads are outdated and can be resolved.

All 22 call sites of getNameForClass and getFunctionalExpressionPresentation now handle the LocalizeValue correctly. Every caller that needs a String calls .get(). Two callers keep the LocalizeValue on purpose:

  • GutterIconTooltipHelper calls .get() itself when it builds the tooltip text.
  • ClassHierarchyScopeDescriptor.java:77 passes it straight into IdeLocalize.scopeHierarchy(...) as an argument, which is fine.

Still open (nit, no new inline comment): ClassPresentationUtil.java:106

  • The localizeTODO text still has the context name built into it, so translators won't get one fixed message with a placeholder.
  • When there is no context, it still shows "Functional expression in null", as it did before this PR.

The existing inline thread on that line covers both points.

No new problems found. I didn't post any new inline comments because the diff has nothing new to fix. I didn't build the project, so I haven't checked that the LanguageLocalize keys used here (enumConstantContext, anonymousClassContextDisplay, classContextDisplay, methodContextDisplay) exist in the platform version this branch builds against.

@VISTALL
VISTALL merged commit 87255c3 into consulo:master Oct 10, 2026
1 check passed
@unv-unv
unv-unv deleted the localizing-class-presentation-util branch October 10, 2026 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants