Copy: Report module accessibility conflicts

This commit is contained in:
Alexey Sedunov
2017-05-16 14:35:52 +03:00
parent bfb3b38ebc
commit a80fb6f20f
30 changed files with 365 additions and 50 deletions
@@ -29,21 +29,37 @@ import org.jetbrains.kotlin.idea.jsonUtils.getString
import org.jetbrains.kotlin.idea.refactoring.AbstractMultifileRefactoringTest
import org.jetbrains.kotlin.idea.refactoring.copy.CopyKotlinDeclarationsHandler.Companion.newName
import org.jetbrains.kotlin.idea.refactoring.runRefactoringTest
import org.jetbrains.kotlin.idea.refactoring.toPsiDirectory
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.utils.ifEmpty
abstract class AbstractCopyTest : AbstractMultifileRefactoringTest(), AbstractMultifileRefactoringTest.RefactoringAction {
override fun runRefactoring(rootDir: VirtualFile, mainFile: PsiFile, elementsAtCaret: List<PsiElement>, config: JsonObject) {
val elementsToCopy = elementsAtCaret.ifEmpty { listOf(mainFile) }.toTypedArray()
assert(CopyHandler.canCopy(elementsToCopy))
abstract class AbstractCopyTest : AbstractMultifileRefactoringTest() {
companion object : RefactoringAction {
fun runCopyRefactoring(path: String, config: JsonObject, rootDir: VirtualFile, project: Project) {
runRefactoringTest(path, config, rootDir, project, this)
}
val packageWrapper = PackageWrapper(mainFile.manager, config.getString("targetPackage"))
project.newName = config.getNullableString("newName")
val targetDirectory = runWriteAction { MultipleRootsMoveDestination(packageWrapper).getTargetDirectory(mainFile) }
CopyHandler.doCopy(elementsToCopy, targetDirectory)
override fun runRefactoring(rootDir: VirtualFile, mainFile: PsiFile, elementsAtCaret: List<PsiElement>, config: JsonObject) {
val project = mainFile.project
val elementsToCopy = elementsAtCaret.ifEmpty { listOf(mainFile) }.toTypedArray()
assert(CopyHandler.canCopy(elementsToCopy))
val targetDirectory = config.getNullableString("targetDirectory")?.let {
rootDir.findFileByRelativePath(it)?.toPsiDirectory(project)
}
?: run {
val packageWrapper = PackageWrapper(mainFile.manager, config.getString("targetPackage"))
runWriteAction { MultipleRootsMoveDestination(packageWrapper).getTargetDirectory(mainFile) }
}
project.newName = config.getNullableString("newName")
CopyHandler.doCopy(elementsToCopy, targetDirectory)
}
}
override fun runRefactoring(path: String, config: JsonObject, rootDir: VirtualFile, project: Project) {
runRefactoringTest(path, config, rootDir, project, this)
runCopyRefactoring(path, config, rootDir, project)
}
}
@@ -0,0 +1,38 @@
/*
* Copyright 2010-2017 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.refactoring.copy
import org.jetbrains.kotlin.idea.refactoring.rename.loadTestConfiguration
import org.jetbrains.kotlin.idea.test.KotlinMultiFileTestCase
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
import java.io.File
abstract class AbstractMultiModuleCopyTest : KotlinMultiFileTestCase() {
override fun getTestRoot(): String = "/refactoring/copyMultiModule/"
override fun getTestDataPath(): String = PluginTestCaseBase.getTestDataPathBase()
fun doTest(path: String) {
val config = loadTestConfiguration(File(path))
isMultiModule = true
doTestCommittingDocuments { rootDir, _ ->
AbstractCopyTest.runCopyRefactoring(path, config, rootDir, project)
}
}
}
@@ -0,0 +1,50 @@
/*
* Copyright 2010-2017 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.refactoring.copy;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/refactoring/copyMultiModule")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class MultiModuleCopyTestGenerated extends AbstractMultiModuleCopyTest {
public void testAllFilesPresentInCopyMultiModule() throws Exception {
KotlinTestUtils.assertAllTestsPresentInSingleGeneratedClass(this.getClass(), new File("idea/testData/refactoring/copyMultiModule"), Pattern.compile("^(.+)\\.test$"), TargetBackend.ANY);
}
@TestMetadata("internalReferencesToAnotherModule2/internalReferencesToAnotherModule.test")
public void testInternalReferencesToAnotherModule2_InternalReferencesToAnotherModule() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/copyMultiModule/internalReferencesToAnotherModule2/internalReferencesToAnotherModule.test");
doTest(fileName);
}
@TestMetadata("referencesToUnrelatedModule/referencesToUnrelatedModule.test")
public void testReferencesToUnrelatedModule_ReferencesToUnrelatedModule() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/refactoring/copyMultiModule/referencesToUnrelatedModule/referencesToUnrelatedModule.test");
doTest(fileName);
}
}