From 5d1a48831231824692389e7354562010dff426cf Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Thu, 16 Aug 2012 16:52:30 +0400 Subject: [PATCH] KT-1389 Ctrl-Alt-B on class declaration does not work - create a special renderer for showing JetLightClass in implementations list #KT-1389 In Progress --- idea/src/META-INF/plugin.xml | 1 + .../plugin/JetGotoTargetRenderProvider.java | 41 ++++++++++++++++ .../jetbrains/jet/plugin/JetIconProvider.java | 6 +++ .../presentation/JetClassPresenter.java | 4 +- .../JetLightClassListCellRenderer.java | 47 +++++++++++++++++++ 5 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 idea/src/org/jetbrains/jet/plugin/JetGotoTargetRenderProvider.java create mode 100644 idea/src/org/jetbrains/jet/plugin/presentation/JetLightClassListCellRenderer.java diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index d0dc9dcf748..4ecc3ed33ed 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -175,6 +175,7 @@ + diff --git a/idea/src/org/jetbrains/jet/plugin/JetGotoTargetRenderProvider.java b/idea/src/org/jetbrains/jet/plugin/JetGotoTargetRenderProvider.java new file mode 100644 index 00000000000..80fdb2c2669 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/JetGotoTargetRenderProvider.java @@ -0,0 +1,41 @@ +/* + * Copyright 2010-2012 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; + +import com.intellij.codeInsight.navigation.GotoTargetHandler; +import com.intellij.codeInsight.navigation.GotoTargetRendererProvider; +import com.intellij.ide.util.PsiElementListCellRenderer; +import com.intellij.psi.PsiElement; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.asJava.JetLightClass; +import org.jetbrains.jet.plugin.presentation.JetLightClassListCellRenderer; + +/** + * @author Nikolay Krasko + */ +public class JetGotoTargetRenderProvider implements GotoTargetRendererProvider { + @Nullable + @Override + public PsiElementListCellRenderer getRenderer(PsiElement element, GotoTargetHandler.GotoData gotoData) { + if (element instanceof JetLightClass) { + // Need to override default Java render + return new JetLightClassListCellRenderer(); + } + + return null; + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/JetIconProvider.java b/idea/src/org/jetbrains/jet/plugin/JetIconProvider.java index 3c6c5ba6227..305c5bd1a64 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetIconProvider.java +++ b/idea/src/org/jetbrains/jet/plugin/JetIconProvider.java @@ -26,6 +26,7 @@ import com.intellij.util.PlatformIcons; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.asJava.JetLightClass; import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lexer.JetTokens; @@ -90,6 +91,11 @@ public class JetIconProvider extends IconProvider { JetProperty property = (JetProperty)psiElement; return property.isVar() ? JetIcons.FIELD_VAR : JetIcons.FIELD_VAL; } + + if (psiElement instanceof JetLightClass) { + return JetIcons.CLASS; + } + return null; } diff --git a/idea/src/org/jetbrains/jet/plugin/presentation/JetClassPresenter.java b/idea/src/org/jetbrains/jet/plugin/presentation/JetClassPresenter.java index 37108920992..1b163ebbb2f 100644 --- a/idea/src/org/jetbrains/jet/plugin/presentation/JetClassPresenter.java +++ b/idea/src/org/jetbrains/jet/plugin/presentation/JetClassPresenter.java @@ -49,10 +49,10 @@ public class JetClassPresenter implements ItemPresentationProvider { public String getLocationString() { FqName name = JetPsiUtil.getFQName(item); if (name != null) { - return name.toString(); + return "(" + name.parent().toString() + ")"; } - return ""; + return null; } @Override diff --git a/idea/src/org/jetbrains/jet/plugin/presentation/JetLightClassListCellRenderer.java b/idea/src/org/jetbrains/jet/plugin/presentation/JetLightClassListCellRenderer.java new file mode 100644 index 00000000000..a119453db49 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/presentation/JetLightClassListCellRenderer.java @@ -0,0 +1,47 @@ +/* + * Copyright 2010-2012 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.presentation; + +import com.intellij.ide.util.PsiElementListCellRenderer; +import com.intellij.psi.presentation.java.ClassPresentationUtil; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.asJava.JetLightClass; + +/** + * @author Nikolay Krasko + */ +public class JetLightClassListCellRenderer extends PsiElementListCellRenderer { + @Override + public String getElementText(JetLightClass element) { + return ClassPresentationUtil.getNameForClass(element, false); + } + + @Override + protected String getContainerText(JetLightClass element, final String name) { + return getContainerTextStatic(element); + } + + @Nullable + public static String getContainerTextStatic(final JetLightClass element) { + return "(" + element.getFqName().parent() + ")"; + } + + @Override + protected int getIconFlags() { + return 0; + } +}