Descriptor kind filter replaced with bit mask
This commit is contained in:
+8
-8
@@ -50,7 +50,7 @@ public abstract class LazyJavaMemberScope(
|
||||
private val containingDeclaration: DeclarationDescriptor
|
||||
) : JetScope {
|
||||
private val allDescriptors = c.storageManager.createRecursionTolerantLazyValue<Collection<DeclarationDescriptor>>(
|
||||
{ computeDescriptors({ true }, { true }) },
|
||||
{ computeDescriptors(JetScope.ALL_KINDS_MASK, JetScope.ALL_NAME_FILTER) },
|
||||
// This is to avoid the following recursive case:
|
||||
// when computing getAllPackageNames() we ask the JavaPsiFacade for all subpackages of foo
|
||||
// it, in turn, asks JavaElementFinder for subpackages of Kotlin package foo, which calls getAllPackageNames() recursively
|
||||
@@ -287,14 +287,14 @@ public abstract class LazyJavaMemberScope(
|
||||
|
||||
override fun getOwnDeclaredDescriptors() = getDescriptors()
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean) = allDescriptors()
|
||||
|
||||
protected fun computeDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
protected fun computeDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): List<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet<DeclarationDescriptor>()
|
||||
|
||||
if (kindFilter(JetScope.DescriptorKind.TYPE)) {
|
||||
if (kindFilterMask and JetScope.TYPE != 0) {
|
||||
for (name in getClassNames(nameFilter)) {
|
||||
if (nameFilter(name)) {
|
||||
// Null signifies that a class found in Java is not present in Kotlin (e.g. package class)
|
||||
@@ -303,7 +303,7 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
if (kindFilter(JetScope.DescriptorKind.ORDINARY_FUNCTION) || kindFilter(JetScope.DescriptorKind.SAM_CONSTRUCTOR)) {
|
||||
if (kindFilterMask and (JetScope.ORDINARY_FUNCTION or JetScope.SAM_CONSTRUCTOR) != 0) {
|
||||
for (name in getFunctionNames(nameFilter)) {
|
||||
if (nameFilter(name)) {
|
||||
result.addAll(getFunctions(name))
|
||||
@@ -311,7 +311,7 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
if (kindFilter(JetScope.DescriptorKind.NON_EXTENSION_PROPERTY)) {
|
||||
if (kindFilterMask and JetScope.NON_EXTENSION_PROPERTY != 0) {
|
||||
for (name in getAllPropertyNames()) {
|
||||
if (nameFilter(name)) {
|
||||
result.addAll(getProperties(name))
|
||||
@@ -319,13 +319,13 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
addExtraDescriptors(result, kindFilter, nameFilter)
|
||||
addExtraDescriptors(result, kindFilterMask, nameFilter)
|
||||
|
||||
return result.toReadOnlyList()
|
||||
}
|
||||
|
||||
protected open fun addExtraDescriptors(result: MutableSet<DeclarationDescriptor>,
|
||||
kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
+4
-4
@@ -68,9 +68,9 @@ public class LazyPackageFragmentScopeForJavaPackage(
|
||||
override fun getFunctions(name: Name) = deserializedPackageScope().getFunctions(name) + super.getFunctions(name)
|
||||
|
||||
override fun addExtraDescriptors(result: MutableSet<DeclarationDescriptor>,
|
||||
kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean) {
|
||||
result.addAll(deserializedPackageScope().getDescriptors(kindFilter, nameFilter))
|
||||
result.addAll(deserializedPackageScope().getDescriptors(kindFilterMask, nameFilter))
|
||||
}
|
||||
|
||||
override fun computeMemberIndex(): MemberIndex = object : MemberIndex by EMPTY_MEMBER_INDEX {
|
||||
@@ -101,7 +101,7 @@ public class LazyPackageFragmentScopeForJavaPackage(
|
||||
override fun getAllPropertyNames() = listOf<Name>()
|
||||
|
||||
// we don't use implementation from super which caches all descriptors and does not use filters
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return computeDescriptors(kindFilter, nameFilter)
|
||||
override fun getDescriptors(kindFilterMask: Int, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return computeDescriptors(kindFilterMask, nameFilter)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -257,7 +257,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDescriptors(
|
||||
@NotNull Function1<? super DescriptorKind, ? extends Boolean> kindFilter,
|
||||
int kindFilterMask,
|
||||
@NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
) {
|
||||
return allDescriptors.invoke();
|
||||
|
||||
@@ -34,9 +34,9 @@ public class SubpackagesScope(private val containingDeclaration: PackageViewDesc
|
||||
return if (name.isSpecial()) null else containingDeclaration.getModule().getPackage(containingDeclaration.getFqName().child(name))
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
if (!kindFilter(JetScope.DescriptorKind.PACKAGE)) return listOf()
|
||||
if (kindFilterMask and JetScope.PACKAGE == 0) return listOf()
|
||||
|
||||
val subFqNames = containingDeclaration.getModule().getPackageFragmentProvider().getSubPackagesOf(containingDeclaration.getFqName(), nameFilter)
|
||||
val result = ArrayList<DeclarationDescriptor>(subFqNames.size())
|
||||
|
||||
@@ -58,9 +58,9 @@ public abstract class AbstractScopeAdapter : JetScope {
|
||||
return workerScope.getDeclarationsByLabel(labelName)
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return workerScope.getDescriptors(kindFilter, nameFilter)
|
||||
return workerScope.getDescriptors(kindFilterMask, nameFilter)
|
||||
}
|
||||
|
||||
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor> {
|
||||
|
||||
@@ -59,10 +59,10 @@ public class ChainedScope(private val containingDeclaration: DeclarationDescript
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name) = scopeChain.flatMap { it.getDeclarationsByLabel(labelName) }
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val result = HashSet<DeclarationDescriptor>()
|
||||
scopeChain.flatMapTo(result) { it.getDescriptors(kindFilter, nameFilter) }
|
||||
scopeChain.flatMapTo(result) { it.getDescriptors(kindFilterMask, nameFilter) }
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -37,8 +37,8 @@ public class FilteringScope(private val workerScope: JetScope, private val predi
|
||||
|
||||
override fun getLocalVariable(name: Name) = filterDescriptor(workerScope.getLocalVariable(name))
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
nameFilter: (Name) -> Boolean) = workerScope.getDescriptors(kindFilter, nameFilter).filter(predicate)
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean) = workerScope.getDescriptors(kindFilterMask, nameFilter).filter(predicate)
|
||||
|
||||
override fun getImplicitReceiversHierarchy() = workerScope.getImplicitReceiversHierarchy()
|
||||
|
||||
|
||||
+3
-5
@@ -21,16 +21,14 @@ import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
|
||||
public class InnerClassesScopeWrapper(override val workerScope: JetScope) : AbstractScopeAdapter() {
|
||||
private val descriptorKinds = setOf(JetScope.DescriptorKind.TYPE, JetScope.DescriptorKind.OBJECT, JetScope.DescriptorKind.ENUM_ENTRY)
|
||||
|
||||
override fun getClassifier(name: Name) = workerScope.getClassifier(name) as? ClassDescriptor
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name) = workerScope.getDeclarationsByLabel(labelName).filterIsInstance(javaClass<ClassDescriptor>())
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): List<ClassDescriptor> {
|
||||
if (!descriptorKinds.any { kindFilter(it) }) return listOf()
|
||||
return workerScope.getDescriptors(JetScope.DescriptorKind.CLASSIFIERS, nameFilter).filterIsInstance(javaClass<ClassDescriptor>())
|
||||
if (kindFilterMask and JetScope.CLASSIFIERS_MASK == 0) return listOf()
|
||||
return workerScope.getDescriptors(JetScope.CLASSIFIERS_MASK, nameFilter).filterIsInstance(javaClass<ClassDescriptor>())
|
||||
}
|
||||
|
||||
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> = listOf()
|
||||
|
||||
@@ -50,7 +50,7 @@ public trait JetScope {
|
||||
* All visible descriptors from current scope possibly filtered by the given name and kind filters
|
||||
* (that means that the implementation is not obliged to use the filters but may do so when it gives any performance advantage).
|
||||
*/
|
||||
public fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean = DescriptorKind.ALL,
|
||||
public fun getDescriptors(kindFilterMask: Int = ALL_KINDS_MASK,
|
||||
nameFilter: (Name) -> Boolean = { true }): Collection<DeclarationDescriptor>
|
||||
|
||||
/**
|
||||
@@ -77,40 +77,28 @@ public trait JetScope {
|
||||
}
|
||||
}
|
||||
|
||||
public enum class DescriptorKind {
|
||||
TYPE // class, trait ot type parameter
|
||||
ENUM_ENTRY
|
||||
OBJECT
|
||||
PACKAGE
|
||||
ORDINARY_FUNCTION // not extension and not SAM-constructor
|
||||
EXTENSION_FUNCTION
|
||||
SAM_CONSTRUCTOR
|
||||
NON_EXTENSION_PROPERTY
|
||||
EXTENSION_PROPERTY
|
||||
LOCAL_VARIABLE
|
||||
|
||||
class object {
|
||||
public val ALL: (DescriptorKind) -> Boolean = { true }
|
||||
public val EXTENSIONS: (DescriptorKind) -> Boolean = { it == EXTENSION_FUNCTION || it == EXTENSION_PROPERTY }
|
||||
public val FUNCTIONS: (DescriptorKind) -> Boolean = { it == ORDINARY_FUNCTION || it == EXTENSION_FUNCTION || it == SAM_CONSTRUCTOR }
|
||||
public val CALLABLES: (DescriptorKind) -> Boolean = { it == ORDINARY_FUNCTION
|
||||
|| it == EXTENSION_FUNCTION
|
||||
|| it == SAM_CONSTRUCTOR
|
||||
|| it == NON_EXTENSION_PROPERTY
|
||||
|| it == EXTENSION_PROPERTY
|
||||
|| it == LOCAL_VARIABLE }
|
||||
public val NON_EXTENSION_CALLABLES: (DescriptorKind) -> Boolean = { it == ORDINARY_FUNCTION
|
||||
|| it == SAM_CONSTRUCTOR
|
||||
|| it == NON_EXTENSION_PROPERTY
|
||||
|| it == LOCAL_VARIABLE }
|
||||
public val NON_EXTENSIONS: (DescriptorKind) -> Boolean = { it != EXTENSION_FUNCTION && it != EXTENSION_PROPERTY }
|
||||
public val CLASSIFIERS: (DescriptorKind) -> Boolean = { it == TYPE || it == ENUM_ENTRY || it == OBJECT }
|
||||
public val PACKAGES: (DescriptorKind) -> Boolean = { it == PACKAGE }
|
||||
public val VARIABLES_AND_PROPERTIES: (DescriptorKind) -> Boolean = { it == LOCAL_VARIABLE || it == NON_EXTENSION_PROPERTY || it == EXTENSION_PROPERTY }
|
||||
}
|
||||
}
|
||||
|
||||
class object {
|
||||
public val TYPE: Int = 0x001 // class, trait ot type parameter
|
||||
public val ENUM_ENTRY: Int = 0x002
|
||||
public val OBJECT: Int = 0x004
|
||||
public val PACKAGE: Int = 0x008
|
||||
public val ORDINARY_FUNCTION: Int = 0x010 // not extension and not SAM-constructor
|
||||
public val EXTENSION_FUNCTION: Int = 0x020
|
||||
public val SAM_CONSTRUCTOR: Int = 0x040
|
||||
public val NON_EXTENSION_PROPERTY: Int = 0x080
|
||||
public val EXTENSION_PROPERTY: Int = 0x100
|
||||
public val LOCAL_VARIABLE: Int = 0x200
|
||||
|
||||
public val ALL_KINDS_MASK: Int = 0xFFFF
|
||||
|
||||
public val EXTENSIONS_MASK: Int = EXTENSION_FUNCTION or EXTENSION_PROPERTY
|
||||
public val FUNCTIONS_MASK: Int = ORDINARY_FUNCTION or EXTENSION_FUNCTION or SAM_CONSTRUCTOR
|
||||
public val PROPERTIES_MASK: Int = NON_EXTENSION_PROPERTY or EXTENSION_PROPERTY
|
||||
public val CALLABLES_MASK: Int = ORDINARY_FUNCTION or EXTENSION_FUNCTION or SAM_CONSTRUCTOR or NON_EXTENSION_PROPERTY or EXTENSION_PROPERTY or LOCAL_VARIABLE
|
||||
public val NON_EXTENSIONS_MASK: Int = ALL_KINDS_MASK and (EXTENSION_FUNCTION or EXTENSION_PROPERTY).inv()
|
||||
public val CLASSIFIERS_MASK: Int = TYPE or ENUM_ENTRY or OBJECT
|
||||
public val VARIABLES_AND_PROPERTIES_MASK: Int = LOCAL_VARIABLE or NON_EXTENSION_PROPERTY or EXTENSION_PROPERTY
|
||||
|
||||
public val ALL_NAME_FILTER: (Name) -> Boolean = { true }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public abstract class JetScopeImpl : JetScope {
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> = listOf()
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class StaticScopeForKotlinClass(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean) = functions
|
||||
|
||||
override fun getOwnDeclaredDescriptors() = functions
|
||||
|
||||
@@ -84,7 +84,7 @@ public class SubstitutingScope(private val workerScope: JetScope, private val su
|
||||
throw UnsupportedOperationException() // TODO
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean) = _allDescriptors
|
||||
|
||||
override fun getOwnDeclaredDescriptors() = substitute(workerScope.getOwnDeclaredDescriptors())
|
||||
|
||||
@@ -126,8 +126,7 @@ public class ErrorUtils {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDescriptors(
|
||||
@NotNull Function1<? super DescriptorKind, ? extends Boolean> kindFilter,
|
||||
@NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
int kindFilterMask, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -207,8 +206,7 @@ public class ErrorUtils {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDescriptors(
|
||||
@NotNull Function1<? super DescriptorKind, ? extends Boolean> kindFilter,
|
||||
@NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
int kindFilterMask, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
+2
-2
@@ -181,9 +181,9 @@ public class DeserializedClassDescriptor(outerContext: DeserializationContext, p
|
||||
|
||||
private inner class DeserializedClassMemberScope : DeserializedMemberScope(context, this@DeserializedClassDescriptor.classProto.getMemberList()) {
|
||||
private val classDescriptor: DeserializedClassDescriptor = this@DeserializedClassDescriptor
|
||||
private val allDescriptors = context.storageManager.createLazyValue { computeDescriptors({ true }, { true }) }
|
||||
private val allDescriptors = context.storageManager.createLazyValue { computeDescriptors(JetScope.ALL_KINDS_MASK, JetScope.ALL_NAME_FILTER) }
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = allDescriptors()
|
||||
|
||||
override fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<FunctionDescriptor>) {
|
||||
|
||||
+4
-4
@@ -101,16 +101,16 @@ public abstract class DeserializedMemberScope protected(
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
protected fun computeDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
protected fun computeDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet<DeclarationDescriptor>(0)
|
||||
|
||||
for (name in membersProtos().keySet()) {
|
||||
if (nameFilter(name)) {
|
||||
if (kindFilter(JetScope.DescriptorKind.ORDINARY_FUNCTION) || kindFilter(JetScope.DescriptorKind.EXTENSION_FUNCTION)) {
|
||||
if (kindFilterMask and JetScope.FUNCTIONS_MASK != 0) {
|
||||
result.addAll(getFunctions(name))
|
||||
}
|
||||
if (kindFilter(JetScope.DescriptorKind.NON_EXTENSION_PROPERTY) || kindFilter(JetScope.DescriptorKind.EXTENSION_PROPERTY)) {
|
||||
if (kindFilterMask and JetScope.PROPERTIES_MASK != 0) {
|
||||
result.addAll(getProperties(name))
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public abstract class DeserializedMemberScope protected(
|
||||
|
||||
addNonDeclaredDescriptors(result)
|
||||
|
||||
if (kindFilter(JetScope.DescriptorKind.TYPE) || kindFilter(JetScope.DescriptorKind.OBJECT) || kindFilter(JetScope.DescriptorKind.ENUM_ENTRY)) {
|
||||
if (kindFilterMask and JetScope.CLASSIFIERS_MASK != 0) {
|
||||
addClassDescriptors(result, nameFilter)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -44,8 +44,8 @@ public open class DeserializedPackageMemberScope(
|
||||
private val packageFqName = packageDescriptor.fqName
|
||||
private val classNames = context.storageManager.createLazyValue(classNames)
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean, nameFilter: (Name) -> Boolean)
|
||||
= computeDescriptors(kindFilter, nameFilter)
|
||||
override fun getDescriptors(kindFilterMask: Int, nameFilter: (Name) -> Boolean)
|
||||
= computeDescriptors(kindFilterMask, nameFilter)
|
||||
|
||||
override fun getClassDescriptor(name: Name) = context.deserializeClass(ClassId(packageFqName, name))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user