KT-999 Show full names of elements in structure view
This commit is contained in:
@@ -15,6 +15,7 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
|
|||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade;
|
||||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -30,6 +31,8 @@ public class JetStructureViewElement implements StructureViewTreeElement {
|
|||||||
// For file context will be updated after each construction
|
// For file context will be updated after each construction
|
||||||
// For other tree sub-elements it's immutable.
|
// For other tree sub-elements it's immutable.
|
||||||
private BindingContext context;
|
private BindingContext context;
|
||||||
|
|
||||||
|
private String elementText;
|
||||||
|
|
||||||
public JetStructureViewElement(NavigatablePsiElement element, BindingContext context) {
|
public JetStructureViewElement(NavigatablePsiElement element, BindingContext context) {
|
||||||
myElement = element;
|
myElement = element;
|
||||||
@@ -59,35 +62,17 @@ public class JetStructureViewElement implements StructureViewTreeElement {
|
|||||||
public boolean canNavigateToSource() {
|
public boolean canNavigateToSource() {
|
||||||
return myElement.canNavigateToSource();
|
return myElement.canNavigateToSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemPresentation getPresentation() {
|
public ItemPresentation getPresentation() {
|
||||||
return new ItemPresentation() {
|
return new ItemPresentation() {
|
||||||
@Override
|
@Override
|
||||||
public String getPresentableText() {
|
public String getPresentableText() {
|
||||||
String text = "";
|
if (elementText == null) {
|
||||||
|
elementText = getElementText();
|
||||||
// Try to find text in correspondent descriptor
|
|
||||||
// if (myElement instanceof JetDeclaration) {
|
|
||||||
// JetDeclaration declaration = (JetDeclaration) myElement;
|
|
||||||
// final DeclarationDescriptor descriptor =
|
|
||||||
// context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
|
||||||
//
|
|
||||||
// if (descriptor != null) {
|
|
||||||
// text = getDescriptorTreeText(descriptor);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (StringUtil.isEmpty(text)) {
|
|
||||||
text = myElement.getName();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtil.isEmpty(text)) {
|
return elementText;
|
||||||
if (myElement instanceof JetClassInitializer) {
|
|
||||||
return "<class initializer>";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -113,8 +98,7 @@ public class JetStructureViewElement implements StructureViewTreeElement {
|
|||||||
if (myElement instanceof JetFile) {
|
if (myElement instanceof JetFile) {
|
||||||
final JetFile jetFile = (JetFile) myElement;
|
final JetFile jetFile = (JetFile) myElement;
|
||||||
|
|
||||||
// TODO: Understand why it significantly reduce responsibility of IDEA during typing
|
context = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(jetFile);
|
||||||
// context = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(jetFile);
|
|
||||||
|
|
||||||
return wrapDeclarations(jetFile.getDeclarations());
|
return wrapDeclarations(jetFile.getDeclarations());
|
||||||
}
|
}
|
||||||
@@ -134,6 +118,33 @@ public class JetStructureViewElement implements StructureViewTreeElement {
|
|||||||
}
|
}
|
||||||
return new TreeElement[0];
|
return new TreeElement[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getElementText() {
|
||||||
|
String text = "";
|
||||||
|
|
||||||
|
// Try to find text in correspondent descriptor
|
||||||
|
if (myElement instanceof JetDeclaration) {
|
||||||
|
JetDeclaration declaration = (JetDeclaration) myElement;
|
||||||
|
|
||||||
|
final DeclarationDescriptor descriptor =
|
||||||
|
context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
||||||
|
if (descriptor != null) {
|
||||||
|
text = getDescriptorTreeText(descriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.isEmpty(text)) {
|
||||||
|
text = myElement.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtil.isEmpty(text)) {
|
||||||
|
if (myElement instanceof JetClassInitializer) {
|
||||||
|
return "<class initializer>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
private TreeElement[] wrapDeclarations(List<JetDeclaration> declarations) {
|
private TreeElement[] wrapDeclarations(List<JetDeclaration> declarations) {
|
||||||
TreeElement[] result = new TreeElement[declarations.size()];
|
TreeElement[] result = new TreeElement[declarations.size()];
|
||||||
|
|||||||
Reference in New Issue
Block a user