mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: presentation provider for record components (IDEA-360262)
GitOrigin-RevId: b3fef1fe5d58659efea5b21eb458d7c2880ba9a7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5dfc9435c4
commit
1ce2fdbcb5
@@ -110,6 +110,8 @@
|
||||
implementationClass="com.intellij.psi.presentation.java.VariablePresentationProvider"/>
|
||||
<itemPresentationProvider forClass="com.intellij.psi.PsiField"
|
||||
implementationClass="com.intellij.psi.presentation.java.FieldPresentationProvider"/>
|
||||
<itemPresentationProvider forClass="com.intellij.psi.PsiRecordComponent"
|
||||
implementationClass="com.intellij.psi.presentation.java.RecordComponentPresentationProvider"/>
|
||||
<itemPresentationProvider forClass="com.intellij.psi.PsiMethod"
|
||||
implementationClass="com.intellij.psi.presentation.java.MethodPresentationProvider"/>
|
||||
<itemPresentationProvider forClass="com.intellij.psi.PsiClass"
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.psi.impl.source;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentationProviders;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.CheckUtil;
|
||||
import com.intellij.psi.impl.ElementPresentationUtil;
|
||||
@@ -159,6 +161,11 @@ public final class PsiRecordComponentImpl extends JavaStubPsiElement<PsiRecordCo
|
||||
.createLayeredIcon(this, IconManager.getInstance().getPlatformIcon(PlatformIcons.Field), ElementPresentationUtil.getFlags(this, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemPresentation getPresentation() {
|
||||
return ItemPresentationProviders.getItemPresentation(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull SearchScope getUseScope() {
|
||||
return PsiImplUtil.getMemberUseScope(this);
|
||||
|
||||
+26
-10
@@ -88,18 +88,37 @@ public final class JavaPresentationUtil {
|
||||
};
|
||||
}
|
||||
|
||||
public static @NotNull ItemPresentation getRecordComponentPresentation(final @NotNull PsiRecordComponent component) {
|
||||
return new ColoredItemPresentation() {
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
return component.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextAttributesKey getTextAttributesKey() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocationString() {
|
||||
return getJavaSymbolContainerText(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getIcon(boolean open) {
|
||||
return component.getIcon(Iconable.ICON_FLAG_VISIBILITY);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static @Nullable String getJavaSymbolContainerText(final @NotNull PsiElement element) {
|
||||
final String result;
|
||||
PsiElement container = PsiTreeUtil.getParentOfType(element, PsiMember.class, PsiFile.class);
|
||||
|
||||
if (container instanceof PsiClass) {
|
||||
String qName = ((PsiClass)container).getQualifiedName();
|
||||
if (qName != null) {
|
||||
result = qName;
|
||||
}
|
||||
else {
|
||||
result = ((PsiClass)container).getName();
|
||||
}
|
||||
result = (qName != null) ? qName : ((PsiClass)container).getName();
|
||||
}
|
||||
else if (container instanceof PsiJavaFile) {
|
||||
result = ((PsiJavaFile)container).getPackageName();
|
||||
@@ -107,9 +126,6 @@ public final class JavaPresentationUtil {
|
||||
else {//TODO: local classes
|
||||
result = null;
|
||||
}
|
||||
if (result != null) {
|
||||
return JavaPsiBundle.message("aux.context.display", result);
|
||||
}
|
||||
return null;
|
||||
return result == null ? null : JavaPsiBundle.message("aux.context.display", result);
|
||||
}
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.psi.presentation.java;
|
||||
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentationProvider;
|
||||
import com.intellij.psi.PsiRecordComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public final class RecordComponentPresentationProvider implements ItemPresentationProvider<PsiRecordComponent> {
|
||||
@Override
|
||||
public ItemPresentation getPresentation(@NotNull PsiRecordComponent item) {
|
||||
return JavaPresentationUtil.getRecordComponentPresentation(item);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user