From f28a490a1e38e9972dbb4b0b295232ee4f4c71e6 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 29 Mar 2012 18:20:04 +0400 Subject: [PATCH] Removed line markers for everything except for overriding functions. --- .../highlighter/JetLineMarkerProvider.java | 203 ++++++------------ 1 file changed, 66 insertions(+), 137 deletions(-) diff --git a/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java b/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java index 94f560c34ef..2a98b1cd32f 100644 --- a/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java @@ -27,17 +27,15 @@ import com.intellij.ide.util.DefaultPsiElementCellRenderer; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.IconLoader; -import com.intellij.openapi.util.Iconable; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiUtilBase; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.Function; -import com.intellij.util.PlatformIcons; -import com.intellij.util.PsiIconUtil; import com.intellij.util.PsiNavigateUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.lang.descriptors.*; -import org.jetbrains.jet.lang.psi.*; +import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; +import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor; +import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.jet.lang.psi.JetNamedFunction; import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade; import org.jetbrains.jet.resolve.DescriptorRenderer; @@ -57,151 +55,82 @@ public class JetLineMarkerProvider implements LineMarkerProvider { @Override public LineMarkerInfo getLineMarkerInfo(PsiElement element) { - JetFile file = (JetFile) element.getContainingFile(); + JetFile file = (JetFile)element.getContainingFile(); if (file == null) return null; + if (!(element instanceof JetNamedFunction)) return null; + JetNamedFunction jetFunction = (JetNamedFunction)element; + final BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file); - if (element instanceof JetClass) { - JetClass jetClass = (JetClass) element; - ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, jetClass); - String text = classDescriptor == null ? "Unresolved" : DescriptorRenderer.HTML.render(classDescriptor); - return createLineMarkerInfo(jetClass, text); - } + final SimpleFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, jetFunction); + if (functionDescriptor == null) return null; + final Set overriddenFunctions = functionDescriptor.getOverriddenDescriptors(); + if (overriddenFunctions.size() == 0) return null; - if (element instanceof JetProperty) { - JetProperty jetProperty = (JetProperty) element; - final VariableDescriptor variableDescriptor = bindingContext.get(BindingContext.VARIABLE, jetProperty); - if (variableDescriptor instanceof PropertyDescriptor) { - return createLineMarkerInfo(element, DescriptorRenderer.HTML.render(variableDescriptor)); - } - } - - if (element instanceof JetNamedFunction) { - JetNamedFunction jetFunction = (JetNamedFunction) element; - - final SimpleFunctionDescriptor functionDescriptor = bindingContext.get(BindingContext.FUNCTION, jetFunction); - if (functionDescriptor == null) return null; - final Set overriddenFunctions = functionDescriptor.getOverriddenDescriptors(); - Icon icon = isMember(functionDescriptor) ? (overriddenFunctions.isEmpty() ? PlatformIcons.METHOD_ICON : OVERRIDING_FUNCTION) : PlatformIcons.FUNCTION_ICON; - return new LineMarkerInfo( - jetFunction, jetFunction.getTextOffset(), icon, Pass.UPDATE_ALL, - new Function() { - @Override - public String fun(JetNamedFunction jetFunction) { - StringBuilder builder = new StringBuilder(); - builder.append(DescriptorRenderer.HTML.render(functionDescriptor)); - int overrideCount = overriddenFunctions.size(); - if (overrideCount >= 1) { - builder.append(" overrides ").append(DescriptorRenderer.HTML.render(overriddenFunctions.iterator().next())); - } - if (overrideCount > 1) { - int count = overrideCount - 1; - builder.append(" and ").append(count).append(" other function"); - if (count > 1) { - builder.append("s"); - } - } - - return builder.toString(); - } - }, - new GutterIconNavigationHandler() { - @Override - public void navigate(MouseEvent event, JetNamedFunction elt) { - if (overriddenFunctions.isEmpty()) return; - final List list = Lists.newArrayList(); - for (FunctionDescriptor overriddenFunction : overriddenFunctions) { - PsiElement declarationPsiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, overriddenFunction); - list.add(declarationPsiElement); - } - if (list.isEmpty()) { - String myEmptyText = "empty text"; - final JComponent renderer = HintUtil.createErrorLabel(myEmptyText); - final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(renderer, renderer).createPopup(); - if (event != null) { - popup.show(new RelativePoint(event)); - } - return; - } - if (list.size() == 1) { - PsiNavigateUtil.navigate(list.iterator().next()); - } - else { - final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilBase.toPsiElementArray(list), new DefaultPsiElementCellRenderer() { - @Override - public String getElementText(PsiElement element) { - if (element instanceof JetNamedFunction) { - JetNamedFunction function = (JetNamedFunction) element; - return DescriptorRenderer.HTML.render(bindingContext.get(BindingContext.FUNCTION, function)); - } - return super.getElementText(element); - } - }, DescriptorRenderer.HTML.render(functionDescriptor)); - if (event != null) { - popup.show(new RelativePoint(event)); - } - } - } - } - ); - } - - if (element instanceof JetNamespaceHeader) { - JetNamespaceHeader header = (JetNamespaceHeader) element; - if (header.getNameIdentifier() != null) { - return createLineMarkerInfo(header, - DescriptorRenderer.HTML.render(bindingContext.get(BindingContext.NAMESPACE, file))); - } - } - - if (element instanceof JetObjectDeclaration && !(element.getParent() instanceof JetExpression)) { - JetObjectDeclaration jetObjectDeclaration = (JetObjectDeclaration) element; - - return new LineMarkerInfo( - jetObjectDeclaration, jetObjectDeclaration.getTextOffset(), PlatformIcons.ANONYMOUS_CLASS_ICON, Pass.UPDATE_ALL, - new Function() { - @Override - public String fun(JetObjectDeclaration jetObjectDeclaration) { - ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, jetObjectDeclaration); - if (classDescriptor != null) { - return DescriptorRenderer.HTML.renderAsObject(classDescriptor); - } - return "<none>"; - } - }, - new GutterIconNavigationHandler() { - @Override - public void navigate(MouseEvent e, JetObjectDeclaration elt) { - } - } - ); - } - - return null; - } - - private LineMarkerInfo createLineMarkerInfo(T element, final String text) { - return new LineMarkerInfo( - element, element.getTextOffset(), PsiIconUtil.getProvidersIcon(element, Iconable.ICON_FLAG_CLOSED), Pass.UPDATE_ALL, - new Function() { + return new LineMarkerInfo( + jetFunction, jetFunction.getTextOffset(), OVERRIDING_FUNCTION, Pass.UPDATE_ALL, + new Function() { @Override - public String fun(T jetNamespace) { - return text; + public String fun(JetNamedFunction jetFunction) { + StringBuilder builder = new StringBuilder(); + builder.append(DescriptorRenderer.HTML.render(functionDescriptor)); + int overrideCount = overriddenFunctions.size(); + if (overrideCount >= 1) { + builder.append(" overrides ").append(DescriptorRenderer.HTML.render(overriddenFunctions.iterator().next())); + } + if (overrideCount > 1) { + int count = overrideCount - 1; + builder.append(" and ").append(count).append(" other function"); + if (count > 1) { + builder.append("s"); + } + } + + return builder.toString(); } }, - new GutterIconNavigationHandler() { + new GutterIconNavigationHandler() { @Override - public void navigate(MouseEvent e, T elt) { + public void navigate(MouseEvent event, JetNamedFunction elt) { + if (overriddenFunctions.isEmpty()) return; + final List list = Lists.newArrayList(); + for (FunctionDescriptor overriddenFunction : overriddenFunctions) { + PsiElement declarationPsiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, overriddenFunction); + list.add(declarationPsiElement); + } + if (list.isEmpty()) { + String myEmptyText = "empty text"; + final JComponent renderer = HintUtil.createErrorLabel(myEmptyText); + final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(renderer, renderer).createPopup(); + if (event != null) { + popup.show(new RelativePoint(event)); + } + return; + } + if (list.size() == 1) { + PsiNavigateUtil.navigate(list.iterator().next()); + } + else { + final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilBase.toPsiElementArray(list), new DefaultPsiElementCellRenderer() { + @Override + public String getElementText(PsiElement element) { + if (element instanceof JetNamedFunction) { + JetNamedFunction function = (JetNamedFunction) element; + return DescriptorRenderer.HTML.render(bindingContext.get(BindingContext.FUNCTION, function)); + } + return super.getElementText(element); + } + }, DescriptorRenderer.HTML.render(functionDescriptor)); + if (event != null) { + popup.show(new RelativePoint(event)); + } + } } } ); } - private boolean isMember(@NotNull SimpleFunctionDescriptor functionDescriptor) { - return functionDescriptor.getContainingDeclaration().getOriginal() instanceof ClassifierDescriptor; - } - @Override public void collectSlowLineMarkers(List elements, Collection result) { }