KT-1294 Class rename fails to update import statement and breaks the code - add test for different packages and public java class.

This commit is contained in:
Nikolay Krasko
2012-02-20 14:52:44 +04:00
parent 9689c30a58
commit 00fa077c34
8 changed files with 122 additions and 1 deletions
+1
View File
@@ -1,5 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="IDEA" type="Application" factoryName="Application">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<option name="MAIN_CLASS_NAME" value="com.intellij.idea.Main" />
<option name="VM_PARAMETERS" value="-Xmx500m -XX:ReservedCodeCacheSize=64m -XX:MaxPermSize=250m -ea -Didea.is.internal=true -Didea.debug.mode=true -Didea.system.path=../system-idea -Didea.config.path=../config -Dapple.laf.useScreenMenuBar=true -Dplugin.path=$PROJECT_DIR$/out/artifacts/Kotlin" />
<option name="PROGRAM_PARAMETERS" value="" />
@@ -2,7 +2,7 @@
<configuration default="false" name="IDEA (No ProcessCanceledException)" type="Application" factoryName="Application">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<option name="MAIN_CLASS_NAME" value="com.intellij.idea.Main" />
<option name="VM_PARAMETERS" value="-Xmx500m -XX:ReservedCodeCacheSize=64m -XX:MaxPermSize=250m -ea -Didea.is.internal=true -Didea.debug.mode=true -Didea.system.path=../system-idea -Didea.config.path=../config -Dapple.laf.useScreenMenuBar=true -Dplugin.path=$PROJECT_DIR$/out/artifacts/Kotlin -Didea.ProcessCanceledException=disabled" />
<option name="VM_PARAMETERS" value="-Xmx500m -XX:ReservedCodeCacheSize=64m -XX:MaxPermSize=250m -ea -Didea.is.internal=true -Didea.debug.mode=false -Didea.system.path=../system-idea -Didea.config.path=../config -Dapple.laf.useScreenMenuBar=true -Dplugin.path=$PROJECT_DIR$/out/artifacts/Kotlin -Didea.ProcessCanceledException=disabled" />
<option name="PROGRAM_PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$/ideaSDK/bin" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
@@ -363,12 +363,14 @@ public class ImportsResolver {
return;
}
// Simple case of no descriptors
if (descriptors.isEmpty()) {
trace.record(BindingContext.RESOLUTION_SCOPE, referenceExpression, resolutionScope);
trace.report(UNRESOLVED_REFERENCE.on(referenceExpression));
return;
}
// Decide if expression has resolved reference
if (descriptors.size() == 1) {
assert canBeImportedDescriptors.size() <= 1;
trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, descriptors.iterator().next());
@@ -377,8 +379,11 @@ public class ImportsResolver {
else if (canBeImportedDescriptors.size() == 1) {
trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, canBeImportedDescriptors.iterator().next());
trace.record(BindingContext.RESOLUTION_SCOPE, referenceExpression, resolutionScope);
} else {
// trace.report(UNRESOLVED_REFERENCE.on(referenceExpression));
}
// Check for more information and additional errors
if (canBeImportedDescriptors.isEmpty()) {
assert descriptors.size() >= 1;
trace.report(CANNOT_BE_IMPORTED.on(referenceExpression, descriptors.iterator().next()));
@@ -0,0 +1,11 @@
package kotlin.testing
import testing.NewName
class Some : NewName() {
val test = NewName()
fun testFun(param : NewName) : NewName {
return test;
}
}
@@ -0,0 +1,5 @@
package testing;
public class NewName {
}
@@ -0,0 +1,11 @@
package kotlin.testing
import testing.SomeClass
class Some : SomeClass() {
val test = SomeClass()
fun testFun(param : SomeClass) : SomeClass {
return test;
}
}
@@ -0,0 +1,5 @@
package testing;
public class SomeClass {
}
@@ -0,0 +1,83 @@
/*
* 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.PsiClass;
import com.intellij.psi.PsiDocumentManager;
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.plugin.PluginTestCaseBase;
/**
* @author Nikolay Krasko
*/
public class RenameInJavaTest 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 testRenameJavaClass() throws Exception {
doTest("testing.SomeClass", "NewName");
}
public void todotestRenameJavaClassSamePackage() throws Exception {
doTest("testing.SomeClass", "NewName");
}
private void doTest(@NonNls final String qClassName, @NonNls final String newName) throws Exception {
doTest(new PerformAction() {
@Override
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
RenameInJavaTest.this.performAction(qClassName, newName);
}
});
}
private void performAction(String qClassName, String newName) throws Exception {
PsiClass aClass = myJavaFacade.findClass(qClassName, GlobalSearchScope.allScope(getProject()));
assertNotNull("Class " + qClassName + " not found", aClass);
new RenameProcessor(myProject, aClass, 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();
}
}