"Show members" option for Project View is now fast (Fixed KT-2061)
This commit is contained in:
@@ -22,22 +22,27 @@ import com.intellij.ide.projectView.impl.nodes.AbstractPsiBasedNode;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClassInitializer;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.plugin.formatter.JetCodeStyleSettings;
|
||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||
import org.jetbrains.jet.plugin.structureView.JetStructureViewElement;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* User: Alefas
|
||||
* Date: 15.02.12
|
||||
*/
|
||||
public class JetDeclarationTreeNode extends AbstractPsiBasedNode<JetDeclaration> {
|
||||
public static final String CLASS_INITIALIZER = "<class initializer>";
|
||||
|
||||
protected JetDeclarationTreeNode(Project project, JetDeclaration jetDeclaration, ViewSettings viewSettings) {
|
||||
super(project, jetDeclaration, viewSettings);
|
||||
}
|
||||
@@ -56,26 +61,54 @@ public class JetDeclarationTreeNode extends AbstractPsiBasedNode<JetDeclaration>
|
||||
protected void updateImpl(PresentationData data) {
|
||||
JetDeclaration declaration = getValue();
|
||||
if (declaration != null) {
|
||||
BindingContext context = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(
|
||||
(JetFile) declaration.getContainingFile())
|
||||
.getBindingContext();
|
||||
String text = declaration.getName();
|
||||
if (text == null) return;
|
||||
JetCodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings()
|
||||
.getCustomSettings(JetCodeStyleSettings.class);
|
||||
if (declaration instanceof JetClassInitializer) {
|
||||
text = CLASS_INITIALIZER;
|
||||
} else if (declaration instanceof JetProperty) {
|
||||
JetProperty property = (JetProperty) declaration;
|
||||
JetTypeReference ref = property.getPropertyTypeRef();
|
||||
if (ref != null) {
|
||||
if (settings.SPACE_BEFORE_TYPE_COLON) text += " ";
|
||||
text += ":";
|
||||
if (settings.SPACE_AFTER_TYPE_COLON) text += " ";
|
||||
text += ref.getText();
|
||||
}
|
||||
} else if (declaration instanceof JetFunction) {
|
||||
JetFunction function = (JetFunction) declaration;
|
||||
JetTypeReference receiverTypeRef = function.getReceiverTypeRef();
|
||||
if (receiverTypeRef != null) {
|
||||
text = receiverTypeRef.getText() + "." + text;
|
||||
}
|
||||
text += "(";
|
||||
List<JetParameter> parameters = function.getValueParameters();
|
||||
for (JetParameter parameter : parameters) {
|
||||
if (parameter.getName() != null) {
|
||||
text += parameter.getName();
|
||||
if (settings.SPACE_BEFORE_TYPE_COLON) text += " ";
|
||||
text += ":";
|
||||
if (settings.SPACE_AFTER_TYPE_COLON) text += " ";
|
||||
}
|
||||
JetTypeReference typeReference = parameter.getTypeReference();
|
||||
if (typeReference != null) {
|
||||
text += typeReference.getText();
|
||||
}
|
||||
text += ", ";
|
||||
}
|
||||
if (parameters.size() > 0) text = text.substring(0, text.length() - 2);
|
||||
text += ")";
|
||||
JetTypeReference typeReference = function.getReturnTypeRef();
|
||||
if (typeReference != null) {
|
||||
if (settings.SPACE_BEFORE_TYPE_COLON) text += " ";
|
||||
text += ":";
|
||||
if (settings.SPACE_AFTER_TYPE_COLON) text += " ";
|
||||
text += typeReference.getText();
|
||||
}
|
||||
}
|
||||
|
||||
final DeclarationDescriptor descriptor =
|
||||
context.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
||||
if (descriptor != null) {
|
||||
String text = JetStructureViewElement.getDescriptorTreeText(descriptor);
|
||||
if (declaration instanceof JetClassInitializer) {
|
||||
text = "<class initializer>";
|
||||
}
|
||||
data.setPresentableText(text);
|
||||
}
|
||||
else {
|
||||
String text = declaration.getName();
|
||||
if (declaration instanceof JetClassInitializer) {
|
||||
text = "<class initializer>";
|
||||
}
|
||||
data.setPresentableText(text);
|
||||
}
|
||||
data.setPresentableText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user