Fix broken NavBar for 201
^KT-38466 Fixed ^KT-38260 Fixed
This commit is contained in:
committed by
igoriakovlev
parent
246c68b0a9
commit
2ef46b586d
@@ -104,6 +104,7 @@ import org.jetbrains.kotlin.idea.kdoc.AbstractKDocTypingTest
|
||||
import org.jetbrains.kotlin.idea.maven.AbstractKotlinMavenInspectionTest
|
||||
import org.jetbrains.kotlin.idea.maven.configuration.AbstractMavenConfigureProjectByChangingFileTest
|
||||
import org.jetbrains.kotlin.idea.navigation.*
|
||||
import org.jetbrains.kotlin.idea.navigationToolbar.AbstractKotlinNavBarTest
|
||||
import org.jetbrains.kotlin.idea.parameterInfo.AbstractParameterInfoTest
|
||||
import org.jetbrains.kotlin.idea.perf.*
|
||||
import org.jetbrains.kotlin.idea.quickfix.AbstractQuickFixMultiFileTest
|
||||
@@ -902,6 +903,10 @@ fun main() {
|
||||
testClass<AbstractSlicerMultiplatformTest> {
|
||||
model("slicer/mpp", recursive = false, extension = null)
|
||||
}
|
||||
|
||||
testClass<AbstractKotlinNavBarTest> {
|
||||
model("navigationToolbar", recursive = false)
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("idea/idea-fir/tests", "idea/testData") {
|
||||
|
||||
+2
-2
@@ -29,8 +29,8 @@ class KotlinStructureViewModel(ktFile: KtFile, editor: Editor?) :
|
||||
override fun isSuitable(element: PsiElement?): Boolean = element is KtDeclaration &&
|
||||
element !is KtPropertyAccessor &&
|
||||
element !is KtFunctionLiteral &&
|
||||
!(element is KtProperty && element.containingClassOrObject !is KtNamedDeclaration) &&
|
||||
!(element is KtFunction && element.containingClassOrObject !is KtNamedDeclaration)
|
||||
!(element is KtProperty && element.parent !is KtFile && element.containingClassOrObject !is KtNamedDeclaration) &&
|
||||
!(element is KtFunction && element.parent !is KtFile && element.containingClassOrObject !is KtNamedDeclaration)
|
||||
|
||||
override fun getNodeProviders() = NODE_PROVIDERS
|
||||
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ package org.jetbrains.kotlin.idea.navigationToolbar
|
||||
import com.intellij.ide.navigationToolbar.AbstractNavBarModelExtension
|
||||
import com.intellij.psi.PsiElement
|
||||
|
||||
// FIX ME WHEN BUNCH 201 REMOVED
|
||||
// FIX ME WHEN BUNCH 193 REMOVED
|
||||
abstract class AbstractNavBarModelExtensionCompatBase : AbstractNavBarModelExtension() {
|
||||
|
||||
protected abstract fun adjustElementImpl(psiElement: PsiElement?): PsiElement?
|
||||
|
||||
+10
-1
@@ -8,9 +8,11 @@ package org.jetbrains.kotlin.idea.navigationToolbar
|
||||
import com.intellij.ide.navigationToolbar.StructureAwareNavBarModelExtension
|
||||
import com.intellij.lang.Language
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.idea.KotlinIconProvider
|
||||
import org.jetbrains.kotlin.idea.KotlinLanguage
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
// FIX ME WHEN BUNCH 201 REMOVED
|
||||
// FIX ME WHEN BUNCH 193 REMOVED
|
||||
abstract class AbstractNavBarModelExtensionCompatBase : StructureAwareNavBarModelExtension() {
|
||||
|
||||
protected abstract fun adjustElementImpl(psiElement: PsiElement?): PsiElement?
|
||||
@@ -20,4 +22,11 @@ abstract class AbstractNavBarModelExtensionCompatBase : StructureAwareNavBarMode
|
||||
|
||||
override val language: Language
|
||||
get() = KotlinLanguage.INSTANCE
|
||||
|
||||
override fun acceptParentFromModel(psiElement: PsiElement?): Boolean {
|
||||
if (psiElement is KtFile) {
|
||||
return KotlinIconProvider.getSingleClass(psiElement) == null
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,14 @@ import org.jetbrains.kotlin.idea.projectView.KtDeclarationTreeNode.Companion.try
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
|
||||
// FIX ME WHEN BUNCH 201 REMOVED
|
||||
class KotlinNavBarModelExtension : AbstractNavBarModelExtensionCompatBase() {
|
||||
override fun getPresentableText(item: Any?): String? =
|
||||
(item as? KtDeclaration)?.let { tryGetRepresentableText(it, it.project) }
|
||||
|
||||
override fun adjustElementImpl(psiElement: PsiElement?): PsiElement? {
|
||||
if (psiElement is KtDeclaration) {
|
||||
return psiElement
|
||||
}
|
||||
val containingFile = psiElement?.containingFile as? KtFile ?: return psiElement
|
||||
if (containingFile.isScript()) return psiElement
|
||||
return KotlinIconProvider.getSingleClass(containingFile) ?: psiElement
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// NAV_BAR_ITEMS: src, ClassProperty
|
||||
|
||||
class ClassProperty {
|
||||
val foo: Int
|
||||
get() {
|
||||
return 42<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// NAV_BAR_ITEMS: src, ClassProperty, foo: Int
|
||||
|
||||
class ClassProperty {
|
||||
val foo: Int
|
||||
get() {
|
||||
return 42<caret>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// NAV_BAR_ITEMS: src, MethodInClass
|
||||
|
||||
class MethodInClass {
|
||||
fun foo() { <caret> }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// NAV_BAR_ITEMS: src, MethodInClass, foo()
|
||||
|
||||
class MethodInClass {
|
||||
fun foo() { <caret> }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// NAV_BAR_ITEMS: src, SeveralClassesInFile.kt
|
||||
|
||||
class Foo {
|
||||
|
||||
}
|
||||
|
||||
class SeveralClassesInFile {
|
||||
<caret>
|
||||
}
|
||||
|
||||
fun method() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// NAV_BAR_ITEMS: src, SeveralClassesInFile.kt, SeveralClassesInFile
|
||||
|
||||
class Foo {
|
||||
|
||||
}
|
||||
|
||||
class SeveralClassesInFile {
|
||||
<caret>
|
||||
}
|
||||
|
||||
fun method() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// NAV_BAR_ITEMS: src, fileNameDoesntMatchClassName.kt
|
||||
|
||||
class Foo {
|
||||
fun bar() { <caret> }
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// NAV_BAR_ITEMS: src, fileNameDoesntMatchClassName.kt, Foo, bar()
|
||||
|
||||
class Foo {
|
||||
fun bar() { <caret> }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// NAV_BAR_ITEMS: src, topLevelFunction.kt
|
||||
|
||||
fun foo() {
|
||||
val bar = <caret>"string"
|
||||
}
|
||||
|
||||
class SomeClass {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// NAV_BAR_ITEMS: src, topLevelFunction.kt, foo()
|
||||
|
||||
fun foo() {
|
||||
val bar = <caret>"string"
|
||||
}
|
||||
|
||||
class SomeClass {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// NAV_BAR_ITEMS: src, topLevelProperty.kt
|
||||
|
||||
val foo: Int
|
||||
get() {
|
||||
return 1<caret>
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// NAV_BAR_ITEMS: src, topLevelProperty.kt, foo: Int
|
||||
|
||||
val foo: Int
|
||||
get() {
|
||||
return 1<caret>
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.navigationToolbar
|
||||
|
||||
import com.intellij.ide.navigationToolbar.NavBarModel
|
||||
import com.intellij.ide.navigationToolbar.NavBarModelExtension
|
||||
import com.intellij.ide.navigationToolbar.NavBarPresentation
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.ex.EditorEx
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
|
||||
|
||||
abstract class AbstractKotlinNavBarTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
|
||||
// inspired by: com.intellij.ide.navigationToolbar.JavaNavBarTest#assertNavBarModel
|
||||
protected fun doTest(testPath: String) {
|
||||
val psiFile = myFixture.configureByFile(testDataFile().name)
|
||||
val model = NavBarModel(myFixture.project)
|
||||
|
||||
model::class.java.getDeclaredMethod("updateModel", DataContext::class.java)
|
||||
.apply { isAccessible = true }
|
||||
.invoke(model, (myFixture.editor as EditorEx).dataContext)
|
||||
|
||||
val actualItems = (0 until model.size()).map {
|
||||
NavBarPresentation.calcPresentableText(model[it])
|
||||
}
|
||||
val expectedItems = InTextDirectivesUtils.findListWithPrefixes(psiFile.text, "// NAV_BAR_ITEMS:")
|
||||
assertOrderedEquals(actualItems, expectedItems)
|
||||
}
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.navigationToolbar
|
||||
|
||||
import com.intellij.ide.navigationToolbar.NavBarModel
|
||||
import com.intellij.ide.navigationToolbar.NavBarModelExtension
|
||||
import com.intellij.ide.navigationToolbar.NavBarPresentation
|
||||
import com.intellij.openapi.actionSystem.DataContext
|
||||
import com.intellij.openapi.editor.ex.EditorEx
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
|
||||
|
||||
abstract class AbstractKotlinNavBarTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
|
||||
// inspired by: com.intellij.ide.navigationToolbar.JavaNavBarTest#assertNavBarModel
|
||||
protected fun doTest(testPath: String) {
|
||||
val psiFile = myFixture.configureByFile(testDataFile().name)
|
||||
val model = NavBarModel(myFixture.project)
|
||||
|
||||
model::class.java.getDeclaredMethod("updateModel", DataContext::class.java)
|
||||
.apply { isAccessible = true }
|
||||
.invoke(model, (myFixture.editor as EditorEx).dataContext)
|
||||
|
||||
val actualItems = (0 until model.size()).map {
|
||||
NavBarPresentation.calcPresentableText(model[it], false)
|
||||
}
|
||||
val expectedItems = InTextDirectivesUtils.findListWithPrefixes(psiFile.text, "// NAV_BAR_ITEMS:")
|
||||
assertOrderedEquals(actualItems, expectedItems)
|
||||
}
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.navigationToolbar;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/navigationToolbar")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class KotlinNavBarTestGenerated extends AbstractKotlinNavBarTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInNavigationToolbar() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/navigationToolbar"), Pattern.compile("^(.+)\\.kt$"), null, false);
|
||||
}
|
||||
|
||||
@TestMetadata("ClassProperty.kt")
|
||||
public void testClassProperty() throws Exception {
|
||||
runTest("idea/testData/navigationToolbar/ClassProperty.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("fileNameDoesntMatchClassName.kt")
|
||||
public void testFileNameDoesntMatchClassName() throws Exception {
|
||||
runTest("idea/testData/navigationToolbar/fileNameDoesntMatchClassName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("MethodInClass.kt")
|
||||
public void testMethodInClass() throws Exception {
|
||||
runTest("idea/testData/navigationToolbar/MethodInClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("SeveralClassesInFile.kt")
|
||||
public void testSeveralClassesInFile() throws Exception {
|
||||
runTest("idea/testData/navigationToolbar/SeveralClassesInFile.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelFunction.kt")
|
||||
public void testTopLevelFunction() throws Exception {
|
||||
runTest("idea/testData/navigationToolbar/topLevelFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("topLevelProperty.kt")
|
||||
public void testTopLevelProperty() throws Exception {
|
||||
runTest("idea/testData/navigationToolbar/topLevelProperty.kt");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user