Cleanup 192 patchset files (KTI-315)

This commit is contained in:
Yunir Salimzyanov
2020-08-13 19:00:06 +03:00
parent 73aa21aab6
commit 42da9e62db
126 changed files with 0 additions and 11671 deletions
@@ -1,61 +0,0 @@
/*
* Copyright 2010-2019 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
import com.intellij.openapi.util.io.FileUtil
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.descriptors.PackageViewDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfoAfter
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue
import org.jetbrains.kotlin.resolve.calls.smartcasts.IdentifierInfo
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
import org.jetbrains.kotlin.test.KotlinTestUtils
import java.io.File
abstract class AbstractDataFlowValueRenderingTest : KotlinLightCodeInsightFixtureTestCase() {
private fun IdentifierInfo.render(): String? = when (this) {
is IdentifierInfo.Expression -> expression.text
is IdentifierInfo.Receiver -> (value as? ImplicitReceiver)?.declarationDescriptor?.name?.let { "this@$it" }
is IdentifierInfo.Variable -> variable.name.asString()
is IdentifierInfo.PackageOrClass -> (descriptor as? PackageViewDescriptor)?.let { it.fqName.asString() }
is IdentifierInfo.Qualified -> receiverInfo.render() + "." + selectorInfo.render()
else -> null
}
private fun DataFlowValue.render() =
// If it is not a stable identifier, there's no point in rendering it
if (!isStable) null
else identifierInfo.render()
override fun getTestDataPath(): String = PluginTestCaseBase.getTestDataPathBase() + "/dataFlowValueRendering/"
override fun getProjectDescriptor(): LightProjectDescriptor {
return LightCodeInsightFixtureTestCase.JAVA_LATEST
}
fun doTest(fileName: String) {
val fixture = myFixture
fixture.configureByFile(fileName)
val jetFile = fixture.file as KtFile
val element = jetFile.findElementAt(fixture.caretOffset)!!
val expression = element.getStrictParentOfType<KtExpression>()!!
val info = expression.analyze().getDataFlowInfoAfter(expression)
val allValues = (info.completeTypeInfo.keySet() + info.completeNullabilityInfo.keySet()).toSet()
val actual = allValues.mapNotNull { it.render() }.sorted().joinToString("\n")
KotlinTestUtils.assertEqualsToFile(File(FileUtil.getNameWithoutExtension(fileName) + ".txt"), actual)
}
}
@@ -1,51 +0,0 @@
/*
* Copyright 2010-2019 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.copyright
import junit.framework.AssertionFailedError
import org.jetbrains.kotlin.idea.copyright.UpdateKotlinCopyright
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.junit.Assert
import java.io.File
abstract class AbstractUpdateKotlinCopyrightTest : KotlinLightCodeInsightFixtureTestCase() {
fun doTest(path: String) {
myFixture.configureByFile(path)
val fileText = myFixture.file.text.trim()
val expectedNumberOfComments = InTextDirectivesUtils.getPrefixedInt(fileText, "// COMMENTS: ") ?: run {
if (fileText.isNotEmpty()) {
throw AssertionFailedError("Every test should assert number of comments with `COMMENTS` directive")
} else {
0
}
}
val comments = UpdateKotlinCopyright.getExistentComments(myFixture.file)
for (comment in comments) {
val commentText = comment.text
when {
commentText.contains("PRESENT") -> {
}
commentText.contains("ABSENT") -> {
throw AssertionFailedError("Unexpected comment found: `$commentText`")
}
else -> {
throw AssertionFailedError("A comment with bad directive found: `$commentText`")
}
}
}
Assert.assertEquals(
"Wrong number of comments found:\n${comments.joinToString(separator = "\n") { it.text }}\n",
expectedNumberOfComments, comments.size
)
}
override fun getTestDataPath() = File(PluginTestCaseBase.getTestDataPathBase(), "/copyright").path + File.separator
}
@@ -1 +0,0 @@
package org.jetbrains.kotlin.idea.codeInsight.codevision
@@ -1 +0,0 @@
package org.jetbrains.kotlin.idea.codeInsight.codevision;
@@ -1,6 +0,0 @@
/*
* 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.codeInsight.hints
@@ -1,6 +0,0 @@
/*
* 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.codeInsight.hints
@@ -1,6 +0,0 @@
/*
* 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.codeInsight.hints;
@@ -1,31 +0,0 @@
/*
* 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
import com.intellij.ide.hierarchy.HierarchyTreeStructure
import com.intellij.openapi.Disposable
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.util.Computable
import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.codeInsight.hierarchy.HierarchyViewTestFixture
// FIX ME WHEN BUNCH 192 REMOVED
@Suppress("UNUSED_PARAMETER")
fun doHierarchyTestCompat(
hierarchyFixture: HierarchyViewTestFixture,
treeStructureComputable: Computable<out HierarchyTreeStructure>,
expectedStructure: String,
) {
hierarchyFixture.doHierarchyTest(treeStructureComputable.compute(), expectedStructure)
}
fun <T> maskExtensions(
pointName: ExtensionPointName<T>,
newExtensions: List<T>,
parentDisposable: Disposable
) {
PlatformTestUtil.maskExtensions(pointName, newExtensions, parentDisposable)
}
@@ -1,169 +0,0 @@
/*
* Copyright 2010-2019 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.configuration;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.OrderRootType;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiJavaModule;
import com.intellij.psi.search.FilenameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.idea.core.script.ScriptUtilsKt;
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase;
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.plugins.groovy.GroovyFileType;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
@SuppressWarnings("deprecation")
public abstract class AbstractConfigureProjectByChangingFileTest<C extends KotlinProjectConfigurator>
extends KotlinLightCodeInsightTestCase {
private static final String DEFAULT_VERSION = "default_version";
private PsiFile moduleInfoFile;
@Override
protected void setUp() throws Exception {
super.setUp();
ApplicationManager.getApplication().runWriteAction(
() -> FileTypeManager.getInstance().associateExtension(GroovyFileType.GROOVY_FILE_TYPE, "gradle")
);
}
@Override
protected void tearDown() throws Exception {
moduleInfoFile = null;
super.tearDown();
}
protected void doTest(@NotNull String beforeFile, @NotNull String afterFile, @NotNull C configurator) throws Exception {
configureByFile(beforeFile);
prepareModuleInfoFile(beforeFile);
String versionFromFile = InTextDirectivesUtils.findStringWithPrefixes(getFile().getText(), "// VERSION:");
String version = versionFromFile != null ? versionFromFile : DEFAULT_VERSION;
NotificationMessageCollector collector = NotificationMessageCollectorKt.createConfigureKotlinNotificationCollector(getProject());
runConfigurator(getModule(), getFile(), configurator, version, collector);
collector.showNotification();
KotlinTestUtils.assertEqualsToFile(new File(afterFile), getFile().getText().replace(version, "$VERSION$"));
checkModuleInfoFile(beforeFile);
}
private void prepareModuleInfoFile(@NotNull String beforeFile) throws IOException {
File file = new File(beforeFile);
String parent = file.getParent();
File moduleInfo = new File(parent, PsiJavaModule.MODULE_INFO_FILE);
moduleInfoFile = null;
if (moduleInfo.exists()) {
String fileText = FileUtilRt.loadFile(moduleInfo, CharsetToolkit.UTF8, true);
createAndSaveFile(PsiJavaModule.MODULE_INFO_FILE, fileText);
PsiFile[] moduleInfoFiles =
FilenameIndex.getFilesByName(getProject(), PsiJavaModule.MODULE_INFO_FILE, GlobalSearchScope.allScope(getProject()));
assertTrue(PsiJavaModule.MODULE_INFO_FILE + " should be present in index", moduleInfoFiles.length == 1);
moduleInfoFile = moduleInfoFiles[0];
}
}
private void checkModuleInfoFile(@NotNull String beforeFile) {
File file = new File(beforeFile);
String parent = file.getParent();
if (moduleInfoFile != null) {
String afterFileName = PsiJavaModule.MODULE_INFO_FILE.replace(".java", "_after.java");
commitAllDocuments();
KotlinTestUtils.assertEqualsToFile(new File(parent, afterFileName), moduleInfoFile.getText());
}
}
protected abstract void runConfigurator(
Module module, @NotNull PsiFile file,
@NotNull C configurator,
@NotNull String version,
@NotNull NotificationMessageCollector collector
);
@NotNull
@Override
protected String getTestDataPath() {
return "";
}
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return new SimpleLightProjectDescriptor(getModuleType(), getProjectJDK());
}
private static class SimpleLightProjectDescriptor extends LightProjectDescriptor {
@NotNull private final ModuleType myModuleType;
@Nullable private final Sdk mySdk;
SimpleLightProjectDescriptor(@NotNull ModuleType moduleType, @Nullable Sdk sdk) {
myModuleType = moduleType;
mySdk = sdk;
}
@NotNull
@Override
public ModuleType getModuleType() {
return myModuleType;
}
@Nullable
@Override
public Sdk getSdk() {
return mySdk;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
SimpleLightProjectDescriptor that = (SimpleLightProjectDescriptor)o;
if (!myModuleType.equals(that.myModuleType)) return false;
return areJdksEqual(that.getSdk());
}
@Override
public int hashCode() {
return myModuleType.hashCode();
}
private boolean areJdksEqual(Sdk newSdk) {
if (mySdk == null || newSdk == null) return mySdk == newSdk;
if (!Objects.equals(mySdk.getVersionString(), newSdk.getVersionString())) {
return false;
}
String[] myUrls = mySdk.getRootProvider().getUrls(OrderRootType.CLASSES);
String[] newUrls = newSdk.getRootProvider().getUrls(OrderRootType.CLASSES);
return ContainerUtil.newHashSet(myUrls).equals(ContainerUtil.newHashSet(newUrls));
}
}
}
@@ -1,15 +0,0 @@
/*
* 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.configuration
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ex.ProjectManagerEx
import java.nio.file.Path
// FIX ME WHEN BUNCH 192 REMOVED
internal fun loadProjectCompat(projectFile: Path): Project {
return (ProjectManagerEx.getInstanceEx()).loadProject(projectFile.toFile().path)!!
}
@@ -1,95 +0,0 @@
/*
* Copyright 2010-2019 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.parameterInfo
import com.intellij.codeInsight.hint.ShowParameterInfoContext
import com.intellij.codeInsight.hint.ShowParameterInfoHandler
import com.intellij.openapi.util.io.FileUtil
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
import com.intellij.testFramework.LightProjectDescriptor
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import com.intellij.util.PathUtil
import org.jetbrains.kotlin.idea.KotlinLanguage
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources
import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor
import org.jetbrains.kotlin.idea.test.withCustomCompilerOptions
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.psiUtil.allChildren
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.junit.Assert
import java.io.File
abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() {
override fun getProjectDescriptor(): LightProjectDescriptor {
val root = KotlinTestUtils.getTestsRoot(this::class.java)
if (root.contains("Lib")) {
return SdkAndMockLibraryProjectDescriptor("$root/sharedLib", true, true, false, false)
}
return ProjectDescriptorWithStdlibSources.INSTANCE
}
override fun setUp() {
super.setUp()
myFixture.testDataPath = PluginTestCaseBase.getTestDataPathBase() + "/parameterInfo"
}
protected fun doTest(fileName: String) {
val prefix = FileUtil.getNameWithoutExtension(PathUtil.getFileName(fileName))
val mainFile = File(FileUtil.toSystemDependentName(fileName))
mainFile.parentFile
.listFiles { _, name -> name.startsWith("$prefix.") && name != mainFile.name }
.forEach { myFixture.configureByFile(FileUtil.toSystemIndependentName(it.path)) }
myFixture.configureByFile(fileName)
val file = myFixture.file as KtFile
withCustomCompilerOptions(file.text, project, myFixture.module) {
val lastChild = file.allChildren.filter { it !is PsiWhiteSpace }.last()
val expectedResultText = when (lastChild.node.elementType) {
KtTokens.BLOCK_COMMENT -> lastChild.text.substring(2, lastChild.text.length - 2).trim()
KtTokens.EOL_COMMENT -> lastChild.text.substring(2).trim()
else -> error("Unexpected last file child")
}
val context = ShowParameterInfoContext(editor, project, file, editor.caretModel.offset, -1, true)
val handlers = ShowParameterInfoHandler.getHandlers(project, KotlinLanguage.INSTANCE)!!
val handler = handlers.firstOrNull { it.findElementForParameterInfo(context) != null }
?: error("Could not find parameter info handler")
val mockCreateParameterInfoContext = MockCreateParameterInfoContext(file, myFixture)
val parameterOwner = handler.findElementForParameterInfo(mockCreateParameterInfoContext) as PsiElement
val textToType = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// TYPE:")
if (textToType != null) {
myFixture.type(textToType)
PsiDocumentManager.getInstance(project).commitAllDocuments()
}
//to update current parameter index
val updateContext = MockUpdateParameterInfoContext(file, myFixture, mockCreateParameterInfoContext)
val elementForUpdating = handler.findElementForUpdatingParameterInfo(updateContext)
if (elementForUpdating != null) {
handler.updateParameterInfo(elementForUpdating, updateContext)
}
val parameterInfoUIContext = MockParameterInfoUIContext(parameterOwner, updateContext.currentParameter)
mockCreateParameterInfoContext.itemsToShow?.forEach {
handler.updateUI(it, parameterInfoUIContext)
}
Assert.assertEquals(expectedResultText, parameterInfoUIContext.resultText)
}
}
}
@@ -1,26 +0,0 @@
/*
* Copyright 2010-2019 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.script
import com.intellij.openapi.Disposable
import com.intellij.openapi.extensions.ExtensionPointName
import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.project.Project
import com.intellij.testFramework.PlatformTestUtil
fun <T> addExtensionPointInTest(
pointName: ExtensionPointName<T>,
project: Project,
provider: T,
testRootDisposable: Disposable
) {
PlatformTestUtil.registerExtension(
Extensions.getArea(project),
pointName,
provider,
testRootDisposable
)
}
@@ -1,55 +0,0 @@
/*
* Copyright 2010-2019 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.test.util
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.DependencyScope
import com.intellij.openapi.roots.ModuleRootModificationUtil
import com.intellij.openapi.roots.OrderRootType
import com.intellij.openapi.roots.impl.libraries.LibraryEx
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable
import com.intellij.openapi.roots.libraries.Library
import com.intellij.openapi.roots.libraries.PersistentLibraryKind
import com.intellij.openapi.vfs.JarFileSystem
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.testFramework.PlatformTestCase
import org.jetbrains.kotlin.test.testFramework.runWriteAction
import java.io.File
fun PlatformTestCase.projectLibrary(
libraryName: String = "TestLibrary",
classesRoot: VirtualFile? = null,
sourcesRoot: VirtualFile? = null,
kind: PersistentLibraryKind<*>? = null
): LibraryEx {
return runWriteAction {
val modifiableModel = ProjectLibraryTable.getInstance(project).modifiableModel
val library = try {
modifiableModel.createLibrary(libraryName, kind) as LibraryEx
} finally {
modifiableModel.commit()
}
with(library.modifiableModel) {
classesRoot?.let { addRoot(it, OrderRootType.CLASSES) }
sourcesRoot?.let { addRoot(it, OrderRootType.SOURCES) }
commit()
}
library
}
}
val File.jarRoot: VirtualFile
get() {
val virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(this) ?: error("Cannot find file $this")
return JarFileSystem.getInstance().getRootByLocal(virtualFile) ?: error("Can't find root by file $virtualFile")
}
fun Module.addDependency(
library: Library,
dependencyScope: DependencyScope = DependencyScope.COMPILE,
exported: Boolean = false
) = ModuleRootModificationUtil.addDependency(this, library, dependencyScope, exported)