diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleCodeInsightBaseTestCase.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleCodeInsightBaseTestCase.kt index f40c208070a5..1e0e6e0cc53b 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleCodeInsightBaseTestCase.kt +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/GradleCodeInsightBaseTestCase.kt @@ -1,30 +1,59 @@ // Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.plugins.gradle.testFramework +import com.intellij.openapi.module.Module +import com.intellij.openapi.project.Project +import com.intellij.testFramework.common.runAll +import com.intellij.testFramework.fixtures.IdeaProjectTestFixture import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture -import org.gradle.util.GradleVersion -import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleCodeInsightTestFixture -import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleTestFixtureFactory +import com.intellij.testFramework.fixtures.impl.JavaCodeInsightTestFixtureImpl +import com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl +import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleProjectTestFixture import org.jetbrains.plugins.groovy.util.BaseTest abstract class GradleCodeInsightBaseTestCase : GradleProjectTestCase(), BaseTest { + private var _codeInsightFixture: JavaCodeInsightTestFixture? = null val codeInsightFixture: JavaCodeInsightTestFixture - get() = (gradleFixture as GradleCodeInsightTestFixture).codeInsightFixture + get() = requireNotNull(_codeInsightFixture) { + "Gradle code insight fixture wasn't setup. Please use [GradleBaseTestCase.test] function inside your tests." + } override fun getFixture(): JavaCodeInsightTestFixture = codeInsightFixture - override fun patchFixtureBuilder(fixtureBuilder: GradleTestFixtureBuilder): GradleTestFixtureBuilder = - GradleCodeInsightTestFixtureBuilder(fixtureBuilder) + override fun setUp() { + super.setUp() - private class GradleCodeInsightTestFixtureBuilder(private val builder: GradleTestFixtureBuilder) : GradleTestFixtureBuilder { + _codeInsightFixture = GradleCodeInsightTestFixture(gradleFixture) + codeInsightFixture.setUp() + } - override val projectName: String by builder::projectName + override fun tearDown() { + runAll( + { _codeInsightFixture?.tearDown() }, + { _codeInsightFixture = null }, + { super.tearDown() } + ) + } - override fun createFixture(gradleVersion: GradleVersion): GradleCodeInsightTestFixture { - val gradleFixture = builder.createFixture(gradleVersion) - val fixtureFactory = GradleTestFixtureFactory.getFixtureFactory() - return fixtureFactory.createGradleCodeInsightTestFixture(gradleFixture) + private class GradleIdeaProjectTestFixture(private val gradleFixture: GradleProjectTestFixture) : IdeaProjectTestFixture { + override fun getProject(): Project = gradleFixture.project + override fun getModule(): Module = gradleFixture.module + override fun setUp() = Unit + override fun tearDown() = Unit + } + + private class GradleCodeInsightTestFixture( + gradleFixture: GradleProjectTestFixture + ) : JavaCodeInsightTestFixtureImpl( + GradleIdeaProjectTestFixture(gradleFixture), + TempDirTestFixtureImpl() + ) { + + override fun shouldTrackVirtualFilePointers(): Boolean = false + + init { + setVirtualFileFilter(null) } } } diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/GradleTestFixtureFactory.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/GradleTestFixtureFactory.kt index 32029a971093..bed1c7600647 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/GradleTestFixtureFactory.kt +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/GradleTestFixtureFactory.kt @@ -30,16 +30,6 @@ interface GradleTestFixtureFactory { configure: FileTestFixture.Builder.() -> Unit ): GradleProjectTestFixture - fun createGradleCodeInsightTestFixture( - projectName: String, - gradleVersion: GradleVersion, - configure: FileTestFixture.Builder.() -> Unit - ): GradleCodeInsightTestFixture - - fun createGradleCodeInsightTestFixture( - gradleProjectTestFixture: GradleProjectTestFixture - ): GradleCodeInsightTestFixture - companion object { private val ourInstance = GradleTestFixtureFactoryImpl() diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/impl/GradleCodeInsightTestFixtureImpl.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/impl/GradleCodeInsightTestFixtureImpl.kt deleted file mode 100644 index f1d45c54e227..000000000000 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/impl/GradleCodeInsightTestFixtureImpl.kt +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. -package org.jetbrains.plugins.gradle.testFramework.fixtures.impl - -import com.intellij.openapi.module.Module -import com.intellij.openapi.project.Project -import com.intellij.testFramework.common.runAll -import com.intellij.testFramework.fixtures.IdeaProjectTestFixture -import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture -import com.intellij.testFramework.fixtures.impl.JavaCodeInsightTestFixtureImpl -import com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl -import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleCodeInsightTestFixture -import org.jetbrains.plugins.gradle.testFramework.fixtures.GradleProjectTestFixture - -class GradleCodeInsightTestFixtureImpl private constructor( - private val gradleFixture: GradleProjectTestFixture, - override val codeInsightFixture: JavaCodeInsightTestFixture -) : GradleCodeInsightTestFixture, GradleProjectTestFixture by gradleFixture { - - constructor(fixture: GradleProjectTestFixture) : this(fixture, createCodeInsightFixture(fixture)) - - override fun setUp() { - gradleFixture.setUp() - codeInsightFixture.setUp() - } - - override fun tearDown() { - runAll( - { codeInsightFixture.tearDown() }, - { gradleFixture.tearDown() } - ) - } - - companion object { - private fun createCodeInsightFixture(gradleFixture: GradleProjectTestFixture): JavaCodeInsightTestFixture { - val tempDirFixture = TempDirTestFixtureImpl() - val projectFixture = object : IdeaProjectTestFixture { - override fun getProject(): Project = gradleFixture.project - override fun getModule(): Module = gradleFixture.module - override fun setUp() = Unit - override fun tearDown() = Unit - } - return object : JavaCodeInsightTestFixtureImpl(projectFixture, tempDirFixture) { - override fun shouldTrackVirtualFilePointers(): Boolean = false - - init { - setVirtualFileFilter(null) - } - } - } - } -} \ No newline at end of file diff --git a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/impl/GradleTestFixtureFactoryImpl.kt b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/impl/GradleTestFixtureFactoryImpl.kt index 1f7f4b642c9a..5e8cf2cb0111 100644 --- a/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/impl/GradleTestFixtureFactoryImpl.kt +++ b/plugins/gradle/testSources/org/jetbrains/plugins/gradle/testFramework/fixtures/impl/GradleTestFixtureFactoryImpl.kt @@ -35,18 +35,4 @@ internal class GradleTestFixtureFactoryImpl : GradleTestFixtureFactory { ): GradleProjectTestFixture { return GradleProjectTestFixtureImpl(projectName, gradleVersion, configure) } - - override fun createGradleCodeInsightTestFixture( - projectName: String, - gradleVersion: GradleVersion, - configure: FileTestFixture.Builder.() -> Unit - ): GradleCodeInsightTestFixture { - return createGradleCodeInsightTestFixture( - createGradleProjectTestFixture(projectName, gradleVersion, configure) - ) - } - - override fun createGradleCodeInsightTestFixture(gradleProjectTestFixture: GradleProjectTestFixture): GradleCodeInsightTestFixture { - return GradleCodeInsightTestFixtureImpl(gradleProjectTestFixture) - } } \ No newline at end of file