as36: Update to AS 3.6 RC (192.7142.36.36.6071332)
^KT-36005 Fixed
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
versions.intellijSdk=192.5728.98
|
versions.intellijSdk=192.7142.36
|
||||||
versions.androidBuildTools=r23.0.1
|
versions.androidBuildTools=r23.0.1
|
||||||
versions.idea.NodeJS=181.3494.12
|
versions.idea.NodeJS=181.3494.12
|
||||||
versions.androidStudioRelease=3.6.0.9
|
versions.androidStudioRelease=3.6.0.18
|
||||||
versions.androidStudioBuild=192.5830636
|
versions.androidStudioBuild=192.6071332
|
||||||
versions.jar.asm-all=7.0.1
|
versions.jar.asm-all=7.0.1
|
||||||
versions.jar.guava=25.1-jre
|
versions.jar.guava=25.1-jre
|
||||||
versions.jar.groovy-all=2.4.17
|
versions.jar.groovy-all=2.4.17
|
||||||
|
|||||||
@@ -192,10 +192,6 @@ dependencies {
|
|||||||
testRuntime(intellijPluginDep("google-login-as"))
|
testRuntime(intellijPluginDep("google-login-as"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ide.AS36()) {
|
|
||||||
testRuntime(intellijPluginDep("android-wizardTemplate-plugin"))
|
|
||||||
}
|
|
||||||
|
|
||||||
performanceTestCompile(sourceSets["test"].output)
|
performanceTestCompile(sourceSets["test"].output)
|
||||||
performanceTestCompile(sourceSets["main"].output)
|
performanceTestCompile(sourceSets["main"].output)
|
||||||
performanceTestCompile(project(":nj2k"))
|
performanceTestCompile(project(":nj2k"))
|
||||||
|
|||||||
@@ -73,10 +73,6 @@ dependencies {
|
|||||||
if (Ide.AS36.orHigher()) {
|
if (Ide.AS36.orHigher()) {
|
||||||
testRuntime(intellijPluginDep("android-layoutlib"))
|
testRuntime(intellijPluginDep("android-layoutlib"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ide.AS36()) {
|
|
||||||
testRuntime(intellijPluginDep("android-wizardTemplate-plugin"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
-184
@@ -1,184 +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.completion.test.confidence;
|
|
||||||
|
|
||||||
import com.intellij.codeInsight.CodeInsightSettings;
|
|
||||||
import com.intellij.codeInsight.completion.*;
|
|
||||||
import com.intellij.codeInsight.lookup.LookupElement;
|
|
||||||
import com.intellij.codeInsight.lookup.LookupManager;
|
|
||||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
|
||||||
import com.intellij.lang.Language;
|
|
||||||
import com.intellij.lang.injection.InjectedLanguageManager;
|
|
||||||
import com.intellij.openapi.editor.Editor;
|
|
||||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
|
||||||
import com.intellij.openapi.projectRoots.Sdk;
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.psi.PsiFile;
|
|
||||||
import com.intellij.psi.util.PsiUtilCore;
|
|
||||||
import com.intellij.util.ArrayUtil;
|
|
||||||
import com.intellij.util.ThreeState;
|
|
||||||
import org.apache.commons.lang.SystemUtils;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.kotlin.idea.completion.test.CompletionTestUtilKt;
|
|
||||||
import org.jetbrains.kotlin.idea.test.TestUtilsKt;
|
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils;
|
|
||||||
import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@RunWith(JUnit3WithIdeaConfigurationRunner.class)
|
|
||||||
public class KotlinConfidenceTest extends LightCompletionTestCase {
|
|
||||||
private static final String TYPE_DIRECTIVE_PREFIX = "// TYPE:";
|
|
||||||
private final ThreadLocal<Boolean> skipComplete = ThreadLocal.withInitial(() -> false);
|
|
||||||
|
|
||||||
public void testCompleteOnDotOutOfRanges() {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testImportAsConfidence() {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testInBlockOfFunctionLiteral() {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testInModifierList() {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNoAutoCompletionForRangeOperator() {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNoAutoPopupInString() {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAutoPopupInStringTemplate() {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAutoPopupInStringTemplateAfterDollar() {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNoAutoPopupInStringTemplateAfterSpace() {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testNoAutoPopupInRawStringTemplateAfterNewLine() {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
TestUtilsKt.invalidateLibraryCache(getProject());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void doTest() {
|
|
||||||
boolean completeByChars = CodeInsightSettings.getInstance().SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS;
|
|
||||||
|
|
||||||
CodeInsightSettings.getInstance().SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS = true;
|
|
||||||
|
|
||||||
try {
|
|
||||||
skipComplete.set(true);
|
|
||||||
try {
|
|
||||||
configureByFile(getBeforeFileName());
|
|
||||||
} finally {
|
|
||||||
skipComplete.set(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
String text = getEditor().getDocument().getText();
|
|
||||||
boolean noLookup = InTextDirectivesUtils.isDirectiveDefined(text, "// NO_LOOKUP");
|
|
||||||
if (!noLookup) complete(); //This will cause NPE in case of absence of autopopup completion
|
|
||||||
|
|
||||||
List<String> expectedElements = InTextDirectivesUtils.findLinesWithPrefixesRemoved(text, "// ELEMENT:");
|
|
||||||
assertFalse("Can't both expect lookup elements and no lookup", !expectedElements.isEmpty() && noLookup);
|
|
||||||
|
|
||||||
if (noLookup) {
|
|
||||||
assertTrue("Should skip autopopup completion", shouldSkipAutoPopup(getEditor(), getFile()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String typeText = getTypeText(text);
|
|
||||||
if (!expectedElements.isEmpty()) {
|
|
||||||
assertContainsItems(ArrayUtil.toStringArray(expectedElements));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
assertNotNull("You must type something, use // TYPE:", typeText);
|
|
||||||
type(typeText);
|
|
||||||
checkResultByFile(getAfterFileName());
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
CodeInsightSettings.getInstance().SELECT_AUTOPOPUP_SUGGESTIONS_BY_CHARS = completeByChars;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getTypeText(String text) {
|
|
||||||
String[] directives = InTextDirectivesUtils.findArrayWithPrefixes(text, TYPE_DIRECTIVE_PREFIX);
|
|
||||||
if (directives.length == 0) return null;
|
|
||||||
assertEquals("One directive with \"" + TYPE_DIRECTIVE_PREFIX +"\" expected", 1, directives.length);
|
|
||||||
|
|
||||||
return StringUtil.unquoteString(directives[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getBeforeFileName() {
|
|
||||||
return getTestName(false) + ".kt";
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getAfterFileName() {
|
|
||||||
return getTestName(false) + ".kt.after";
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
protected String getTestDataPath() {
|
|
||||||
return new File(CompletionTestUtilKt.getCOMPLETION_TEST_DATA_BASE_PATH(), "/confidence/").getPath() + File.separator;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Sdk getProjectJDK() {
|
|
||||||
return JavaSdk.getInstance().createJdk("JDK", SystemUtils.getJavaHome().getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void complete() {
|
|
||||||
if (skipComplete.get()) return;
|
|
||||||
new CodeCompletionHandlerBase(CompletionType.BASIC, false, true, true).invokeCompletion(
|
|
||||||
getProject(), getEditor(), 0, false);
|
|
||||||
|
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean shouldSkipAutoPopup(Editor editor, PsiFile psiFile) {
|
|
||||||
int offset = editor.getCaretModel().getOffset();
|
|
||||||
int psiOffset = Math.max(0, offset - 1);
|
|
||||||
|
|
||||||
PsiElement elementAt = InjectedLanguageManager.getInstance(psiFile.getProject()).findInjectedElementAt(psiFile, psiOffset);
|
|
||||||
if (elementAt == null) {
|
|
||||||
elementAt = psiFile.findElementAt(psiOffset);
|
|
||||||
}
|
|
||||||
if (elementAt == null) return true;
|
|
||||||
|
|
||||||
Language language = PsiUtilCore.findLanguageFromElement(elementAt);
|
|
||||||
|
|
||||||
for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) {
|
|
||||||
ThreeState result = confidence.shouldSkipAutopopup(elementAt, psiFile, offset);
|
|
||||||
if (result != ThreeState.UNSURE) {
|
|
||||||
return result == ThreeState.YES;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -75,10 +75,6 @@ dependencies {
|
|||||||
if (Ide.AS36.orHigher()) {
|
if (Ide.AS36.orHigher()) {
|
||||||
testRuntime(intellijPluginDep("android-layoutlib"))
|
testRuntime(intellijPluginDep("android-layoutlib"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ide.AS36()) {
|
|
||||||
testRuntime(intellijPluginDep("android-wizardTemplate-plugin"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
@@ -78,10 +78,6 @@ dependencies {
|
|||||||
if (Ide.AS36.orHigher()) {
|
if (Ide.AS36.orHigher()) {
|
||||||
testRuntime(intellijPluginDep("android-layoutlib"))
|
testRuntime(intellijPluginDep("android-layoutlib"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ide.AS36()) {
|
|
||||||
testRuntime(intellijPluginDep("android-wizardTemplate-plugin"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
-37
@@ -1,37 +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.scripting.gradle.importing
|
|
||||||
|
|
||||||
import org.gradle.tooling.BuildController
|
|
||||||
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.ProjectImportExtraModelProvider
|
|
||||||
|
|
||||||
class KotlinDslScriptModelProvider : ProjectImportExtraModelProvider {
|
|
||||||
private val kotlinDslScriptModelClass: Class<*> = KotlinDslScriptsModel::class.java
|
|
||||||
|
|
||||||
override fun populateBuildModels(
|
|
||||||
controller: BuildController,
|
|
||||||
project: IdeaProject,
|
|
||||||
consumer: ProjectImportExtraModelProvider.BuildModelConsumer
|
|
||||||
) {
|
|
||||||
project.modules.forEach { module ->
|
|
||||||
if (module.gradleProject.parent == null) {
|
|
||||||
val model = controller.findModel(module.gradleProject, kotlinDslScriptModelClass)
|
|
||||||
if (model != null) {
|
|
||||||
consumer.consume(module, model, kotlinDslScriptModelClass)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun populateProjectModels(
|
|
||||||
controller: BuildController,
|
|
||||||
module: IdeaModule?,
|
|
||||||
modelConsumer: ProjectImportExtraModelProvider.ProjectModelConsumer
|
|
||||||
) = Unit
|
|
||||||
}
|
|
||||||
-42
@@ -1,42 +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.scripting.gradle.importing
|
|
||||||
|
|
||||||
import com.intellij.openapi.externalSystem.model.DataNode
|
|
||||||
import com.intellij.openapi.externalSystem.model.project.ProjectData
|
|
||||||
import org.gradle.tooling.model.idea.IdeaProject
|
|
||||||
import org.gradle.tooling.model.kotlin.dsl.KotlinDslScriptsModel
|
|
||||||
import org.jetbrains.kotlin.idea.scripting.gradle.kotlinDslScriptsModelImportSupported
|
|
||||||
|
|
||||||
class KotlinDslScriptModelResolver : KotlinDslScriptModelResolverCommon() {
|
|
||||||
override fun getExtraModelProvider() = KotlinDslScriptModelProvider()
|
|
||||||
override fun requiresTaskRunning() = true
|
|
||||||
|
|
||||||
override fun populateProjectExtraModels(gradleProject: IdeaProject, ideProject: DataNode<ProjectData>) {
|
|
||||||
super.populateProjectExtraModels(gradleProject, ideProject)
|
|
||||||
|
|
||||||
if (kotlinDslScriptsModelImportSupported(resolverCtx.projectGradleVersion)) {
|
|
||||||
populateBuildModels(gradleProject, ideProject)
|
|
||||||
|
|
||||||
resolverCtx.models.includedBuilds.forEach { includedRoot ->
|
|
||||||
populateBuildModels(includedRoot, ideProject)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun populateBuildModels(
|
|
||||||
root: IdeaProject,
|
|
||||||
ideProject: DataNode<ProjectData>
|
|
||||||
) {
|
|
||||||
root.modules.forEach {
|
|
||||||
if (it.gradleProject.parent == null) {
|
|
||||||
resolverCtx.getExtraProject(it, KotlinDslScriptsModel::class.java)?.let { model ->
|
|
||||||
ideProject.KOTLIN_DSL_SCRIPT_MODELS.addAll(model.toListOfScriptModels())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-262
@@ -1,262 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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<Object[]> 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<ProjectImportAction.AllModels> 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<Class> getToolingExtensionClasses() {
|
|
||||||
Set<Class> classes = ContainerUtil.<Class>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<Class> doGetToolingExtensionClasses() {
|
|
||||||
return Collections.emptySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
if (testDir != null) {
|
|
||||||
FileUtil.delete(testDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Set<Class> getModels();
|
|
||||||
|
|
||||||
|
|
||||||
private <T> Map<String, T> getModulesMap(final Class<T> aClass) {
|
|
||||||
DomainObjectSet<? extends IdeaModule> ideaModules = allModels.getIdeaProject().getModules();
|
|
||||||
|
|
||||||
final String filterKey = "to_filter";
|
|
||||||
Map<String, T> map = ContainerUtil.map2Map(ideaModules, new Function<IdeaModule, Pair<String, T>>() {
|
|
||||||
@Override
|
|
||||||
public Pair<String, T> 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -66,10 +66,6 @@ dependencies {
|
|||||||
if (Ide.AS36.orHigher()) {
|
if (Ide.AS36.orHigher()) {
|
||||||
testRuntime(intellijPluginDep("android-layoutlib"))
|
testRuntime(intellijPluginDep("android-layoutlib"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ide.AS36()) {
|
|
||||||
testRuntime(intellijPluginDep("android-wizardTemplate-plugin"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ide.IJ()) {
|
if (Ide.IJ()) {
|
||||||
|
|||||||
-39
@@ -1,39 +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.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()
|
|
||||||
}
|
|
||||||
-74
@@ -1,74 +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.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<StreamChain>) {
|
|
||||||
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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,7 +13,7 @@ The Kotlin plugin provides language support in IntelliJ IDEA and Android Studio.
|
|||||||
<version>@snapshot@</version>
|
<version>@snapshot@</version>
|
||||||
<vendor url="http://www.jetbrains.com">JetBrains</vendor>
|
<vendor url="http://www.jetbrains.com">JetBrains</vendor>
|
||||||
|
|
||||||
<idea-version since-build="192.4787.16.36.5737808" until-build="192.*"/>
|
<idea-version since-build="192.7142.36.36.6071332" until-build="192.*"/>
|
||||||
|
|
||||||
<depends>com.intellij.modules.platform</depends>
|
<depends>com.intellij.modules.platform</depends>
|
||||||
<depends>com.intellij.modules.androidstudio</depends>
|
<depends>com.intellij.modules.androidstudio</depends>
|
||||||
|
|||||||
-130
@@ -1,130 +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.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
|
|
||||||
import com.intellij.codeInsight.editorActions.moveUpDown.MoveStatementUpAction
|
|
||||||
import com.intellij.codeInsight.editorActions.moveUpDown.StatementUpDownMover
|
|
||||||
import com.intellij.openapi.application.ApplicationManager
|
|
||||||
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
|
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.upDownMover.KotlinDeclarationMover
|
|
||||||
import org.jetbrains.kotlin.idea.codeInsight.upDownMover.KotlinExpressionMover
|
|
||||||
import org.jetbrains.kotlin.idea.core.script.isScriptChangesNotifierDisabled
|
|
||||||
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightTestCase
|
|
||||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils
|
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
abstract class AbstractMoveStatementTest : AbstractCodeMoverTest() {
|
|
||||||
protected fun doTestClassBodyDeclaration(path: String) {
|
|
||||||
doTest(path, KotlinDeclarationMover::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun doTestExpression(path: String) {
|
|
||||||
doTest(path, KotlinExpressionMover::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun doTest(path: String, defaultMoverClass: Class<out StatementUpDownMover>) {
|
|
||||||
doTest(path) { isApplicableExpected, direction ->
|
|
||||||
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")
|
|
||||||
} ?: error("No mover found")
|
|
||||||
|
|
||||||
assertEquals("Unmatched movers", defaultMoverClass.name, actualMover::class.java.name)
|
|
||||||
assertEquals("Invalid applicability", isApplicableExpected, info.toMove2 != null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class AbstractMoveLeftRightTest : AbstractCodeMoverTest() {
|
|
||||||
protected fun doTest(path: String) {
|
|
||||||
doTest(path) { _, _ -> }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
abstract class AbstractCodeMoverTest : KotlinLightCodeInsightTestCase() {
|
|
||||||
override fun setUp() {
|
|
||||||
super.setUp()
|
|
||||||
ApplicationManager.getApplication().isScriptChangesNotifierDisabled = true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun tearDown() {
|
|
||||||
ApplicationManager.getApplication().isScriptChangesNotifierDisabled = false
|
|
||||||
super.tearDown()
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun doTest(path: String, isApplicableChecker: (isApplicableExpected: Boolean, direction: String) -> Unit) {
|
|
||||||
configureByFile(path)
|
|
||||||
|
|
||||||
val fileText = FileUtil.loadFile(File(path), true)
|
|
||||||
val direction = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MOVE: ")
|
|
||||||
?: error("No MOVE directive found")
|
|
||||||
|
|
||||||
val action = when (direction) {
|
|
||||||
"up" -> MoveStatementUpAction()
|
|
||||||
"down" -> MoveStatementDownAction()
|
|
||||||
"left" -> MoveElementLeftAction()
|
|
||||||
"right" -> MoveElementRightAction()
|
|
||||||
else -> error("Unknown direction: $direction")
|
|
||||||
}
|
|
||||||
|
|
||||||
val isApplicableString = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// IS_APPLICABLE: ")
|
|
||||||
val isApplicableExpected = isApplicableString == null || isApplicableString == "true"
|
|
||||||
|
|
||||||
isApplicableChecker(isApplicableExpected, direction)
|
|
||||||
|
|
||||||
invokeAndCheck(fileText, path, action, isApplicableExpected)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun invokeAndCheck(fileText: String, path: String, action: EditorAction, isApplicableExpected: Boolean) {
|
|
||||||
val editor = editor_
|
|
||||||
val project = editor.project!!
|
|
||||||
|
|
||||||
val codeStyleSettings = CodeStyle.getSettings(project)
|
|
||||||
val configurator = FormatSettingsUtil.createConfigurator(fileText, codeStyleSettings)
|
|
||||||
configurator.configureSettings()
|
|
||||||
|
|
||||||
try {
|
|
||||||
val dataContext = currentEditorDataContext_
|
|
||||||
|
|
||||||
val before = editor.document.text
|
|
||||||
runWriteAction { action.actionPerformed(editor, dataContext) }
|
|
||||||
|
|
||||||
val after = editor.document.text
|
|
||||||
val actionDoesNothing = after == before
|
|
||||||
|
|
||||||
TestCase.assertEquals(isApplicableExpected, !actionDoesNothing)
|
|
||||||
|
|
||||||
if (isApplicableExpected) {
|
|
||||||
val afterFilePath = path + ".after"
|
|
||||||
try {
|
|
||||||
checkResultByFile(afterFilePath)
|
|
||||||
}
|
|
||||||
catch (e: ComparisonFailure) {
|
|
||||||
KotlinTestUtils.assertEqualsToFile(File(afterFilePath), editor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally {
|
|
||||||
codeStyleSettings.clearCodeStyleSettings()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getTestDataPath() = ""
|
|
||||||
}
|
|
||||||
@@ -1,257 +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
|
|
||||||
|
|
||||||
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<KtNameReferenceExpression>(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<Any>(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<Any>(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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -65,10 +65,6 @@ dependencies {
|
|||||||
if (Ide.AS36.orHigher()) {
|
if (Ide.AS36.orHigher()) {
|
||||||
testRuntime(intellijPluginDep("android-layoutlib"))
|
testRuntime(intellijPluginDep("android-layoutlib"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ide.AS36()) {
|
|
||||||
testRuntime(intellijPluginDep("android-wizardTemplate-plugin"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
@@ -64,10 +64,6 @@ dependencies {
|
|||||||
if (Ide.AS36.orHigher()) {
|
if (Ide.AS36.orHigher()) {
|
||||||
testRuntime(intellijPluginDep("android-layoutlib"))
|
testRuntime(intellijPluginDep("android-layoutlib"))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Ide.AS36()) {
|
|
||||||
testRuntime(intellijPluginDep("android-wizardTemplate-plugin"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceSets {
|
sourceSets {
|
||||||
|
|||||||
Reference in New Issue
Block a user