Add debug strings to frontend scopes-related structures

Such as:
- PackageFragmentProviders, and, in particular,
CompositePackageFragmentProviders
- JavaPackageFragments
- Scopes produced by those providers

The rationale is that a lot of frontend-facing bugs (like red code) are
easily recognizeable in resolution. But at that point you just see a
bunch of scopes, without meaningful toStrings, you don't know who has
produced them, and what's exactly wrong.

With this commit it should make debugging slightly easier: now at least
you'll be able to see that "this scope is a scope of package fragment
for foo.bar of module baz" and decide whether the declaration should or
should not have been resolved from such scope.
This commit is contained in:
Dmitry Savvinov
2021-05-21 11:35:26 +03:00
committed by teamcityserver
parent a51c65ed60
commit 708fead1cc
32 changed files with 137 additions and 48 deletions
@@ -22,7 +22,8 @@ import java.util.*
import org.jetbrains.kotlin.name.Name
class CompositePackageFragmentProvider(// can be modified from outside
private val providers: List<PackageFragmentProvider>
private val providers: List<PackageFragmentProvider>,
private val debugName: String
) : PackageFragmentProviderOptimized {
init {
@@ -55,4 +56,6 @@ class CompositePackageFragmentProvider(// can be modified from outside
}
return result
}
override fun toString(): String = debugName
}
@@ -101,9 +101,12 @@ class ModuleDescriptorImpl @JvmOverloads constructor(
"Dependency module ${dependency.id} was not initialized by the time contents of dependent module ${this.id} were queried"
}
}
CompositePackageFragmentProvider(dependenciesDescriptors.map {
it.packageFragmentProviderForModuleContent!!
})
CompositePackageFragmentProvider(
dependenciesDescriptors.map {
it.packageFragmentProviderForModuleContent!!
},
"CompositeProvider@ModuleDescriptor for $name"
)
}
private val isInitialized: Boolean
@@ -22,12 +22,16 @@ import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.descriptorUtil.module
abstract class PackageFragmentDescriptorImpl(
module: ModuleDescriptor,
final override val fqName: FqName
) : DeclarationDescriptorNonRootImpl(module, Annotations.EMPTY, fqName.shortNameOrSpecial(), SourceElement.NO_SOURCE),
PackageFragmentDescriptor {
// Not inlined in order to not capture ref on 'module'
private val debugString: String = "package $fqName of $module"
override fun <R, D> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R =
visitor.visitPackageFragmentDescriptor(this, data)
@@ -39,5 +43,5 @@ abstract class PackageFragmentDescriptorImpl(
return SourceElement.NO_SOURCE
}
override fun toString(): String = "package $fqName"
override fun toString(): String = debugString
}
@@ -66,4 +66,6 @@ open class SubpackagesScope(private val moduleDescriptor: ModuleDescriptor, priv
p.popIndent()
p.println("}")
}
override fun toString(): String = "subpackages of $fqName from $moduleDescriptor"
}