as40: Fix test compilation for AS 4.0 C7

This commit is contained in:
Vyacheslav Gerasimov
2019-12-25 20:17:00 +03:00
parent 89a259837f
commit d8d21b0cba
6 changed files with 29 additions and 36 deletions
@@ -155,7 +155,7 @@ public class KotlinConfidenceTest extends LightCompletionTestCase {
new CodeCompletionHandlerBase(CompletionType.BASIC, false, true, true).invokeCompletion( new CodeCompletionHandlerBase(CompletionType.BASIC, false, true, true).invokeCompletion(
getProject(), getEditor(), 0, false); 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); myItems = lookup == null ? null : lookup.getItems().toArray(LookupElement.EMPTY_ARRAY);
myPrefix = lookup == null ? null : lookup.itemPattern(lookup.getItems().get(0)); myPrefix = lookup == null ? null : lookup.itemPattern(lookup.getItems().get(0));
} }
@@ -31,7 +31,7 @@ import org.gradle.tooling.model.DomainObjectSet;
import org.gradle.tooling.model.idea.IdeaModule; import org.gradle.tooling.model.idea.IdeaModule;
import org.gradle.util.GradleVersion; import org.gradle.util.GradleVersion;
import org.jetbrains.annotations.NotNull; 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.ExternalProject;
import org.jetbrains.plugins.gradle.model.ProjectImportAction; import org.jetbrains.plugins.gradle.model.ProjectImportAction;
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper; import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper;
@@ -141,7 +141,7 @@ public abstract class AbstractModelBuilderTest {
try { try {
ProjectImportAction projectImportAction = new ProjectImportAction(false); ProjectImportAction projectImportAction = new ProjectImportAction(false);
projectImportAction.addProjectImportExtraModelProvider(new ClassSetProjectImportExtraModelProvider(getModels())); projectImportAction.addProjectImportModelProvider(new ClassSetProjectImportModelProvider(getModels()));
BuildActionExecuter<ProjectImportAction.AllModels> buildActionExecutor = connection.action(projectImportAction); BuildActionExecuter<ProjectImportAction.AllModels> buildActionExecutor = connection.action(projectImportAction);
File initScript = GradleExecutionHelper.generateInitScript(false, getToolingExtensionClasses()); File initScript = GradleExecutionHelper.generateInitScript(false, getToolingExtensionClasses());
assertNotNull(initScript); assertNotNull(initScript);
@@ -196,7 +196,7 @@ public abstract class AbstractModelBuilderTest {
Map<String, T> map = ContainerUtil.map2Map(ideaModules, new Function<IdeaModule, Pair<String, T>>() { Map<String, T> map = ContainerUtil.map2Map(ideaModules, new Function<IdeaModule, Pair<String, T>>() {
@Override @Override
public Pair<String, T> fun(IdeaModule module) { public Pair<String, T> fun(IdeaModule module) {
T value = allModels.getExtraProject(module, aClass); T value = allModels.getModel(module, aClass);
String key = value != null ? module.getGradleProject().getPath() : filterKey; String key = value != null ? module.getGradleProject().getPath() : filterKey;
return Pair.create(key, value); return Pair.create(key, value);
} }
@@ -14,26 +14,24 @@ import com.intellij.openapi.module.Module
import com.intellij.openapi.project.Project import com.intellij.openapi.project.Project
import com.intellij.psi.PsiFile import com.intellij.psi.PsiFile
import com.intellij.testFramework.LightIdeaTestCase import com.intellij.testFramework.LightIdeaTestCase
import com.intellij.testFramework.LightPlatformCodeInsightTestCase
import com.intellij.testFramework.LightPlatformTestCase
// BUNCH: as36, 191 // BUNCH: as36, 191
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
@Deprecated("Use KotlinLightCodeInsightFixtureTestCase instead") @Deprecated("Use KotlinLightCodeInsightFixtureTestCase instead")
abstract class KotlinLightCodeInsightTestCase : com.intellij.testFramework.LightCodeInsightTestCase() { abstract class KotlinLightCodeInsightTestCase : com.intellij.testFramework.LightCodeInsightTestCase() {
protected inline val project_: Project get() = LightPlatformTestCase.getProject() protected inline val project_: Project get() = project
protected inline val module_: Module get() = LightPlatformTestCase.getModule() protected inline val module_: Module get() = module
protected inline val editor_: Editor get() = LightPlatformCodeInsightTestCase.getEditor() protected inline val editor_: Editor get() = editor
protected inline val file_: PsiFile get() = LightPlatformCodeInsightTestCase.getFile() protected inline val file_: PsiFile get() = file
protected inline val currentEditorDataContext_: DataContext get() = LightPlatformCodeInsightTestCase.getCurrentEditorDataContext() protected inline val currentEditorDataContext_: DataContext get() = currentEditorDataContext
protected fun configureFromFileText_(fileName: String, fileText: String): Document { protected fun configureFromFileText_(fileName: String, fileText: String): Document {
return LightPlatformCodeInsightTestCase.configureFromFileText(fileName, fileText, false) return configureFromFileText(fileName, fileText, false)
} }
} }
// BUNCH: as36, 191 // BUNCH: as36, 191
abstract class KotlinLightIdeaTestCase : LightIdeaTestCase() { abstract class KotlinLightIdeaTestCase : LightIdeaTestCase() {
protected inline val project_: Project get() = LightPlatformTestCase.getProject() protected inline val project_: Project get() = project
protected inline val module_: Module get() = LightPlatformTestCase.getModule() protected inline val module_: Module get() = module
} }
@@ -10,7 +10,6 @@ import com.intellij.debugger.streams.wrapper.StreamChainBuilder
import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.projectRoots.Sdk import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable import com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable
import com.intellij.testFramework.LightPlatformTestCase
import com.intellij.testFramework.PsiTestUtil import com.intellij.testFramework.PsiTestUtil
import junit.framework.TestCase import junit.framework.TestCase
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
@@ -34,18 +33,18 @@ abstract class KotlinPsiChainBuilderTestCase(private val relativePath: String) :
super.setUp() super.setUp()
ApplicationManager.getApplication().runWriteAction { ApplicationManager.getApplication().runWriteAction {
@Suppress("UnstableApiUsage") @Suppress("UnstableApiUsage")
if (ProjectLibraryTable.getInstance(LightPlatformTestCase.getProject()).getLibraryByName(stdLibName) == null) { if (ProjectLibraryTable.getInstance(project).getLibraryByName(stdLibName) == null) {
val stdLibPath = ForTestCompileRuntime.runtimeJarForTests() val stdLibPath = ForTestCompileRuntime.runtimeJarForTests()
PsiTestUtil.addLibrary( PsiTestUtil.addLibrary(
testRootDisposable, testRootDisposable,
LightPlatformTestCase.getModule(), module,
stdLibName, stdLibName,
stdLibPath.parent, stdLibPath.parent,
stdLibPath.name stdLibPath.name
) )
} }
} }
LibraryModificationTracker.getInstance(LightPlatformTestCase.getProject()).incModificationCount() LibraryModificationTracker.getInstance(project).incModificationCount()
} }
@@ -16,7 +16,6 @@ import com.intellij.openapi.application.runWriteAction
import com.intellij.openapi.editor.actionSystem.EditorAction import com.intellij.openapi.editor.actionSystem.EditorAction
import com.intellij.openapi.extensions.Extensions import com.intellij.openapi.extensions.Extensions
import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.io.FileUtil
import com.intellij.testFramework.LightPlatformCodeInsightTestCase
import junit.framework.ComparisonFailure import junit.framework.ComparisonFailure
import junit.framework.TestCase import junit.framework.TestCase
import org.jetbrains.kotlin.formatter.FormatSettingsUtil import org.jetbrains.kotlin.formatter.FormatSettingsUtil
@@ -42,7 +41,7 @@ abstract class AbstractMoveStatementTest : AbstractCodeMoverTest() {
val movers = Extensions.getExtensions(StatementUpDownMover.STATEMENT_UP_DOWN_MOVER_EP) val movers = Extensions.getExtensions(StatementUpDownMover.STATEMENT_UP_DOWN_MOVER_EP)
val info = StatementUpDownMover.MoveInfo() val info = StatementUpDownMover.MoveInfo()
val actualMover = movers.firstOrNull { val actualMover = movers.firstOrNull {
it.checkAvailable(LightPlatformCodeInsightTestCase.getEditor(), LightPlatformCodeInsightTestCase.getFile(), info, direction == "down") it.checkAvailable(editor, file, info, direction == "down")
} ?: error("No mover found") } ?: error("No mover found")
assertEquals("Unmatched movers", defaultMoverClass.name, actualMover::class.java.name) assertEquals("Unmatched movers", defaultMoverClass.name, actualMover::class.java.name)
@@ -53,7 +52,7 @@ abstract class AbstractMoveStatementTest : AbstractCodeMoverTest() {
abstract class AbstractMoveLeftRightTest : AbstractCodeMoverTest() { abstract class AbstractMoveLeftRightTest : AbstractCodeMoverTest() {
protected fun doTest(path: String) { protected fun doTest(path: String) {
doTest(path) { _, _ -> } doTest(path) { _, _ -> }
} }
} }
@@ -73,8 +72,7 @@ abstract class AbstractCodeMoverTest : KotlinLightCodeInsightTestCase() {
configureByFile(path) configureByFile(path)
val fileText = FileUtil.loadFile(File(path), true) val fileText = FileUtil.loadFile(File(path), true)
val direction = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MOVE: ") val direction = InTextDirectivesUtils.findStringWithPrefixes(fileText, "// MOVE: ") ?: error("No MOVE directive found")
?: error("No MOVE directive found")
val action = when (direction) { val action = when (direction) {
"up" -> MoveStatementUpAction() "up" -> MoveStatementUpAction()
@@ -112,16 +110,14 @@ abstract class AbstractCodeMoverTest : KotlinLightCodeInsightTestCase() {
TestCase.assertEquals(isApplicableExpected, !actionDoesNothing) TestCase.assertEquals(isApplicableExpected, !actionDoesNothing)
if (isApplicableExpected) { if (isApplicableExpected) {
val afterFilePath = path + ".after" val afterFilePath = "$path.after"
try { try {
checkResultByFile(afterFilePath) checkResultByFile(afterFilePath)
} } catch (e: ComparisonFailure) {
catch (e: ComparisonFailure) {
KotlinTestUtils.assertEqualsToFile(File(afterFilePath), editor) KotlinTestUtils.assertEqualsToFile(File(afterFilePath), editor)
} }
} }
} } finally {
finally {
codeStyleSettings.clearCodeStyleSettings() codeStyleSettings.clearCodeStyleSettings()
} }
} }
@@ -191,8 +191,10 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() {
val element = file.findElementForRename<KtNameReferenceExpression>(editor.caretModel.offset)!! val element = file.findElementForRename<KtNameReferenceExpression>(editor.caretModel.offset)!!
assertNotNull(element) assertNotNull(element)
val dataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.name, element, val dataContext = SimpleDataContext.getSimpleContext(
getCurrentEditorDataContext()) CommonDataKeys.PSI_ELEMENT.name, element,
getCurrentEditorDataContext()
)
val handler = RenameKotlinImplicitLambdaParameter() val handler = RenameKotlinImplicitLambdaParameter()
assertTrue(handler.isRenaming(dataContext), "In-place rename not allowed for " + element) assertTrue(handler.isRenaming(dataContext), "In-place rename not allowed for " + element)
@@ -231,25 +233,23 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() {
private fun doTestInplaceRename(newName: String?, handler: VariableInplaceRenameHandler = KotlinVariableInplaceRenameHandler()) { private fun doTestInplaceRename(newName: String?, handler: VariableInplaceRenameHandler = KotlinVariableInplaceRenameHandler()) {
configureByFile(getTestName(false) + ".kt") configureByFile(getTestName(false) + ".kt")
val element = TargetElementUtil.findTargetElement( val element = TargetElementUtil.findTargetElement(
myEditor, editor,
TargetElementUtil.ELEMENT_NAME_ACCEPTED or TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED TargetElementUtil.ELEMENT_NAME_ACCEPTED or TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED
) )
assertNotNull(element) assertNotNull(element)
val dataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.name, element!!, val dataContext = SimpleDataContext.getSimpleContext(CommonDataKeys.PSI_ELEMENT.name, element!!, currentEditorDataContext)
getCurrentEditorDataContext())
if (newName == null) { if (newName == null) {
assertFalse(handler.isRenaming(dataContext), "In-place rename is allowed for " + element) assertFalse(handler.isRenaming(dataContext), "In-place rename is allowed for " + element)
} } else {
else {
try { try {
assertTrue(handler.isRenaming(dataContext), "In-place rename not allowed for " + element) assertTrue(handler.isRenaming(dataContext), "In-place rename not allowed for " + element)
CodeInsightTestUtil.doInlineRename(handler, newName, getEditor(), element) CodeInsightTestUtil.doInlineRename(handler, newName, getEditor(), element)
checkResultByFile(getTestName(false) + ".kt.after") checkResultByFile(getTestName(false) + ".kt.after")
} catch (e: BaseRefactoringProcessor.ConflictsInTestsException) { } 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()) TestCase.assertEquals(expectedMessage, e.messages.joinToString())
} }
} }