Tune location string in structure view

This commit is contained in:
Nikolay Krasko
2014-05-29 14:40:01 +04:00
parent 3797210b43
commit 582c5874b7
9 changed files with 184 additions and 18 deletions
@@ -33,13 +33,15 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.psi.JetClassInitializer;
import org.jetbrains.jet.lang.psi.JetModifierListOwner;
import org.jetbrains.jet.lang.psi.JetPsiUtil;
import org.jetbrains.jet.lang.resolve.OverrideResolver;
import org.jetbrains.jet.plugin.JetDescriptorIconProvider;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import javax.swing.*;
import java.util.Set;
import static org.jetbrains.jet.lang.resolve.OverrideResolver.filterOutOverridden;
import static org.jetbrains.jet.lang.resolve.OverrideResolver.getAllOverriddenDeclarations;
import static org.jetbrains.jet.renderer.DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES;
class KotlinStructureElementPresentation implements ColoredItemPresentation, LocationPresentation {
private final TextAttributesKey attributesKey;
private final String elementText;
@@ -55,7 +57,7 @@ class KotlinStructureElementPresentation implements ColoredItemPresentation, Loc
this.isInherited = isInherited;
attributesKey = getElementAttributesKey(isInherited, navigatablePsiElement);
elementText = getElementText(navigatablePsiElement, descriptor);
locationString = isInherited ? getElementLocationString(descriptor) : null;
locationString = getElementLocationString(isInherited, descriptor);
icon = getElementIcon(navigatablePsiElement, descriptor);
}
@@ -118,7 +120,7 @@ class KotlinStructureElementPresentation implements ColoredItemPresentation, Loc
@Nullable
private static String getElementText(@NotNull NavigatablePsiElement navigatablePsiElement, @Nullable DeclarationDescriptor descriptor) {
if (descriptor != null) {
return DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES.render(descriptor);
return ONLY_NAMES_WITH_SHORT_TYPES.render(descriptor);
}
String text = navigatablePsiElement.getName();
@@ -134,20 +136,22 @@ class KotlinStructureElementPresentation implements ColoredItemPresentation, Loc
}
@Nullable
private static String getElementLocationString(@Nullable DeclarationDescriptor descriptor) {
if (descriptor instanceof CallableMemberDescriptor) {
Set<CallableMemberDescriptor>
baseCallableDescriptors = OverrideResolver.getDeepestSuperDeclarations((CallableMemberDescriptor) descriptor);
CallableMemberDescriptor first = ContainerUtil.getFirstItem(baseCallableDescriptors);
if (first != null) {
DeclarationDescriptor typeDescriptor = first.getContainingDeclaration();
private static String getElementLocationString(boolean isInherited, @Nullable DeclarationDescriptor descriptor) {
if (!(isInherited && descriptor instanceof CallableMemberDescriptor)) return null;
String typeName = DescriptorRenderer.ONLY_NAMES_WITH_SHORT_TYPES.render(typeDescriptor);
return withRightArrow(typeName);
}
CallableMemberDescriptor callableMemberDescriptor = (CallableMemberDescriptor) descriptor;
if (callableMemberDescriptor.getKind() == CallableMemberDescriptor.Kind.DECLARATION) {
return withRightArrow(ONLY_NAMES_WITH_SHORT_TYPES.render(callableMemberDescriptor.getContainingDeclaration()));
}
return null;
Set<CallableMemberDescriptor> overridingDescriptors = filterOutOverridden(getAllOverriddenDeclarations(callableMemberDescriptor));
CallableMemberDescriptor firstOverriding = ContainerUtil.getFirstItem(overridingDescriptors);
if (firstOverriding != null) {
return withRightArrow(ONLY_NAMES_WITH_SHORT_TYPES.render(firstOverriding.getContainingDeclaration()));
}
throw new IllegalStateException("At least one element should be returned");
}
private static String withRightArrow(String str) {
@@ -0,0 +1,62 @@
trait First {
fun foo123()
fun foo12_()
fun foo1_3()
fun foo_23()
val bar123: String
val bar12_: String
val bar1_3: String
val bar_23: String
fun foo1__()
fun foo_2_()
fun foo__3()
val bar1__: String
val bar_2_: String
val bar__3: String
fun foo___()
val bar___: String
}
abstract class A1 : First {
override fun foo123() {}
override fun foo12_() {}
override fun foo1_3() {}
override val bar123 = "test"
override val bar12_ = "test"
override val bar1_3 = "test"
override fun foo1__() {}
override val bar1__ = "test"
}
abstract class A2 : A1() {
override fun foo123() {}
override fun foo12_() {}
override fun foo_23() {}
override val bar123 = "test"
override val bar12_ = "test"
override val bar_23 = "test"
override fun foo_2_() {}
override val bar_2_ = "test"
}
open class A3 : A2() {
override fun foo123() {}
override fun foo1_3() {}
override fun foo_23() {}
override val bar123 = "test"
override val bar1_3 = "test"
override val bar_23 = "test"
override fun foo__3() {}
override val bar__3 = "test"
}
@@ -0,0 +1,21 @@
-CheckLocationForKotlin.kt
-Third
bar123: String location=→A3
bar12_: String location=→A2
bar1_3: String location=→A3
bar1__: String location=→A1
bar_23: String location=→A3
bar_2_: String location=→A2
bar__3: String location=→A3
bar___: String location=→First
equals(Any?): Boolean location=→Any
foo123(): Unit location=→A3
foo12_(): Unit location=→A2
foo1_3(): Unit location=→A3
foo1__(): Unit location=→A1
foo_23(): Unit location=→A3
foo_2_(): Unit location=→A2
foo__3(): Unit location=→A3
foo___(): Unit location=→First
hashCode(): Int location=→Any
toString(): String location=→Any
@@ -0,0 +1,5 @@
class Third : A3() {
}
// WITH_INHERITED
@@ -0,0 +1,40 @@
public class JavaClass {
public interface First {
void foo123();
void foo12_();
void foo1_3();
void foo_23();
void foo1__();
void foo_2_();
void foo__3();
void foo___();
}
public static abstract class A1 implements First {
@Override public void foo123() {}
@Override public void foo12_() {}
@Override public void foo1_3() {}
@Override public void foo1__() {}
}
public static abstract class A2 extends A1 {
@Override public void foo123() {}
@Override public void foo12_() {}
@Override public void foo_23() {}
@Override public void foo_2_() {}
}
public static class A3 extends A2 {
@Override public void foo123() {}
@Override public void foo1_3() {}
@Override public void foo_23() {}
@Override public void foo__3() {}
// @Override public void foo___() {} // Removed intentionally
}
}
@@ -0,0 +1,21 @@
-CheckMemberLocationForJava.kt
-Some
clone(): Any location=→Object
equals(Any?): Boolean location=→Object
finalize(): Unit location=→Object
foo123(): Unit location=→A3
foo12_(): Unit location=→A2
foo1_3(): Unit location=→A3
foo1__(): Unit location=→A1
foo_23(): Unit location=→A3
foo_2_(): Unit location=→A2
foo__3(): Unit location=→A3
foo___(): Unit location=→First
getClass(): Class<out Any?> location=→Object
hashCode(): Int location=→Object
notify(): Unit location=→Object
notifyAll(): Unit location=→Object
toString(): String location=→Object
wait(): Unit location=→Object
wait(Long): Unit location=→Object
wait(Long, Int): Unit location=→Object
@@ -0,0 +1,3 @@
class Some: JavaClass.A3()
// WITH_INHERITED
@@ -2,14 +2,14 @@
-InheritedJavaMembers
call(): String? location=→Callable
clone(): Any location=→Object
equals(Any?): Boolean location=→Any
equals(Any?): Boolean location=→Object
finalize(): Unit location=→Object
getClass(): Class<out Any?> location=→Object
hashCode(): Int location=→Any
hashCode(): Int location=→Object
notify(): Unit location=→Object
notifyAll(): Unit location=→Object
test(): Unit
toString(): String location=→Any
toString(): String location=→Object
wait(): Unit location=→Object
wait(Long): Unit location=→Object
wait(Long, Int): Unit location=→Object
@@ -36,6 +36,16 @@ public class KotlinFileStructureTestGenerated extends AbstractKotlinFileStructur
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/structureView/fileStructure"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
}
@TestMetadata("CheckLocationForKotlin.kt")
public void testCheckLocationForKotlin() throws Exception {
doTest("idea/testData/structureView/fileStructure/CheckLocationForKotlin.kt");
}
@TestMetadata("CheckMemberLocationForJava.kt")
public void testCheckMemberLocationForJava() throws Exception {
doTest("idea/testData/structureView/fileStructure/CheckMemberLocationForJava.kt");
}
@TestMetadata("DoNotShowParentsInLocationJava.kt")
public void testDoNotShowParentsInLocationJava() throws Exception {
doTest("idea/testData/structureView/fileStructure/DoNotShowParentsInLocationJava.kt");