KT-43205 Ignore annotations in CallableClsStubBuilder when needed

Kotlin compiler can add `@Deprecated` annotations to the fields of
private companion objects, and if those annotations are not supposed to
be shown in decompiled code and used, the field is marked with
`HAS_ANNOTATIONS=false` flag (see KT-25009)

However, it was not taken into account in stubs building process, which
led to the 'Stubs vs PSI mismatch' exceptions

^KT-43205 Fixed

Also, restore the order of nested typealiases and classes (see KT-41859)

We didn't want to bump the version of the stubs when we fixed this
issue; now we have an opportunity to restore the order back to
match the `MemberComparator`

Also, some refactoring is done to underscore that
`createPackageDeclarationsStubs` is suitable only for packages, not
for any declarations container
This commit is contained in:
Roman Golyshev
2020-11-09 15:49:50 +00:00
parent fdd7fa5aea
commit ebfbc2f601
13 changed files with 202 additions and 51 deletions
@@ -99,24 +99,13 @@ abstract class DeserializedMemberScope protected constructor(
return impl.getContributedVariables(name, location)
}
/**
* N.B. Currently the order of declarations here and in the [MemberComparator] is intentionally different:
* [MemberComparator] places classes first and typealiases second.
*
* However, `ClassClsStubBuilder` places typealiases first and classes second. This leads to
* Stub vs Psi mismatch error, when we have a class which have both inner typealiases and inner classes.
* This is unintentional and should be fixed.
*
* We do not want to update stubs versions prematurely, so we temporary mitigate the issue by making sure that
* order in stubs (in `ClassClsStubBuilder`) and here (in [DeserializedMemberScope]) is the same. As soon as the
* opportunity to bump the stubs version arises, we should fix the bug in the `ClassClsStubBuilder`, and
* fix the order here accordingly.
*/
protected fun computeDescriptors(
kindFilter: DescriptorKindFilter,
nameFilter: (Name) -> Boolean,
location: LookupLocation
): Collection<DeclarationDescriptor> {
//NOTE: descriptors should be in the same order they were serialized in
// see MemberComparator
val result = ArrayList<DeclarationDescriptor>(0)
if (kindFilter.acceptsKinds(DescriptorKindFilter.SINGLETON_CLASSIFIERS_MASK)) {
@@ -125,14 +114,6 @@ abstract class DeserializedMemberScope protected constructor(
impl.addFunctionsAndPropertiesTo(result, kindFilter, nameFilter, location)
if (kindFilter.acceptsKinds(DescriptorKindFilter.TYPE_ALIASES_MASK)) {
for (typeAliasName in impl.typeAliasNames) {
if (nameFilter(typeAliasName)) {
result.addIfNotNull(impl.getTypeAliasByName(typeAliasName))
}
}
}
if (kindFilter.acceptsKinds(DescriptorKindFilter.CLASSIFIERS_MASK)) {
for (className in classNames) {
if (nameFilter(className)) {
@@ -141,6 +122,14 @@ abstract class DeserializedMemberScope protected constructor(
}
}
if (kindFilter.acceptsKinds(DescriptorKindFilter.TYPE_ALIASES_MASK)) {
for (typeAliasName in impl.typeAliasNames) {
if (nameFilter(typeAliasName)) {
result.addIfNotNull(impl.getTypeAliasByName(typeAliasName))
}
}
}
return result.compact()
}