Show members from supertypes in file structure view (KT-4448)
#KT-4448 Fixed
This commit is contained in:
@@ -47,13 +47,27 @@ public class JetStructureViewElement implements StructureViewTreeElement, Colore
|
||||
|
||||
private String elementText;
|
||||
private Icon icon;
|
||||
private final boolean isInherited;
|
||||
|
||||
public JetStructureViewElement(@NotNull NavigatablePsiElement element) {
|
||||
public JetStructureViewElement(@NotNull NavigatablePsiElement element, @NotNull DeclarationDescriptor descriptor, boolean isInherited) {
|
||||
this.element = element;
|
||||
this.isInherited = isInherited;
|
||||
|
||||
if (!(element instanceof JetElement)) {
|
||||
// Avoid storing descriptor in fields
|
||||
elementText = getElementText(element, descriptor);
|
||||
icon = getElementIcon(element, descriptor);
|
||||
}
|
||||
}
|
||||
|
||||
public JetStructureViewElement(@NotNull NavigatablePsiElement element, boolean isInherited) {
|
||||
this.element = element;
|
||||
this.isInherited = isInherited;
|
||||
}
|
||||
|
||||
public JetStructureViewElement(@NotNull JetFile fileElement) {
|
||||
element = fileElement;
|
||||
isInherited = false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -94,7 +108,7 @@ public class JetStructureViewElement implements StructureViewTreeElement, Colore
|
||||
return ArrayUtil.toObjectArray(ContainerUtil.map(childrenDeclarations, new Function<JetDeclaration, TreeElement>() {
|
||||
@Override
|
||||
public TreeElement fun(JetDeclaration declaration) {
|
||||
return new JetStructureViewElement(declaration);
|
||||
return new JetStructureViewElement(declaration, false);
|
||||
}
|
||||
}), TreeElement.class);
|
||||
}
|
||||
@@ -102,9 +116,15 @@ public class JetStructureViewElement implements StructureViewTreeElement, Colore
|
||||
@Nullable
|
||||
@Override
|
||||
public TextAttributesKey getTextAttributesKey() {
|
||||
if (isInherited()) {
|
||||
return CodeInsightColors.NOT_USED_ELEMENT_ATTRIBUTES;
|
||||
}
|
||||
|
||||
|
||||
if (element instanceof JetModifierListOwner && JetPsiUtil.isDeprecated((JetModifierListOwner) element)) {
|
||||
return CodeInsightColors.DEPRECATED_ATTRIBUTES;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -134,6 +154,10 @@ public class JetStructureViewElement implements StructureViewTreeElement, Colore
|
||||
return icon;
|
||||
}
|
||||
|
||||
public boolean isInherited() {
|
||||
return isInherited;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private DeclarationDescriptor getDescriptor() {
|
||||
if (!(element.isValid() && element instanceof JetDeclaration)) {
|
||||
@@ -175,6 +199,7 @@ public class JetStructureViewElement implements StructureViewTreeElement, Colore
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Icon getElementIcon(@NotNull NavigatablePsiElement navigatablePsiElement, @Nullable DeclarationDescriptor descriptor) {
|
||||
if (descriptor != null) {
|
||||
return JetDescriptorIconProvider.getIcon(descriptor, navigatablePsiElement, Iconable.ICON_FLAG_VISIBILITY);
|
||||
|
||||
@@ -17,12 +17,19 @@
|
||||
package org.jetbrains.jet.plugin.structureView;
|
||||
|
||||
import com.intellij.ide.structureView.StructureViewModelBase;
|
||||
import com.intellij.ide.util.treeView.smartTree.NodeProvider;
|
||||
import com.intellij.ide.util.treeView.smartTree.Sorter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
public class JetStructureViewModel extends StructureViewModelBase {
|
||||
private static final Collection<NodeProvider> NODE_PROVIDERS = Arrays.<NodeProvider>asList(
|
||||
new KotlinInheritedMembersNodeProvider());
|
||||
|
||||
private static final Sorter[] sorters = new Sorter[] {Sorter.ALPHA_SORTER};
|
||||
|
||||
public JetStructureViewModel(@NotNull JetFile jetFile) {
|
||||
@@ -30,6 +37,12 @@ public class JetStructureViewModel extends StructureViewModelBase {
|
||||
withSuitableClasses(JetDeclaration.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<NodeProvider> getNodeProviders() {
|
||||
return NODE_PROVIDERS;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Sorter[] getSorters() {
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2010-2014 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.structureView
|
||||
|
||||
import com.intellij.ide.util.treeView.smartTree.TreeElement
|
||||
import com.intellij.ide.util.InheritedMembersNodeProvider
|
||||
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor
|
||||
import org.jetbrains.jet.plugin.codeInsight.DescriptorToDeclarationUtil
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor
|
||||
import com.intellij.psi.NavigatablePsiElement
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||
|
||||
public class KotlinInheritedMembersNodeProvider: InheritedMembersNodeProvider<TreeElement>() {
|
||||
override fun provideNodes(node: TreeElement): Collection<TreeElement> {
|
||||
if (node !is JetStructureViewElement) return listOf()
|
||||
|
||||
val element = node.getElement()
|
||||
if (element !is JetClassOrObject) return listOf()
|
||||
|
||||
[suppress("USELESS_CAST")] // KT-3996 Workaround
|
||||
val project = (element as NavigatablePsiElement).getProject()
|
||||
|
||||
val context = AnalyzerFacadeWithCache.getContextForElement(element)
|
||||
val descriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, element]
|
||||
|
||||
if (descriptor !is ClassifierDescriptor) return listOf()
|
||||
|
||||
val children = ArrayList<TreeElement>()
|
||||
|
||||
val defaultType = descriptor.getDefaultType()
|
||||
for (memberDescriptor in defaultType.getMemberScope().getAllDescriptors()) {
|
||||
if (memberDescriptor !is CallableMemberDescriptor) continue
|
||||
if (memberDescriptor.getKind() != CallableMemberDescriptor.Kind.FAKE_OVERRIDE) continue
|
||||
|
||||
val superTypeMember = DescriptorToDeclarationUtil.getDeclaration(project, memberDescriptor, context)
|
||||
if (superTypeMember is NavigatablePsiElement) {
|
||||
children.add(JetStructureViewElement(superTypeMember, memberDescriptor, true))
|
||||
}
|
||||
}
|
||||
|
||||
return children
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user