Moved KindFilter and DescriptorKindExclude out of JetScope, moved constants as well and renamed them
This commit is contained in:
+2
-3
@@ -16,11 +16,10 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.descriptor
|
||||
|
||||
import org.jetbrains.jet.lang.descriptors.ClassOrPackageFragmentDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindExclude
|
||||
|
||||
public class SamConstructorDescriptor(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
@@ -34,6 +33,6 @@ public class SamConstructorDescriptor(
|
||||
samInterface.getSource()
|
||||
)
|
||||
|
||||
public object SamConstructorDescriptorKindExclude : JetScope.DescriptorKindExclude {
|
||||
public object SamConstructorDescriptorKindExclude : DescriptorKindExclude {
|
||||
override fun matches(descriptor: DeclarationDescriptor) = descriptor is SamConstructorDescriptor
|
||||
}
|
||||
|
||||
+3
-3
@@ -35,7 +35,7 @@ import org.jetbrains.jet.lang.resolve.java.JavaVisibilities
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.JavaConstructorDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.java.resolver.DescriptorResolverUtils
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
|
||||
|
||||
public class LazyJavaClassMemberScope(
|
||||
c: LazyJavaResolverContextWithTypes,
|
||||
@@ -47,7 +47,7 @@ public class LazyJavaClassMemberScope(
|
||||
return object : ClassMemberIndex(jClass, { !it.isStatic() }) {
|
||||
// For SAM-constructors
|
||||
override fun getMethodNames(nameFilter: (Name) -> Boolean): Collection<Name>
|
||||
= super.getMethodNames(nameFilter) + getClassNames(JetScope.KindFilter.CLASSIFIERS, nameFilter)
|
||||
= super.getMethodNames(nameFilter) + getClassNames(DescriptorKindFilter.CLASSIFIERS, nameFilter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ public class LazyJavaClassMemberScope(
|
||||
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? = nestedClasses(name)
|
||||
|
||||
override fun getClassNames(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): Collection<Name>
|
||||
override fun getClassNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name>
|
||||
= nestedClassIndex().keySet() + enumEntryIndex().keySet()
|
||||
|
||||
// TODO
|
||||
|
||||
+11
-10
@@ -44,7 +44,8 @@ import org.jetbrains.jet.lang.resolve.java.resolver.ExternalSignatureResolver
|
||||
import org.jetbrains.jet.utils.*
|
||||
import org.jetbrains.jet.lang.resolve.java.PLATFORM_TYPES
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope.DescriptorKindExclude.NonExtensions
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindExclude.NonExtensions
|
||||
|
||||
public abstract class LazyJavaMemberScope(
|
||||
protected val c: LazyJavaResolverContextWithTypes,
|
||||
@@ -53,7 +54,7 @@ public abstract class LazyJavaMemberScope(
|
||||
// this lazy value is not used at all in LazyPackageFragmentScopeForJavaPackage because we do not use caching there
|
||||
// but is placed in the base class to not duplicate code
|
||||
private val allDescriptors = c.storageManager.createRecursionTolerantLazyValue<Collection<DeclarationDescriptor>>(
|
||||
{ computeDescriptors(JetScope.KindFilter.ALL, JetScope.ALL_NAME_FILTER) },
|
||||
{ computeDescriptors(DescriptorKindFilter.ALL, 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
|
||||
@@ -212,7 +213,7 @@ public abstract class LazyJavaMemberScope(
|
||||
|
||||
override fun getFunctions(name: Name) = functions(name)
|
||||
|
||||
protected open fun getFunctionNames(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): Collection<Name>
|
||||
protected open fun getFunctionNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name>
|
||||
= memberIndex().getMethodNames(nameFilter)
|
||||
|
||||
protected abstract fun computeNonDeclaredProperties(name: Name, result: MutableCollection<PropertyDescriptor>)
|
||||
@@ -294,14 +295,14 @@ public abstract class LazyJavaMemberScope(
|
||||
|
||||
override fun getOwnDeclaredDescriptors() = getDescriptors()
|
||||
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean) = allDescriptors()
|
||||
|
||||
protected fun computeDescriptors(kindFilter: JetScope.KindFilter,
|
||||
protected fun computeDescriptors(kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean): List<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet<DeclarationDescriptor>()
|
||||
|
||||
if (kindFilter.acceptsKind(JetScope.CLASSIFIERS_MASK)) {
|
||||
if (kindFilter.acceptsKind(DescriptorKindFilter.CLASSIFIERS_MASK)) {
|
||||
for (name in getClassNames(kindFilter, nameFilter)) {
|
||||
if (nameFilter(name)) {
|
||||
// Null signifies that a class found in Java is not present in Kotlin (e.g. package class)
|
||||
@@ -310,7 +311,7 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
if (kindFilter.acceptsKind(JetScope.FUNCTION) && !kindFilter.excludes.contains(NonExtensions)) {
|
||||
if (kindFilter.acceptsKind(DescriptorKindFilter.FUNCTIONS_MASK) && !kindFilter.excludes.contains(NonExtensions)) {
|
||||
for (name in getFunctionNames(kindFilter, nameFilter)) {
|
||||
if (nameFilter(name)) {
|
||||
result.addAll(getFunctions(name))
|
||||
@@ -318,7 +319,7 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
if (kindFilter.acceptsKind(JetScope.VARIABLE) && !kindFilter.excludes.contains(NonExtensions)) {
|
||||
if (kindFilter.acceptsKind(DescriptorKindFilter.VARIABLES_MASK) && !kindFilter.excludes.contains(NonExtensions)) {
|
||||
for (name in getAllPropertyNames()) {
|
||||
if (nameFilter(name)) {
|
||||
result.addAll(getProperties(name))
|
||||
@@ -332,12 +333,12 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
|
||||
protected open fun addExtraDescriptors(result: MutableSet<DeclarationDescriptor>,
|
||||
kindFilter: JetScope.KindFilter,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
protected abstract fun getClassNames(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): Collection<Name>
|
||||
protected abstract fun getClassNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name>
|
||||
|
||||
override fun toString() = "Lazy scope for ${getContainingDeclaration()}"
|
||||
|
||||
|
||||
+3
-3
@@ -23,7 +23,7 @@ import org.jetbrains.jet.lang.resolve.java.lazy.LazyJavaResolverContext
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaClass
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorFactory.*
|
||||
import org.jetbrains.jet.utils.addIfNotNull
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
|
||||
|
||||
public class LazyJavaStaticClassScope(
|
||||
c: LazyJavaResolverContext,
|
||||
@@ -43,14 +43,14 @@ public class LazyJavaStaticClassScope(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFunctionNames(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): Collection<Name> {
|
||||
override fun getFunctionNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name> {
|
||||
if (jClass.isEnum()) {
|
||||
return super.getFunctionNames(kindFilter, nameFilter) + listOf(DescriptorUtils.ENUM_VALUE_OF, DescriptorUtils.ENUM_VALUES)
|
||||
}
|
||||
return super.getFunctionNames(kindFilter, nameFilter)
|
||||
}
|
||||
|
||||
override fun getClassNames(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): Collection<Name> = listOf()
|
||||
override fun getClassNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name> = listOf()
|
||||
override fun getClassifier(name: Name): ClassifierDescriptor? = null
|
||||
|
||||
override fun getSubPackages(): Collection<FqName> = listOf()
|
||||
|
||||
+7
-6
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.KotlinJvmBinaryClass
|
||||
import org.jetbrains.jet.utils.addIfNotNull
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptorKindExclude
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
|
||||
|
||||
public class LazyPackageFragmentScopeForJavaPackage(
|
||||
c: LazyJavaResolverContext,
|
||||
@@ -69,26 +70,26 @@ public class LazyPackageFragmentScopeForJavaPackage(
|
||||
override fun getFunctions(name: Name) = deserializedPackageScope().getFunctions(name) + super.getFunctions(name)
|
||||
|
||||
override fun addExtraDescriptors(result: MutableSet<DeclarationDescriptor>,
|
||||
kindFilter: JetScope.KindFilter,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean) {
|
||||
result.addAll(deserializedPackageScope().getDescriptors(kindFilter, nameFilter))
|
||||
}
|
||||
|
||||
override fun computeMemberIndex(): MemberIndex = object : MemberIndex by EMPTY_MEMBER_INDEX {
|
||||
// For SAM-constructors
|
||||
override fun getMethodNames(nameFilter: (Name) -> Boolean): Collection<Name> = getClassNames(JetScope.KindFilter.CLASSIFIERS, nameFilter)
|
||||
override fun getMethodNames(nameFilter: (Name) -> Boolean): Collection<Name> = getClassNames(DescriptorKindFilter.CLASSIFIERS, nameFilter)
|
||||
}
|
||||
|
||||
override fun getClassNames(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): Collection<Name> {
|
||||
override fun getClassNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name> {
|
||||
// neither objects nor enum members can be in java package
|
||||
if (!kindFilter.acceptsKind(JetScope.NON_SINGLETON_CLASSIFIER)) return listOf()
|
||||
if (!kindFilter.acceptsKind(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS_MASK)) return listOf()
|
||||
|
||||
return jPackage.getClasses(nameFilter).stream()
|
||||
.filter { c -> c.getOriginKind() != JavaClass.OriginKind.KOTLIN_LIGHT_CLASS }
|
||||
.map { c -> c.getName() }.toList()
|
||||
}
|
||||
|
||||
override fun getFunctionNames(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): Collection<Name> {
|
||||
override fun getFunctionNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name> {
|
||||
// optimization: only SAM-constructors may exist in java package
|
||||
if (kindFilter.excludes.contains(SamConstructorDescriptorKindExclude)) return listOf()
|
||||
|
||||
@@ -112,7 +113,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.KindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return computeDescriptors(kindFilter, nameFilter)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.resolve.DescriptorFactory;
|
||||
import org.jetbrains.jet.lang.resolve.OverridingUtil;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScopeImpl;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.StaticScopeForKotlinClass;
|
||||
@@ -257,7 +258,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDescriptors(
|
||||
@NotNull JetScope.KindFilter kindFilter,
|
||||
@NotNull DescriptorKindFilter kindFilter,
|
||||
@NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
) {
|
||||
return allDescriptors.invoke();
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.jet.utils.*
|
||||
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
|
||||
|
||||
public class SubpackagesScope(private val containingDeclaration: PackageViewDescriptor) : JetScopeImpl() {
|
||||
override fun getContainingDeclaration(): DeclarationDescriptor {
|
||||
@@ -34,9 +35,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.KindFilter,
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
if (!kindFilter.acceptsKind(JetScope.PACKAGE)) return listOf()
|
||||
if (!kindFilter.acceptsKind(DescriptorKindFilter.PACKAGES_MASK)) return listOf()
|
||||
|
||||
val subFqNames = containingDeclaration.getModule().getPackageFragmentProvider().getSubPackagesOf(containingDeclaration.getFqName(), nameFilter)
|
||||
val result = ArrayList<DeclarationDescriptor>(subFqNames.size())
|
||||
|
||||
@@ -58,7 +58,7 @@ public abstract class AbstractScopeAdapter : JetScope {
|
||||
return workerScope.getDeclarationsByLabel(labelName)
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return workerScope.getDescriptors(kindFilter, nameFilter)
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ public class ChainedScope(private val containingDeclaration: DeclarationDescript
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name) = scopeChain.flatMap { it.getDeclarationsByLabel(labelName) }
|
||||
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet<DeclarationDescriptor>()
|
||||
scopeChain.flatMapTo(result) { it.getDescriptors(kindFilter, nameFilter) }
|
||||
|
||||
@@ -37,7 +37,7 @@ public class FilteringScope(private val workerScope: JetScope, private val predi
|
||||
|
||||
override fun getLocalVariable(name: Name) = filterDescriptor(workerScope.getLocalVariable(name))
|
||||
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean) = workerScope.getDescriptors(kindFilter, nameFilter).filter(predicate)
|
||||
|
||||
override fun getImplicitReceiversHierarchy() = workerScope.getImplicitReceiversHierarchy()
|
||||
|
||||
+2
-2
@@ -25,9 +25,9 @@ public class InnerClassesScopeWrapper(override val workerScope: JetScope) : Abst
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name) = workerScope.getDeclarationsByLabel(labelName).filterIsInstance(javaClass<ClassDescriptor>())
|
||||
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean): List<ClassDescriptor> {
|
||||
val restrictedFilter = kindFilter.restrictedToKinds(JetScope.CLASSIFIERS_MASK) ?: return listOf()
|
||||
val restrictedFilter = kindFilter.restrictedToKinds(DescriptorKindFilter.CLASSIFIERS_MASK) ?: return listOf()
|
||||
return workerScope.getDescriptors(restrictedFilter, nameFilter).filterIsInstance(javaClass<ClassDescriptor>())
|
||||
}
|
||||
|
||||
|
||||
@@ -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.KindFilter = KindFilter(ALL_KINDS_MASK),
|
||||
public fun getDescriptors(kindFilter: DescriptorKindFilter = DescriptorKindFilter.ALL,
|
||||
nameFilter: (Name) -> Boolean = ALL_NAME_FILTER): Collection<DeclarationDescriptor>
|
||||
|
||||
/**
|
||||
@@ -77,77 +77,7 @@ public trait JetScope {
|
||||
}
|
||||
}
|
||||
|
||||
public trait DescriptorKindExclude {
|
||||
public fun matches(descriptor: DeclarationDescriptor): Boolean
|
||||
|
||||
public object Extensions : DescriptorKindExclude {
|
||||
override fun matches(descriptor: DeclarationDescriptor)
|
||||
= descriptor is CallableDescriptor && descriptor.getExtensionReceiverParameter() != null
|
||||
}
|
||||
|
||||
public object NonExtensions : DescriptorKindExclude {
|
||||
override fun matches(descriptor: DeclarationDescriptor)
|
||||
= descriptor !is CallableDescriptor || descriptor.getExtensionReceiverParameter() == null
|
||||
}
|
||||
}
|
||||
|
||||
public class KindFilter(
|
||||
public val kindMask: Int,
|
||||
public val excludes: List<DescriptorKindExclude> = listOf()
|
||||
) {
|
||||
public fun accepts(descriptor: DeclarationDescriptor): Boolean
|
||||
= kindMask and descriptor.kind() != 0 && excludes.all { !it.matches(descriptor) }
|
||||
|
||||
public fun acceptsKind(kinds: Int): Boolean
|
||||
= kindMask and kinds != 0
|
||||
|
||||
public fun exclude(exclude: DescriptorKindExclude): KindFilter
|
||||
= KindFilter(kindMask, excludes + listOf(exclude))
|
||||
|
||||
public fun withoutKind(kinds: Int): KindFilter
|
||||
= KindFilter(kindMask and kinds.inv(), excludes)
|
||||
|
||||
public fun restrictedToKinds(kinds: Int): KindFilter? {
|
||||
val mask = kindMask and kinds
|
||||
if (mask == 0) return null
|
||||
return KindFilter(mask, excludes)
|
||||
}
|
||||
|
||||
class object {
|
||||
public val ALL: KindFilter = KindFilter(ALL_KINDS_MASK)
|
||||
public val CALLABLES: KindFilter = KindFilter(FUNCTION or VARIABLE)
|
||||
public val NON_SINGLETON_CLASSIFIERS: KindFilter = KindFilter(NON_SINGLETON_CLASSIFIER)
|
||||
public val SINGLETON_CLASSIFIERS: KindFilter = KindFilter(SINGLETON_CLASSIFIER)
|
||||
public val CLASSIFIERS: KindFilter = KindFilter(CLASSIFIERS_MASK)
|
||||
public val PACKAGES: KindFilter = KindFilter(PACKAGE)
|
||||
public val FUNCTIONS: KindFilter = KindFilter(FUNCTION)
|
||||
public val VARIABLES: KindFilter = KindFilter(VARIABLE)
|
||||
public val VALUES: KindFilter = KindFilter(VALUES_MASK)
|
||||
}
|
||||
}
|
||||
|
||||
class object {
|
||||
public val NON_SINGLETON_CLASSIFIER: Int = 0x01
|
||||
public val SINGLETON_CLASSIFIER: Int = 0x02
|
||||
public val PACKAGE: Int = 0x04
|
||||
public val FUNCTION: Int = 0x08
|
||||
public val VARIABLE: Int = 0x10
|
||||
|
||||
public val ALL_KINDS_MASK: Int = 0x1F
|
||||
public val CLASSIFIERS_MASK: Int = NON_SINGLETON_CLASSIFIER or SINGLETON_CLASSIFIER
|
||||
public val VALUES_MASK: Int = SINGLETON_CLASSIFIER or FUNCTION or VARIABLE
|
||||
|
||||
public fun DeclarationDescriptor.kind(): Int {
|
||||
return when (this) {
|
||||
is ClassDescriptor -> if (this.getKind().isSingleton()) SINGLETON_CLASSIFIER else NON_SINGLETON_CLASSIFIER
|
||||
is ClassifierDescriptor -> NON_SINGLETON_CLASSIFIER
|
||||
is PackageFragmentDescriptor, is PackageViewDescriptor -> PACKAGE
|
||||
is FunctionDescriptor -> FUNCTION
|
||||
is VariableDescriptor -> VARIABLE
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
public val ALL_NAME_FILTER: (Name) -> Boolean = { true }
|
||||
}
|
||||
}
|
||||
@@ -156,11 +86,78 @@ public trait JetScope {
|
||||
* The same as getDescriptors(kindFilter, nameFilter) but the result is guaranteed to be filtered by kind and name.
|
||||
*/
|
||||
public fun JetScope.getDescriptorsFiltered(
|
||||
kindFilter: JetScope.KindFilter,
|
||||
kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
return getDescriptors(kindFilter, nameFilter).filter { kindFilter.accepts(it) && nameFilter(it.getName()) }
|
||||
}
|
||||
|
||||
public class DescriptorKindFilter(
|
||||
public val kindMask: Int,
|
||||
public val excludes: List<DescriptorKindExclude> = listOf()
|
||||
) {
|
||||
public fun accepts(descriptor: DeclarationDescriptor): Boolean
|
||||
= kindMask and descriptor.kind() != 0 && excludes.all { !it.matches(descriptor) }
|
||||
|
||||
public fun acceptsKind(kinds: Int): Boolean
|
||||
= kindMask and kinds != 0
|
||||
|
||||
public fun exclude(exclude: DescriptorKindExclude): DescriptorKindFilter
|
||||
= DescriptorKindFilter(kindMask, excludes + listOf(exclude))
|
||||
|
||||
public fun withoutKind(kinds: Int): DescriptorKindFilter
|
||||
= DescriptorKindFilter(kindMask and kinds.inv(), excludes)
|
||||
|
||||
public fun restrictedToKinds(kinds: Int): DescriptorKindFilter? {
|
||||
val mask = kindMask and kinds
|
||||
if (mask == 0) return null
|
||||
return DescriptorKindFilter(mask, excludes)
|
||||
}
|
||||
|
||||
private fun DeclarationDescriptor.kind(): Int {
|
||||
return when (this) {
|
||||
is ClassDescriptor -> if (this.getKind().isSingleton()) SINGLETON_CLASSIFIERS_MASK else NON_SINGLETON_CLASSIFIERS_MASK
|
||||
is ClassifierDescriptor -> NON_SINGLETON_CLASSIFIERS_MASK
|
||||
is PackageFragmentDescriptor, is PackageViewDescriptor -> PACKAGES_MASK
|
||||
is FunctionDescriptor -> FUNCTIONS_MASK
|
||||
is VariableDescriptor -> VARIABLES_MASK
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
class object {
|
||||
public val NON_SINGLETON_CLASSIFIERS_MASK: Int = 0x01
|
||||
public val SINGLETON_CLASSIFIERS_MASK: Int = 0x02
|
||||
public val PACKAGES_MASK: Int = 0x04
|
||||
public val FUNCTIONS_MASK: Int = 0x08
|
||||
public val VARIABLES_MASK: Int = 0x10
|
||||
|
||||
public val ALL_KINDS_MASK: Int = 0x1F
|
||||
public val CLASSIFIERS_MASK: Int = NON_SINGLETON_CLASSIFIERS_MASK or SINGLETON_CLASSIFIERS_MASK
|
||||
public val VALUES_MASK: Int = SINGLETON_CLASSIFIERS_MASK or FUNCTIONS_MASK or VARIABLES_MASK
|
||||
|
||||
public val ALL: DescriptorKindFilter = DescriptorKindFilter(ALL_KINDS_MASK)
|
||||
public val CALLABLES: DescriptorKindFilter = DescriptorKindFilter(FUNCTIONS_MASK or VARIABLES_MASK)
|
||||
public val NON_SINGLETON_CLASSIFIERS: DescriptorKindFilter = DescriptorKindFilter(NON_SINGLETON_CLASSIFIERS_MASK)
|
||||
public val SINGLETON_CLASSIFIERS: DescriptorKindFilter = DescriptorKindFilter(SINGLETON_CLASSIFIERS_MASK)
|
||||
public val CLASSIFIERS: DescriptorKindFilter = DescriptorKindFilter(CLASSIFIERS_MASK)
|
||||
public val PACKAGES: DescriptorKindFilter = DescriptorKindFilter(PACKAGES_MASK)
|
||||
public val FUNCTIONS: DescriptorKindFilter = DescriptorKindFilter(FUNCTIONS_MASK)
|
||||
public val VARIABLES: DescriptorKindFilter = DescriptorKindFilter(VARIABLES_MASK)
|
||||
public val VALUES: DescriptorKindFilter = DescriptorKindFilter(VALUES_MASK)
|
||||
}
|
||||
}
|
||||
|
||||
public trait DescriptorKindExclude {
|
||||
public fun matches(descriptor: DeclarationDescriptor): Boolean
|
||||
|
||||
public object Extensions : DescriptorKindExclude {
|
||||
override fun matches(descriptor: DeclarationDescriptor)
|
||||
= descriptor is CallableDescriptor && descriptor.getExtensionReceiverParameter() != null
|
||||
}
|
||||
|
||||
public object NonExtensions : DescriptorKindExclude {
|
||||
override fun matches(descriptor: DeclarationDescriptor)
|
||||
= descriptor !is CallableDescriptor || descriptor.getExtensionReceiverParameter() == null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public abstract class JetScopeImpl : JetScope {
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
||||
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.KindFilter,
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
||||
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.KindFilter,
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean) = _allDescriptors
|
||||
|
||||
override fun getOwnDeclaredDescriptors() = substitute(workerScope.getOwnDeclaredDescriptors())
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.error.ErrorSimpleFunctionDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
@@ -126,7 +127,7 @@ public class ErrorUtils {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDescriptors(
|
||||
@NotNull JetScope.KindFilter kindFilter, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
@NotNull DescriptorKindFilter kindFilter, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -206,7 +207,7 @@ public class ErrorUtils {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDescriptors(
|
||||
@NotNull JetScope.KindFilter kindFilter, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
@NotNull DescriptorKindFilter kindFilter, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
+3
-2
@@ -40,6 +40,7 @@ import org.jetbrains.jet.lang.resolve.name.SpecialNames.getClassObjectName
|
||||
import org.jetbrains.jet.descriptors.serialization.classKind
|
||||
import org.jetbrains.jet.utils.addIfNotNull
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
|
||||
|
||||
public fun DeserializedClassDescriptor(globalContext: DeserializationGlobalContext, classData: ClassData): DeserializedClassDescriptor
|
||||
= DeserializedClassDescriptor(globalContext.withNameResolver(classData.getNameResolver()), classData.getClassProto())
|
||||
@@ -181,9 +182,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(JetScope.KindFilter.ALL, JetScope.ALL_NAME_FILTER) }
|
||||
private val allDescriptors = context.storageManager.createLazyValue { computeDescriptors(DescriptorKindFilter.ALL, JetScope.ALL_NAME_FILTER) }
|
||||
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = allDescriptors()
|
||||
|
||||
override fun computeNonDeclaredFunctions(name: Name, functions: MutableCollection<FunctionDescriptor>) {
|
||||
|
||||
+5
-4
@@ -26,6 +26,7 @@ import org.jetbrains.jet.utils.Printer
|
||||
|
||||
import java.util.*
|
||||
import org.jetbrains.jet.utils.toReadOnlyList
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
|
||||
|
||||
public abstract class DeserializedMemberScope protected(
|
||||
private val context: DeserializationContextWithTypes,
|
||||
@@ -101,16 +102,16 @@ public abstract class DeserializedMemberScope protected(
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
protected fun computeDescriptors(kindFilter: JetScope.KindFilter,
|
||||
protected fun computeDescriptors(kindFilter: DescriptorKindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet<DeclarationDescriptor>(0)
|
||||
|
||||
for (name in membersProtos().keySet()) {
|
||||
if (nameFilter(name)) {
|
||||
if (kindFilter.acceptsKind(JetScope.FUNCTION)) {
|
||||
if (kindFilter.acceptsKind(DescriptorKindFilter.FUNCTIONS_MASK)) {
|
||||
result.addAll(getFunctions(name))
|
||||
}
|
||||
if (kindFilter.acceptsKind(JetScope.VARIABLE)) {
|
||||
if (kindFilter.acceptsKind(DescriptorKindFilter.VARIABLES_MASK)) {
|
||||
result.addAll(getProperties(name))
|
||||
}
|
||||
}
|
||||
@@ -118,7 +119,7 @@ public abstract class DeserializedMemberScope protected(
|
||||
|
||||
addNonDeclaredDescriptors(result)
|
||||
|
||||
if (kindFilter.acceptsKind(JetScope.CLASSIFIERS_MASK)) {
|
||||
if (kindFilter.acceptsKind(DescriptorKindFilter.CLASSIFIERS_MASK)) {
|
||||
addClassDescriptors(result, nameFilter)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -24,8 +24,8 @@ import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.name.ClassId
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.utils.addIfNotNull
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
|
||||
|
||||
|
||||
public fun DeserializedPackageMemberScope(packageDescriptor: PackageFragmentDescriptor,
|
||||
@@ -44,7 +44,7 @@ public open class DeserializedPackageMemberScope(
|
||||
private val packageFqName = packageDescriptor.fqName
|
||||
private val classNames = context.storageManager.createLazyValue(classNames)
|
||||
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean)
|
||||
override fun getDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
|
||||
= computeDescriptors(kindFilter, nameFilter)
|
||||
|
||||
override fun getClassDescriptor(name: Name) = context.deserializeClass(ClassId(packageFqName, name))
|
||||
|
||||
Reference in New Issue
Block a user