mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
[java] show records in structure view IDEA-229845
GitOrigin-RevId: dc192337f323c1cf79a8a97aedeac41b97e5ab7c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
251178cb8b
commit
6cff3bf1cb
@@ -57,6 +57,12 @@ public class JavaClassTreeElement extends JavaClassTreeElementBase<PsiClass> {
|
||||
children.add(new ClassInitializerTreeElement((PsiClassInitializer)child));
|
||||
}
|
||||
}
|
||||
PsiRecordHeader header = aClass.getRecordHeader();
|
||||
if (header != null) {
|
||||
for (PsiRecordComponent recordComponent : header.getRecordComponents()) {
|
||||
children.add(new JavaRecordComponentTreeElement(recordComponent, false));
|
||||
}
|
||||
}
|
||||
return children;
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ public class JavaFileTreeModel extends TextEditorBasedStructureViewModel impleme
|
||||
|
||||
@Override
|
||||
protected Class @NotNull [] getSuitableClasses() {
|
||||
return new Class[]{PsiClass.class, PsiMethod.class, PsiField.class, PsiLambdaExpression.class, PsiJavaFile.class};
|
||||
return new Class[]{PsiClass.class, PsiMethod.class, PsiField.class, PsiLambdaExpression.class, PsiJavaFile.class, PsiRecordComponent.class};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.structureView.impl.java;
|
||||
|
||||
import com.intellij.ide.structureView.StructureViewTreeElement;
|
||||
import com.intellij.psi.PsiRecordComponent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class JavaRecordComponentTreeElement extends JavaVariableBaseTreeElement<PsiRecordComponent> {
|
||||
public JavaRecordComponentTreeElement(PsiRecordComponent field, boolean isInherited) {
|
||||
super(isInherited, field);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<StructureViewTreeElement> getChildrenBase() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.structureView.impl.java;
|
||||
|
||||
import com.intellij.ide.util.treeView.smartTree.SortableTreeElement;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiSubstitutor;
|
||||
import com.intellij.psi.PsiVariable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import static com.intellij.psi.util.PsiFormatUtil.formatVariable;
|
||||
import static com.intellij.psi.util.PsiFormatUtilBase.*;
|
||||
import static com.intellij.psi.util.PsiFormatUtilBase.SHOW_INITIALIZER;
|
||||
|
||||
abstract class JavaVariableBaseTreeElement<T extends PsiVariable> extends JavaClassTreeElementBase<T> implements SortableTreeElement {
|
||||
protected JavaVariableBaseTreeElement(boolean isInherited, T element) {
|
||||
super(isInherited, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getPresentableText() {
|
||||
final T field = getElement();
|
||||
if (field == null) return "";
|
||||
|
||||
final boolean dumb = DumbService.isDumb(field.getProject());
|
||||
return StringUtil.replace(formatVariable(
|
||||
field,
|
||||
SHOW_NAME | (dumb ? 0 : SHOW_TYPE) | TYPE_AFTER | (dumb ? 0 : SHOW_INITIALIZER),
|
||||
PsiSubstitutor.EMPTY
|
||||
), ":", ": ");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getAlphaSortKey() {
|
||||
final T element = getElement();
|
||||
if (element != null) {
|
||||
String name = element.getName();
|
||||
if (name != null) return name;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -14,9 +14,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import static com.intellij.psi.util.PsiFormatUtil.*;
|
||||
|
||||
public class PsiFieldTreeElement extends JavaClassTreeElementBase<PsiField> implements SortableTreeElement {
|
||||
public class PsiFieldTreeElement extends JavaVariableBaseTreeElement<PsiField> {
|
||||
public PsiFieldTreeElement(PsiField field, boolean isInherited) {
|
||||
super(isInherited,field);
|
||||
}
|
||||
@@ -34,30 +32,7 @@ public class PsiFieldTreeElement extends JavaClassTreeElementBase<PsiField> impl
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPresentableText() {
|
||||
final PsiField field = getElement();
|
||||
if (field == null) return "";
|
||||
|
||||
final boolean dumb = DumbService.isDumb(field.getProject());
|
||||
return StringUtil.replace(formatVariable(
|
||||
field,
|
||||
SHOW_NAME | (dumb ? 0 : SHOW_TYPE) | TYPE_AFTER | (dumb ? 0 : SHOW_INITIALIZER),
|
||||
PsiSubstitutor.EMPTY
|
||||
), ":", ": ");
|
||||
}
|
||||
|
||||
public PsiField getField() {
|
||||
return getElement();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getAlphaSortKey() {
|
||||
final PsiField field = getElement();
|
||||
if (field != null) {
|
||||
return field.getName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user