Load additional JDK functions into built-ins member scope
#KT-5990 Fixed #KT-7127 Fixed #KT-10370 Fixed
This commit is contained in:
+40
-12
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.caches.resolve
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.ProjectRootModificationTracker
|
||||
import com.intellij.openapi.util.ModificationTracker
|
||||
import com.intellij.psi.util.CachedValue
|
||||
@@ -44,8 +45,8 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.KotlinSuppressCache
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.sumByLong
|
||||
import org.jetbrains.kotlin.utils.keysToMap
|
||||
|
||||
internal val LOG = Logger.getInstance(KotlinCacheService::class.java)
|
||||
|
||||
@@ -56,14 +57,20 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
|
||||
|
||||
override fun getSuppressionCache(): KotlinSuppressCache = kotlinSuppressCache.value
|
||||
|
||||
private val globalFacadesPerPlatform = listOf(JvmPlatform, JsPlatform).keysToMap { platform -> GlobalFacade(platform) }
|
||||
private val globalFacadesPerPlatformAndSdk: SLRUCache<Pair<TargetPlatform, Sdk?>, GlobalFacade> =
|
||||
object : SLRUCache<Pair<TargetPlatform, Sdk?>, GlobalFacade>(2 * 3, 2 * 3) {
|
||||
override fun createValue(key: Pair<TargetPlatform, Sdk?>): GlobalFacade {
|
||||
return GlobalFacade(key.first, key.second)
|
||||
}
|
||||
}
|
||||
|
||||
private inner class GlobalFacade(platform: TargetPlatform) {
|
||||
private inner class GlobalFacade(platform: TargetPlatform, sdk: Sdk?) {
|
||||
val facadeForLibraries = ProjectResolutionFacade(project) {
|
||||
globalResolveSessionProvider(
|
||||
"project libraries for platform $platform",
|
||||
project,
|
||||
platform,
|
||||
sdk,
|
||||
logProcessCanceled = true,
|
||||
moduleFilter = { it.isLibraryClasses() },
|
||||
dependencies = listOf(
|
||||
@@ -78,6 +85,7 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
|
||||
"project source roots and libraries for platform $platform",
|
||||
project,
|
||||
platform,
|
||||
sdk,
|
||||
reuseDataFrom = facadeForLibraries,
|
||||
moduleFilter = { !it.isLibraryClasses() },
|
||||
dependencies = listOf(PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT))
|
||||
@@ -86,17 +94,24 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
|
||||
|
||||
@Deprecated("Use JetElement.getResolutionFacade(), please avoid introducing new usages")
|
||||
fun <T : Any> getProjectService(platform: TargetPlatform, ideaModuleInfo: IdeaModuleInfo, serviceClass: Class<T>): T {
|
||||
return globalFacade(platform).resolverForModuleInfo(ideaModuleInfo).componentProvider.getService(serviceClass)
|
||||
return globalFacade(platform, ideaModuleInfo.sdk).resolverForModuleInfo(ideaModuleInfo).componentProvider.getService(serviceClass)
|
||||
}
|
||||
|
||||
private fun globalFacade(platform: TargetPlatform) = globalFacadesPerPlatform[platform]!!.facadeForModules
|
||||
private fun globalFacade(platform: TargetPlatform, sdk: Sdk?) =
|
||||
getOrBuildGlobalFacade(platform, sdk).facadeForModules
|
||||
|
||||
private fun librariesFacade(platform: TargetPlatform) = globalFacadesPerPlatform[platform]!!.facadeForLibraries
|
||||
private fun librariesFacade(platform: TargetPlatform, sdk: Sdk?) = getOrBuildGlobalFacade(platform, sdk).facadeForLibraries
|
||||
|
||||
@Synchronized
|
||||
private fun getOrBuildGlobalFacade(platform: TargetPlatform, sdk: Sdk?) = globalFacadesPerPlatformAndSdk[Pair(platform, sdk)]
|
||||
|
||||
private val IdeaModuleInfo.sdk: Sdk? get() = dependencies().firstIsInstanceOrNull<SdkInfo>()?.sdk
|
||||
|
||||
private fun createFacadeForSyntheticFiles(files: Set<KtFile>): ProjectResolutionFacade {
|
||||
// we assume that all files come from the same module
|
||||
val targetPlatform = files.map { TargetPlatformDetector.getPlatform(it) }.toSet().single()
|
||||
val syntheticFileModule = files.map { it.getModuleInfo() }.toSet().single()
|
||||
val sdk = syntheticFileModule.sdk
|
||||
val filesModificationTracker = ModificationTracker {
|
||||
files.sumByLong { it.outOfBlockModificationCount }
|
||||
}
|
||||
@@ -110,8 +125,9 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
|
||||
debugName,
|
||||
project,
|
||||
targetPlatform,
|
||||
sdk,
|
||||
syntheticFiles = files,
|
||||
reuseDataFrom = globalFacade(targetPlatform),
|
||||
reuseDataFrom = globalFacade(targetPlatform, sdk),
|
||||
moduleFilter = { it in dependentModules },
|
||||
dependencies = dependenciesForSyntheticFileCache
|
||||
)
|
||||
@@ -124,8 +140,9 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
|
||||
debugName,
|
||||
project,
|
||||
targetPlatform,
|
||||
sdk,
|
||||
syntheticFiles = files,
|
||||
reuseDataFrom = librariesFacade(targetPlatform),
|
||||
reuseDataFrom = librariesFacade(targetPlatform, sdk),
|
||||
moduleFilter = { it == syntheticFileModule },
|
||||
dependencies = dependenciesForSyntheticFileCache
|
||||
)
|
||||
@@ -142,6 +159,7 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
|
||||
debugName,
|
||||
project,
|
||||
targetPlatform,
|
||||
sdk,
|
||||
syntheticFiles = files,
|
||||
moduleFilter = { true },
|
||||
dependencies = dependenciesForSyntheticFileCache
|
||||
@@ -201,13 +219,14 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService {
|
||||
private fun getFacadeToAnalyzeFiles(files: Collection<KtFile>): ResolutionFacade {
|
||||
val syntheticFiles = findSyntheticFiles(files)
|
||||
val file = files.first()
|
||||
val moduleInfo = file.getModuleInfo()
|
||||
val projectFacade = if (syntheticFiles.isNotEmpty()) {
|
||||
getFacadeForSyntheticFiles(syntheticFiles)
|
||||
}
|
||||
else {
|
||||
globalFacade(TargetPlatformDetector.getPlatform(file))
|
||||
globalFacade(TargetPlatformDetector.getPlatform(file), moduleInfo.sdk)
|
||||
}
|
||||
return ResolutionFacadeImpl(projectFacade, file.getModuleInfo())
|
||||
return ResolutionFacadeImpl(projectFacade, moduleInfo)
|
||||
}
|
||||
|
||||
private fun findSyntheticFiles(files: Collection<KtFile>) = files.mapNotNull {
|
||||
@@ -228,6 +247,7 @@ private fun globalResolveSessionProvider(
|
||||
debugName: String,
|
||||
project: Project,
|
||||
platform: TargetPlatform,
|
||||
sdk: Sdk?,
|
||||
dependencies: Collection<Any>,
|
||||
moduleFilter: (IdeaModuleInfo) -> Boolean,
|
||||
reuseDataFrom: ProjectResolutionFacade? = null,
|
||||
@@ -242,16 +262,24 @@ private fun globalResolveSessionProvider(
|
||||
|
||||
val builtIns: KotlinBuiltIns = when (platform) {
|
||||
is JsPlatform -> JsPlatform.builtIns
|
||||
is JvmPlatform -> JvmBuiltIns.Instance
|
||||
is JvmPlatform -> JvmBuiltIns(globalContext.storageManager)
|
||||
else -> DefaultBuiltIns.Instance
|
||||
}
|
||||
|
||||
val moduleResolverProvider = createModuleResolverProvider(
|
||||
debugName, project, globalContext,
|
||||
debugName, project, globalContext, sdk,
|
||||
AnalyzerFacadeProvider.getAnalyzerFacade(platform),
|
||||
syntheticFiles, delegateResolverForProject, moduleFilter,
|
||||
builtIns
|
||||
)
|
||||
|
||||
if (builtIns is JvmBuiltIns) {
|
||||
val moduleInfoToUse = sdk?.let { SdkInfo(project, it) } ?: moduleResolverProvider.resolverForProject.allModules.firstOrNull()
|
||||
if (moduleInfoToUse != null) {
|
||||
builtIns.setOwnerModuleDescriptor(moduleResolverProvider.resolverForProject.descriptorForModule(moduleInfoToUse))
|
||||
}
|
||||
}
|
||||
|
||||
val allDependencies = dependencies + listOf(moduleResolverProvider.exceptionTracker)
|
||||
return CachedValueProvider.Result.create(moduleResolverProvider, allDependencies)
|
||||
}
|
||||
|
||||
+4
-1
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea.caches.resolve
|
||||
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.JdkOrderEntry
|
||||
import com.intellij.openapi.roots.LibraryOrderEntry
|
||||
import com.intellij.openapi.roots.ModuleRootManager
|
||||
@@ -38,6 +39,7 @@ fun createModuleResolverProvider(
|
||||
debugName: String,
|
||||
project: Project,
|
||||
globalContext: GlobalContextImpl,
|
||||
sdk: Sdk?,
|
||||
analyzerFacade: AnalyzerFacade<JvmPlatformParameters>,
|
||||
syntheticFiles: Collection<KtFile>,
|
||||
delegateResolver: ResolverForProject<IdeaModuleInfo>,
|
||||
@@ -67,7 +69,8 @@ fun createModuleResolverProvider(
|
||||
val resolverForProject = analyzerFacade.setupResolverForProject(
|
||||
debugName, globalContext.withProject(project), modulesToCreateResolversFor, modulesContent,
|
||||
jvmPlatformParameters, IdeaEnvironment, builtIns,
|
||||
delegateResolver, { m, c -> IDEPackagePartProvider(c.moduleContentScope) }
|
||||
delegateResolver, { m, c -> IDEPackagePartProvider(c.moduleContentScope) },
|
||||
sdk?.let { SdkInfo(project, it) }
|
||||
)
|
||||
return resolverForProject
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(x: MutableList<String>) {
|
||||
x.<caret>
|
||||
}
|
||||
|
||||
// EXIST: {"lookupString":"stream","tailText":"()","typeText":"Stream<String!>!"}
|
||||
// EXIST: {"lookupString":"removeIf","tailText":"(Predicate<in String!>!)","typeText":"Boolean"}
|
||||
// EXIST: {"lookupString":"removeIf","tailText":" {...} (((String!) -> Boolean)!)","typeText":"Boolean"}
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo(x: List<String>) {
|
||||
x.stream().<caret>
|
||||
}
|
||||
|
||||
// EXIST: {"lookupString":"allMatch","tailText":" {...} (((String!) -> Boolean)!)","typeText":"Boolean","attributes":"bold"}
|
||||
// EXIST: {"lookupString":"allMatch","tailText":"(Predicate<in String!>!)","typeText":"Boolean","attributes":"bold"}
|
||||
// EXIST: {"lookupString":"count","tailText":"()","typeText":"Long","attributes":"bold"}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.testFramework.LightProjectDescriptor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor;
|
||||
|
||||
public abstract class AbstractJava8BasicCompletionTest extends AbstractJvmBasicCompletionTest {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE_FULL_JDK;
|
||||
}
|
||||
}
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.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/idea-completion/testData/basic/java8")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public class Java8BasicCompletionTestGenerated extends AbstractJava8BasicCompletionTest {
|
||||
public void testAllFilesPresentInJava8() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/idea-completion/testData/basic/java8"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("CollectionMethods.kt")
|
||||
public void testCollectionMethods() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/java8/CollectionMethods.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("StreamMethods.kt")
|
||||
public void testStreamMethods() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/idea-completion/testData/basic/java8/StreamMethods.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
+7
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.test;
|
||||
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
||||
|
||||
public class KotlinWithJdkAndRuntimeLightProjectDescriptor extends KotlinJdkAndLibraryProjectDescriptor {
|
||||
@@ -24,4 +25,10 @@ public class KotlinWithJdkAndRuntimeLightProjectDescriptor extends KotlinJdkAndL
|
||||
}
|
||||
|
||||
public static final KotlinWithJdkAndRuntimeLightProjectDescriptor INSTANCE = new KotlinWithJdkAndRuntimeLightProjectDescriptor();
|
||||
public static final KotlinWithJdkAndRuntimeLightProjectDescriptor INSTANCE_FULL_JDK = new KotlinWithJdkAndRuntimeLightProjectDescriptor() {
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return PluginTestCaseBase.fullJdk();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
abstract class A : List<String> {
|
||||
<caret>
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import java.util.stream.Stream
|
||||
|
||||
abstract class A : List<String> {
|
||||
override fun stream(): Stream<String>? {
|
||||
<selection><caret>return super.stream()</selection>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package foo
|
||||
|
||||
fun mainJdk8(x: List<String>, j6List: Jdk6List<String>) {
|
||||
x.stream().filter { it.length > 0 }
|
||||
|
||||
j6List.size
|
||||
// TODO: stream should be available
|
||||
j6List.stream()
|
||||
|
||||
buildList().stream()
|
||||
|
||||
myFile().toPath()
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package foo
|
||||
import java.io.File
|
||||
|
||||
class Jdk6List<F> : List<F> {
|
||||
override val size: Int
|
||||
get() = null!!
|
||||
|
||||
override fun contains(element: F): Boolean {
|
||||
null!!
|
||||
}
|
||||
|
||||
override fun containsAll(elements: Collection<F>): Boolean {
|
||||
null!!
|
||||
}
|
||||
|
||||
override fun get(index: Int): F {
|
||||
null!!
|
||||
}
|
||||
|
||||
override fun indexOf(element: F): Int {
|
||||
null!!
|
||||
}
|
||||
|
||||
override fun isEmpty(): Boolean {
|
||||
null!!
|
||||
}
|
||||
|
||||
override fun iterator(): Iterator<F> {
|
||||
null!!
|
||||
}
|
||||
|
||||
override fun lastIndexOf(element: F): Int {
|
||||
null!!
|
||||
}
|
||||
|
||||
override fun listIterator(): ListIterator<F> {
|
||||
null!!
|
||||
}
|
||||
|
||||
override fun listIterator(index: Int): ListIterator<F> {
|
||||
null!!
|
||||
}
|
||||
|
||||
override fun subList(fromIndex: Int, toIndex: Int): List<F> {
|
||||
null!!
|
||||
}
|
||||
}
|
||||
|
||||
fun buildList(): List<String> = null!!
|
||||
fun myFile(): File = null!!
|
||||
|
||||
fun mainJdk6(x: List<String>) {
|
||||
x.<error descr="[UNRESOLVED_REFERENCE] Unresolved reference: stream">stream</error>().filter { <error descr="[UNRESOLVED_REFERENCE] Unresolved reference: it">it</error>.length > 0 }
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* 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.caches.resolve
|
||||
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import com.intellij.openapi.module.StdModuleTypes
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import org.jetbrains.kotlin.idea.project.PluginJetFilesProvider
|
||||
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.testFramework.PsiTestUtil
|
||||
import java.io.File
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.roots.DependencyScope
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
|
||||
import org.junit.Assert
|
||||
|
||||
abstract class AbstractMultiModuleHighlightingTest : DaemonAnalyzerTestCase() {
|
||||
|
||||
private val TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/multiModuleHighlighting/"
|
||||
|
||||
protected fun checkHighlightingInAllFiles() {
|
||||
var atLeastOneFile = false
|
||||
PluginJetFilesProvider.allFilesInProject(myProject!!).forEach { file ->
|
||||
atLeastOneFile = true
|
||||
configureByExistingFile(file.virtualFile!!)
|
||||
checkHighlighting(myEditor, true, false)
|
||||
}
|
||||
Assert.assertTrue(atLeastOneFile)
|
||||
}
|
||||
|
||||
protected fun module(name: String, hasTestRoot: Boolean = false, useFullJdk: Boolean = false): Module {
|
||||
val srcDir = TEST_DATA_PATH + "${getTestName(true)}/$name"
|
||||
val moduleWithSrcRootSet = createModuleFromTestData(srcDir, "$name", StdModuleTypes.JAVA, true)!!
|
||||
if (hasTestRoot) {
|
||||
setTestRoot(moduleWithSrcRootSet, name)
|
||||
}
|
||||
|
||||
val jdkToUse = if (useFullJdk) PluginTestCaseBase.fullJdk() else PluginTestCaseBase.mockJdk()
|
||||
ConfigLibraryUtil.configureSdk(moduleWithSrcRootSet, jdkToUse)
|
||||
|
||||
return moduleWithSrcRootSet
|
||||
}
|
||||
|
||||
protected fun setTestRoot(module: Module, name: String) {
|
||||
val testDir = TEST_DATA_PATH + "${getTestName(true)}/${name}Test"
|
||||
val testRootDirInTestData = File(testDir)
|
||||
val testRootDir = createTempDirectory()!!
|
||||
FileUtil.copyDir(testRootDirInTestData, testRootDir)
|
||||
val testRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(testRootDir)!!
|
||||
object : WriteCommandAction.Simple<Unit>(project) {
|
||||
override fun run() {
|
||||
testRoot.refresh(false, true)
|
||||
}
|
||||
}.execute().throwException()
|
||||
PsiTestUtil.addSourceRoot(module, testRoot, true)
|
||||
}
|
||||
|
||||
protected fun Module.addDependency(
|
||||
other: Module,
|
||||
dependencyScope: DependencyScope = DependencyScope.COMPILE,
|
||||
exported: Boolean = false
|
||||
) = ModuleRootModificationUtil.addDependency(this, other, dependencyScope, exported)
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 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.caches.resolve
|
||||
|
||||
class Java8MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() {
|
||||
fun testDifferentJdk() {
|
||||
val module1 = module("jdk8", useFullJdk = true)
|
||||
val module2 = module("mockJdk")
|
||||
|
||||
module1.addDependency(module2)
|
||||
|
||||
checkHighlightingInAllFiles()
|
||||
}
|
||||
}
|
||||
@@ -16,24 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.caches.resolve
|
||||
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import com.intellij.openapi.module.StdModuleTypes
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import org.jetbrains.kotlin.idea.project.PluginJetFilesProvider
|
||||
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.testFramework.PsiTestUtil
|
||||
import java.io.File
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.roots.DependencyScope
|
||||
import org.junit.Assert
|
||||
|
||||
class MultiModuleHighlightingTest : DaemonAnalyzerTestCase() {
|
||||
|
||||
private val TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/multiModuleHighlighting/"
|
||||
|
||||
class MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() {
|
||||
fun testVisibility() {
|
||||
val module1 = module("m1")
|
||||
val module2 = module("m2")
|
||||
@@ -73,43 +58,4 @@ class MultiModuleHighlightingTest : DaemonAnalyzerTestCase() {
|
||||
|
||||
checkHighlightingInAllFiles()
|
||||
}
|
||||
|
||||
private fun checkHighlightingInAllFiles() {
|
||||
var atLeastOneFile = false
|
||||
PluginJetFilesProvider.allFilesInProject(myProject!!).forEach { file ->
|
||||
atLeastOneFile = true
|
||||
configureByExistingFile(file.virtualFile!!)
|
||||
checkHighlighting(myEditor, true, false)
|
||||
}
|
||||
Assert.assertTrue(atLeastOneFile)
|
||||
}
|
||||
|
||||
private fun module(name: String, hasTestRoot: Boolean = false): Module {
|
||||
val srcDir = TEST_DATA_PATH + "${getTestName(true)}/$name"
|
||||
val moduleWithSrcRootSet = createModuleFromTestData(srcDir, "$name", StdModuleTypes.JAVA, true)!!
|
||||
if (hasTestRoot) {
|
||||
setTestRoot(moduleWithSrcRootSet, name)
|
||||
}
|
||||
return moduleWithSrcRootSet
|
||||
}
|
||||
|
||||
private fun setTestRoot(module: Module, name: String) {
|
||||
val testDir = TEST_DATA_PATH + "${getTestName(true)}/${name}Test"
|
||||
val testRootDirInTestData = File(testDir)
|
||||
val testRootDir = createTempDirectory()!!
|
||||
FileUtil.copyDir(testRootDirInTestData, testRootDir)
|
||||
val testRoot = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(testRootDir)!!
|
||||
object : WriteCommandAction.Simple<Unit>(project) {
|
||||
override fun run() {
|
||||
testRoot.refresh(false, true)
|
||||
}
|
||||
}.execute().throwException()
|
||||
PsiTestUtil.addSourceRoot(module, testRoot, true)
|
||||
}
|
||||
|
||||
private fun Module.addDependency(
|
||||
other: Module,
|
||||
dependencyScope: DependencyScope = DependencyScope.COMPILE,
|
||||
exported: Boolean = false
|
||||
) = ModuleRootModificationUtil.addDependency(this, other, dependencyScope, exported)
|
||||
}
|
||||
|
||||
@@ -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.codeInsight
|
||||
|
||||
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
|
||||
class Java8OverrideImplementTest : AbstractOverrideImplementTest() {
|
||||
companion object {
|
||||
private val TEST_PATH = PluginTestCaseBase.getTestDataPathBase() + "/codeInsight/overrideImplement/jdk8"
|
||||
}
|
||||
|
||||
override fun setUp() {
|
||||
super.setUp()
|
||||
myFixture.testDataPath = TEST_PATH
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE_FULL_JDK
|
||||
|
||||
fun testOverrideCollectionStream() {
|
||||
doOverrideFileTest("stream")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user