Refactoring: move utility methods to idea module
This commit is contained in:
@@ -16,38 +16,19 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.util
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
|
||||
import com.intellij.util.SmartFMap
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtPackageDirective
|
||||
import org.jetbrains.kotlin.psi.KtTreeVisitorVoid
|
||||
import java.io.File
|
||||
|
||||
fun String.trimTrailingWhitespacesAndAddNewlineAtEOF(): String =
|
||||
this.split('\n').map { it.trimEnd() }.joinToString(separator = "\n").let {
|
||||
result -> if (result.endsWith("\n")) result else result + "\n"
|
||||
}
|
||||
|
||||
fun CodeInsightTestFixture.configureWithExtraFileAbs(path: String, vararg extraNameParts: String) {
|
||||
configureWithExtraFile(path, *extraNameParts, relativePaths = false)
|
||||
}
|
||||
|
||||
fun CodeInsightTestFixture.configureWithExtraFile(path: String, vararg extraNameParts: String = arrayOf(".Data"), relativePaths: Boolean = false) {
|
||||
fun String.toFile(): File = if (relativePaths) File(testDataPath, this) else File(this)
|
||||
|
||||
val noExtensionPath = FileUtil.getNameWithoutExtension(path)
|
||||
val extensions = arrayOf("kt", "java")
|
||||
val extraPaths: List<String> = extraNameParts
|
||||
.flatMap { extensions.map { ext -> "$noExtensionPath$it.$ext" } }
|
||||
.filter { it.toFile().exists() }
|
||||
|
||||
configureByFiles(*(listOf(path) + extraPaths).toTypedArray())
|
||||
}
|
||||
|
||||
fun PsiFile.findElementByCommentPrefix(commentText: String): PsiElement? =
|
||||
findElementsByCommentPrefix(commentText).keys.singleOrNull()
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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.completion.test
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture
|
||||
import java.io.File
|
||||
|
||||
fun CodeInsightTestFixture.configureWithExtraFileAbs(path: String, vararg extraNameParts: String) {
|
||||
configureWithExtraFile(path, *extraNameParts, relativePaths = false)
|
||||
}
|
||||
|
||||
fun CodeInsightTestFixture.configureWithExtraFile(path: String, vararg extraNameParts: String = arrayOf(".Data"), relativePaths: Boolean = false) {
|
||||
fun String.toFile(): File = if (relativePaths) File(testDataPath, this) else File(this)
|
||||
|
||||
val noExtensionPath = FileUtil.getNameWithoutExtension(path)
|
||||
val extensions = arrayOf("kt", "java")
|
||||
val extraPaths: List<String> = extraNameParts
|
||||
.flatMap { extensions.map { ext -> "$noExtensionPath$it.$ext" } }
|
||||
.filter { it.toFile().exists() }
|
||||
|
||||
configureByFiles(*(listOf(path) + extraPaths).toTypedArray())
|
||||
}
|
||||
+1
-1
@@ -17,13 +17,13 @@
|
||||
package org.jetbrains.kotlin.idea.completion.test.weighers
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionType
|
||||
import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile
|
||||
import org.jetbrains.kotlin.idea.completion.test.COMPLETION_TEST_DATA_BASE_PATH
|
||||
import org.jetbrains.kotlin.idea.completion.test.RELATIVE_COMPLETION_TEST_DATA_BASE_PATH
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
||||
import org.jetbrains.kotlin.test.util.configureWithExtraFile
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
|
||||
|
||||
+2
-2
@@ -24,17 +24,17 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.idea.completion.test.IdeaTestUtilsKt;
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources;
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
||||
import org.jetbrains.kotlin.test.util.JetTestUtilsKt;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractQuickDocProviderTest extends KotlinLightCodeInsightFixtureTestCase {
|
||||
public void doTest(@NotNull String path) throws Exception {
|
||||
JetTestUtilsKt.configureWithExtraFileAbs(myFixture, path, "_Data");
|
||||
IdeaTestUtilsKt.configureWithExtraFileAbs(myFixture, path, "_Data");
|
||||
|
||||
PsiElement element = myFixture.getFile().findElementAt(myFixture.getEditor().getCaretModel().getOffset());
|
||||
assertNotNull("Can't find element at caret in file: " + path, element);
|
||||
|
||||
@@ -22,12 +22,12 @@ import com.intellij.psi.PsiReference
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import com.intellij.util.PathUtil
|
||||
import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightPlatformCodeInsightFixtureTestCase
|
||||
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.configureWithExtraFile
|
||||
import org.junit.Assert
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
|
||||
+1
-1
@@ -23,12 +23,12 @@ import com.intellij.openapi.ui.Queryable.PrintInfo
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.ui.treeStructure.filtered.FilteringTreeStructure
|
||||
import com.intellij.util.ui.tree.TreeUtil
|
||||
import org.jetbrains.kotlin.idea.completion.test.configureWithExtraFile
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
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.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.util.configureWithExtraFile
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractKotlinFileStructureTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
|
||||
Reference in New Issue
Block a user