mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
[tests] Finally remove deprecated SdkAndMockLibraryProjectDescriptor
Remove SdkAndMockLibraryProjectDescriptor from `AbstractFirLibraryModuleDeclarationResolveTest`. Also changed a root path for libraries in test. Instead of `idea/tests/testData` it is now current test directory. This needed for `fir-low-level-api-ide-impl` tests which are not in `idea` directory. This also affected paths in WITH_LIBRARY directives in other tests. GitOrigin-RevId: 2d0068e5ed1e625f35c907dd790f6add515a9dee
This commit is contained in:
committed by
intellij-monorepo-bot
parent
5e1be42954
commit
719ac4a54b
@@ -4,14 +4,12 @@
|
||||
*/
|
||||
package org.jetbrains.kotlin.idea.fir.low.level.api
|
||||
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.resolveToFirSymbol
|
||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||
import org.jetbrains.kotlin.fir.renderer.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.idea.test.SdkAndMockLibraryProjectDescriptor
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import java.io.File
|
||||
@@ -19,13 +17,6 @@ import java.io.File
|
||||
abstract class AbstractFirLibraryModuleDeclarationResolveTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||
override fun isFirPlugin(): Boolean = true
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor {
|
||||
val pathToLibraryFiles = File(testDataPath).resolve("_library")
|
||||
assertExists(pathToLibraryFiles)
|
||||
|
||||
return SdkAndMockLibraryProjectDescriptor(pathToLibraryFiles.toString(), true)
|
||||
}
|
||||
|
||||
/**
|
||||
* We want to check that resolving 'compiled' PSI-elements (i.e. elements from libraries)
|
||||
* works as expected.
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import library.TopLevelEnum
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import implicitJavaTypes.listOfStrings
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import implicitJavaTypes.string
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import implicitJavaTypes.stringFun
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import library.TopLevelClass
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import library.TopLevelClass
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import library.TopLevelClass
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import library.TopLevelClass
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import library.TopLevelClass
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import library.TopLevelClass
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import library.topLevelFunction
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import library.topLevelFunction
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// WITH_LIBRARY: _library
|
||||
package test
|
||||
|
||||
import library.topLevelProperty
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// WITH_LIBRARY: copyPaste/imports/KotlinLibrary
|
||||
// WITH_LIBRARY: KotlinLibrary
|
||||
|
||||
package a
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// WITH_LIBRARY: copyPaste/imports/KotlinLibrary
|
||||
// WITH_LIBRARY: KotlinLibrary
|
||||
<selection>
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// WITH_LIBRARY: copyPaste/imports/KotlinLibrary
|
||||
// WITH_LIBRARY: KotlinLibrary
|
||||
package d
|
||||
<selection>
|
||||
/*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// WITH_LIBRARY: copyPaste/imports/KotlinLibrary
|
||||
// WITH_LIBRARY: KotlinLibrary
|
||||
package a
|
||||
|
||||
import d.*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// WITH_LIBRARY: copyPaste/imports/KotlinLibrary
|
||||
// WITH_LIBRARY: KotlinLibrary
|
||||
<selection>
|
||||
<caret>/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
// K2_INSPECTION_CLASS: org.jetbrains.kotlin.idea.inspections.EnumValuesSoftDeprecateInJavaInspection
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+EnumEntries
|
||||
// LANGUAGE_VERSION: 1.9
|
||||
// WITH_LIBRARY: inspections/enumValuesSoftDeprecateInJava/inspectionData/lib
|
||||
// WITH_LIBRARY: lib
|
||||
@@ -3,6 +3,6 @@ import inlibrary.test.*
|
||||
val a: <caret>ReferenceTest? = null
|
||||
|
||||
// CONTEXT: val test: <ref-caret>Test? = null
|
||||
// WITH_LIBRARY: resolve/referenceInLib/inLibrarySource
|
||||
// WITH_LIBRARY: inLibrarySource
|
||||
|
||||
// REF: (inlibrary.test).Test
|
||||
@@ -3,6 +3,6 @@ import inlibrary.test.*
|
||||
val a: <caret>FunParameter? = null
|
||||
|
||||
// CONTEXT: val a = <ref-caret>p
|
||||
// WITH_LIBRARY: resolve/referenceInLib/inLibrarySource
|
||||
// WITH_LIBRARY: inLibrarySource
|
||||
|
||||
// REF: p
|
||||
@@ -3,6 +3,6 @@ import inlibrary.test.*
|
||||
val tl = <caret>topLevel()
|
||||
|
||||
// CONTEXT: return <ref-caret>local()
|
||||
// WITH_LIBRARY: resolve/referenceInLib/inLibrarySource
|
||||
// WITH_LIBRARY: inLibrarySource
|
||||
|
||||
// REF: (in inlibrary.test.topLevel).local()
|
||||
@@ -133,7 +133,7 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix
|
||||
0 -> return null
|
||||
1 -> {
|
||||
return MockLibraryFacility(
|
||||
source = IDEA_TEST_DATA_DIR.resolve(withLibraryDirective[0]),
|
||||
source = testDataDirectory.resolve(withLibraryDirective[0]),
|
||||
)
|
||||
}
|
||||
else -> error("Only one library directive is allowed")
|
||||
|
||||
@@ -1,140 +0,0 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package org.jetbrains.kotlin.idea.test;
|
||||
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.impl.libraries.LibraryEx;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.roots.libraries.LibraryTable;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import kotlin.collections.CollectionsKt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.idea.base.platforms.KotlinJavaScriptLibraryKind;
|
||||
import org.jetbrains.kotlin.idea.base.plugin.artifacts.TestKotlinArtifacts;
|
||||
import org.jetbrains.kotlin.idea.framework.KotlinSdkType;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
|
||||
/* Use MockLibraryFacility instead. */
|
||||
@Deprecated
|
||||
public class SdkAndMockLibraryProjectDescriptor extends KotlinLightProjectDescriptor {
|
||||
public static final String MOCK_LIBRARY_NAME = "myKotlinLib";
|
||||
|
||||
private final boolean withSources;
|
||||
private final boolean withRuntime;
|
||||
private final boolean isJsLibrary;
|
||||
private final boolean allowKotlinPackage;
|
||||
private final String sourcesPath;
|
||||
private final List<String> classpath;
|
||||
|
||||
public SdkAndMockLibraryProjectDescriptor(@NotNull String sourcesPath, boolean withSources) {
|
||||
this(sourcesPath, withSources, false, false, false);
|
||||
}
|
||||
|
||||
public SdkAndMockLibraryProjectDescriptor(
|
||||
@NotNull String sourcesPath,
|
||||
boolean withSources,
|
||||
boolean withRuntime,
|
||||
boolean isJsLibrary,
|
||||
boolean allowKotlinPackage
|
||||
) {
|
||||
this(sourcesPath, withSources, withRuntime, isJsLibrary, allowKotlinPackage, emptyList());
|
||||
}
|
||||
|
||||
public SdkAndMockLibraryProjectDescriptor(
|
||||
@NotNull String sourcesPath,
|
||||
boolean withSources,
|
||||
boolean withRuntime,
|
||||
boolean isJsLibrary,
|
||||
boolean allowKotlinPackage,
|
||||
@NotNull List<String> classpath
|
||||
) {
|
||||
this.withSources = withSources;
|
||||
this.withRuntime = withRuntime;
|
||||
this.isJsLibrary = isJsLibrary;
|
||||
this.allowKotlinPackage = allowKotlinPackage;
|
||||
this.sourcesPath = sourcesPath;
|
||||
this.classpath = classpath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model) {
|
||||
String jarUrl = getJarUrl(compileLibrary());
|
||||
|
||||
LibraryTable.ModifiableModel libraryTableModel = model.getModuleLibraryTable().getModifiableModel();
|
||||
|
||||
Library.ModifiableModel mockLibraryModel = libraryTableModel.createLibrary(MOCK_LIBRARY_NAME).getModifiableModel();
|
||||
mockLibraryModel.addRoot(jarUrl, OrderRootType.CLASSES);
|
||||
|
||||
if (withRuntime && !isJsLibrary) {
|
||||
mockLibraryModel.addRoot(getJarUrl(TestKotlinArtifacts.getKotlinStdlib()), OrderRootType.CLASSES);
|
||||
}
|
||||
|
||||
if (isJsLibrary && mockLibraryModel instanceof LibraryEx.ModifiableModelEx) {
|
||||
((LibraryEx.ModifiableModelEx) mockLibraryModel).setKind(KotlinJavaScriptLibraryKind.INSTANCE);
|
||||
}
|
||||
|
||||
if (withSources) {
|
||||
mockLibraryModel.addRoot(jarUrl + "src", OrderRootType.SOURCES);
|
||||
}
|
||||
|
||||
mockLibraryModel.commit();
|
||||
|
||||
if (withRuntime && isJsLibrary) {
|
||||
KotlinStdJSProjectDescriptor.INSTANCE.configureModule(module, model);
|
||||
}
|
||||
}
|
||||
|
||||
private File compileLibrary() {
|
||||
List<String> extraOptions = allowKotlinPackage ? Collections.singletonList("-Xallow-kotlin-package") : emptyList();
|
||||
KotlinCompilerStandalone.Platform platform = isJsLibrary
|
||||
? new KotlinCompilerStandalone.Platform.JavaScript(MOCK_LIBRARY_NAME, "test")
|
||||
: new KotlinCompilerStandalone.Platform.Jvm();
|
||||
List<File> sources = Collections.singletonList(new File(sourcesPath));
|
||||
List<File> classpath = isJsLibrary ? emptyList() : CollectionsKt.map(this.classpath, File::new);
|
||||
File libraryJar = KotlinCompilerStandalone.defaultTargetJar();
|
||||
new KotlinCompilerStandalone(sources, libraryJar, platform, extraOptions, classpath).compile();
|
||||
return libraryJar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return isJsLibrary ? KotlinSdkType.INSTANCE.createSdkWithUniqueName(emptyList()) : IdeaTestUtil.getMockJdk18();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getJarUrl(@NotNull File libraryJar) {
|
||||
return "jar://" + FileUtilRt.toSystemIndependentName(libraryJar.getAbsolutePath()) + "!/";
|
||||
}
|
||||
|
||||
public static void tearDown(Module module) {
|
||||
ConfigLibraryUtil.INSTANCE.removeLibrary(module, SdkAndMockLibraryProjectDescriptor.MOCK_LIBRARY_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SdkAndMockLibraryProjectDescriptor that = (SdkAndMockLibraryProjectDescriptor) o;
|
||||
return withSources == that.withSources &&
|
||||
withRuntime == that.withRuntime &&
|
||||
isJsLibrary == that.isJsLibrary &&
|
||||
allowKotlinPackage == that.allowKotlinPackage &&
|
||||
sourcesPath.equals(that.sourcesPath) &&
|
||||
classpath.equals(that.classpath);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(withSources, withRuntime, isJsLibrary, allowKotlinPackage, sourcesPath, classpath);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user