diff --git a/gradle/versions.properties b/gradle/versions.properties index 62f86bb1210..562adb50368 100644 --- a/gradle/versions.properties +++ b/gradle/versions.properties @@ -1,4 +1,4 @@ -versions.intellijSdk=192.5728.98 +versions.intellijSdk=192.7142.36 versions.androidBuildTools=r23.0.1 versions.idea.NodeJS=181.3494.12 versions.jar.asm-all=7.0.1 diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/confidence/KotlinConfidenceTest.java b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/confidence/KotlinConfidenceTest.java index 96372ee9bbe..1d2a7c781e9 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/confidence/KotlinConfidenceTest.java +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/confidence/KotlinConfidenceTest.java @@ -155,7 +155,7 @@ public class KotlinConfidenceTest extends LightCompletionTestCase { new CodeCompletionHandlerBase(CompletionType.BASIC, false, true, true).invokeCompletion( getProject(), getEditor(), 0, false); - LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor); + LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(getEditor()); myItems = lookup == null ? null : lookup.getItems().toArray(LookupElement.EMPTY_ARRAY); myPrefix = lookup == null ? null : lookup.itemPattern(lookup.getItems().get(0)); } diff --git a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/confidence/KotlinConfidenceTest.java.193 b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/confidence/KotlinConfidenceTest.java.as36 similarity index 99% rename from idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/confidence/KotlinConfidenceTest.java.193 rename to idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/confidence/KotlinConfidenceTest.java.as36 index 1d2a7c781e9..96372ee9bbe 100644 --- a/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/confidence/KotlinConfidenceTest.java.193 +++ b/idea/idea-completion/tests/org/jetbrains/kotlin/idea/completion/test/confidence/KotlinConfidenceTest.java.as36 @@ -155,7 +155,7 @@ public class KotlinConfidenceTest extends LightCompletionTestCase { new CodeCompletionHandlerBase(CompletionType.BASIC, false, true, true).invokeCompletion( getProject(), getEditor(), 0, false); - LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(getEditor()); + LookupImpl lookup = (LookupImpl) LookupManager.getActiveLookup(myEditor); myItems = lookup == null ? null : lookup.getItems().toArray(LookupElement.EMPTY_ARRAY); myPrefix = lookup == null ? null : lookup.itemPattern(lookup.getItems().get(0)); } diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinDslScriptModelProvider.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinDslScriptModelProvider.kt index f0334f74583..24d752d3167 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinDslScriptModelProvider.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinDslScriptModelProvider.kt @@ -6,28 +6,28 @@ package org.jetbrains.kotlin.idea.configuration import org.gradle.tooling.BuildController -import org.gradle.tooling.model.idea.IdeaModule -import org.gradle.tooling.model.idea.IdeaProject +import org.gradle.tooling.model.Model +import org.gradle.tooling.model.gradle.GradleBuild import org.gradle.tooling.model.kotlin.dsl.KotlinDslScriptsModel -import org.jetbrains.plugins.gradle.model.ProjectImportExtraModelProvider +import org.jetbrains.plugins.gradle.model.ProjectImportModelProvider -class KotlinDslScriptModelProvider : ProjectImportExtraModelProvider { +class KotlinDslScriptModelProvider : ProjectImportModelProvider { private val kotlinDslScriptModelClass: Class<*> = KotlinDslScriptsModel::class.java override fun populateBuildModels( controller: BuildController, - project: IdeaProject, - consumer: ProjectImportExtraModelProvider.BuildModelConsumer + buildModel: GradleBuild, + consumer: ProjectImportModelProvider.BuildModelConsumer ) { val model = controller.findModel(kotlinDslScriptModelClass) if (model != null) { - consumer.consume(null, model, kotlinDslScriptModelClass) + consumer.consume(buildModel, model, kotlinDslScriptModelClass) } } override fun populateProjectModels( controller: BuildController, - module: IdeaModule?, - modelConsumer: ProjectImportExtraModelProvider.ProjectModelConsumer + projectModel: Model, + modelConsumer: ProjectImportModelProvider.ProjectModelConsumer ) = Unit } \ No newline at end of file diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinDslScriptModelProvider.kt.193 b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinDslScriptModelProvider.kt.as36 similarity index 59% rename from idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinDslScriptModelProvider.kt.193 rename to idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinDslScriptModelProvider.kt.as36 index 24d752d3167..f0334f74583 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinDslScriptModelProvider.kt.193 +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinDslScriptModelProvider.kt.as36 @@ -6,28 +6,28 @@ package org.jetbrains.kotlin.idea.configuration import org.gradle.tooling.BuildController -import org.gradle.tooling.model.Model -import org.gradle.tooling.model.gradle.GradleBuild +import org.gradle.tooling.model.idea.IdeaModule +import org.gradle.tooling.model.idea.IdeaProject import org.gradle.tooling.model.kotlin.dsl.KotlinDslScriptsModel -import org.jetbrains.plugins.gradle.model.ProjectImportModelProvider +import org.jetbrains.plugins.gradle.model.ProjectImportExtraModelProvider -class KotlinDslScriptModelProvider : ProjectImportModelProvider { +class KotlinDslScriptModelProvider : ProjectImportExtraModelProvider { private val kotlinDslScriptModelClass: Class<*> = KotlinDslScriptsModel::class.java override fun populateBuildModels( controller: BuildController, - buildModel: GradleBuild, - consumer: ProjectImportModelProvider.BuildModelConsumer + project: IdeaProject, + consumer: ProjectImportExtraModelProvider.BuildModelConsumer ) { val model = controller.findModel(kotlinDslScriptModelClass) if (model != null) { - consumer.consume(buildModel, model, kotlinDslScriptModelClass) + consumer.consume(null, model, kotlinDslScriptModelClass) } } override fun populateProjectModels( controller: BuildController, - projectModel: Model, - modelConsumer: ProjectImportModelProvider.ProjectModelConsumer + module: IdeaModule?, + modelConsumer: ProjectImportExtraModelProvider.ProjectModelConsumer ) = Unit } \ No newline at end of file diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleBuildScriptsResolver.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleBuildScriptsResolver.kt index b197e09d428..e5e419f9ec1 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleBuildScriptsResolver.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleBuildScriptsResolver.kt @@ -14,7 +14,7 @@ import org.gradle.tooling.model.kotlin.dsl.KotlinDslModelsParameters.* import org.gradle.tooling.model.kotlin.dsl.KotlinDslScriptsModel import org.jetbrains.kotlin.idea.scripting.gradle.kotlinDslScriptsModelImportSupported import org.jetbrains.kotlin.idea.scripting.gradle.minimal_gradle_version_supported -import org.jetbrains.plugins.gradle.model.ProjectImportExtraModelProvider +import org.jetbrains.plugins.gradle.model.ProjectImportModelProvider import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension class KotlinGradleBuildScriptsResolver : AbstractProjectResolverExtension() { @@ -37,7 +37,7 @@ class KotlinGradleBuildScriptsResolver : AbstractProjectResolverExtension() { ) } - override fun getExtraModelProvider(): ProjectImportExtraModelProvider { + override fun getModelProvider(): ProjectImportModelProvider { return KotlinDslScriptModelProvider() } diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleBuildScriptsResolver.kt.193 b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleBuildScriptsResolver.kt.as36 similarity index 94% rename from idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleBuildScriptsResolver.kt.193 rename to idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleBuildScriptsResolver.kt.as36 index e5e419f9ec1..b197e09d428 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleBuildScriptsResolver.kt.193 +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleBuildScriptsResolver.kt.as36 @@ -14,7 +14,7 @@ import org.gradle.tooling.model.kotlin.dsl.KotlinDslModelsParameters.* import org.gradle.tooling.model.kotlin.dsl.KotlinDslScriptsModel import org.jetbrains.kotlin.idea.scripting.gradle.kotlinDslScriptsModelImportSupported import org.jetbrains.kotlin.idea.scripting.gradle.minimal_gradle_version_supported -import org.jetbrains.plugins.gradle.model.ProjectImportModelProvider +import org.jetbrains.plugins.gradle.model.ProjectImportExtraModelProvider import org.jetbrains.plugins.gradle.service.project.AbstractProjectResolverExtension class KotlinGradleBuildScriptsResolver : AbstractProjectResolverExtension() { @@ -37,7 +37,7 @@ class KotlinGradleBuildScriptsResolver : AbstractProjectResolverExtension() { ) } - override fun getModelProvider(): ProjectImportModelProvider { + override fun getExtraModelProvider(): ProjectImportExtraModelProvider { return KotlinDslScriptModelProvider() } diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java index 42fdde3a79e..b473aa5f250 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java @@ -1,37 +1,22 @@ /* - * 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. + * 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.codeInsight.gradle; import com.google.common.collect.Multimap; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.StreamUtil; import com.intellij.testFramework.IdeaTestUtil; -import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling; import org.gradle.tooling.BuildActionExecuter; import org.gradle.tooling.GradleConnector; import org.gradle.tooling.ProjectConnection; import org.gradle.tooling.internal.consumer.DefaultGradleConnector; -import org.gradle.tooling.model.DomainObjectSet; -import org.gradle.tooling.model.idea.IdeaModule; import org.gradle.util.GradleVersion; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.gradle.model.ClassSetProjectImportExtraModelProvider; +import org.jetbrains.plugins.gradle.model.ClassSetProjectImportModelProvider; import org.jetbrains.plugins.gradle.model.ExternalProject; import org.jetbrains.plugins.gradle.model.ProjectImportAction; import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper; @@ -49,7 +34,10 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -141,7 +129,7 @@ public abstract class AbstractModelBuilderTest { try { ProjectImportAction projectImportAction = new ProjectImportAction(false); - projectImportAction.addProjectImportExtraModelProvider(new ClassSetProjectImportExtraModelProvider(getModels())); + projectImportAction.addProjectImportModelProvider(new ClassSetProjectImportModelProvider(getModels())); BuildActionExecuter buildActionExecutor = connection.action(projectImportAction); File initScript = GradleExecutionHelper.generateInitScript(false, getToolingExtensionClasses()); assertNotNull(initScript); @@ -189,23 +177,6 @@ public abstract class AbstractModelBuilderTest { protected abstract Set getModels(); - private Map getModulesMap(final Class aClass) { - DomainObjectSet ideaModules = allModels.getIdeaProject().getModules(); - - final String filterKey = "to_filter"; - Map map = ContainerUtil.map2Map(ideaModules, new Function>() { - @Override - public Pair fun(IdeaModule module) { - T value = allModels.getExtraProject(module, aClass); - String key = value != null ? module.getGradleProject().getPath() : filterKey; - return Pair.create(key, value); - } - }); - - map.remove(filterKey); - return map; - } - private static void ensureTempDirCreated() throws IOException { if (ourTempDir != null) return; diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.193 b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.191 similarity index 89% rename from idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.193 rename to idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.191 index a88edb92c07..42fdde3a79e 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.193 +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.191 @@ -16,18 +16,22 @@ package org.jetbrains.kotlin.idea.codeInsight.gradle; import com.google.common.collect.Multimap; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.StreamUtil; import com.intellij.testFramework.IdeaTestUtil; +import com.intellij.util.Function; import com.intellij.util.containers.ContainerUtil; import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling; import org.gradle.tooling.BuildActionExecuter; import org.gradle.tooling.GradleConnector; import org.gradle.tooling.ProjectConnection; import org.gradle.tooling.internal.consumer.DefaultGradleConnector; +import org.gradle.tooling.model.DomainObjectSet; +import org.gradle.tooling.model.idea.IdeaModule; import org.gradle.util.GradleVersion; import org.jetbrains.annotations.NotNull; -import org.jetbrains.plugins.gradle.model.ClassSetProjectImportModelProvider; +import org.jetbrains.plugins.gradle.model.ClassSetProjectImportExtraModelProvider; import org.jetbrains.plugins.gradle.model.ExternalProject; import org.jetbrains.plugins.gradle.model.ProjectImportAction; import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper; @@ -45,10 +49,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Set; +import java.util.*; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -140,7 +141,7 @@ public abstract class AbstractModelBuilderTest { try { ProjectImportAction projectImportAction = new ProjectImportAction(false); - projectImportAction.addProjectImportModelProvider(new ClassSetProjectImportModelProvider(getModels())); + projectImportAction.addProjectImportExtraModelProvider(new ClassSetProjectImportExtraModelProvider(getModels())); BuildActionExecuter buildActionExecutor = connection.action(projectImportAction); File initScript = GradleExecutionHelper.generateInitScript(false, getToolingExtensionClasses()); assertNotNull(initScript); @@ -188,6 +189,23 @@ public abstract class AbstractModelBuilderTest { protected abstract Set getModels(); + private Map getModulesMap(final Class aClass) { + DomainObjectSet ideaModules = allModels.getIdeaProject().getModules(); + + final String filterKey = "to_filter"; + Map map = ContainerUtil.map2Map(ideaModules, new Function>() { + @Override + public Pair fun(IdeaModule module) { + T value = allModels.getExtraProject(module, aClass); + String key = value != null ? module.getGradleProject().getPath() : filterKey; + return Pair.create(key, value); + } + }); + + map.remove(filterKey); + return map; + } + private static void ensureTempDirCreated() throws IOException { if (ourTempDir != null) return; diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.as36 b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.as36 new file mode 100644 index 00000000000..42fdde3a79e --- /dev/null +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/AbstractModelBuilderTest.java.as36 @@ -0,0 +1,262 @@ +/* + * 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.gradle; + +import com.google.common.collect.Multimap; +import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.util.io.StreamUtil; +import com.intellij.testFramework.IdeaTestUtil; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; +import org.codehaus.groovy.runtime.typehandling.ShortTypeHandling; +import org.gradle.tooling.BuildActionExecuter; +import org.gradle.tooling.GradleConnector; +import org.gradle.tooling.ProjectConnection; +import org.gradle.tooling.internal.consumer.DefaultGradleConnector; +import org.gradle.tooling.model.DomainObjectSet; +import org.gradle.tooling.model.idea.IdeaModule; +import org.gradle.util.GradleVersion; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.gradle.model.ClassSetProjectImportExtraModelProvider; +import org.jetbrains.plugins.gradle.model.ExternalProject; +import org.jetbrains.plugins.gradle.model.ProjectImportAction; +import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper; +import org.jetbrains.plugins.gradle.tooling.builder.ModelBuildScriptClasspathBuilderImpl; +import org.jetbrains.plugins.gradle.util.GradleConstants; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TestName; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assume.assumeThat; + +// part of org.jetbrains.plugins.gradle.tooling.builder.AbstractModelBuilderTest +@RunWith(value = Parameterized.class) +public abstract class AbstractModelBuilderTest { + + public static final Object[][] SUPPORTED_GRADLE_VERSIONS = {{"4.9"}, {"5.6.4"}}; + + private static final Pattern TEST_METHOD_NAME_PATTERN = Pattern.compile("(.*)\\[(\\d*: with Gradle-.*)\\]"); + + private static File ourTempDir; + + @NotNull + private final String gradleVersion; + private File testDir; + private ProjectImportAction.AllModels allModels; + + @Rule public TestName name = new TestName(); + @Rule public VersionMatcherRule versionMatcherRule = new VersionMatcherRule(); + + public AbstractModelBuilderTest(@NotNull String gradleVersion) { + this.gradleVersion = gradleVersion; + } + + @Parameterized.Parameters(name = "{index}: with Gradle-{0}") + public static Collection data() { + return Arrays.asList(SUPPORTED_GRADLE_VERSIONS); + } + + + @Before + public void setUp() throws Exception { + assumeThat(gradleVersion, versionMatcherRule.getMatcher()); + + ensureTempDirCreated(); + + String methodName = name.getMethodName(); + Matcher m = TEST_METHOD_NAME_PATTERN.matcher(methodName); + if (m.matches()) { + methodName = m.group(1); + } + + testDir = new File(ourTempDir, methodName); + FileUtil.ensureExists(testDir); + + InputStream buildScriptStream = getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.DEFAULT_SCRIPT_NAME); + try { + FileUtil.writeToFile( + new File(testDir, GradleConstants.DEFAULT_SCRIPT_NAME), + FileUtil.loadTextAndClose(buildScriptStream) + ); + } + finally { + StreamUtil.closeStream(buildScriptStream); + } + + InputStream settingsStream = getClass().getResourceAsStream("/" + methodName + "/" + GradleConstants.SETTINGS_FILE_NAME); + try { + if (settingsStream != null) { + FileUtil.writeToFile( + new File(testDir, GradleConstants.SETTINGS_FILE_NAME), + FileUtil.loadTextAndClose(settingsStream) + ); + } + } + finally { + StreamUtil.closeStream(settingsStream); + } + + GradleConnector connector = GradleConnector.newConnector(); + + URI distributionUri = new DistributionLocator().getDistributionFor(GradleVersion.version(gradleVersion)); + connector.useDistribution(distributionUri); + connector.forProjectDirectory(testDir); + int daemonMaxIdleTime = 10; + try { + daemonMaxIdleTime = Integer.parseInt(System.getProperty("gradleDaemonMaxIdleTime", "10")); + } + catch (NumberFormatException ignore) { + } + + ((DefaultGradleConnector) connector).daemonMaxIdleTime(daemonMaxIdleTime, TimeUnit.SECONDS); + ProjectConnection connection = connector.connect(); + + try { + ProjectImportAction projectImportAction = new ProjectImportAction(false); + projectImportAction.addProjectImportExtraModelProvider(new ClassSetProjectImportExtraModelProvider(getModels())); + BuildActionExecuter buildActionExecutor = connection.action(projectImportAction); + File initScript = GradleExecutionHelper.generateInitScript(false, getToolingExtensionClasses()); + assertNotNull(initScript); + String jdkHome = IdeaTestUtil.requireRealJdkHome(); + buildActionExecutor.setJavaHome(new File(jdkHome)); + buildActionExecutor.setJvmArguments("-Xmx128m", "-XX:MaxPermSize=64m"); + buildActionExecutor + .withArguments("--info", "--recompile-scripts", GradleConstants.INIT_SCRIPT_CMD_OPTION, initScript.getAbsolutePath()); + allModels = buildActionExecutor.run(); + assertNotNull(allModels); + } + finally { + connection.close(); + } + } + + @NotNull + private static Set getToolingExtensionClasses() { + Set classes = ContainerUtil.set( + ExternalProject.class, + // gradle-tooling-extension-api jar + ProjectImportAction.class, + // gradle-tooling-extension-impl jar + ModelBuildScriptClasspathBuilderImpl.class, + Multimap.class, + ShortTypeHandling.class + ); + + ContainerUtil.addAllNotNull(classes, doGetToolingExtensionClasses()); + return classes; + } + + @NotNull + private static Set doGetToolingExtensionClasses() { + return Collections.emptySet(); + } + + @After + public void tearDown() throws Exception { + if (testDir != null) { + FileUtil.delete(testDir); + } + } + + protected abstract Set getModels(); + + + private Map getModulesMap(final Class aClass) { + DomainObjectSet ideaModules = allModels.getIdeaProject().getModules(); + + final String filterKey = "to_filter"; + Map map = ContainerUtil.map2Map(ideaModules, new Function>() { + @Override + public Pair fun(IdeaModule module) { + T value = allModels.getExtraProject(module, aClass); + String key = value != null ? module.getGradleProject().getPath() : filterKey; + return Pair.create(key, value); + } + }); + + map.remove(filterKey); + return map; + } + + private static void ensureTempDirCreated() throws IOException { + if (ourTempDir != null) return; + + ourTempDir = new File(FileUtil.getTempDirectory(), "gradleTests"); + FileUtil.delete(ourTempDir); + FileUtil.ensureExists(ourTempDir); + } + + public static class DistributionLocator { + private static final String RELEASE_REPOSITORY_ENV = "GRADLE_RELEASE_REPOSITORY"; + private static final String SNAPSHOT_REPOSITORY_ENV = "GRADLE_SNAPSHOT_REPOSITORY"; + private static final String GRADLE_RELEASE_REPO = "https://services.gradle.org/distributions"; + private static final String GRADLE_SNAPSHOT_REPO = "https://services.gradle.org/distributions-snapshots"; + + @NotNull private final String myReleaseRepoUrl; + @NotNull private final String mySnapshotRepoUrl; + + public DistributionLocator() { + this(DistributionLocator.getRepoUrl(false), DistributionLocator.getRepoUrl(true)); + } + + public DistributionLocator(@NotNull String releaseRepoUrl, @NotNull String snapshotRepoUrl) { + myReleaseRepoUrl = releaseRepoUrl; + mySnapshotRepoUrl = snapshotRepoUrl; + } + + @NotNull + public URI getDistributionFor(@NotNull GradleVersion version) throws URISyntaxException { + return getDistribution(getDistributionRepository(version), version, "gradle", "bin"); + } + + @NotNull + private String getDistributionRepository(@NotNull GradleVersion version) { + return version.isSnapshot() ? mySnapshotRepoUrl : myReleaseRepoUrl; + } + + private static URI getDistribution( + @NotNull String repositoryUrl, + @NotNull GradleVersion version, + @NotNull String archiveName, + @NotNull String archiveClassifier + ) throws URISyntaxException { + return new URI(String.format("%s/%s-%s-%s.zip", repositoryUrl, archiveName, version.getVersion(), archiveClassifier)); + } + + @NotNull + public static String getRepoUrl(boolean isSnapshotUrl) { + String envRepoUrl = System.getenv(isSnapshotUrl ? SNAPSHOT_REPOSITORY_ENV : RELEASE_REPOSITORY_ENV); + if (envRepoUrl != null) return envRepoUrl; + + return isSnapshotUrl ? GRADLE_SNAPSHOT_REPO : GRADLE_RELEASE_REPO; + } + } +} diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt index 207efe333c8..2461ca991fa 100644 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt @@ -7,24 +7,31 @@ package org.jetbrains.kotlin.idea.test +import com.intellij.openapi.actionSystem.DataContext +import com.intellij.openapi.editor.Document import com.intellij.openapi.editor.Editor import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project +import com.intellij.psi.PsiFile import com.intellij.testFramework.LightIdeaTestCase -import com.intellij.testFramework.LightPlatformCodeInsightTestCase -import com.intellij.testFramework.LightPlatformTestCase -// BUNCH: 192 +// BUNCH: as36, 191 @Suppress("DEPRECATION") @Deprecated("Use KotlinLightCodeInsightFixtureTestCase instead") abstract class KotlinLightCodeInsightTestCase : com.intellij.testFramework.LightCodeInsightTestCase() { - protected inline val project_: Project get() = LightPlatformTestCase.getProject() - protected inline val module_: Module get() = LightPlatformTestCase.getModule() - protected inline val editor_: Editor get() = LightPlatformCodeInsightTestCase.getEditor() + protected inline val project_: Project get() = project + protected inline val module_: Module get() = module + protected inline val editor_: Editor get() = editor + protected inline val file_: PsiFile get() = file + protected inline val currentEditorDataContext_: DataContext get() = currentEditorDataContext + + protected fun configureFromFileText_(fileName: String, fileText: String): Document { + return configureFromFileText(fileName, fileText, false) + } } -// BUNCH: 192 +// BUNCH: as36, 191 abstract class KotlinLightIdeaTestCase : LightIdeaTestCase() { - protected inline val project_: Project get() = LightPlatformTestCase.getProject() - protected inline val module_: Module get() = LightPlatformTestCase.getModule() + protected inline val project_: Project get() = project + protected inline val module_: Module get() = module } \ No newline at end of file diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.191 b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.191 new file mode 100644 index 00000000000..e44198d0879 --- /dev/null +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.191 @@ -0,0 +1,39 @@ +/* + * 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. + */ + +@file:Suppress("unused", "IncompatibleAPI", "PropertyName") + +package org.jetbrains.kotlin.idea.test + +import com.intellij.openapi.actionSystem.DataContext +import com.intellij.openapi.editor.Document +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.module.Module +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiFile +import com.intellij.testFramework.LightIdeaTestCase +import com.intellij.testFramework.LightPlatformCodeInsightTestCase +import com.intellij.testFramework.LightPlatformTestCase + +// BUNCH: as36, 191 +@Suppress("DEPRECATION") +@Deprecated("Use KotlinLightCodeInsightFixtureTestCase instead") +abstract class KotlinLightCodeInsightTestCase : com.intellij.testFramework.LightCodeInsightTestCase() { + protected inline val project_: Project get() = LightPlatformTestCase.getProject() + protected inline val module_: Module get() = LightPlatformTestCase.getModule() + protected inline val editor_: Editor get() = LightPlatformCodeInsightTestCase.getEditor() + protected inline val file_: PsiFile get() = LightPlatformCodeInsightTestCase.getFile() + protected inline val currentEditorDataContext_: DataContext get() = LightPlatformCodeInsightTestCase.getCurrentEditorDataContext() + + protected fun configureFromFileText_(fileName: String, fileText: String): Document { + return LightPlatformCodeInsightTestCase.configureFromFileText(fileName, fileText, false) + } +} + +// BUNCH: as36, 191 +abstract class KotlinLightIdeaTestCase : LightIdeaTestCase() { + protected inline val project_: Project get() = LightPlatformTestCase.getProject() + protected inline val module_: Module get() = LightPlatformTestCase.getModule() +} \ No newline at end of file diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.193 b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.193 deleted file mode 100644 index 7e28bfe2707..00000000000 --- a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.193 +++ /dev/null @@ -1,28 +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. - */ - -@file:Suppress("unused", "IncompatibleAPI", "PropertyName") - -package org.jetbrains.kotlin.idea.test - -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.module.Module -import com.intellij.openapi.project.Project -import com.intellij.testFramework.LightIdeaTestCase - -// BUNCH: 192 -@Suppress("DEPRECATION") -@Deprecated("Use KotlinLightCodeInsightFixtureTestCase instead") -abstract class KotlinLightCodeInsightTestCase : com.intellij.testFramework.LightCodeInsightTestCase() { - protected inline val project_: Project get() = project - protected inline val module_: Module get() = module - protected inline val editor_: Editor get() = editor -} - -// BUNCH: 192 -abstract class KotlinLightIdeaTestCase : LightIdeaTestCase() { - protected inline val project_: Project get() = project - protected inline val module_: Module get() = module -} \ No newline at end of file diff --git a/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.as36 b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.as36 new file mode 100644 index 00000000000..e44198d0879 --- /dev/null +++ b/idea/idea-test-framework/test/org/jetbrains/kotlin/idea/test/compatTestWrappers.kt.as36 @@ -0,0 +1,39 @@ +/* + * 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. + */ + +@file:Suppress("unused", "IncompatibleAPI", "PropertyName") + +package org.jetbrains.kotlin.idea.test + +import com.intellij.openapi.actionSystem.DataContext +import com.intellij.openapi.editor.Document +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.module.Module +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiFile +import com.intellij.testFramework.LightIdeaTestCase +import com.intellij.testFramework.LightPlatformCodeInsightTestCase +import com.intellij.testFramework.LightPlatformTestCase + +// BUNCH: as36, 191 +@Suppress("DEPRECATION") +@Deprecated("Use KotlinLightCodeInsightFixtureTestCase instead") +abstract class KotlinLightCodeInsightTestCase : com.intellij.testFramework.LightCodeInsightTestCase() { + protected inline val project_: Project get() = LightPlatformTestCase.getProject() + protected inline val module_: Module get() = LightPlatformTestCase.getModule() + protected inline val editor_: Editor get() = LightPlatformCodeInsightTestCase.getEditor() + protected inline val file_: PsiFile get() = LightPlatformCodeInsightTestCase.getFile() + protected inline val currentEditorDataContext_: DataContext get() = LightPlatformCodeInsightTestCase.getCurrentEditorDataContext() + + protected fun configureFromFileText_(fileName: String, fileText: String): Document { + return LightPlatformCodeInsightTestCase.configureFromFileText(fileName, fileText, false) + } +} + +// BUNCH: as36, 191 +abstract class KotlinLightIdeaTestCase : LightIdeaTestCase() { + protected inline val project_: Project get() = LightPlatformTestCase.getProject() + protected inline val module_: Module get() = LightPlatformTestCase.getModule() +} \ No newline at end of file diff --git a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt index 251877e099f..418a1681e4f 100644 --- a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt +++ b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt @@ -10,7 +10,6 @@ import com.intellij.debugger.streams.wrapper.StreamChainBuilder import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable -import com.intellij.testFramework.LightPlatformTestCase import com.intellij.testFramework.PsiTestUtil import junit.framework.TestCase import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime @@ -34,18 +33,18 @@ abstract class KotlinPsiChainBuilderTestCase(private val relativePath: String) : super.setUp() ApplicationManager.getApplication().runWriteAction { @Suppress("UnstableApiUsage") - if (ProjectLibraryTable.getInstance(LightPlatformTestCase.getProject()).getLibraryByName(stdLibName) == null) { + if (ProjectLibraryTable.getInstance(project).getLibraryByName(stdLibName) == null) { val stdLibPath = ForTestCompileRuntime.runtimeJarForTests() PsiTestUtil.addLibrary( testRootDisposable, - LightPlatformTestCase.getModule(), + module, stdLibName, stdLibPath.parent, stdLibPath.name ) } } - LibraryModificationTracker.getInstance(LightPlatformTestCase.getProject()).incModificationCount() + LibraryModificationTracker.getInstance(project).incModificationCount() } diff --git a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt.193 b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt.191 similarity index 89% rename from idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt.193 rename to idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt.191 index 418a1681e4f..251877e099f 100644 --- a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt.193 +++ b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt.191 @@ -10,6 +10,7 @@ import com.intellij.debugger.streams.wrapper.StreamChainBuilder import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable +import com.intellij.testFramework.LightPlatformTestCase import com.intellij.testFramework.PsiTestUtil import junit.framework.TestCase import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime @@ -33,18 +34,18 @@ abstract class KotlinPsiChainBuilderTestCase(private val relativePath: String) : super.setUp() ApplicationManager.getApplication().runWriteAction { @Suppress("UnstableApiUsage") - if (ProjectLibraryTable.getInstance(project).getLibraryByName(stdLibName) == null) { + if (ProjectLibraryTable.getInstance(LightPlatformTestCase.getProject()).getLibraryByName(stdLibName) == null) { val stdLibPath = ForTestCompileRuntime.runtimeJarForTests() PsiTestUtil.addLibrary( testRootDisposable, - module, + LightPlatformTestCase.getModule(), stdLibName, stdLibPath.parent, stdLibPath.name ) } } - LibraryModificationTracker.getInstance(project).incModificationCount() + LibraryModificationTracker.getInstance(LightPlatformTestCase.getProject()).incModificationCount() } diff --git a/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt.as36 b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt.as36 new file mode 100644 index 00000000000..251877e099f --- /dev/null +++ b/idea/jvm-debugger/jvm-debugger-test/test/org/jetbrains/kotlin/idea/debugger/test/sequence/KotlinPsiChainBuilderTestCase.kt.as36 @@ -0,0 +1,74 @@ +/* + * 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.debugger.test.sequence + +import com.intellij.debugger.streams.test.StreamChainBuilderTestCase +import com.intellij.debugger.streams.wrapper.StreamChain +import com.intellij.debugger.streams.wrapper.StreamChainBuilder +import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.projectRoots.Sdk +import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable +import com.intellij.testFramework.LightPlatformTestCase +import com.intellij.testFramework.PsiTestUtil +import junit.framework.TestCase +import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime +import org.jetbrains.kotlin.idea.caches.project.LibraryModificationTracker +import org.jetbrains.kotlin.idea.debugger.test.DEBUGGER_TESTDATA_PATH_BASE +import org.jetbrains.kotlin.idea.test.PluginTestCaseBase + +abstract class KotlinPsiChainBuilderTestCase(private val relativePath: String) : StreamChainBuilderTestCase() { + override fun getTestDataPath(): String = "$DEBUGGER_TESTDATA_PATH_BASE/sequence/psi/$relativeTestPath" + + override fun getFileExtension(): String = ".kt" + abstract val kotlinChainBuilder: StreamChainBuilder + override fun getChainBuilder(): StreamChainBuilder = kotlinChainBuilder + private val stdLibName = "kotlin-stdlib" + + protected abstract fun doTest() + + final override fun getRelativeTestPath(): String = relativePath + + override fun setUp() { + super.setUp() + ApplicationManager.getApplication().runWriteAction { + @Suppress("UnstableApiUsage") + if (ProjectLibraryTable.getInstance(LightPlatformTestCase.getProject()).getLibraryByName(stdLibName) == null) { + val stdLibPath = ForTestCompileRuntime.runtimeJarForTests() + PsiTestUtil.addLibrary( + testRootDisposable, + LightPlatformTestCase.getModule(), + stdLibName, + stdLibPath.parent, + stdLibPath.name + ) + } + } + LibraryModificationTracker.getInstance(LightPlatformTestCase.getProject()).incModificationCount() + } + + + override fun getProjectJDK(): Sdk { + return PluginTestCaseBase.mockJdk9() + } + + abstract class Positive(relativePath: String) : KotlinPsiChainBuilderTestCase(relativePath) { + override fun doTest() { + val chains = buildChains() + checkChains(chains) + } + + private fun checkChains(chains: MutableList) { + TestCase.assertFalse(chains.isEmpty()) + } + } + + abstract class Negative(relativePath: String) : KotlinPsiChainBuilderTestCase(relativePath) { + override fun doTest() { + val elementAtCaret = configureAndGetElementAtCaret() + TestCase.assertFalse(chainBuilder.isChainExists(elementAtCaret)) + TestCase.assertTrue(chainBuilder.build(elementAtCaret).isEmpty()) + } + } +} diff --git a/idea/resources/META-INF/plugin.xml b/idea/resources/META-INF/plugin.xml index 85928be5131..97b36144124 100644 --- a/idea/resources/META-INF/plugin.xml +++ b/idea/resources/META-INF/plugin.xml @@ -13,7 +13,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio. @snapshot@ JetBrains - + com.intellij.modules.platform diff --git a/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java b/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java index 6bf6240e5e5..71fe797671e 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.formatter; +import com.intellij.application.options.CodeStyle; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.Document; @@ -46,13 +47,13 @@ public abstract class AbstractFormatterTest extends KotlinLightIdeaTestCase { ACTIONS.put(Action.REFORMAT, new TestFormatAction() { @Override public void run(PsiFile psiFile, int startOffset, int endOffset) { - CodeStyleManager.getInstance(getProject()).reformatText(psiFile, startOffset, endOffset); + CodeStyleManager.getInstance(psiFile.getProject()).reformatText(psiFile, startOffset, endOffset); } }); ACTIONS.put(Action.INDENT, new TestFormatAction() { @Override public void run(PsiFile psiFile, int startOffset, int endOffset) { - CodeStyleManager.getInstance(getProject()).adjustLineIndent(psiFile, startOffset); + CodeStyleManager.getInstance(psiFile.getProject()).adjustLineIndent(psiFile, startOffset); } }); } @@ -131,7 +132,7 @@ public abstract class AbstractFormatterTest extends KotlinLightIdeaTestCase { String testFileExtension = expectedFileNameWithExtension.substring(expectedFileNameWithExtension.lastIndexOf(".")); String originalFileText = FileUtil.loadFile(new File(testFileName + testFileExtension), true); - CodeStyleSettings codeStyleSettings = FormatSettingsUtil.getSettings(getProject()); + CodeStyleSettings codeStyleSettings = CodeStyle.getSettings(getProject_()); try { Integer rightMargin = InTextDirectivesUtils.getPrefixedInt(originalFileText, "// RIGHT_MARGIN: "); if (rightMargin != null) { diff --git a/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java.191 b/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java.191 deleted file mode 100644 index 56c2a3ca83a..00000000000 --- a/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java.191 +++ /dev/null @@ -1,154 +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.formatter; - -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.command.CommandProcessor; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.impl.DocumentImpl; -import com.intellij.openapi.roots.LanguageLevelProjectExtension; -import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.pom.java.LanguageLevel; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.psi.PsiFile; -import com.intellij.psi.codeStyle.CodeStyleManager; -import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.KotlinLanguage; -import org.jetbrains.kotlin.idea.test.KotlinLightIdeaTestCase; -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; -import org.jetbrains.kotlin.test.InTextDirectivesUtils; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.SettingsConfigurator; - -import java.io.File; -import java.util.EnumMap; -import java.util.Map; - -// Based on from com.intellij.psi.formatter.java.AbstractJavaFormatterTest -@SuppressWarnings("UnusedDeclaration") -public abstract class AbstractFormatterTest extends KotlinLightIdeaTestCase { - - protected enum Action {REFORMAT, INDENT} - - private interface TestFormatAction { - void run(PsiFile psiFile, int startOffset, int endOffset); - } - - private static final Map ACTIONS = new EnumMap(Action.class); - static { - ACTIONS.put(Action.REFORMAT, new TestFormatAction() { - @Override - public void run(PsiFile psiFile, int startOffset, int endOffset) { - CodeStyleManager.getInstance(getProject()).reformatText(psiFile, startOffset, endOffset); - } - }); - ACTIONS.put(Action.INDENT, new TestFormatAction() { - @Override - public void run(PsiFile psiFile, int startOffset, int endOffset) { - CodeStyleManager.getInstance(getProject()).adjustLineIndent(psiFile, startOffset); - } - }); - } - - private static final String BASE_PATH = - new File(PluginTestCaseBase.getTestDataPathBase(), "/formatter/").getAbsolutePath(); - - public TextRange myTextRange; - public TextRange myLineRange; - - @Override - protected void setUp() throws Exception { - super.setUp(); - LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.HIGHEST); - } - - public void doTextTest(@NonNls String text, File fileAfter, String extension) throws IncorrectOperationException { - doTextTest(Action.REFORMAT, text, fileAfter, extension); - } - - public void doTextTest(final Action action, final String text, File fileAfter, String extension) throws IncorrectOperationException { - final PsiFile file = createFile("A" + extension, text); - - if (myLineRange != null) { - DocumentImpl document = new DocumentImpl(text); - myTextRange = - new TextRange(document.getLineStartOffset(myLineRange.getStartOffset()), document.getLineEndOffset(myLineRange.getEndOffset())); - } - - final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject()); - final Document document = manager.getDocument(file); - - CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { - @Override - public void run() { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - document.replaceString(0, document.getTextLength(), text); - manager.commitDocument(document); - try { - TextRange rangeToUse = myTextRange; - if (rangeToUse == null) { - rangeToUse = file.getTextRange(); - } - ACTIONS.get(action).run(file, rangeToUse.getStartOffset(), rangeToUse.getEndOffset()); - } - catch (IncorrectOperationException e) { - assertTrue(e.getLocalizedMessage(), false); - } - } - }); - } - }, "", ""); - - - if (document == null) { - fail("Don't expect the document to be null"); - return; - } - KotlinTestUtils.assertEqualsToFile(fileAfter, document.getText()); - manager.commitDocument(document); - KotlinTestUtils.assertEqualsToFile(fileAfter, file.getText()); - } - - public void doTest(@NotNull String expectedFileNameWithExtension) throws Exception { - doTest(expectedFileNameWithExtension, false); - } - - public void doTestInverted(@NotNull String expectedFileNameWithExtension) throws Exception { - doTest(expectedFileNameWithExtension, true); - } - - public void doTest(@NotNull String expectedFileNameWithExtension, boolean inverted) throws Exception { - String testFileName = expectedFileNameWithExtension.substring(0, expectedFileNameWithExtension.indexOf(".")); - String testFileExtension = expectedFileNameWithExtension.substring(expectedFileNameWithExtension.lastIndexOf(".")); - String originalFileText = FileUtil.loadFile(new File(testFileName + testFileExtension), true); - - CodeStyleSettings codeStyleSettings = FormatSettingsUtil.getSettings(); - try { - Integer rightMargin = InTextDirectivesUtils.getPrefixedInt(originalFileText, "// RIGHT_MARGIN: "); - if (rightMargin != null) { - codeStyleSettings.setRightMargin(KotlinLanguage.INSTANCE, rightMargin); - } - - SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(originalFileText, codeStyleSettings); - if (!inverted) { - configurator.configureSettings(); - } - else { - configurator.configureInvertedSettings(); - } - - doTextTest(originalFileText, new File(expectedFileNameWithExtension), testFileExtension); - } finally { - codeStyleSettings.clearCodeStyleSettings(); - } - } -} diff --git a/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java.193 b/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java.193 deleted file mode 100644 index bbd9aa8cbca..00000000000 --- a/idea/tests/org/jetbrains/kotlin/formatter/AbstractFormatterTest.java.193 +++ /dev/null @@ -1,146 +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.formatter; - -import com.intellij.openapi.application.ApplicationManager; -import com.intellij.openapi.command.CommandProcessor; -import com.intellij.openapi.editor.Document; -import com.intellij.openapi.editor.impl.DocumentImpl; -import com.intellij.openapi.roots.LanguageLevelProjectExtension; -import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.pom.java.LanguageLevel; -import com.intellij.psi.PsiDocumentManager; -import com.intellij.psi.PsiFile; -import com.intellij.psi.codeStyle.CodeStyleManager; -import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.KotlinLanguage; -import org.jetbrains.kotlin.idea.test.KotlinLightIdeaTestCase; -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; -import org.jetbrains.kotlin.test.InTextDirectivesUtils; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.SettingsConfigurator; - -import java.io.File; -import java.util.EnumMap; -import java.util.Map; - -// Based on from com.intellij.psi.formatter.java.AbstractJavaFormatterTest -@SuppressWarnings("UnusedDeclaration") -public abstract class AbstractFormatterTest extends KotlinLightIdeaTestCase { - - protected enum Action {REFORMAT, INDENT} - - private interface TestFormatAction { - void run(PsiFile psiFile, int startOffset, int endOffset); - } - - private static final Map ACTIONS = new EnumMap<>(Action.class); - static { - ACTIONS.put(Action.REFORMAT, - (psiFile, startOffset, endOffset) -> CodeStyleManager.getInstance(psiFile.getProject()).reformatText(psiFile, startOffset, endOffset)); - ACTIONS.put(Action.INDENT, - (psiFile, startOffset, endOffset) -> CodeStyleManager.getInstance(psiFile.getProject()).adjustLineIndent(psiFile, startOffset)); - } - - private static final String BASE_PATH = - new File(PluginTestCaseBase.getTestDataPathBase(), "/formatter/").getAbsolutePath(); - - public TextRange myTextRange; - public TextRange myLineRange; - - @Override - protected void setUp() throws Exception { - super.setUp(); - LanguageLevelProjectExtension.getInstance(getProject()).setLanguageLevel(LanguageLevel.HIGHEST); - } - - public void doTextTest(@NonNls String text, File fileAfter, String extension) throws IncorrectOperationException { - doTextTest(Action.REFORMAT, text, fileAfter, extension); - } - - public void doTextTest(final Action action, final String text, File fileAfter, String extension) throws IncorrectOperationException { - final PsiFile file = createFile("A" + extension, text); - - if (myLineRange != null) { - DocumentImpl document = new DocumentImpl(text); - myTextRange = - new TextRange(document.getLineStartOffset(myLineRange.getStartOffset()), document.getLineEndOffset(myLineRange.getEndOffset())); - } - - final PsiDocumentManager manager = PsiDocumentManager.getInstance(getProject()); - final Document document = manager.getDocument(file); - - CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { - @Override - public void run() { - ApplicationManager.getApplication().runWriteAction(new Runnable() { - @Override - public void run() { - document.replaceString(0, document.getTextLength(), text); - manager.commitDocument(document); - try { - TextRange rangeToUse = myTextRange; - if (rangeToUse == null) { - rangeToUse = file.getTextRange(); - } - ACTIONS.get(action).run(file, rangeToUse.getStartOffset(), rangeToUse.getEndOffset()); - } - catch (IncorrectOperationException e) { - assertTrue(e.getLocalizedMessage(), false); - } - } - }); - } - }, "", ""); - - - if (document == null) { - fail("Don't expect the document to be null"); - return; - } - KotlinTestUtils.assertEqualsToFile(fileAfter, document.getText()); - manager.commitDocument(document); - KotlinTestUtils.assertEqualsToFile(fileAfter, file.getText()); - } - - public void doTest(@NotNull String expectedFileNameWithExtension) throws Exception { - doTest(expectedFileNameWithExtension, false); - } - - public void doTestInverted(@NotNull String expectedFileNameWithExtension) throws Exception { - doTest(expectedFileNameWithExtension, true); - } - - public void doTest(@NotNull String expectedFileNameWithExtension, boolean inverted) throws Exception { - String testFileName = expectedFileNameWithExtension.substring(0, expectedFileNameWithExtension.indexOf(".")); - String testFileExtension = expectedFileNameWithExtension.substring(expectedFileNameWithExtension.lastIndexOf(".")); - String originalFileText = FileUtil.loadFile(new File(testFileName + testFileExtension), true); - - CodeStyleSettings codeStyleSettings = FormatSettingsUtil.getSettings(getProject()); - try { - Integer rightMargin = InTextDirectivesUtils.getPrefixedInt(originalFileText, "// RIGHT_MARGIN: "); - if (rightMargin != null) { - codeStyleSettings.setRightMargin(KotlinLanguage.INSTANCE, rightMargin); - } - - SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(originalFileText, codeStyleSettings); - if (!inverted) { - configurator.configureSettings(); - } - else { - configurator.configureInvertedSettings(); - } - - doTextTest(originalFileText, new File(expectedFileNameWithExtension), testFileExtension); - } finally { - codeStyleSettings.clearCodeStyleSettings(); - } - } -} diff --git a/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java b/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java index f01e0cea11a..eb5bb58994d 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.formatter; import com.intellij.application.options.CodeStyle; import com.intellij.openapi.editor.CaretModel; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.testFramework.EditorTestUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase; @@ -35,7 +34,7 @@ public abstract class AbstractTypingIndentationTestBase extends KotlinLightCodeI String originalFileText = FileUtil.loadFile(new File(originFilePath), true); try { - SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(originalFileText, getProject()); + SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(originalFileText, CodeStyle.getSettings(getProject_())); if (!inverted) { configurator.configureSettings(); } @@ -46,7 +45,7 @@ public abstract class AbstractTypingIndentationTestBase extends KotlinLightCodeI doNewlineTest(originFilePath, afterFilePath); } finally { - getSettings().clearCodeStyleSettings(); + CodeStyle.getSettings(getProject_()).clearCodeStyleSettings(); } } @@ -61,10 +60,6 @@ public abstract class AbstractTypingIndentationTestBase extends KotlinLightCodeI KotlinTestUtils.assertEqualsToFile(new File(afterFilePath), actualTextWithCaret); } - public static CodeStyleSettings getSettings() { - return CodeStyle.getSettings(getProject()); - } - @NotNull @Override protected String getTestDataPath() { diff --git a/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java.191 b/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java.191 deleted file mode 100644 index 36ba7bb9fe0..00000000000 --- a/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java.191 +++ /dev/null @@ -1,73 +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.formatter; - -import com.intellij.application.options.CodeStyle; -import com.intellij.openapi.editor.CaretModel; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.testFramework.EditorTestUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.SettingsConfigurator; - -import java.io.File; - -@SuppressWarnings("deprecation") -public abstract class AbstractTypingIndentationTestBase extends KotlinLightCodeInsightTestCase { - public void doNewlineTest(String afterFilePath) throws Exception { - doNewlineTest(afterFilePath, false); - } - - public void doNewlineTestWithInvert(String afterInvFilePath) throws Exception { - doNewlineTest(afterInvFilePath, true); - } - - public void doNewlineTest(String afterFilePath, boolean inverted) throws Exception { - String testFileName = afterFilePath.substring(0, afterFilePath.indexOf(".")); - String testFileExtension = afterFilePath.substring(afterFilePath.lastIndexOf(".")); - - String originFilePath = testFileName + testFileExtension; - String originalFileText = FileUtil.loadFile(new File(originFilePath), true); - - try { - SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(originalFileText); - if (!inverted) { - configurator.configureSettings(); - } - else { - configurator.configureInvertedSettings(); - } - - doNewlineTest(originFilePath, afterFilePath); - } - finally { - getSettings().clearCodeStyleSettings(); - } - } - - private void doNewlineTest(String beforeFilePath, String afterFilePath) { - configureByFile(beforeFilePath); - type('\n'); - - CaretModel caretModel = getEditor().getCaretModel(); - int offset = caretModel.getOffset(); - String actualTextWithCaret = new StringBuilder(getEditor().getDocument().getText()).insert(offset, EditorTestUtil.CARET_TAG).toString(); - - KotlinTestUtils.assertEqualsToFile(new File(afterFilePath), actualTextWithCaret); - } - - public static CodeStyleSettings getSettings() { - return CodeStyle.getSettings(getProject()); - } - - @NotNull - @Override - protected String getTestDataPath() { - return ""; - } -} diff --git a/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java.193 b/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java.193 deleted file mode 100644 index 2f41e0bccd3..00000000000 --- a/idea/tests/org/jetbrains/kotlin/formatter/AbstractTypingIndentationTestBase.java.193 +++ /dev/null @@ -1,68 +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.formatter; - -import com.intellij.application.options.CodeStyle; -import com.intellij.openapi.editor.CaretModel; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.testFramework.EditorTestUtil; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.SettingsConfigurator; - -import java.io.File; - -@SuppressWarnings("deprecation") -public abstract class AbstractTypingIndentationTestBase extends KotlinLightCodeInsightTestCase { - public void doNewlineTest(String afterFilePath) throws Exception { - doNewlineTest(afterFilePath, false); - } - - public void doNewlineTestWithInvert(String afterInvFilePath) throws Exception { - doNewlineTest(afterInvFilePath, true); - } - - public void doNewlineTest(String afterFilePath, boolean inverted) throws Exception { - String testFileName = afterFilePath.substring(0, afterFilePath.indexOf(".")); - String testFileExtension = afterFilePath.substring(afterFilePath.lastIndexOf(".")); - - String originFilePath = testFileName + testFileExtension; - String originalFileText = FileUtil.loadFile(new File(originFilePath), true); - - try { - SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(originalFileText, getProject()); - if (!inverted) { - configurator.configureSettings(); - } - else { - configurator.configureInvertedSettings(); - } - - doNewlineTest(originFilePath, afterFilePath); - } - finally { - CodeStyle.getSettings(getProject()).clearCodeStyleSettings(); - } - } - - private void doNewlineTest(String beforeFilePath, String afterFilePath) { - configureByFile(beforeFilePath); - type('\n'); - - CaretModel caretModel = getEditor().getCaretModel(); - int offset = caretModel.getOffset(); - String actualTextWithCaret = new StringBuilder(getEditor().getDocument().getText()).insert(offset, EditorTestUtil.CARET_TAG).toString(); - - KotlinTestUtils.assertEqualsToFile(new File(afterFilePath), actualTextWithCaret); - } - - @NotNull - @Override - protected String getTestDataPath() { - return ""; - } -} diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatSettingsUtil.java b/idea/tests/org/jetbrains/kotlin/formatter/FormatSettingsUtil.java index c9fceaf42db..89c39e1eeb6 100644 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatSettingsUtil.java +++ b/idea/tests/org/jetbrains/kotlin/formatter/FormatSettingsUtil.java @@ -5,8 +5,6 @@ package org.jetbrains.kotlin.formatter; -import com.intellij.application.options.CodeStyle; -import com.intellij.openapi.project.Project; import com.intellij.psi.codeStyle.CodeStyleSettings; import org.jetbrains.kotlin.idea.KotlinLanguage; import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings; @@ -16,17 +14,9 @@ public class FormatSettingsUtil { private FormatSettingsUtil() { } - public static CodeStyleSettings getSettings(Project project) { - return CodeStyle.getSettings(project); - } - public static SettingsConfigurator createConfigurator(String fileText, CodeStyleSettings settings) { return new SettingsConfigurator(fileText, settings.getCustomSettings(KotlinCodeStyleSettings.class), settings.getCommonSettings(KotlinLanguage.INSTANCE)); } - - public static SettingsConfigurator createConfigurator(String fileText, Project project) { - return createConfigurator(fileText, getSettings(project)); - } } diff --git a/idea/tests/org/jetbrains/kotlin/formatter/FormatSettingsUtil.java.191 b/idea/tests/org/jetbrains/kotlin/formatter/FormatSettingsUtil.java.191 deleted file mode 100644 index 65e52c81923..00000000000 --- a/idea/tests/org/jetbrains/kotlin/formatter/FormatSettingsUtil.java.191 +++ /dev/null @@ -1,32 +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.formatter; - -import com.intellij.application.options.CodeStyle; -import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.testFramework.LightPlatformTestCase; -import org.jetbrains.kotlin.idea.KotlinLanguage; -import org.jetbrains.kotlin.idea.core.formatter.KotlinCodeStyleSettings; -import org.jetbrains.kotlin.test.SettingsConfigurator; - -public class FormatSettingsUtil { - private FormatSettingsUtil() { - } - - public static CodeStyleSettings getSettings() { - return CodeStyle.getSettings(LightPlatformTestCase.getProject()); - } - - public static SettingsConfigurator createConfigurator(String fileText, CodeStyleSettings settings) { - return new SettingsConfigurator(fileText, - settings.getCustomSettings(KotlinCodeStyleSettings.class), - settings.getCommonSettings(KotlinLanguage.INSTANCE)); - } - - public static SettingsConfigurator createConfigurator(String fileText) { - return createConfigurator(fileText, getSettings()); - } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/actions/QualifiedNamesTest.kt b/idea/tests/org/jetbrains/kotlin/idea/actions/QualifiedNamesTest.kt index 8ab7f7fa81a..1b30a60ffbf 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/actions/QualifiedNamesTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/actions/QualifiedNamesTest.kt @@ -7,7 +7,6 @@ package org.jetbrains.kotlin.idea.actions import com.intellij.ide.actions.CopyReferenceAction import com.intellij.psi.PsiElement -import com.intellij.testFramework.LightPlatformCodeInsightTestCase import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase import org.jetbrains.kotlin.psi.KtNamedDeclaration import org.jetbrains.kotlin.psi.KtVisitorVoid @@ -19,7 +18,7 @@ import java.util.* @RunWith(JUnit3WithIdeaConfigurationRunner::class) class QualifiedNamesTest : KotlinLightCodeInsightTestCase() { fun testClassRef() { - LightPlatformCodeInsightTestCase.configureFromFileText( + configureFromFileText_( "class.kt", """ package foo.bar @@ -43,7 +42,7 @@ class QualifiedNamesTest : KotlinLightCodeInsightTestCase() { } fun testFunRef() { - LightPlatformCodeInsightTestCase.configureFromFileText( + configureFromFileText_( "fun.kt", """ package foo.bar @@ -66,7 +65,7 @@ class QualifiedNamesTest : KotlinLightCodeInsightTestCase() { private fun getQualifiedNamesForDeclarations(): List { val result = ArrayList() - LightPlatformCodeInsightTestCase.myFile.accept(object : KtVisitorVoid() { + file_.accept(object : KtVisitorVoid() { override fun visitElement(element: PsiElement) { element.acceptChildren(this) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/actions/QualifiedNamesTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/actions/QualifiedNamesTest.kt.193 deleted file mode 100644 index 14086d694e5..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/actions/QualifiedNamesTest.kt.193 +++ /dev/null @@ -1,80 +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.actions - -import com.intellij.ide.actions.CopyReferenceAction -import com.intellij.psi.PsiElement -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase -import org.jetbrains.kotlin.psi.KtNamedDeclaration -import org.jetbrains.kotlin.psi.KtVisitorVoid -import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner -import org.junit.runner.RunWith -import java.util.* - -@Suppress("DEPRECATION") -@RunWith(JUnit3WithIdeaConfigurationRunner::class) -class QualifiedNamesTest : KotlinLightCodeInsightTestCase() { - fun testClassRef() { - configureFromFileText( - "class.kt", - """ - package foo.bar - - class Klass { - class Nested - - companion object { - } - } - - object Object { - } - - val anonymous = object { - } - """ - ) - assertEquals(listOf("foo.bar.Klass", "foo.bar.Klass.Nested", "foo.bar.Klass.Companion", "foo.bar.Object", "foo.bar.ClassKt#getAnonymous", null), - getQualifiedNamesForDeclarations()) - } - - fun testFunRef() { - configureFromFileText( - "fun.kt", - """ - package foo.bar - - class Klass { - fun memberFun() { - } - - val memberVal = ":)" - } - - fun topLevelFun() - - val topLevelVal = ":)" - """ - ) - assertEquals(listOf("foo.bar.Klass", "foo.bar.Klass#memberFun", "foo.bar.Klass#getMemberVal", "foo.bar.FunKt#topLevelFun", "foo.bar.FunKt#getTopLevelVal"), - getQualifiedNamesForDeclarations()) - } - - private fun getQualifiedNamesForDeclarations(): List { - val result = ArrayList() - file.accept(object : KtVisitorVoid() { - override fun visitElement(element: PsiElement) { - element.acceptChildren(this) - } - - override fun visitNamedDeclaration(declaration: KtNamedDeclaration) { - result.add(CopyReferenceAction.elementToFqn(declaration)) - super.visitNamedDeclaration(declaration) - } - }) - return result - } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt index 34ea5b2f932..2df2557ea8c 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.idea.codeInsight.moveUpDown +import com.intellij.application.options.CodeStyle import com.intellij.codeInsight.editorActions.moveLeftRight.MoveElementLeftAction import com.intellij.codeInsight.editorActions.moveLeftRight.MoveElementRightAction import com.intellij.codeInsight.editorActions.moveUpDown.MoveStatementDownAction @@ -15,7 +16,6 @@ import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.editor.actionSystem.EditorAction import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.util.io.FileUtil -import com.intellij.testFramework.LightPlatformCodeInsightTestCase import junit.framework.ComparisonFailure import junit.framework.TestCase import org.jetbrains.kotlin.formatter.FormatSettingsUtil @@ -41,7 +41,7 @@ abstract class AbstractMoveStatementTest : AbstractCodeMoverTest() { val movers = Extensions.getExtensions(StatementUpDownMover.STATEMENT_UP_DOWN_MOVER_EP) val info = StatementUpDownMover.MoveInfo() val actualMover = movers.firstOrNull { - it.checkAvailable(LightPlatformCodeInsightTestCase.getEditor(), LightPlatformCodeInsightTestCase.getFile(), info, direction == "down") + it.checkAvailable(editor, file, info, direction == "down") } ?: error("No mover found") assertEquals("Unmatched movers", defaultMoverClass.name, actualMover::class.java.name) @@ -92,15 +92,15 @@ abstract class AbstractCodeMoverTest : KotlinLightCodeInsightTestCase() { } private fun invokeAndCheck(fileText: String, path: String, action: EditorAction, isApplicableExpected: Boolean) { - val editor = LightPlatformCodeInsightTestCase.getEditor() + val editor = editor_ val project = editor.project!! - val codeStyleSettings = FormatSettingsUtil.getSettings(project) + val codeStyleSettings = CodeStyle.getSettings(project) val configurator = FormatSettingsUtil.createConfigurator(fileText, codeStyleSettings) configurator.configureSettings() try { - val dataContext = LightPlatformCodeInsightTestCase.getCurrentEditorDataContext() + val dataContext = currentEditorDataContext_ val before = editor.document.text runWriteAction { action.actionPerformed(editor, dataContext) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt.191 b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt.191 index a8d0ae1c352..21c296ff460 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt.191 +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt.191 @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.idea.codeInsight.moveUpDown +import com.intellij.application.options.CodeStyle import com.intellij.codeInsight.editorActions.moveLeftRight.MoveElementLeftAction import com.intellij.codeInsight.editorActions.moveLeftRight.MoveElementRightAction import com.intellij.codeInsight.editorActions.moveUpDown.MoveStatementDownAction @@ -92,13 +93,15 @@ abstract class AbstractCodeMoverTest : KotlinLightCodeInsightTestCase() { } private fun invokeAndCheck(fileText: String, path: String, action: EditorAction, isApplicableExpected: Boolean) { - val codeStyleSettings = FormatSettingsUtil.getSettings() + val editor = editor_ + val project = editor.project!! + + val codeStyleSettings = CodeStyle.getSettings(project) val configurator = FormatSettingsUtil.createConfigurator(fileText, codeStyleSettings) configurator.configureSettings() try { - val editor = LightPlatformCodeInsightTestCase.getEditor() - val dataContext = LightPlatformCodeInsightTestCase.getCurrentEditorDataContext() + val dataContext = currentEditorDataContext_ val before = editor.document.text runWriteAction { action.actionPerformed(editor, dataContext) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt.as36 similarity index 92% rename from idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt.193 rename to idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt.as36 index 3b7fd831941..21c296ff460 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt.193 +++ b/idea/tests/org/jetbrains/kotlin/idea/codeInsight/moveUpDown/AbstractCodeMoverTest.kt.as36 @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.idea.codeInsight.moveUpDown +import com.intellij.application.options.CodeStyle import com.intellij.codeInsight.editorActions.moveLeftRight.MoveElementLeftAction import com.intellij.codeInsight.editorActions.moveLeftRight.MoveElementRightAction import com.intellij.codeInsight.editorActions.moveUpDown.MoveStatementDownAction @@ -15,6 +16,7 @@ import com.intellij.openapi.application.runWriteAction import com.intellij.openapi.editor.actionSystem.EditorAction import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.util.io.FileUtil +import com.intellij.testFramework.LightPlatformCodeInsightTestCase import junit.framework.ComparisonFailure import junit.framework.TestCase import org.jetbrains.kotlin.formatter.FormatSettingsUtil @@ -40,7 +42,7 @@ abstract class AbstractMoveStatementTest : AbstractCodeMoverTest() { val movers = Extensions.getExtensions(StatementUpDownMover.STATEMENT_UP_DOWN_MOVER_EP) val info = StatementUpDownMover.MoveInfo() val actualMover = movers.firstOrNull { - it.checkAvailable(editor, file, info, direction == "down") + it.checkAvailable(LightPlatformCodeInsightTestCase.getEditor(), LightPlatformCodeInsightTestCase.getFile(), info, direction == "down") } ?: error("No mover found") assertEquals("Unmatched movers", defaultMoverClass.name, actualMover::class.java.name) @@ -91,14 +93,15 @@ abstract class AbstractCodeMoverTest : KotlinLightCodeInsightTestCase() { } private fun invokeAndCheck(fileText: String, path: String, action: EditorAction, isApplicableExpected: Boolean) { + val editor = editor_ val project = editor.project!! - val codeStyleSettings = FormatSettingsUtil.getSettings(project) + val codeStyleSettings = CodeStyle.getSettings(project) val configurator = FormatSettingsUtil.createConfigurator(fileText, codeStyleSettings) configurator.configureSettings() try { - val dataContext = currentEditorDataContext + val dataContext = currentEditorDataContext_ val before = editor.document.text runWriteAction { action.actionPerformed(editor, dataContext) } diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java b/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java index f937ede8db8..11bbd851bd1 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java @@ -5,6 +5,7 @@ package org.jetbrains.kotlin.idea.editor; +import com.intellij.application.options.CodeStyle; import com.intellij.openapi.util.io.FileUtil; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.testFramework.EditorTestUtil; @@ -53,9 +54,9 @@ public class KotlinCommenterTest extends KotlinLightCodeInsightTestCase { private void doLineCommentTest() throws Exception { configure(); - CodeStyleSettings codeStyleSettings = FormatSettingsUtil.getSettings(getProject()); + CodeStyleSettings codeStyleSettings = CodeStyle.getSettings(getProject_()); try { - String text = myFile.getText(); + String text = getFile_().getText(); SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(text, codeStyleSettings); configurator.configureSettings(); diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java.191 b/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java.191 deleted file mode 100644 index c7762cdbcec..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java.191 +++ /dev/null @@ -1,88 +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.editor; - -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.testFramework.EditorTestUtil; -import org.jetbrains.kotlin.formatter.FormatSettingsUtil; -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase; -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; -import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.SettingsConfigurator; -import org.junit.runner.RunWith; - -import java.io.File; - -@SuppressWarnings("deprecation") -@RunWith(JUnit3WithIdeaConfigurationRunner.class) -public class KotlinCommenterTest extends KotlinLightCodeInsightTestCase { - private static final String BASE_PATH = - new File(PluginTestCaseBase.getTestDataPathBase(), "/editor/commenter/").getAbsolutePath(); - - public void testGenerateDocComment() throws Exception { - doNewLineTypingTest(); - } - - public void testNewLineInComment() throws Exception { - doNewLineTypingTest(); - } - - public void testNewLineInTag() throws Exception { - doNewLineTypingTest(); - } - - public void testNotFirstColumnWithSpace() throws Exception { - doLineCommentTest(); - } - - public void testNotFirstColumnWithoutSpace() throws Exception { - doLineCommentTest(); - } - - private void doNewLineTypingTest() throws Exception { - configure(); - EditorTestUtil.performTypingAction(getEditor(), '\n'); - check(); - } - - private void doLineCommentTest() throws Exception { - configure(); - - CodeStyleSettings codeStyleSettings = FormatSettingsUtil.getSettings(); - try { - String text = myFile.getText(); - - SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(text, codeStyleSettings); - configurator.configureSettings(); - - executeAction("CommentByLineComment"); - } finally { - codeStyleSettings.clearCodeStyleSettings(); - } - - check(); - } - - private void configure() throws Exception { - configureFromFileText("a.kt", loadFile(getTestName(true) + ".kt")); - } - - private void check() { - File afterFile = getTestFile(getTestName(true) + "_after.kt"); - KotlinTestUtils.assertEqualsToFile(afterFile, getEditor(), false); - } - - private static File getTestFile(String name) { - return new File(BASE_PATH, name); - } - - private static String loadFile(String name) throws Exception { - File file = getTestFile(name); - return FileUtil.loadFile(file, true); - } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java.193 b/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java.193 deleted file mode 100644 index db4c75e43f1..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/editor/KotlinCommenterTest.java.193 +++ /dev/null @@ -1,88 +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.editor; - -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.psi.codeStyle.CodeStyleSettings; -import com.intellij.testFramework.EditorTestUtil; -import org.jetbrains.kotlin.formatter.FormatSettingsUtil; -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase; -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; -import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner; -import org.jetbrains.kotlin.test.KotlinTestUtils; -import org.jetbrains.kotlin.test.SettingsConfigurator; -import org.junit.runner.RunWith; - -import java.io.File; - -@SuppressWarnings("deprecation") -@RunWith(JUnit3WithIdeaConfigurationRunner.class) -public class KotlinCommenterTest extends KotlinLightCodeInsightTestCase { - private static final String BASE_PATH = - new File(PluginTestCaseBase.getTestDataPathBase(), "/editor/commenter/").getAbsolutePath(); - - public void testGenerateDocComment() throws Exception { - doNewLineTypingTest(); - } - - public void testNewLineInComment() throws Exception { - doNewLineTypingTest(); - } - - public void testNewLineInTag() throws Exception { - doNewLineTypingTest(); - } - - public void testNotFirstColumnWithSpace() throws Exception { - doLineCommentTest(); - } - - public void testNotFirstColumnWithoutSpace() throws Exception { - doLineCommentTest(); - } - - private void doNewLineTypingTest() throws Exception { - configure(); - EditorTestUtil.performTypingAction(getEditor(), '\n'); - check(); - } - - private void doLineCommentTest() throws Exception { - configure(); - - CodeStyleSettings codeStyleSettings = FormatSettingsUtil.getSettings(getProject()); - try { - String text = getFile().getText(); - - SettingsConfigurator configurator = FormatSettingsUtil.createConfigurator(text, codeStyleSettings); - configurator.configureSettings(); - - executeAction("CommentByLineComment"); - } finally { - codeStyleSettings.clearCodeStyleSettings(); - } - - check(); - } - - private void configure() throws Exception { - configureFromFileText("a.kt", loadFile(getTestName(true) + ".kt")); - } - - private void check() { - File afterFile = getTestFile(getTestName(true) + "_after.kt"); - KotlinTestUtils.assertEqualsToFile(afterFile, getEditor(), false); - } - - private static File getTestFile(String name) { - return new File(BASE_PATH, name); - } - - private static String loadFile(String name) throws Exception { - File file = getTestFile(name); - return FileUtil.loadFile(file, true); - } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/kdoc/KdocRenameTest.java b/idea/tests/org/jetbrains/kotlin/idea/kdoc/KdocRenameTest.java index 5ef823c08a6..d6e3e2de264 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/kdoc/KdocRenameTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/kdoc/KdocRenameTest.java @@ -46,7 +46,7 @@ public class KdocRenameTest extends KotlinLightCodeInsightTestCase { private void doTest(String newName) { configureByFile(getTestName(false) + ".kt"); PsiElement element = TargetElementUtil - .findTargetElement(myEditor, + .findTargetElement(getEditor_(), TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED); assertNotNull(element); new RenameProcessor(getProject(), element, newName, true, true).run(); diff --git a/idea/tests/org/jetbrains/kotlin/idea/kdoc/KdocRenameTest.java.193 b/idea/tests/org/jetbrains/kotlin/idea/kdoc/KdocRenameTest.java.193 deleted file mode 100644 index dc5ff6755be..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/kdoc/KdocRenameTest.java.193 +++ /dev/null @@ -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.idea.kdoc; - -import com.intellij.codeInsight.TargetElementUtil; -import com.intellij.ide.startup.impl.StartupManagerImpl; -import com.intellij.openapi.startup.StartupManager; -import com.intellij.psi.PsiElement; -import com.intellij.refactoring.rename.RenameProcessor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase; -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; -import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner; -import org.junit.runner.RunWith; - -@SuppressWarnings("deprecation") -@RunWith(JUnit3WithIdeaConfigurationRunner.class) -public class KdocRenameTest extends KotlinLightCodeInsightTestCase { - @NotNull - @Override - protected String getTestDataPath() { - return PluginTestCaseBase.getTestDataPathBase() + "/kdoc/rename/"; - } - - public void testParamReference() { - doTest("bar"); - } - - public void testTypeParamReference() { - doTest("R"); - } - - public void testCodeReference() { - doTest("xyzzy"); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - ((StartupManagerImpl) StartupManager.getInstance(getProject())).runPostStartupActivities(); - } - - private void doTest(String newName) { - configureByFile(getTestName(false) + ".kt"); - PsiElement element = TargetElementUtil - .findTargetElement(getEditor(), - TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED); - assertNotNull(element); - new RenameProcessor(getProject(), element, newName, true, true).run(); - checkResultByFile(getTestName(false) + ".kt.after"); - } -} diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoImplementationTest.kt b/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoImplementationTest.kt index 62c094c85bb..bf93096b374 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoImplementationTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoImplementationTest.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.idea.navigation import com.intellij.openapi.projectRoots.Sdk -import com.intellij.testFramework.LightPlatformCodeInsightTestCase import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.test.invalidateLibraryCache @@ -18,7 +17,7 @@ abstract class AbstractKotlinGotoImplementationTest : KotlinLightCodeInsightTest override fun setUp() { super.setUp() - invalidateLibraryCache(getProject()) + invalidateLibraryCache(project_) } override fun getTestDataPath(): String = KotlinTestUtils.getHomeDirectory() + File.separator @@ -27,10 +26,7 @@ abstract class AbstractKotlinGotoImplementationTest : KotlinLightCodeInsightTest protected fun doTest(path: String) { configureByFile(path) - val gotoData = NavigationTestUtils.invokeGotoImplementations( - LightPlatformCodeInsightTestCase.getEditor(), - LightPlatformCodeInsightTestCase.getFile() - ) - NavigationTestUtils.assertGotoDataMatching(LightPlatformCodeInsightTestCase.getEditor(), gotoData) + val gotoData = NavigationTestUtils.invokeGotoImplementations(editor_, file_) + NavigationTestUtils.assertGotoDataMatching(editor_, gotoData) } } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoImplementationTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoImplementationTest.kt.193 deleted file mode 100644 index 4752016dbd7..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/navigation/AbstractKotlinGotoImplementationTest.kt.193 +++ /dev/null @@ -1,32 +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.navigation - -import com.intellij.openapi.projectRoots.Sdk -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase -import org.jetbrains.kotlin.idea.test.invalidateLibraryCache -import org.jetbrains.kotlin.test.KotlinTestUtils -import java.io.File - -@Suppress("DEPRECATION") -abstract class AbstractKotlinGotoImplementationTest : KotlinLightCodeInsightTestCase() { - - override fun setUp() { - super.setUp() - invalidateLibraryCache(project) - } - - override fun getTestDataPath(): String = KotlinTestUtils.getHomeDirectory() + File.separator - - override fun getProjectJDK(): Sdk = PluginTestCaseBase.mockJdk() - - protected fun doTest(path: String) { - configureByFile(path) - val gotoData = NavigationTestUtils.invokeGotoImplementations(editor, file) - NavigationTestUtils.assertGotoDataMatching(editor, gotoData) - } -} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt b/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt index beda0e405d4..643ff9a9aaa 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt @@ -231,14 +231,13 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() { private fun doTestInplaceRename(newName: String?, handler: VariableInplaceRenameHandler = KotlinVariableInplaceRenameHandler()) { configureByFile(getTestName(false) + ".kt") val element = TargetElementUtil.findTargetElement( - myEditor, + editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED or TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED ) assertNotNull(element) - val dataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.name, element!!, - getCurrentEditorDataContext()) + val dataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.name, element!!, currentEditorDataContext) if (newName == null) { assertFalse(handler.isRenaming(dataContext), "In-place rename is allowed for " + element) @@ -249,7 +248,7 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() { CodeInsightTestUtil.doInlineRename(handler, newName, getEditor(), element) checkResultByFile(getTestName(false) + ".kt.after") } catch (e: BaseRefactoringProcessor.ConflictsInTestsException) { - val expectedMessage = InTextDirectivesUtils.findStringWithPrefixes(myFile.text, "// SHOULD_FAIL_WITH: ") + val expectedMessage = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// SHOULD_FAIL_WITH: ") TestCase.assertEquals(expectedMessage, e.messages.joinToString()) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt.193 b/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt.191 similarity index 97% rename from idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt.193 rename to idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt.191 index 643ff9a9aaa..beda0e405d4 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt.193 +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt.191 @@ -231,13 +231,14 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() { private fun doTestInplaceRename(newName: String?, handler: VariableInplaceRenameHandler = KotlinVariableInplaceRenameHandler()) { configureByFile(getTestName(false) + ".kt") val element = TargetElementUtil.findTargetElement( - editor, + myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED or TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED ) assertNotNull(element) - val dataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.name, element!!, currentEditorDataContext) + val dataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.name, element!!, + getCurrentEditorDataContext()) if (newName == null) { assertFalse(handler.isRenaming(dataContext), "In-place rename is allowed for " + element) @@ -248,7 +249,7 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() { CodeInsightTestUtil.doInlineRename(handler, newName, getEditor(), element) checkResultByFile(getTestName(false) + ".kt.after") } catch (e: BaseRefactoringProcessor.ConflictsInTestsException) { - val expectedMessage = InTextDirectivesUtils.findStringWithPrefixes(file.text, "// SHOULD_FAIL_WITH: ") + val expectedMessage = InTextDirectivesUtils.findStringWithPrefixes(myFile.text, "// SHOULD_FAIL_WITH: ") TestCase.assertEquals(expectedMessage, e.messages.joinToString()) } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt.as36 b/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt.as36 new file mode 100644 index 00000000000..beda0e405d4 --- /dev/null +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/InplaceRenameTest.kt.as36 @@ -0,0 +1,257 @@ +/* + * 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.refactoring + +import com.intellij.codeInsight.TargetElementUtil +import com.intellij.codeInsight.template.impl.TemplateManagerImpl +import com.intellij.openapi.actionSystem.CommonDataKeys +import com.intellij.openapi.actionSystem.impl.SimpleDataContext +import com.intellij.openapi.command.WriteCommandAction +import com.intellij.refactoring.BaseRefactoringProcessor +import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler +import com.intellij.testFramework.LightPlatformCodeInsightTestCase +import com.intellij.testFramework.fixtures.CodeInsightTestUtil +import junit.framework.TestCase +import org.jetbrains.kotlin.idea.refactoring.rename.KotlinMemberInplaceRenameHandler +import org.jetbrains.kotlin.idea.refactoring.rename.KotlinVariableInplaceRenameHandler +import org.jetbrains.kotlin.idea.refactoring.rename.RenameKotlinImplicitLambdaParameter +import org.jetbrains.kotlin.idea.refactoring.rename.findElementForRename +import org.jetbrains.kotlin.idea.test.PluginTestCaseBase +import org.jetbrains.kotlin.psi.KtNameReferenceExpression +import org.jetbrains.kotlin.test.InTextDirectivesUtils +import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner +import org.junit.runner.RunWith +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +@RunWith(JUnit3WithIdeaConfigurationRunner::class) +class InplaceRenameTest : LightPlatformCodeInsightTestCase() { + override fun isRunInWriteAction(): Boolean = false + override fun getTestDataPath(): String = PluginTestCaseBase.getTestDataPathBase() + "/refactoring/rename/inplace/" + + fun testLocalVal() { + doTestMemberInplaceRename("y") + } + + fun testForLoop() { + doTestInplaceRename("j") + } + + fun testTryCatch() { + doTestInplaceRename("e1") + } + + fun testFunctionLiteral() { + doTestInplaceRename("y") + } + + fun testFunctionLiteralIt() { + doTestImplicitLambdaParameter("y") + } + + fun testFunctionLiteralItEndCaret() { + doTestImplicitLambdaParameter("y") + } + + fun testFunctionLiteralParenthesis() { + doTestInplaceRename("y") + } + + fun testLocalFunction() { + doTestMemberInplaceRename("bar") + } + + fun testFunctionParameterNotInplace() { + doTestInplaceRename(null) + } + + fun testGlobalFunctionNotInplace() { + doTestInplaceRename(null) + } + + fun testTopLevelValNotInplace() { + doTestInplaceRename(null) + } + + fun testLabelFromFunction() { + doTestMemberInplaceRename("foo") + } + + fun testMultiDeclaration() { + doTestInplaceRename("foo") + } + + fun testLocalVarShadowingMemberProperty() { + doTestMemberInplaceRename("name1") + } + + fun testNoReformat() { + doTestMemberInplaceRename("subject2") + } + + fun testInvokeToFoo() { + doTestMemberInplaceRename("foo") + } + + fun testInvokeToGet() { + doTestMemberInplaceRename("get") + } + + fun testInvokeToGetWithQualifiedExpr() { + doTestMemberInplaceRename("get") + } + + fun testInvokeToGetWithSafeQualifiedExpr() { + doTestMemberInplaceRename("get") + } + + fun testInvokeToPlus() { + doTestMemberInplaceRename("plus") + } + + fun testGetToFoo() { + doTestMemberInplaceRename("foo") + } + + fun testGetToInvoke() { + doTestMemberInplaceRename("invoke") + } + + fun testGetToInvokeWithQualifiedExpr() { + doTestMemberInplaceRename("invoke") + } + + fun testGetToInvokeWithSafeQualifiedExpr() { + doTestMemberInplaceRename("invoke") + } + + fun testGetToPlus() { + doTestMemberInplaceRename("plus") + } + + fun testAddQuotes() { + doTestMemberInplaceRename("is") + } + + fun testAddThis() { + doTestMemberInplaceRename("foo") + } + + fun testExtensionAndNoReceiver() { + doTestMemberInplaceRename("b") + } + + fun testTwoExtensions() { + doTestMemberInplaceRename("example") + } + + fun testQuotedLocalVar() { + doTestMemberInplaceRename("x") + } + + fun testQuotedParameter() { + doTestMemberInplaceRename("x") + } + + fun testEraseCompanionName() { + doTestMemberInplaceRename("") + } + + fun testLocalVarRedeclaration() { + doTestMemberInplaceRename("localValB") + } + + fun testLocalFunRedeclaration() { + doTestMemberInplaceRename("localFunB") + } + + fun testLocalClassRedeclaration() { + doTestMemberInplaceRename("LocalClassB") + } + + fun testBacktickedWithAccessors() { + doTestMemberInplaceRename("`object`") + } + + fun testNoTextUsagesForLocalVar() { + doTestMemberInplaceRename("w") + } + + private fun doTestImplicitLambdaParameter(newName: String) { + configureByFile(getTestName(false) + ".kt") + + // This code is copy-pasted from CodeInsightTestUtil.doInlineRename() and slightly modified. + // Original method was not suitable because it expects renamed element to be reference to other or referrable + + val file = getFile()!! + val editor = getEditor()!! + val element = file.findElementForRename(editor.caretModel.offset)!! + assertNotNull(element) + + val dataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.name, element, + getCurrentEditorDataContext()) + val handler = RenameKotlinImplicitLambdaParameter() + + assertTrue(handler.isRenaming(dataContext), "In-place rename not allowed for " + element) + + val project = editor.project!! + + TemplateManagerImpl.setTemplateTesting(project, testRootDisposable) + + object : WriteCommandAction.Simple(project) { + override fun run() { + handler.invoke(project, editor, file, dataContext) + } + }.execute() + + var state = TemplateManagerImpl.getTemplateState(editor) + assert(state != null) + val range = state!!.currentVariableRange + assert(range != null) + object : WriteCommandAction.Simple(project) { + override fun run() { + editor.document.replaceString(range!!.startOffset, range.endOffset, newName) + } + }.execute().throwException() + + state = TemplateManagerImpl.getTemplateState(editor) + assert(state != null) + state!!.gotoEnd(false) + + checkResultByFile(getTestName(false) + ".kt.after") + } + + private fun doTestMemberInplaceRename(newName: String?) { + doTestInplaceRename(newName, KotlinMemberInplaceRenameHandler()) + } + + private fun doTestInplaceRename(newName: String?, handler: VariableInplaceRenameHandler = KotlinVariableInplaceRenameHandler()) { + configureByFile(getTestName(false) + ".kt") + val element = TargetElementUtil.findTargetElement( + myEditor, + TargetElementUtil.ELEMENT_NAME_ACCEPTED or TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED + ) + + assertNotNull(element) + + val dataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.name, element!!, + getCurrentEditorDataContext()) + + if (newName == null) { + assertFalse(handler.isRenaming(dataContext), "In-place rename is allowed for " + element) + } + else { + try { + assertTrue(handler.isRenaming(dataContext), "In-place rename not allowed for " + element) + CodeInsightTestUtil.doInlineRename(handler, newName, getEditor(), element) + checkResultByFile(getTestName(false) + ".kt.after") + } catch (e: BaseRefactoringProcessor.ConflictsInTestsException) { + val expectedMessage = InTextDirectivesUtils.findStringWithPrefixes(myFile.text, "// SHOULD_FAIL_WITH: ") + TestCase.assertEquals(expectedMessage, e.messages.joinToString()) + } + } + } +} diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/SimpleNameReferenceRenameTest.java b/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/SimpleNameReferenceRenameTest.java index d84ca59346a..f429d1e828d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/SimpleNameReferenceRenameTest.java +++ b/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/SimpleNameReferenceRenameTest.java @@ -52,7 +52,7 @@ public class SimpleNameReferenceRenameTest extends KotlinLightCodeInsightTestCas private void doTest(String newName) throws Exception { configureByFile(getTestName(true) + ".kt"); PsiElement element = TargetElementUtil - .findTargetElement(myEditor, + .findTargetElement(getEditor_(), TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED); assertNotNull(element); new RenameProcessor(getProject(), element, newName, true, true).run(); diff --git a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/SimpleNameReferenceRenameTest.java.193 b/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/SimpleNameReferenceRenameTest.java.193 deleted file mode 100644 index 36d1ee44305..00000000000 --- a/idea/tests/org/jetbrains/kotlin/idea/refactoring/rename/SimpleNameReferenceRenameTest.java.193 +++ /dev/null @@ -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.idea.refactoring.rename; - -import com.intellij.codeInsight.TargetElementUtil; -import com.intellij.psi.PsiElement; -import com.intellij.refactoring.rename.RenameProcessor; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase; -import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; - -@SuppressWarnings("deprecation") -public class SimpleNameReferenceRenameTest extends KotlinLightCodeInsightTestCase { - - @NotNull - @Override - protected String getTestDataPath() { - return PluginTestCaseBase.getTestDataPathBase() + "/refactoring/rename/simpleNameReference/"; - } - - public void testRenameLabel() throws Exception { - doTest("foo"); - } - - public void testRenameLabel2() throws Exception { - doTest("anotherFoo"); - } - - public void testRenameField() throws Exception { - doTest("renamed"); - } - - public void testRenameFieldIdentifier() throws Exception { - doTest("anotherRenamed"); - } - - public void testMemberOfLocalObject() throws Exception { - doTest("bar"); - } - - public void testLocalFunction() throws Exception { - doTest("xyzzy"); - } - - public void testParameterOfCopyMethod() throws Exception { - doTest("y"); - } - - private void doTest(String newName) throws Exception { - configureByFile(getTestName(true) + ".kt"); - PsiElement element = TargetElementUtil - .findTargetElement(getEditor(), - TargetElementUtil.ELEMENT_NAME_ACCEPTED | TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED); - assertNotNull(element); - new RenameProcessor(getProject(), element, newName, true, true).run(); - checkResultByFile(getTestName(true) + ".kt.after"); - } -}