From 1e2ef9fbf1d28f500c89a4b111b52a6c000c35df Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 20 Feb 2012 15:54:05 +0400 Subject: [PATCH] KT-1294 Class rename fails to update import statement and breaks the code - test for kotlin class rename --- .../rename/RenameKotlinClass/after/First.kt | 4 + .../rename/RenameKotlinClass/after/Second.kt | 18 ++++ .../rename/RenameKotlinClass/before/First.kt | 4 + .../rename/RenameKotlinClass/before/Second.kt | 18 ++++ .../rename/RenameInKotlinTest.java | 82 +++++++++++++++++++ 5 files changed, 126 insertions(+) create mode 100644 idea/testData/refactoring/rename/RenameKotlinClass/after/First.kt create mode 100644 idea/testData/refactoring/rename/RenameKotlinClass/after/Second.kt create mode 100644 idea/testData/refactoring/rename/RenameKotlinClass/before/First.kt create mode 100644 idea/testData/refactoring/rename/RenameKotlinClass/before/Second.kt create mode 100644 idea/tests/org/jetbrains/jet/plugin/refactoring/rename/RenameInKotlinTest.java diff --git a/idea/testData/refactoring/rename/RenameKotlinClass/after/First.kt b/idea/testData/refactoring/rename/RenameKotlinClass/after/First.kt new file mode 100644 index 00000000000..d0902675688 --- /dev/null +++ b/idea/testData/refactoring/rename/RenameKotlinClass/after/First.kt @@ -0,0 +1,4 @@ +package testing.first + +public open class Third { +} \ No newline at end of file diff --git a/idea/testData/refactoring/rename/RenameKotlinClass/after/Second.kt b/idea/testData/refactoring/rename/RenameKotlinClass/after/Second.kt new file mode 100644 index 00000000000..6f1425f51aa --- /dev/null +++ b/idea/testData/refactoring/rename/RenameKotlinClass/after/Second.kt @@ -0,0 +1,18 @@ +package testing.second + +import testing.first.Third +import testing.* +import java.util.ArrayList + +// Extends testing.first.Third +public class Second : Third() { + val temp : testing.first.Third = Third() + + fun tempName(param : Third) : first.Third { + val local = Third() + val otherLocal = param + val arr = ArrayList() + + return testing.first.Third() + } +} \ No newline at end of file diff --git a/idea/testData/refactoring/rename/RenameKotlinClass/before/First.kt b/idea/testData/refactoring/rename/RenameKotlinClass/before/First.kt new file mode 100644 index 00000000000..14e66920c8a --- /dev/null +++ b/idea/testData/refactoring/rename/RenameKotlinClass/before/First.kt @@ -0,0 +1,4 @@ +package testing.first + +public open class First { +} \ No newline at end of file diff --git a/idea/testData/refactoring/rename/RenameKotlinClass/before/Second.kt b/idea/testData/refactoring/rename/RenameKotlinClass/before/Second.kt new file mode 100644 index 00000000000..0bc1ef5f46f --- /dev/null +++ b/idea/testData/refactoring/rename/RenameKotlinClass/before/Second.kt @@ -0,0 +1,18 @@ +package testing.second + +import testing.first.First +import testing.* +import java.util.ArrayList + +// Extends testing.first.First +public class Second : First() { + val temp : testing.first.First = First() + + fun tempName(param : First) : first.First { + val local = First() + val otherLocal = param + val arr = ArrayList() + + return testing.first.First() + } +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/refactoring/rename/RenameInKotlinTest.java b/idea/tests/org/jetbrains/jet/plugin/refactoring/rename/RenameInKotlinTest.java new file mode 100644 index 00000000000..abf8f1d72ca --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/refactoring/rename/RenameInKotlinTest.java @@ -0,0 +1,82 @@ +/* + * Copyright 2000-2012 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.jet.plugin.refactoring.rename; + +import com.intellij.openapi.fileEditor.FileDocumentManager; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.PsiElement; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.refactoring.MultiFileTestCase; +import com.intellij.refactoring.rename.RenameProcessor; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.jet.lang.descriptors.ClassDescriptor; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.plugin.PluginTestCaseBase; +import org.jetbrains.jet.plugin.compiler.WholeProjectAnalyzerFacade; + +/** + * @author Nikolay Krasko + */ +public class RenameInKotlinTest extends MultiFileTestCase { + @Override + protected void setUp() throws Exception { + super.setUp(); + + String path = getTestDataPath() + getTestRoot(); + VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(path); + if (virtualFile != null) { + virtualFile.getChildren(); + virtualFile.refresh(false, true); + } + } + + public void testRenameKotlinClass() throws Exception { + doTestWithRenameClass("testing.first.First", "Third"); + } + + private void doTestWithRenameClass(@NonNls final String qClassName, @NonNls final String newName) throws Exception { + doTest(new PerformAction() { + @Override + public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception { + BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCache(getProject(), GlobalSearchScope.allScope(getProject())); + ClassDescriptor classDescriptor = bindingContext.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, qClassName); + + assertNotNull(classDescriptor); + + PsiElement psiElement = bindingContext.get(BindingContext.DESCRIPTOR_TO_DECLARATION, classDescriptor); + + assertNotNull(psiElement); + + new RenameProcessor(myProject, psiElement, newName, true, true).run(); + PsiDocumentManager.getInstance(myProject).commitAllDocuments(); + FileDocumentManager.getInstance().saveAllDocuments(); + } + }); + } + + @Override + protected String getTestRoot() { + return "/refactoring/rename/"; + } + + @Override + protected String getTestDataPath() { + return PluginTestCaseBase.getTestDataPathBase(); + } +}