Descriptor kind filter replaced with bit mask
This commit is contained in:
@@ -151,7 +151,7 @@ public class PackageCodegen {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<DeserializedCallableMemberDescriptor> callables = Lists.newArrayList();
|
||||
for (DeclarationDescriptor member : packageFragment.getMemberScope().getDescriptors(JetScope.DescriptorKind.CALLABLES, JetScope.ALL_NAME_FILTER)) {
|
||||
for (DeclarationDescriptor member : packageFragment.getMemberScope().getDescriptors(JetScope.CALLABLES_MASK, JetScope.ALL_NAME_FILTER)) {
|
||||
if (member instanceof DeserializedCallableMemberDescriptor) {
|
||||
callables.add((DeserializedCallableMemberDescriptor) member);
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ public class BuiltInsSerializer(val out: PrintStream?) {
|
||||
})
|
||||
|
||||
val classNames = ArrayList<Name>()
|
||||
val classifierDescriptors = DescriptorSerializer.sort(packageView.getMemberScope().getDescriptors({ it == JetScope.DescriptorKind.TYPE }))
|
||||
val classifierDescriptors = DescriptorSerializer.sort(packageView.getMemberScope().getDescriptors(JetScope.CLASSIFIERS_MASK))
|
||||
|
||||
ClassSerializationUtil.serializeClasses(classifierDescriptors, serializer, object : ClassSerializationUtil.Sink {
|
||||
override fun writeClass(classDescriptor: ClassDescriptor, classProto: ProtoBuf.Class) {
|
||||
|
||||
+1
-1
@@ -216,7 +216,7 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
|
||||
PackageViewDescriptor packageView = getModule().getPackage(fqn);
|
||||
if (packageView == null) return Collections.emptyList();
|
||||
|
||||
Collection<DeclarationDescriptor> members = packageView.getMemberScope().getDescriptors(JetScope.DescriptorKind.PACKAGES, JetScope.ALL_NAME_FILTER);
|
||||
Collection<DeclarationDescriptor> members = packageView.getMemberScope().getDescriptors(JetScope.PACKAGE, JetScope.ALL_NAME_FILTER);
|
||||
return ContainerUtil.mapNotNull(members, new Function<DeclarationDescriptor, FqName>() {
|
||||
@Override
|
||||
public FqName fun(DeclarationDescriptor member) {
|
||||
|
||||
@@ -158,7 +158,7 @@ public class LazyImportScope(private val resolveSession: ResolveSession,
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
override fun getDescriptors(kindFilterMask: Int, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return resolveSession.getStorageManager().compute {
|
||||
val descriptors = HashSet<DeclarationDescriptor>()
|
||||
for (directive in importsProvider.getAllImports()) {
|
||||
@@ -170,7 +170,7 @@ public class LazyImportScope(private val resolveSession: ResolveSession,
|
||||
val importPath = directive.getImportPath() ?: continue
|
||||
val importedName = importPath.getImportedName()
|
||||
if (importedName == null || nameFilter(importedName)) {
|
||||
descriptors.addAll(getImportScope(directive, LookupMode.EVERYTHING).getDescriptors(kindFilter, nameFilter))
|
||||
descriptors.addAll(getImportScope(directive, LookupMode.EVERYTHING).getDescriptors(kindFilterMask, nameFilter))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public abstract class AbstractPsiBasedDeclarationProvider(storageManager: Storag
|
||||
|
||||
protected abstract fun doCreateIndex(index: Index)
|
||||
|
||||
override fun getDeclarations(kindFilter: (JetScope.DescriptorKind) -> Boolean, nameFilter: (Name) -> Boolean): List<JetDeclaration>
|
||||
override fun getDeclarations(kindFilterMask: Int, nameFilter: (Name) -> Boolean): List<JetDeclaration>
|
||||
= index().allDeclarations
|
||||
|
||||
override fun getFunctionDeclarations(name: Name): List<JetNamedFunction>
|
||||
|
||||
+1
-2
@@ -22,10 +22,9 @@ import org.jetbrains.jet.lang.psi.JetProperty
|
||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope.DescriptorKind
|
||||
|
||||
public trait DeclarationProvider {
|
||||
public fun getDeclarations(kindFilter: (JetScope.DescriptorKind) -> Boolean, nameFilter: (Name) -> Boolean): List<JetDeclaration>
|
||||
public fun getDeclarations(kindFilterMask: Int, nameFilter: (Name) -> Boolean): List<JetDeclaration>
|
||||
|
||||
public fun getFunctionDeclarations(name: Name): Collection<JetNamedFunction>
|
||||
|
||||
|
||||
+2
-2
@@ -118,9 +118,9 @@ public abstract class AbstractLazyMemberScope<D : DeclarationDescriptor, DP : De
|
||||
|
||||
override fun getDeclarationsByLabel(labelName: Name) = setOf<DeclarationDescriptor>()
|
||||
|
||||
protected fun computeDescriptorsFromDeclaredElements(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
protected fun computeDescriptorsFromDeclaredElements(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): List<DeclarationDescriptor> {
|
||||
val declarations = declarationProvider.getDeclarations(kindFilter, nameFilter)
|
||||
val declarations = declarationProvider.getDeclarations(kindFilterMask, nameFilter)
|
||||
val result = ArrayList<DeclarationDescriptor>(declarations.size())
|
||||
for (declaration in declarations) {
|
||||
if (declaration is JetClassOrObject) {
|
||||
|
||||
+2
-2
@@ -46,13 +46,13 @@ public open class LazyClassMemberScope(resolveSession: ResolveSession,
|
||||
: AbstractLazyMemberScope<LazyClassDescriptor, ClassMemberDeclarationProvider>(resolveSession, declarationProvider, thisClass, trace) {
|
||||
|
||||
private val descriptorsFromDeclaredElements = storageManager.createLazyValue {
|
||||
computeDescriptorsFromDeclaredElements({true}, {true})
|
||||
computeDescriptorsFromDeclaredElements(JetScope.ALL_KINDS_MASK, JetScope.ALL_NAME_FILTER)
|
||||
}
|
||||
private val extraDescriptors: NotNullLazyValue<Collection<DeclarationDescriptor>> = storageManager.createLazyValue {
|
||||
computeExtraDescriptors()
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val result = LinkedHashSet(descriptorsFromDeclaredElements())
|
||||
result.addAll(extraDescriptors())
|
||||
|
||||
+2
-2
@@ -29,8 +29,8 @@ public class LazyPackageMemberScope(
|
||||
thisPackage: PackageFragmentDescriptor)
|
||||
: AbstractLazyMemberScope<PackageFragmentDescriptor, PackageMemberDeclarationProvider>(resolveSession, declarationProvider, thisPackage, resolveSession.getTrace()) {
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return computeDescriptorsFromDeclaredElements(kindFilter, nameFilter)
|
||||
override fun getDescriptors(kindFilterMask: Int, nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
return computeDescriptorsFromDeclaredElements(kindFilterMask, nameFilter)
|
||||
}
|
||||
|
||||
override fun getPackage(name: Name): PackageViewDescriptor? = null
|
||||
|
||||
@@ -61,7 +61,7 @@ public final class JetScopeUtils {
|
||||
public static Collection<CallableDescriptor> getAllExtensions(@NotNull JetScope scope) {
|
||||
Set<CallableDescriptor> result = Sets.newHashSet();
|
||||
|
||||
for (DeclarationDescriptor descriptor : scope.getDescriptors(JetScope.DescriptorKind.EXTENSIONS, JetScope.ALL_NAME_FILTER)) {
|
||||
for (DeclarationDescriptor descriptor : scope.getDescriptors(JetScope.EXTENSIONS_MASK, JetScope.ALL_NAME_FILTER)) {
|
||||
if (descriptor instanceof CallableDescriptor) {
|
||||
CallableDescriptor callDescriptor = (CallableDescriptor) descriptor;
|
||||
if (callDescriptor.getExtensionReceiverParameter() != null) {
|
||||
|
||||
@@ -94,15 +94,15 @@ public class WritableScopeImpl(scope: JetScope,
|
||||
super.clearImports()
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
checkMayRead()
|
||||
changeLockLevel(WritableScope.LockLevel.READING)
|
||||
|
||||
val result = ArrayList<DeclarationDescriptor>()
|
||||
result.addAll(explicitlyAddedDescriptors)
|
||||
result.addAll(workerScope.getDescriptors(kindFilter, nameFilter))
|
||||
getImports().flatMapTo(result) { it.getDescriptors(kindFilter, nameFilter) }
|
||||
result.addAll(workerScope.getDescriptors(kindFilterMask, nameFilter))
|
||||
getImports().flatMapTo(result) { it.getDescriptors(kindFilterMask, nameFilter) }
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ public class WriteThroughScope(outerScope: JetScope, private val writableWorker:
|
||||
writableWorker.setImplicitReceiver(implicitReceiver)
|
||||
}
|
||||
|
||||
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||
override fun getDescriptors(kindFilterMask: Int,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
checkMayRead()
|
||||
|
||||
|
||||
+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))
|
||||
|
||||
|
||||
+2
-3
@@ -19,15 +19,14 @@ package org.jetbrains.jet.plugin.stubindex.resolve
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclarationProvider
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope.DescriptorKind
|
||||
|
||||
public class CombinedPackageMemberDeclarationProvider(val providers: Collection<PackageMemberDeclarationProvider>) : PackageMemberDeclarationProvider {
|
||||
override fun getAllDeclaredSubPackages() = providers.flatMap { it.getAllDeclaredSubPackages() }
|
||||
|
||||
override fun getPackageFiles() = providers.flatMap { it.getPackageFiles() }
|
||||
|
||||
override fun getDeclarations(kindFilter: (JetScope.DescriptorKind) -> Boolean, nameFilter: (Name) -> Boolean)
|
||||
= providers.flatMap { it.getDeclarations(kindFilter, nameFilter) }
|
||||
override fun getDeclarations(kindFilterMask: Int, nameFilter: (Name) -> Boolean)
|
||||
= providers.flatMap { it.getDeclarations(kindFilterMask, nameFilter) }
|
||||
|
||||
override fun getFunctionDeclarations(name: Name) = providers.flatMap { it.getFunctionDeclarations(name) }
|
||||
|
||||
|
||||
+4
-4
@@ -39,18 +39,18 @@ public class StubBasedPackageMemberDeclarationProvider(
|
||||
private val searchScope: GlobalSearchScope
|
||||
) : PackageMemberDeclarationProvider {
|
||||
|
||||
override fun getDeclarations(kindFilter: (JetScope.DescriptorKind) -> Boolean, nameFilter: (Name) -> Boolean): List<JetDeclaration> {
|
||||
override fun getDeclarations(kindFilterMask: Int, nameFilter: (Name) -> Boolean): List<JetDeclaration> {
|
||||
val result = ArrayList<JetDeclaration>()
|
||||
|
||||
if (kindFilter(JetScope.DescriptorKind.TYPE) || kindFilter(JetScope.DescriptorKind.OBJECT)) {
|
||||
if (kindFilterMask and (JetScope.TYPE or JetScope.OBJECT) != 0) {
|
||||
result.addDeclarations(JetFullClassNameIndex.getInstance(), nameFilter)
|
||||
}
|
||||
|
||||
if (kindFilter(JetScope.DescriptorKind.ORDINARY_FUNCTION) || kindFilter(JetScope.DescriptorKind.EXTENSION_FUNCTION)) {
|
||||
if (kindFilterMask and JetScope.FUNCTIONS_MASK != 0) {
|
||||
result.addDeclarations(JetTopLevelFunctionsFqnNameIndex.getInstance(), nameFilter)
|
||||
}
|
||||
|
||||
if (kindFilter(JetScope.DescriptorKind.NON_EXTENSION_PROPERTY) || kindFilter(JetScope.DescriptorKind.EXTENSION_PROPERTY)) {
|
||||
if (kindFilterMask and JetScope.PROPERTIES_MASK != 0) {
|
||||
result.addDeclarations(JetTopLevelPropertiesFqnNameIndex.getInstance(), nameFilter)
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public object TipsManager{
|
||||
if (qualifier != null) {
|
||||
//TODO: filter out extensions!
|
||||
// It's impossible to add extension function for package or class (if it's class object, expression type is not null)
|
||||
qualifier.scope.getDescriptors(JetScope.DescriptorKind.NON_EXTENSIONS, nameFilter).filterTo(descriptors, ::filterIfInfix)
|
||||
qualifier.scope.getDescriptors(JetScope.NON_EXTENSIONS_MASK, nameFilter).filterTo(descriptors, ::filterIfInfix)
|
||||
}
|
||||
|
||||
val expressionType = context[BindingContext.EXPRESSION_TYPE, receiverExpression]
|
||||
@@ -87,7 +87,7 @@ public object TipsManager{
|
||||
}
|
||||
|
||||
if (parent is JetImportDirective || parent is JetPackageDirective) {
|
||||
return excludeNonPackageDescriptors(resolutionScope.getDescriptors({ it == JetScope.DescriptorKind.PACKAGE }, nameFilter))
|
||||
return excludeNonPackageDescriptors(resolutionScope.getDescriptors(JetScope.PACKAGE, nameFilter))
|
||||
}
|
||||
else {
|
||||
val descriptorsSet = HashSet<DeclarationDescriptor>()
|
||||
@@ -96,7 +96,7 @@ public object TipsManager{
|
||||
receiverDescriptor.getType().getMemberScope().getDescriptors().filterTo(descriptorsSet) { !it.isExtension }
|
||||
}
|
||||
|
||||
descriptorsSet.addAll(resolutionScope.getDescriptors({ true }, nameFilter))
|
||||
descriptorsSet.addAll(resolutionScope.getDescriptors(JetScope.ALL_KINDS_MASK, nameFilter))
|
||||
|
||||
descriptorsSet.excludeNotCallableExtensions(resolutionScope, context, context.getDataFlowInfo(expression))
|
||||
|
||||
@@ -108,7 +108,7 @@ public object TipsManager{
|
||||
context: BindingContext,
|
||||
nameFilter: (Name) -> Boolean): Collection<DeclarationDescriptor> {
|
||||
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
|
||||
return excludeNonPackageDescriptors(resolutionScope.getDescriptors({ it == JetScope.DescriptorKind.PACKAGE }, nameFilter))
|
||||
return excludeNonPackageDescriptors(resolutionScope.getDescriptors(JetScope.PACKAGE, nameFilter))
|
||||
}
|
||||
|
||||
public fun excludeNotCallableExtensions(descriptors: Collection<DeclarationDescriptor>,
|
||||
|
||||
@@ -75,7 +75,7 @@ public abstract class BaseJetVariableMacro extends Macro {
|
||||
new InjectorForMacros(project, resolveSession.getModuleDescriptor()).getExpressionTypingComponents();
|
||||
|
||||
List<VariableDescriptor> filteredDescriptors = new ArrayList<VariableDescriptor>();
|
||||
for (DeclarationDescriptor declarationDescriptor : scope.getDescriptors(JetScope.DescriptorKind.VARIABLES_AND_PROPERTIES, JetScope.ALL_NAME_FILTER)) {
|
||||
for (DeclarationDescriptor declarationDescriptor : scope.getDescriptors(JetScope.VARIABLES_AND_PROPERTIES_MASK, JetScope.ALL_NAME_FILTER)) {
|
||||
if (declarationDescriptor instanceof VariableDescriptor) {
|
||||
VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor;
|
||||
if (isSuitable(variableDescriptor, scope, project, components)) {
|
||||
|
||||
@@ -96,7 +96,7 @@ public class JetAnonymousSuperMacro extends Macro {
|
||||
|
||||
List<PsiNamedElement> result = new ArrayList<PsiNamedElement>();
|
||||
|
||||
for (DeclarationDescriptor descriptor : scope.getDescriptors(JetScope.DescriptorKind.CLASSIFIERS, JetScope.ALL_NAME_FILTER)) {
|
||||
for (DeclarationDescriptor descriptor : scope.getDescriptors(JetScope.TYPE, JetScope.ALL_NAME_FILTER)) {
|
||||
if (!(descriptor instanceof ClassDescriptor)) continue;
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
|
||||
if (!classDescriptor.getModality().isOverridable()) continue;
|
||||
|
||||
@@ -144,7 +144,7 @@ public class ManglingUtils {
|
||||
int counter = 0;
|
||||
|
||||
if (jetScope != null) {
|
||||
Collection<DeclarationDescriptor> declarations = jetScope.getDescriptors(JetScope.DescriptorKind.CALLABLES, JetScope.ALL_NAME_FILTER);
|
||||
Collection<DeclarationDescriptor> declarations = jetScope.getDescriptors(JetScope.CALLABLES_MASK, JetScope.ALL_NAME_FILTER);
|
||||
List<CallableMemberDescriptor>
|
||||
overloadedFunctions = ContainerUtil.mapNotNull(declarations, new Function<DeclarationDescriptor, CallableMemberDescriptor>() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user