do not treat usages of constructor as non-code (although !reference.isResolvedTo(element) as reference resolves to the constructor's class)

This commit is contained in:
anna
2010-05-27 20:00:10 +04:00
parent 8a9488c613
commit 9e165bcd23
3 changed files with 24 additions and 1 deletions
@@ -0,0 +1,5 @@
public class T<caret>oFind {
void foo() {
new ToFind();
}
}
@@ -6,9 +6,14 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.psi.PsiElement;
import com.intellij.refactoring.rename.RenameProcessor;
import com.intellij.refactoring.rename.RenameUtil;
import com.intellij.refactoring.util.MoveRenameUsageInfo;
import com.intellij.testFramework.LightCodeInsightTestCase;
import com.intellij.usageView.UsageInfo;
import org.junit.Assert;
import java.util.HashMap;
/**
* @author sashache
*/
@@ -165,4 +170,17 @@ public class RenameCollisionsTest extends LightCodeInsightTestCase {
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk15("java 1.5");
}
public void testAllUsagesInCode() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
PsiElement element = TargetElementUtilBase
.findTargetElement(myEditor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED | TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED);
assertNotNull(element);
final UsageInfo[] usageInfos = RenameUtil.findUsages(element, "newName", true, true, new HashMap<PsiElement, String>());
assertSize(1, usageInfos);
for (UsageInfo usageInfo : usageInfos) {
assertTrue(usageInfo instanceof MoveRenameUsageInfo);
assertFalse(usageInfo.isNonCodeUsage);
}
}
}
@@ -69,7 +69,7 @@ public class RenameUtil {
PsiElement referenceElement = ref.getElement();
result.add(new MoveRenameUsageInfo(referenceElement, ref, ref.getRangeInElement().getStartOffset(),
ref.getRangeInElement().getEndOffset(), element,
!ref.isReferenceTo(element)));
ref.resolve() == null));
}
processor.findCollisions(element, newName, allRenames, result);