Cleanup 201 and as41 bunch files

This commit is contained in:
Vyacheslav Gerasimov
2021-03-28 16:26:32 +03:00
parent 943f03e55f
commit f2a892a972
135 changed files with 28 additions and 12127 deletions
@@ -95,7 +95,6 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
}
runPostStartupActivitiesOnce(project)
VfsRootAccess.allowRootAccess(project, KtTestUtil.getHomeDirectory())
EditorTracker.getInstance(project)
@@ -1,98 +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.test;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.testFramework.TempFiles;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.WithMutedInDatabaseRunTest;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.Collection;
@WithMutedInDatabaseRunTest
public abstract class KotlinLightCodeInsightFixtureTestCaseBase extends LightCodeInsightFixtureTestCase {
@NotNull
@Override
public Project getProject() {
return super.getProject();
}
@NotNull
@Override
public Editor getEditor() {
return super.getEditor();
}
@Override
public PsiFile getFile() {
return super.getFile();
}
protected final Collection<File> myFilesToDelete = new THashSet<>();
private final TempFiles myTempFiles = new TempFiles(myFilesToDelete);
@Override
protected void tearDown() throws Exception {
myTempFiles.deleteAll();
super.tearDown();
}
@NotNull
public VirtualFile createTempFile(
@NonNls @NotNull String ext,
@Nullable byte[] bom,
@NonNls @NotNull String content,
@NotNull Charset charset
) throws IOException {
File temp = FileUtil.createTempFile("copy", "." + ext);
setContentOnDisk(temp, bom, content, charset);
myFilesToDelete.add(temp);
final VirtualFile file = getVirtualFile(temp);
assert file != null : temp;
return file;
}
public static void setContentOnDisk(@NotNull File file, @Nullable byte[] bom, @NotNull String content, @NotNull Charset charset)
throws IOException {
FileOutputStream stream = new FileOutputStream(file);
if (bom != null) {
stream.write(bom);
}
try (OutputStreamWriter writer = new OutputStreamWriter(stream, charset)) {
writer.write(content);
}
}
protected static VirtualFile getVirtualFile(@NotNull File file) {
return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
}
@Override
protected void runTest() throws Throwable {
//noinspection Convert2MethodRef
KotlinTestUtils.runTestWithThrowable(this, () -> super.runTest());
}
protected boolean isFirPlugin() {
return false;
}
}
@@ -26,7 +26,6 @@ abstract class KotlinLightPlatformCodeInsightFixtureTestCase : LightPlatformCode
override fun setUp() {
super.setUp()
enableKotlinOfficialCodeStyle(project)
runPostStartupActivitiesOnce(project)
VfsRootAccess.allowRootAccess(KtTestUtil.getHomeDirectory())
if (!isFirPlugin()) {
invalidateLibraryCache(project)
@@ -1,137 +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.idea.test;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
import kotlin.jvm.functions.Function0;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.kotlin.idea.util.IjPlatformUtil;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TestJdkKind;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import java.io.File;
public class PluginTestCaseBase {
public static final String TEST_DATA_DIR = "idea/testData";
public static final String TEST_DATA_PROJECT_RELATIVE = "/" + TEST_DATA_DIR;
private PluginTestCaseBase() {
}
@NotNull
public static String getTestDataPathBase() {
return KtTestUtil.getHomeDirectory() + TEST_DATA_PROJECT_RELATIVE;
}
@NotNull
@TestOnly
private static Sdk createMockJdk(@NotNull String name, String path) {
return ((JavaSdkImpl)JavaSdk.getInstance()).createMockJdk(name, path, false);
}
@NotNull
private static Sdk getSdk(String sdkHome, String name) {
ProjectJdkTable table = IjPlatformUtil.getProjectJdkTableSafe();
Sdk existing = table.findJdk(name);
if (existing != null) {
return existing;
}
return JavaSdk.getInstance().createJdk(name, sdkHome, true);
}
@NotNull
public static Sdk mockJdk() {
return getSdk("compiler/testData/mockJDK/jre", "Mock JDK");
}
@NotNull
public static Sdk mockJdk6() {
return getSdk("compiler/testData/mockJDK/jre", "1.6");
}
@NotNull
public static Sdk mockJdk8() {
// Using JDK 6, but with version 1.8
return getSdk("compiler/testData/mockJDK/jre", "1.8");
}
@TestOnly
@NotNull
public static Sdk mockJdk9() {
return getSdk("compiler/testData/mockJDK9/jre", "9");
}
@NotNull
public static Sdk fullJdk() {
String javaHome = System.getProperty("java.home");
assert new File(javaHome).isDirectory();
return getSdk(javaHome, "Full JDK");
}
@NotNull
public static Sdk addJdk(@NotNull Disposable disposable, @NotNull Function0<Sdk> getJdk) {
Sdk jdk = getJdk.invoke();
Sdk[] allJdks = IjPlatformUtil.getProjectJdkTableSafe().getAllJdks();
for (Sdk existingJdk : allJdks) {
if (existingJdk == jdk) {
return existingJdk;
}
}
ApplicationManager.getApplication().runWriteAction(() -> IjPlatformUtil.getProjectJdkTableSafe().addJdk(jdk, disposable));
return jdk;
}
@NotNull
public static Sdk jdk(@NotNull TestJdkKind kind) {
switch (kind) {
case MOCK_JDK:
return mockJdk();
case FULL_JDK_9:
String jre9 = KtTestUtil.getJdk9Home().getPath();
VfsRootAccess.allowRootAccess(jre9);
return getSdk(jre9, "Full JDK 9");
case FULL_JDK:
return fullJdk();
default:
throw new UnsupportedOperationException(kind.toString());
}
}
public static boolean isAllFilesPresentTest(@NotNull String testName) {
return StringUtil.startsWithIgnoreCase(testName, "allFilesPresentIn");
}
@TestOnly
public static void clearSdkTable(@NotNull Disposable disposable) {
Disposer.register(disposable, () -> ApplicationManager.getApplication().runWriteAction(() -> {
ProjectJdkTable jdkTable = IjPlatformUtil.getProjectJdkTableSafe();
for (Sdk sdk : jdkTable.getAllJdks()) {
jdkTable.removeJdk(sdk);
}
}));
}
}
@@ -1,11 +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.test
import com.intellij.openapi.project.Project
fun runPostStartupActivitiesOnce(project: Project) {
}
@@ -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.test
import com.intellij.ide.startup.impl.StartupManagerImpl
import com.intellij.openapi.project.Project
import com.intellij.openapi.startup.StartupManager
// FIX ME WHEN BUNCH 201 REMOVED
fun runPostStartupActivitiesOnce(project: Project) {
(StartupManager.getInstance(project) as StartupManagerImpl).runPostStartupActivitiesRegisteredDynamically()
}