Refactored filtering by descriptor kind so that no knowledge about SAM-constructors required in core
This commit is contained in:
+39
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
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
|
||||
|
||||
public class SamConstructorDescriptor(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
samInterface: JavaClassDescriptor
|
||||
) : SimpleFunctionDescriptorImpl(
|
||||
containingDeclaration,
|
||||
null,
|
||||
samInterface.getAnnotations(),
|
||||
samInterface.getName(),
|
||||
CallableMemberDescriptor.Kind.SYNTHESIZED,
|
||||
samInterface.getSource()
|
||||
)
|
||||
|
||||
public object SamConstructorDescriptorKindExclude : JetScope.DescriptorKindExclude {
|
||||
override fun matches(descriptor: DeclarationDescriptor) = descriptor is SamConstructorDescriptor
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.java.descriptor;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SamConstructorDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.SimpleFunctionDescriptorImpl;
|
||||
|
||||
public class SamConstructorDescriptorImpl extends SimpleFunctionDescriptorImpl implements SamConstructorDescriptor {
|
||||
public SamConstructorDescriptorImpl(@NotNull DeclarationDescriptor containingDeclaration, @NotNull JavaClassDescriptor samInterface) {
|
||||
super(containingDeclaration, null, samInterface.getAnnotations(), samInterface.getName(),
|
||||
Kind.SYNTHESIZED, samInterface.getSource());
|
||||
}
|
||||
}
|
||||
+10
-8
@@ -52,7 +52,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.ALL_KINDS_MASK, JetScope.ALL_NAME_FILTER) },
|
||||
{ computeDescriptors(JetScope.KindFilter.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
|
||||
@@ -291,14 +291,15 @@ public abstract class LazyJavaMemberScope(
|
||||
|
||||
override fun getOwnDeclaredDescriptors() = getDescriptors()
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean) = allDescriptors()
|
||||
|
||||
protected fun computeDescriptors(kindFilterMask: Int,
|
||||
protected fun computeDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): List<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet<DeclarationDescriptor>()
|
||||
|
||||
if (kindFilterMask and JetScope.TYPE != 0) {
|
||||
//TODO: only non-singleton classifiers in package!
|
||||
if (kindFilter.acceptsKind(JetScope.CLASSIFIERS_MASK)) {
|
||||
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)
|
||||
@@ -307,7 +308,8 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
if (kindFilterMask and (JetScope.ORDINARY_FUNCTION or JetScope.SAM_CONSTRUCTOR) != 0) {
|
||||
//TODO: SAM-constructors only in package!
|
||||
if (kindFilter.acceptsKind(JetScope.FUNCTION) && !kindFilter.excludes.contains(JetScope.DescriptorKindExclude.NonExtensions)) {
|
||||
for (name in getFunctionNames(nameFilter)) {
|
||||
if (nameFilter(name)) {
|
||||
result.addAll(getFunctions(name))
|
||||
@@ -315,7 +317,7 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
if (kindFilterMask and JetScope.NON_EXTENSION_PROPERTY != 0) {
|
||||
if (kindFilter.acceptsKind(JetScope.VARIABLE) && !kindFilter.excludes.contains(JetScope.DescriptorKindExclude.NonExtensions)) {
|
||||
for (name in getAllPropertyNames()) {
|
||||
if (nameFilter(name)) {
|
||||
result.addAll(getProperties(name))
|
||||
@@ -323,13 +325,13 @@ public abstract class LazyJavaMemberScope(
|
||||
}
|
||||
}
|
||||
|
||||
addExtraDescriptors(result, kindFilterMask, nameFilter)
|
||||
addExtraDescriptors(result, kindFilter, nameFilter)
|
||||
|
||||
return result.toReadOnlyList()
|
||||
}
|
||||
|
||||
protected open fun addExtraDescriptors(result: MutableSet<DeclarationDescriptor>,
|
||||
kindFilterMask: Int,
|
||||
kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ import org.jetbrains.jet.lang.resolve.java.lazy.LazyJavaResolverContext
|
||||
import org.jetbrains.jet.lang.resolve.java.lazy.withTypes
|
||||
import org.jetbrains.jet.lang.resolve.java.structure.JavaMethod
|
||||
import org.jetbrains.jet.lang.types.JetType
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptorImpl
|
||||
import org.jetbrains.jet.lang.resolve.java.descriptor.SamConstructorDescriptor
|
||||
|
||||
public abstract class LazyJavaStaticScope(
|
||||
c: LazyJavaResolverContext,
|
||||
|
||||
+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>,
|
||||
kindFilterMask: Int,
|
||||
kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean) {
|
||||
result.addAll(deserializedPackageScope().getDescriptors(kindFilterMask, nameFilter))
|
||||
result.addAll(deserializedPackageScope().getDescriptors(kindFilter, 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(kindFilterMask: Int, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return computeDescriptors(kindFilterMask, nameFilter)
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return computeDescriptors(kindFilter, nameFilter)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.descriptors;
|
||||
|
||||
public interface SamConstructorDescriptor extends SimpleFunctionDescriptor {
|
||||
}
|
||||
+1
-1
@@ -257,7 +257,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDescriptors(
|
||||
int kindFilterMask,
|
||||
@NotNull JetScope.KindFilter kindFilter,
|
||||
@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(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
if (kindFilterMask and JetScope.PACKAGE == 0) return listOf()
|
||||
if (!kindFilter.acceptsKind(JetScope.PACKAGE)) 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(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return workerScope.getDescriptors(kindFilterMask, nameFilter)
|
||||
return workerScope.getDescriptors(kindFilter, 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(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet<DeclarationDescriptor>()
|
||||
scopeChain.flatMapTo(result) { it.getDescriptors(kindFilterMask, nameFilter) }
|
||||
scopeChain.flatMapTo(result) { it.getDescriptors(kindFilter, 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(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean) = workerScope.getDescriptors(kindFilterMask, nameFilter).filter(predicate)
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean) = workerScope.getDescriptors(kindFilter, nameFilter).filter(predicate)
|
||||
|
||||
override fun getImplicitReceiversHierarchy() = workerScope.getImplicitReceiversHierarchy()
|
||||
|
||||
|
||||
+3
-3
@@ -25,10 +25,10 @@ public class InnerClassesScopeWrapper(override val workerScope: JetScope) : Abst
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name) = workerScope.getDeclarationsByLabel(labelName).filterIsInstance(javaClass<ClassDescriptor>())
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): List<ClassDescriptor> {
|
||||
if (kindFilterMask and JetScope.CLASSIFIERS_MASK == 0) return listOf()
|
||||
return workerScope.getDescriptors(JetScope.CLASSIFIERS_MASK, nameFilter).filterIsInstance(javaClass<ClassDescriptor>())
|
||||
val restrictedFilter = kindFilter.restrictedToKinds(JetScope.CLASSIFIERS_MASK) ?: return listOf()
|
||||
return workerScope.getDescriptors(restrictedFilter, 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(kindFilterMask: Int = ALL_KINDS_MASK,
|
||||
public fun getDescriptors(kindFilter: JetScope.KindFilter = KindFilter(ALL_KINDS_MASK),
|
||||
nameFilter: (Name) -> Boolean = ALL_NAME_FILTER): Collection<DeclarationDescriptor>
|
||||
|
||||
/**
|
||||
@@ -77,62 +77,92 @@ 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 data 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)
|
||||
}
|
||||
|
||||
public val isEmpty: Boolean
|
||||
get() = kindMask == 0
|
||||
|
||||
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 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 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 = 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 }
|
||||
|
||||
public fun descriptorKind(descriptor: DeclarationDescriptor): Int {
|
||||
return when (descriptor) {
|
||||
is ClassDescriptor -> when (descriptor.getKind()) {
|
||||
ClassKind.OBJECT, ClassKind.CLASS_OBJECT -> OBJECT
|
||||
ClassKind.ENUM_ENTRY -> ENUM_ENTRY
|
||||
else -> TYPE
|
||||
}
|
||||
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 SamConstructorDescriptor -> SAM_CONSTRUCTOR
|
||||
|
||||
is FunctionDescriptor -> if (descriptor.getExtensionReceiverParameter() != null) EXTENSION_FUNCTION else ORDINARY_FUNCTION
|
||||
|
||||
is PropertyDescriptor -> if (descriptor.getExtensionReceiverParameter() != null) EXTENSION_PROPERTY else NON_EXTENSION_PROPERTY
|
||||
|
||||
is VariableDescriptor -> LOCAL_VARIABLE
|
||||
|
||||
else -> 0 /* unknown */
|
||||
is FunctionDescriptor -> FUNCTION
|
||||
is VariableDescriptor -> VARIABLE
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
public val ALL_NAME_FILTER: (Name) -> Boolean = { true }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The same as getDescriptors(kindFilterMask, nameFilter) but the result is guaranteed to be filtered by kind and name.
|
||||
* The same as getDescriptors(kindFilter, nameFilter) but the result is guaranteed to be filtered by kind and name.
|
||||
*/
|
||||
public fun JetScope.getDescriptorsFiltered(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return getDescriptors(kindFilterMask, nameFilter).filter {
|
||||
(JetScope.descriptorKind(it) and kindFilterMask) != 0 && nameFilter(it.getName())
|
||||
}
|
||||
public fun JetScope.getDescriptorsFiltered(
|
||||
kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean
|
||||
): Collection<DeclarationDescriptor> {
|
||||
return getDescriptors(kindFilter, nameFilter).filter { kindFilter.accepts(it) && nameFilter(it.getName()) }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public abstract class JetScopeImpl : JetScope {
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> = listOf()
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public class StaticScopeForKotlinClass(
|
||||
}
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
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(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean) = _allDescriptors
|
||||
|
||||
override fun getOwnDeclaredDescriptors() = substitute(workerScope.getOwnDeclaredDescriptors())
|
||||
|
||||
@@ -126,7 +126,7 @@ public class ErrorUtils {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDescriptors(
|
||||
int kindFilterMask, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
@NotNull JetScope.KindFilter kindFilter, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -206,7 +206,7 @@ public class ErrorUtils {
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<DeclarationDescriptor> getDescriptors(
|
||||
int kindFilterMask, @NotNull Function1<? super Name, ? extends Boolean> nameFilter
|
||||
@NotNull JetScope.KindFilter kindFilter, @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(JetScope.ALL_KINDS_MASK, JetScope.ALL_NAME_FILTER) }
|
||||
private val allDescriptors = context.storageManager.createLazyValue { computeDescriptors(JetScope.KindFilter.ALL, JetScope.ALL_NAME_FILTER) }
|
||||
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter,
|
||||
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(kindFilterMask: Int,
|
||||
protected fun computeDescriptors(kindFilter: JetScope.KindFilter,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet<DeclarationDescriptor>(0)
|
||||
|
||||
for (name in membersProtos().keySet()) {
|
||||
if (nameFilter(name)) {
|
||||
if (kindFilterMask and JetScope.FUNCTIONS_MASK != 0) {
|
||||
if (kindFilter.acceptsKind(JetScope.FUNCTION)) {
|
||||
result.addAll(getFunctions(name))
|
||||
}
|
||||
if (kindFilterMask and JetScope.PROPERTIES_MASK != 0) {
|
||||
if (kindFilter.acceptsKind(JetScope.VARIABLE)) {
|
||||
result.addAll(getProperties(name))
|
||||
}
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public abstract class DeserializedMemberScope protected(
|
||||
|
||||
addNonDeclaredDescriptors(result)
|
||||
|
||||
if (kindFilterMask and JetScope.CLASSIFIERS_MASK != 0) {
|
||||
if (kindFilter.acceptsKind(JetScope.CLASSIFIERS_MASK)) {
|
||||
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(kindFilterMask: Int, nameFilter: (Name) -> Boolean)
|
||||
= computeDescriptors(kindFilterMask, nameFilter)
|
||||
override fun getDescriptors(kindFilter: JetScope.KindFilter, nameFilter: (Name) -> Boolean)
|
||||
= computeDescriptors(kindFilter, nameFilter)
|
||||
|
||||
override fun getClassDescriptor(name: Name) = context.deserializeClass(ClassId(packageFqName, name))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user