DeprecatedSymbolUsageFix: fixed bug with symbols from root package not imported

This commit is contained in:
Valentin Kipyatkov
2015-05-22 11:46:41 +03:00
parent 97d3620262
commit be9a3d10f6
8 changed files with 41 additions and 5 deletions
@@ -72,11 +72,12 @@ public class KotlinCacheService(val project: Project) {
return cache.getLazyResolveSession(file).getScopeProvider().getFileScope(file) return cache.getLazyResolveSession(file).getScopeProvider().getFileScope(file)
} }
override fun resolveImportReference(file: JetFile, fqName: FqName): Collection<DeclarationDescriptor> { override fun resolveImportReference(file: JetFile, fqName: FqName, isDefaultImport: Boolean): Collection<DeclarationDescriptor> {
val importDirective = JetPsiFactory(project).createImportDirective(ImportPath(fqName, false)) val importDirective = JetPsiFactory(project).createImportDirective(ImportPath(fqName, false))
val moduleDescriptor = findModuleDescriptor(file) val moduleDescriptor = findModuleDescriptor(file)
val scope = JetModuleUtil.getSubpackagesOfRootScope(moduleDescriptor) val resolveSession = cache.getLazyResolveSession(file)
val resolver = cache.getLazyResolveSession(file).getQualifiedExpressionResolver() val scope = JetModuleUtil.getImportsResolutionScope(moduleDescriptor, !isDefaultImport)
val resolver = resolveSession.getQualifiedExpressionResolver()
return resolver.processImportReference( return resolver.processImportReference(
importDirective, scope, scope, BindingTraceContext(), QualifiedExpressionResolver.LookupMode.EVERYTHING).getAllDescriptors() importDirective, scope, scope, BindingTraceContext(), QualifiedExpressionResolver.LookupMode.EVERYTHING).getAllDescriptors()
} }
@@ -38,7 +38,7 @@ public trait ResolutionFacade {
public fun getFileTopLevelScope(file: JetFile): JetScope public fun getFileTopLevelScope(file: JetFile): JetScope
//TODO: better pass ModuleDescriptor here //TODO: better pass ModuleDescriptor here
public fun resolveImportReference(file: JetFile, fqName: FqName): Collection<DeclarationDescriptor> public fun resolveImportReference(file: JetFile, fqName: FqName, isDefaultImport: Boolean = false): Collection<DeclarationDescriptor>
public fun findModuleDescriptor(element: JetElement): ModuleDescriptor public fun findModuleDescriptor(element: JetElement): ModuleDescriptor
@@ -310,7 +310,7 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Kotlin
= this == KotlinReferenceData.Kind.EXTENSION_FUNCTION || this == KotlinReferenceData.Kind.EXTENSION_PROPERTY = this == KotlinReferenceData.Kind.EXTENSION_FUNCTION || this == KotlinReferenceData.Kind.EXTENSION_PROPERTY
private fun findImportableDescriptors(fqName: FqName, file: JetFile): Collection<DeclarationDescriptor> { private fun findImportableDescriptors(fqName: FqName, file: JetFile): Collection<DeclarationDescriptor> {
return file.getResolutionFacade().resolveImportReference(file, fqName) return file.getResolutionFacade().resolveImportReference(file, fqName, isDefaultImport = true/*TODO: temporary hack until we don't have ability to insert qualified reference into root package*/)
} }
private fun findCallableToImport(fqName: FqName, file: JetFile): CallableDescriptor? private fun findCallableToImport(fqName: FqName, file: JetFile): CallableDescriptor?
@@ -0,0 +1,6 @@
@deprecated("", ReplaceWith("newFun()"))
fun oldFun() {
newFun()
}
fun newFun() {}
@@ -0,0 +1,9 @@
// "Replace with 'newFun()'" "true"
package pack5
import newFun
import oldFun
fun foo() {
<caret>newFun()
}
@@ -0,0 +1,6 @@
@deprecated("", ReplaceWith("newFun()"))
fun oldFun() {
newFun()
}
fun newFun() {}
@@ -0,0 +1,8 @@
// "Replace with 'newFun()'" "true"
package pack5
import oldFun
fun foo() {
<caret>oldFun()
}
@@ -889,6 +889,12 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
public void testAllFilesPresentInImports() throws Exception { public void testAllFilesPresentInImports() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/deprecatedSymbolUsage/imports"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true); JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/deprecatedSymbolUsage/imports"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
} }
@TestMetadata("rootPackage.before.Main.kt")
public void testRootPackage() throws Exception {
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/deprecatedSymbolUsage/imports/rootPackage.before.Main.kt");
doTestWithExtraFile(fileName);
}
} }
@TestMetadata("idea/testData/quickfix/deprecatedSymbolUsage/wholeProject") @TestMetadata("idea/testData/quickfix/deprecatedSymbolUsage/wholeProject")