From b12de14482d635ff645558c6f924cf286b3a1a5f Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Thu, 8 Jun 2017 14:49:05 +0300 Subject: [PATCH] Refactor, extract some 'goto' related testing utils --- .../codeInsight/AbstractLineMarkersTest.kt | 4 +- .../navigation/AbstractKotlinGotoTest.java | 69 +--------------- .../kotlin/idea/navigation/GotoCheck.kt | 81 +++++++++++++++++++ .../idea/navigation/NavigationTestUtils.java | 2 +- .../BuiltInsReferenceResolverTest.java | 19 ++--- .../resolve/AbstractReferenceResolveTest.kt | 6 +- .../script/AbstractScriptConfigurationTest.kt | 7 +- .../jetbrains/kotlin/test/ReferenceUtils.java | 73 ----------------- .../kotlin/test/util/ReferenceUtils.kt | 62 ++++++++++++++ 9 files changed, 161 insertions(+), 162 deletions(-) create mode 100644 idea/tests/org/jetbrains/kotlin/idea/navigation/GotoCheck.kt delete mode 100644 idea/tests/org/jetbrains/kotlin/test/ReferenceUtils.java create mode 100644 idea/tests/org/jetbrains/kotlin/test/util/ReferenceUtils.kt diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractLineMarkersTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractLineMarkersTest.kt index c124dd5f994..ee70551c59a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractLineMarkersTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/AbstractLineMarkersTest.kt @@ -34,8 +34,8 @@ import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescrip import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.test.KotlinTestUtils -import org.jetbrains.kotlin.test.ReferenceUtils import org.jetbrains.kotlin.test.TagsTestDataUtil +import org.jetbrains.kotlin.test.util.renderAsGotoImplementation import org.junit.Assert import java.io.File @@ -114,7 +114,7 @@ abstract class AbstractLineMarkersTest : KotlinLightCodeInsightFixtureTestCase() val handler = navigateMarker.navigationHandler if (handler is TestableLineMarkerNavigator) { - val navigateElements = handler.getTargetsPopupDescriptor(navigateMarker.element)?.targets?.sortedBy { ReferenceUtils.renderAsGotoImplementation(it) } + val navigateElements = handler.getTargetsPopupDescriptor(navigateMarker.element)?.targets?.sortedBy { it.renderAsGotoImplementation() } val actualNavigationData = NavigationTestUtils.getNavigateElementsText(myFixture.project, navigateElements) UsefulTestCase.assertSameLines(getExpectedNavigationText(navigationComment), actualNavigationData) diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoTest.java b/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoTest.java index 786047569f1..c16e61fc5ff 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoTest.java @@ -16,39 +16,23 @@ package org.jetbrains.kotlin.idea.navigation; -import com.google.common.base.Function; -import com.google.common.collect.Lists; -import com.google.common.collect.Ordering; -import com.intellij.ide.util.gotoByName.FilteringGotoByModel; import com.intellij.ide.util.gotoByName.GotoClassModel2; import com.intellij.ide.util.gotoByName.GotoSymbolModel2; -import com.intellij.lang.Language; -import com.intellij.openapi.editor.Editor; -import com.intellij.psi.PsiElement; -import com.intellij.testFramework.UsefulTestCase; -import kotlin.collections.CollectionsKt; -import kotlin.jvm.functions.Function1; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase; -import org.jetbrains.kotlin.test.InTextDirectivesUtils; import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.ReferenceUtils; -import org.junit.Assert; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import static org.jetbrains.kotlin.idea.navigation.GotoCheck.checkGotoDirectives; public abstract class AbstractKotlinGotoTest extends KotlinLightCodeInsightFixtureTestCase { protected void doSymbolTest(String path) { myFixture.configureByFile(path); - assertGotoSymbol(new GotoSymbolModel2(getProject()), myFixture.getEditor()); + checkGotoDirectives(new GotoSymbolModel2(getProject()), myFixture.getEditor()); } protected void doClassTest(String path) { myFixture.configureByFile(path); - assertGotoSymbol(new GotoClassModel2(getProject()), myFixture.getEditor()); + checkGotoDirectives(new GotoClassModel2(getProject()), myFixture.getEditor()); } private String dirPath = null; @@ -75,51 +59,4 @@ public abstract class AbstractKotlinGotoTest extends KotlinLightCodeInsightFixtu protected String fileName() { return getTestName(true) + ".kt"; } - - private static void assertGotoSymbol(@NotNull FilteringGotoByModel model, @NotNull Editor editor) { - String documentText = editor.getDocument().getText(); - List searchTextList = InTextDirectivesUtils.findListWithPrefixes(documentText, "// SEARCH_TEXT:"); - Assert.assertFalse("There's no search text in test data file given. Use '// SEARCH_TEXT:' directive", - searchTextList.isEmpty()); - - List expectedReferences = CollectionsKt.map( - InTextDirectivesUtils.findLinesWithPrefixesRemoved(documentText, "// REF:"), - new Function1() { - @Override - public String invoke(String input) { - return input.trim(); - } - } - ); - boolean enableCheckbox = InTextDirectivesUtils.isDirectiveDefined(documentText, "// CHECK_BOX"); - - String searchText = searchTextList.get(0); - - List elementsByName = new ArrayList(); - - String[] names = model.getNames(enableCheckbox); - for (String name : names) { - if (name != null && name.startsWith(searchText)) { - elementsByName.addAll(Arrays.asList(model.getElementsByName(name, enableCheckbox, name + "*"))); - } - } - - List renderedElements = Lists.transform(elementsByName, new Function() { - @Override - public String apply(@Nullable Object element) { - Assert.assertNotNull(element); - Assert.assertTrue(element instanceof PsiElement); - return ReferenceUtils.renderAsGotoImplementation((PsiElement) element); - } - }); - - boolean inexactMatching = InTextDirectivesUtils.isDirectiveDefined(documentText, "// ALLOW_MORE_RESULTS"); - - if (inexactMatching) { - UsefulTestCase.assertContainsElements(renderedElements, expectedReferences); - } - else { - UsefulTestCase.assertOrderedEquals(Ordering.natural().sortedCopy(renderedElements), expectedReferences); - } - } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoCheck.kt b/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoCheck.kt new file mode 100644 index 00000000000..6f239dc1c45 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/GotoCheck.kt @@ -0,0 +1,81 @@ +/* + * Copyright 2010-2017 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.kotlin.idea.navigation + +import com.intellij.ide.util.gotoByName.FilteringGotoByModel +import com.intellij.lang.Language +import com.intellij.openapi.editor.Editor +import com.intellij.psi.PsiElement +import com.intellij.testFramework.UsefulTestCase +import org.jetbrains.kotlin.test.InTextDirectivesUtils +import org.jetbrains.kotlin.test.util.renderAsGotoImplementation +import org.jetbrains.kotlin.utils.sure +import org.junit.Assert +import kotlin.test.assertEquals + +object GotoCheck { + @JvmStatic @JvmOverloads + fun checkGotoDirectives(model: FilteringGotoByModel, editor: Editor, nonProjectSymbols: Boolean = false, checkNavigation: Boolean = false) { + val documentText = editor.document.text + val searchTextList = InTextDirectivesUtils.findListWithPrefixes(documentText, "// SEARCH_TEXT:") + Assert.assertFalse("There's no search text in test data file given. Use '// SEARCH_TEXT:' directive", + searchTextList.isEmpty()) + + val expectedReferences = InTextDirectivesUtils.findLinesWithPrefixesRemoved(documentText, "// REF:").map { input -> input.trim { it <= ' ' } } + val includeNonProjectSymbols = nonProjectSymbols || InTextDirectivesUtils.isDirectiveDefined(documentText, "// CHECK_BOX") + + val searchText = searchTextList.first() + + val foundSymbols = model.getNames(includeNonProjectSymbols).filter { it?.startsWith(searchText) ?: false }.flatMap { + model.getElementsByName(it, includeNonProjectSymbols, it + "*").toList() + } + + val inexactMatching = InTextDirectivesUtils.isDirectiveDefined(documentText, "// ALLOW_MORE_RESULTS") + val renderedSymbols = foundSymbols.map { (it as PsiElement).renderAsGotoImplementation() } + + if (checkNavigation && (expectedReferences.size != 1 || inexactMatching)) { + error("Cannot check navigation targets when multiple references are expected") + } + + if (inexactMatching) { + UsefulTestCase.assertContainsElements(renderedSymbols, expectedReferences) + } + else { + UsefulTestCase.assertOrderedEquals(renderedSymbols.sorted(), expectedReferences) + } + if (!checkNavigation) return + + assertNavigationElementMatches(foundSymbols.single() as PsiElement, documentText) + } + + @JvmStatic + fun assertNavigationElementMatches(resolved: PsiElement, textWithDirectives: String) { + val expectedBinaryFile = InTextDirectivesUtils.findStringWithPrefixes(textWithDirectives, "// BINARY:") + val expectedSourceFile = InTextDirectivesUtils.findStringWithPrefixes(textWithDirectives, "// SRC:") + assertEquals(expectedBinaryFile, getFileWithDir(resolved)) + val srcElement = resolved.navigationElement + Assert.assertNotEquals(srcElement, resolved) + assertEquals(expectedSourceFile, getFileWithDir(srcElement)) + } + + // TODO: move somewhere + fun getFileWithDir(resolved: PsiElement): String { + val targetFile = resolved.containingFile + val targetDir = targetFile.parent + return targetDir!!.name + "/" + targetFile.name + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/NavigationTestUtils.java b/idea/tests/org/jetbrains/kotlin/idea/navigation/NavigationTestUtils.java index cc50ff81fe1..5c2031c8bfe 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/NavigationTestUtils.java +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/NavigationTestUtils.java @@ -36,7 +36,7 @@ import junit.framework.TestCase; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.test.InTextDirectivesUtils; -import org.jetbrains.kotlin.test.ReferenceUtils; +import org.jetbrains.kotlin.test.util.ReferenceUtils; import org.junit.Assert; import java.util.*; diff --git a/idea/tests/org/jetbrains/kotlin/idea/references/BuiltInsReferenceResolverTest.java b/idea/tests/org/jetbrains/kotlin/idea/references/BuiltInsReferenceResolverTest.java index ee9182e33da..7be7080e468 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/references/BuiltInsReferenceResolverTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/references/BuiltInsReferenceResolverTest.java @@ -16,9 +16,7 @@ package org.jetbrains.kotlin.idea.references; -import com.intellij.psi.PsiDirectory; import com.intellij.psi.PsiElement; -import com.intellij.psi.PsiFile; import com.intellij.psi.PsiPolyVariantReference; import com.intellij.testFramework.LightProjectDescriptor; import org.jetbrains.annotations.NotNull; @@ -28,20 +26,18 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor; import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies; import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde; +import org.jetbrains.kotlin.idea.navigation.GotoCheck; import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase; import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources; import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.test.InTextDirectivesUtils; -import org.jetbrains.kotlin.test.ReferenceUtils; -import org.junit.Assert; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import static org.jetbrains.kotlin.test.ReferenceUtils.getFileWithDir; -import static org.jetbrains.kotlin.test.ReferenceUtils.renderAsGotoImplementation; +import static org.jetbrains.kotlin.test.util.ReferenceUtils.renderAsGotoImplementation; public class BuiltInsReferenceResolverTest extends KotlinLightCodeInsightFixtureTestCase { public void testAny() throws Exception { @@ -122,16 +118,11 @@ public class BuiltInsReferenceResolverTest extends KotlinLightCodeInsightFixture assertEquals(1, reference.multiResolve(false).length); String text = myFixture.getFile().getText(); - String expectedBinaryFile = InTextDirectivesUtils.findStringWithPrefixes(text, "// BINARY:"); - String expectedSourceFile = InTextDirectivesUtils.findStringWithPrefixes(text, "// SRC:"); - String expectedTarget = InTextDirectivesUtils.findStringWithPrefixes(text, "// TARGET:"); - assertEquals(expectedBinaryFile, getFileWithDir(resolved)); + String expectedTarget = InTextDirectivesUtils.findStringWithPrefixes(text, "// TARGET:"); assertEquals(expectedTarget, renderAsGotoImplementation(resolved)); - PsiElement srcElement = resolved.getNavigationElement(); - Assert.assertNotEquals(srcElement, resolved); - assertEquals(expectedSourceFile, getFileWithDir(srcElement)); - assertEquals(expectedTarget, renderAsGotoImplementation(srcElement)); + + GotoCheck.assertNavigationElementMatches(resolved, text); } @Override diff --git a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveTest.kt b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveTest.kt index 25a50394c8a..a295326d041 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/resolve/AbstractReferenceResolveTest.kt @@ -28,7 +28,7 @@ import org.jetbrains.kotlin.idea.test.KotlinLightPlatformCodeInsightFixtureTestC import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.test.InTextDirectivesUtils -import org.jetbrains.kotlin.test.ReferenceUtils +import org.jetbrains.kotlin.test.util.renderAsGotoImplementation import org.junit.Assert import kotlin.test.assertTrue @@ -82,7 +82,7 @@ abstract class AbstractReferenceResolveTest : KotlinLightPlatformCodeInsightFixt val actualResolvedTo = Lists.newArrayList() for (result in results) { - actualResolvedTo.add(ReferenceUtils.renderAsGotoImplementation(result.element!!)) + actualResolvedTo.add(result.element!!.renderAsGotoImplementation()) } UsefulTestCase.assertOrderedEquals("Not matching for reference #$index", actualResolvedTo.sorted(), expectedReferences.sorted()) @@ -138,7 +138,7 @@ abstract class AbstractReferenceResolveTest : KotlinLightPlatformCodeInsightFixt val resolvedTo = psiReference.resolve() if (resolvedTo != null) { checkResolvedTo(resolvedTo) - val resolvedToElementStr = replacePlaceholders(ReferenceUtils.renderAsGotoImplementation(resolvedTo)) + val resolvedToElementStr = replacePlaceholders(resolvedTo.renderAsGotoImplementation()) assertEquals("Found reference to '$resolvedToElementStr', but '$expectedString' was expected", expectedString, resolvedToElementStr) } else { diff --git a/idea/tests/org/jetbrains/kotlin/idea/script/AbstractScriptConfigurationTest.kt b/idea/tests/org/jetbrains/kotlin/idea/script/AbstractScriptConfigurationTest.kt index 33bf0b5b57a..e776b5a0dfe 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/script/AbstractScriptConfigurationTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/script/AbstractScriptConfigurationTest.kt @@ -25,12 +25,13 @@ import com.intellij.testFramework.PlatformTestUtil import org.jetbrains.kotlin.checkers.AbstractPsiCheckerTest import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime import org.jetbrains.kotlin.idea.core.script.KotlinScriptConfigurationManager +import org.jetbrains.kotlin.idea.navigation.GotoCheck import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor import org.jetbrains.kotlin.script.ScriptTemplatesProvider import org.jetbrains.kotlin.test.InTextDirectivesUtils import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.MockLibraryUtil -import org.jetbrains.kotlin.test.ReferenceUtils +import org.jetbrains.kotlin.test.util.renderAsGotoImplementation import org.jetbrains.kotlin.utils.PathUtil import org.junit.Assert import java.io.File @@ -56,12 +57,12 @@ abstract class AbstractScriptConfigurationNavigationTest : AbstractScriptConfigu val resolved = reference.resolve()!!.navigationElement!! val expectedReference = InTextDirectivesUtils.findStringWithPrefixes(myFixture.file.text, "// REF:") - val actualReference = ReferenceUtils.renderAsGotoImplementation(resolved) + val actualReference = resolved.renderAsGotoImplementation() Assert.assertEquals(expectedReference, actualReference) val expectedFile = InTextDirectivesUtils.findStringWithPrefixes(myFixture.file.text, "// FILE:") - val actualFile = ReferenceUtils.getFileWithDir(resolved) + val actualFile = GotoCheck.getFileWithDir(resolved) Assert.assertEquals(expectedFile, actualFile) } diff --git a/idea/tests/org/jetbrains/kotlin/test/ReferenceUtils.java b/idea/tests/org/jetbrains/kotlin/test/ReferenceUtils.java deleted file mode 100644 index 4b6d3a6036a..00000000000 --- a/idea/tests/org/jetbrains/kotlin/test/ReferenceUtils.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2010-2015 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.kotlin.test; - -import com.intellij.navigation.ItemPresentation; -import com.intellij.navigation.NavigationItem; -import com.intellij.psi.*; -import com.intellij.psi.util.PsiTreeUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.psi.KtClass; -import org.jetbrains.kotlin.psi.KtObjectDeclaration; -import org.jetbrains.kotlin.psi.KtStringTemplateExpression; -import org.jetbrains.kotlin.psi.psiUtil.KtPsiUtilKt; -import org.junit.Assert; - -public final class ReferenceUtils { - private ReferenceUtils() { - } - - public static String renderAsGotoImplementation(@NotNull PsiElement element) { - PsiElement navigationElement = element.getNavigationElement(); - - if (navigationElement instanceof KtObjectDeclaration && ((KtObjectDeclaration) navigationElement).isCompanion()) { - //default presenter return null for companion object - KtClass containingClass = PsiTreeUtil.getParentOfType(navigationElement, KtClass.class); - assert containingClass != null; - return "companion object of " + renderAsGotoImplementation(containingClass); - } - - if (navigationElement instanceof KtStringTemplateExpression) { - return KtPsiUtilKt.getPlainContent((KtStringTemplateExpression) navigationElement); - } - - Assert.assertTrue(navigationElement instanceof NavigationItem); - ItemPresentation presentation = ((NavigationItem) navigationElement).getPresentation(); - - if (presentation == null) { - String elementText = element.getText(); - return elementText != null ? elementText : navigationElement.getText(); - } - - String presentableText = presentation.getPresentableText(); - String locationString = presentation.getLocationString(); - if (locationString == null && element.getParent() instanceof PsiAnonymousClass) { - locationString = ""; - } - return locationString == null || navigationElement instanceof PsiPackage - // for PsiPackage, presentableText is FQ name of current package - ? presentableText - : locationString + "." + presentableText; - } - - @NotNull - public static String getFileWithDir(@NotNull PsiElement resolved) { - PsiFile targetFile = resolved.getContainingFile(); - PsiDirectory targetDir = targetFile.getParent(); - return targetDir.getName() + "/" + targetFile.getName(); - } -} diff --git a/idea/tests/org/jetbrains/kotlin/test/util/ReferenceUtils.kt b/idea/tests/org/jetbrains/kotlin/test/util/ReferenceUtils.kt new file mode 100644 index 00000000000..ebf86eae50b --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/test/util/ReferenceUtils.kt @@ -0,0 +1,62 @@ +/* + * Copyright 2010-2017 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. + */ + +@file:JvmName("ReferenceUtils") + +package org.jetbrains.kotlin.test.util + +import com.intellij.navigation.NavigationItem +import com.intellij.psi.PsiAnonymousClass +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiPackage +import com.intellij.psi.util.PsiTreeUtil +import org.jetbrains.kotlin.psi.KtClass +import org.jetbrains.kotlin.psi.KtObjectDeclaration +import org.jetbrains.kotlin.psi.KtStringTemplateExpression +import org.jetbrains.kotlin.psi.psiUtil.plainContent +import org.junit.Assert + +fun PsiElement.renderAsGotoImplementation(): String { + val navigationElement = navigationElement + + if (navigationElement is KtObjectDeclaration && navigationElement.isCompanion()) { + //default presenter return null for companion object + val containingClass = PsiTreeUtil.getParentOfType(navigationElement, KtClass::class.java)!! + return "companion object of " + containingClass.renderAsGotoImplementation() + } + + if (navigationElement is KtStringTemplateExpression) { + return navigationElement.plainContent + } + + Assert.assertTrue(navigationElement is NavigationItem) + val presentation = (navigationElement as NavigationItem).presentation + + if (presentation == null) { + val elementText = text + return elementText ?: navigationElement.text + } + + val presentableText = presentation.presentableText + var locationString = presentation.locationString + if (locationString == null && parent is PsiAnonymousClass) { + locationString = "" + } + return if (locationString == null || navigationElement is PsiPackage) + presentableText!! + else + locationString + "." + presentableText// for PsiPackage, presentableText is FQ name of current package +} \ No newline at end of file