structure view: show members of the current class only (IDEA-168769)

This commit is contained in:
Daniil Ovchinnikov
2017-03-09 19:27:49 +03:00
parent 7728bbe44c
commit eb2307a61b
3 changed files with 35 additions and 12 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -68,19 +68,20 @@ public class JavaClassTreeElement extends JavaClassTreeElementBase<PsiClass> {
return children;
}
static LinkedHashSet<PsiElement> getOwnChildren(PsiClass aClass) {
static LinkedHashSet<PsiElement> getOwnChildren(@NotNull PsiClass aClass) {
LinkedHashSet<PsiElement> members = new LinkedHashSet<>();
addPhysicalElements(aClass.getFields(), members);
addPhysicalElements(aClass.getMethods(), members);
addPhysicalElements(aClass.getInnerClasses(), members);
addPhysicalElements(aClass.getInitializers(), members);
addPhysicalElements(aClass.getFields(), members, aClass);
addPhysicalElements(aClass.getMethods(), members, aClass);
addPhysicalElements(aClass.getInnerClasses(), members, aClass);
addPhysicalElements(aClass.getInitializers(), members, aClass);
return members;
}
private static void addPhysicalElements(PsiElement[] elements, LinkedHashSet<PsiElement> to) {
for (PsiElement element : elements) {
private static void addPhysicalElements(@NotNull PsiMember[] elements, @NotNull Collection<PsiElement> to, @NotNull PsiClass aClass) {
for (PsiMember element : elements) {
PsiElement mirror = PsiImplUtil.handleMirror(element);
if (!(mirror instanceof LightElement)) {
if (mirror instanceof LightElement) continue;
if (mirror instanceof PsiMember && aClass.equals(((PsiMember)mirror).getContainingClass())) {
to.add(mirror);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,9 @@ public class JavaInheritedMembersNodeProvider extends InheritedMembersNodeProvid
@Override
public Collection<TreeElement> provideNodes(@NotNull TreeElement node) {
if (node instanceof JavaClassTreeElement) {
final PsiClass aClass = ((JavaClassTreeElement)node).getValue();
final PsiClass aClass = ((JavaClassTreeElement)node).getElement();
if (aClass == null) return Collections.emptyList();
Collection<PsiElement> inherited = new LinkedHashSet<>();
Collection<PsiElement> ownChildren = JavaClassTreeElement.getOwnChildren(aClass);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -125,4 +125,24 @@ class Foo {
}
void testTraitMembers() {
myFixture.addFileToProject 'T.groovy', '''\
trait T {
def tProperty
def tMethod() {}
}
'''
myFixture.configureByText '_.groovy', '''\
class C implements T {
void ownMethod() {}
}
'''
myFixture.testStructureView {
it.setActionActive InheritedMembersNodeProvider.ID, false
assertTreeEqual(it.tree, """-_.groovy
-C
ownMethod(): void
""")
}
}
}