Added JetScope.getDescriptors(nameFilter, kindFilter) but the filters are never used yet
This commit is contained in:
@@ -173,7 +173,8 @@ public class LazyImportScope(private val resolveSession: ResolveSession,
|
|||||||
|
|
||||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||||
|
|
||||||
override fun getAllDescriptors() = collectFromImports(LookupMode.EVERYTHING, JetScopeSelectorUtil.ALL_DESCRIPTORS_SCOPE_SELECTOR)
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
|
nameFilter: (String) -> Boolean) = collectFromImports(LookupMode.EVERYTHING, JetScopeSelectorUtil.ALL_DESCRIPTORS_SCOPE_SELECTOR)
|
||||||
|
|
||||||
override fun getImplicitReceiversHierarchy() = listOf<ReceiverParameterDescriptor>()
|
override fun getImplicitReceiversHierarchy() = listOf<ReceiverParameterDescriptor>()
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -143,7 +143,8 @@ public abstract class AbstractLazyMemberScope<D : DeclarationDescriptor, DP : De
|
|||||||
|
|
||||||
override fun getDeclarationsByLabel(labelName: Name) = setOf<DeclarationDescriptor>()
|
override fun getDeclarationsByLabel(labelName: Name) = setOf<DeclarationDescriptor>()
|
||||||
|
|
||||||
override fun getAllDescriptors(): Collection<DeclarationDescriptor> {
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
|
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
val result = LinkedHashSet(descriptorsFromDeclaredElements())
|
val result = LinkedHashSet(descriptorsFromDeclaredElements())
|
||||||
result.addAll(extraDescriptors())
|
result.addAll(extraDescriptors())
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -99,7 +99,8 @@ public class WritableScopeImpl(scope: JetScope,
|
|||||||
super.clearImports()
|
super.clearImports()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllDescriptors(): Collection<DeclarationDescriptor> {
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
|
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
checkMayRead()
|
checkMayRead()
|
||||||
|
|
||||||
if (!allDescriptorsDone) {
|
if (!allDescriptorsDone) {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import org.jetbrains.jet.utils.Printer
|
|||||||
public class WriteThroughScope(outerScope: JetScope, private val writableWorker: WritableScope, redeclarationHandler: RedeclarationHandler, debugName: String)
|
public class WriteThroughScope(outerScope: JetScope, private val writableWorker: WritableScope, redeclarationHandler: RedeclarationHandler, debugName: String)
|
||||||
: WritableScopeWithImports(outerScope, redeclarationHandler, debugName) {
|
: WritableScopeWithImports(outerScope, redeclarationHandler, debugName) {
|
||||||
|
|
||||||
private var allDescriptors: MutableCollection<DeclarationDescriptor>? = null
|
private var _allDescriptors: MutableCollection<DeclarationDescriptor>? = null
|
||||||
|
|
||||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> {
|
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> {
|
||||||
checkMayRead()
|
checkMayRead()
|
||||||
@@ -164,18 +164,19 @@ public class WriteThroughScope(outerScope: JetScope, private val writableWorker:
|
|||||||
writableWorker.setImplicitReceiver(implicitReceiver)
|
writableWorker.setImplicitReceiver(implicitReceiver)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllDescriptors(): Collection<DeclarationDescriptor> {
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
|
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
checkMayRead()
|
checkMayRead()
|
||||||
|
|
||||||
if (allDescriptors == null) {
|
if (_allDescriptors == null) {
|
||||||
allDescriptors = Lists.newArrayList<DeclarationDescriptor>()
|
_allDescriptors = Lists.newArrayList<DeclarationDescriptor>()
|
||||||
allDescriptors!!.addAll(workerScope.getAllDescriptors())
|
_allDescriptors!!.addAll(workerScope.getAllDescriptors())
|
||||||
|
|
||||||
for (imported in getImports()) {
|
for (imported in getImports()) {
|
||||||
allDescriptors!!.addAll(imported.getAllDescriptors())
|
_allDescriptors!!.addAll(imported.getAllDescriptors())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return allDescriptors!!
|
return _allDescriptors!!
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun printAdditionalScopeStructure(p: Printer) {
|
override fun printAdditionalScopeStructure(p: Printer) {
|
||||||
|
|||||||
+3
-1
@@ -283,7 +283,9 @@ public abstract class LazyJavaMemberScope(
|
|||||||
override fun getDeclarationsByLabel(labelName: Name) = listOf<DeclarationDescriptor>()
|
override fun getDeclarationsByLabel(labelName: Name) = listOf<DeclarationDescriptor>()
|
||||||
|
|
||||||
override fun getOwnDeclaredDescriptors() = getAllDescriptors()
|
override fun getOwnDeclaredDescriptors() = getAllDescriptors()
|
||||||
override fun getAllDescriptors() = allDescriptors()
|
|
||||||
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
|
nameFilter: (String) -> Boolean) = allDescriptors()
|
||||||
|
|
||||||
private fun computeAllDescriptors(): List<DeclarationDescriptor> {
|
private fun computeAllDescriptors(): List<DeclarationDescriptor> {
|
||||||
val result = LinkedHashSet<DeclarationDescriptor>()
|
val result = LinkedHashSet<DeclarationDescriptor>()
|
||||||
|
|||||||
+4
-1
@@ -256,7 +256,10 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
public Collection<DeclarationDescriptor> getDescriptors(
|
||||||
|
@NotNull Function1<? super DescriptorKind, ? extends Boolean> kindFilter,
|
||||||
|
@NotNull Function1<? super String, ? extends Boolean> nameFilter
|
||||||
|
) {
|
||||||
return allDescriptors.invoke();
|
return allDescriptors.invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ package org.jetbrains.jet.lang.descriptors.impl
|
|||||||
|
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor
|
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name
|
import org.jetbrains.jet.lang.resolve.name.Name
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.JetScopeImpl
|
import org.jetbrains.jet.lang.resolve.scopes.JetScopeImpl
|
||||||
import org.jetbrains.jet.utils.Printer
|
|
||||||
import org.jetbrains.jet.utils.*
|
import org.jetbrains.jet.utils.*
|
||||||
|
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope.DescriptorKind
|
||||||
|
|
||||||
public class SubpackagesScope(private val containingDeclaration: PackageViewDescriptor) : JetScopeImpl() {
|
public class SubpackagesScope(private val containingDeclaration: PackageViewDescriptor) : JetScopeImpl() {
|
||||||
override fun getContainingDeclaration(): DeclarationDescriptor {
|
override fun getContainingDeclaration(): DeclarationDescriptor {
|
||||||
@@ -35,7 +35,8 @@ public class SubpackagesScope(private val containingDeclaration: PackageViewDesc
|
|||||||
return if (name.isSpecial()) null else containingDeclaration.getModule().getPackage(containingDeclaration.getFqName().child(name))
|
return if (name.isSpecial()) null else containingDeclaration.getModule().getPackage(containingDeclaration.getFqName().child(name))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllDescriptors(): Collection<DeclarationDescriptor> {
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
|
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
val subFqNames = containingDeclaration.getModule().getPackageFragmentProvider().getSubPackagesOf(containingDeclaration.getFqName())
|
val subFqNames = containingDeclaration.getModule().getPackageFragmentProvider().getSubPackagesOf(containingDeclaration.getFqName())
|
||||||
val result = ArrayList<DeclarationDescriptor>(subFqNames.size())
|
val result = ArrayList<DeclarationDescriptor>(subFqNames.size())
|
||||||
for (subFqName in subFqNames) {
|
for (subFqName in subFqNames) {
|
||||||
|
|||||||
@@ -58,8 +58,9 @@ public abstract class AbstractScopeAdapter : JetScope {
|
|||||||
return workerScope.getDeclarationsByLabel(labelName)
|
return workerScope.getDeclarationsByLabel(labelName)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllDescriptors(): Collection<DeclarationDescriptor> {
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
return workerScope.getAllDescriptors()
|
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
|
return workerScope.getDescriptors(kindFilter, nameFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor> {
|
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor> {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class ChainedScope(private val containingDeclaration: DeclarationDescript
|
|||||||
private val debugName: String,
|
private val debugName: String,
|
||||||
vararg scopes: JetScope) : JetScope {
|
vararg scopes: JetScope) : JetScope {
|
||||||
private val scopeChain = scopes.clone()
|
private val scopeChain = scopes.clone()
|
||||||
private var allDescriptors: MutableCollection<DeclarationDescriptor>? = null
|
private var _allDescriptors: MutableCollection<DeclarationDescriptor>? = null
|
||||||
private var implicitReceiverHierarchy: List<ReceiverParameterDescriptor>? = null
|
private var implicitReceiverHierarchy: List<ReceiverParameterDescriptor>? = null
|
||||||
|
|
||||||
override fun getClassifier(name: Name): ClassifierDescriptor?
|
override fun getClassifier(name: Name): ClassifierDescriptor?
|
||||||
@@ -72,14 +72,15 @@ public class ChainedScope(private val containingDeclaration: DeclarationDescript
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllDescriptors(): Collection<DeclarationDescriptor> {
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
if (allDescriptors == null) {
|
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> {
|
||||||
allDescriptors = HashSet<DeclarationDescriptor>()
|
if (_allDescriptors == null) {
|
||||||
|
_allDescriptors = HashSet<DeclarationDescriptor>()
|
||||||
for (scope in scopeChain) {
|
for (scope in scopeChain) {
|
||||||
allDescriptors!!.addAll(scope.getAllDescriptors())
|
_allDescriptors!!.addAll(scope.getAllDescriptors())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return allDescriptors!!
|
return _allDescriptors!!
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor> {
|
override fun getOwnDeclaredDescriptors(): Collection<DeclarationDescriptor> {
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ public class FilteringScope(private val workerScope: JetScope, private val predi
|
|||||||
|
|
||||||
override fun getLocalVariable(name: Name) = filterDescriptor(workerScope.getLocalVariable(name))
|
override fun getLocalVariable(name: Name) = filterDescriptor(workerScope.getLocalVariable(name))
|
||||||
|
|
||||||
override fun getAllDescriptors() = workerScope.getAllDescriptors().filter(predicate)
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
|
nameFilter: (String) -> Boolean) = workerScope.getDescriptors(kindFilter, nameFilter).filter(predicate)
|
||||||
|
|
||||||
override fun getImplicitReceiversHierarchy() = workerScope.getImplicitReceiversHierarchy()
|
override fun getImplicitReceiversHierarchy() = workerScope.getImplicitReceiversHierarchy()
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -29,7 +29,8 @@ public class InnerClassesScopeWrapper(override val workerScope: JetScope) : Abst
|
|||||||
|
|
||||||
override fun getDeclarationsByLabel(labelName: Name) = workerScope.getDeclarationsByLabel(labelName).filterIsInstance(javaClass<ClassDescriptor>())
|
override fun getDeclarationsByLabel(labelName: Name) = workerScope.getDeclarationsByLabel(labelName).filterIsInstance(javaClass<ClassDescriptor>())
|
||||||
|
|
||||||
override fun getAllDescriptors() = workerScope.getAllDescriptors().filterIsInstance(javaClass<ClassDescriptor>())
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
|
nameFilter: (String) -> Boolean) = workerScope.getDescriptors(kindFilter, nameFilter).filterIsInstance(javaClass<ClassDescriptor>())
|
||||||
|
|
||||||
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> = listOf()
|
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> = listOf()
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.lang.resolve.scopes
|
package org.jetbrains.jet.lang.resolve.scopes
|
||||||
|
|
||||||
import org.jetbrains.annotations.ReadOnly
|
|
||||||
import org.jetbrains.jet.lang.descriptors.*
|
import org.jetbrains.jet.lang.descriptors.*
|
||||||
import org.jetbrains.jet.lang.resolve.name.Name
|
import org.jetbrains.jet.lang.resolve.name.Name
|
||||||
import org.jetbrains.jet.utils.Printer
|
import org.jetbrains.jet.utils.Printer
|
||||||
@@ -45,7 +44,14 @@ public trait JetScope {
|
|||||||
*
|
*
|
||||||
* @return All visible descriptors from current scope.
|
* @return All visible descriptors from current scope.
|
||||||
*/
|
*/
|
||||||
public fun getAllDescriptors(): Collection<DeclarationDescriptor>
|
public fun getAllDescriptors(): Collection<DeclarationDescriptor> = getDescriptors(DescriptorKind.ALL, {true})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,
|
||||||
|
nameFilter: (String) -> kotlin.Boolean = { true }): Collection<DeclarationDescriptor>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds receivers to the list in order of locality, so that the closest (the most local) receiver goes first
|
* Adds receivers to the list in order of locality, so that the closest (the most local) receiver goes first
|
||||||
@@ -70,5 +76,26 @@ public trait JetScope {
|
|||||||
p.println("Empty")
|
p.println("Empty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum class DescriptorKind {
|
||||||
|
CLASSIFIER
|
||||||
|
PACKAGE
|
||||||
|
NON_EXTENSION_FUNCTION
|
||||||
|
EXTENSION_FUNCTION
|
||||||
|
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 == NON_EXTENSION_FUNCTION || it == EXTENSION_FUNCTION }
|
||||||
|
public val NON_EXTENSION_CALLABLES: (DescriptorKind) -> Boolean = { it == NON_EXTENSION_FUNCTION || it == NON_EXTENSION_PROPERTY || it == LOCAL_VARIABLE }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class object {
|
||||||
|
public val ALL_NAME_FILTER: (String) -> Boolean = { true }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ public abstract class JetScopeImpl : JetScope {
|
|||||||
|
|
||||||
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
override fun getDeclarationsByLabel(labelName: Name): Collection<DeclarationDescriptor> = listOf()
|
||||||
|
|
||||||
override fun getAllDescriptors(): Collection<DeclarationDescriptor> = listOf()
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
|
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> = listOf()
|
||||||
|
|
||||||
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> = listOf()
|
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> = listOf()
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -37,7 +37,8 @@ public class StaticScopeForKotlinClass(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllDescriptors() = functions
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
|
nameFilter: (String) -> Boolean) = functions
|
||||||
|
|
||||||
override fun getOwnDeclaredDescriptors() = functions
|
override fun getOwnDeclaredDescriptors() = functions
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,8 @@ public class SubstitutingScope(private val workerScope: JetScope, private val su
|
|||||||
throw UnsupportedOperationException() // TODO
|
throw UnsupportedOperationException() // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAllDescriptors() = _allDescriptors
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
|
nameFilter: (String) -> Boolean) = _allDescriptors
|
||||||
|
|
||||||
override fun getOwnDeclaredDescriptors() = substitute(workerScope.getOwnDeclaredDescriptors())
|
override fun getOwnDeclaredDescriptors() = substitute(workerScope.getOwnDeclaredDescriptors())
|
||||||
|
|
||||||
|
|||||||
@@ -123,6 +123,15 @@ public class ErrorUtils {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<DeclarationDescriptor> getDescriptors(
|
||||||
|
@NotNull Function1<? super DescriptorKind, ? extends Boolean> kindFilter,
|
||||||
|
@NotNull Function1<? super String, ? extends Boolean> nameFilter
|
||||||
|
) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||||
@@ -195,6 +204,15 @@ public class ErrorUtils {
|
|||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<DeclarationDescriptor> getDescriptors(
|
||||||
|
@NotNull Function1<? super DescriptorKind, ? extends Boolean> kindFilter,
|
||||||
|
@NotNull Function1<? super String, ? extends Boolean> nameFilter
|
||||||
|
) {
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
public Collection<DeclarationDescriptor> getAllDescriptors() {
|
||||||
|
|||||||
+2
-1
@@ -119,7 +119,8 @@ public abstract class DeserializedMemberScope protected(
|
|||||||
|
|
||||||
protected abstract fun addNonDeclaredDescriptors(result: MutableCollection<DeclarationDescriptor>)
|
protected abstract fun addNonDeclaredDescriptors(result: MutableCollection<DeclarationDescriptor>)
|
||||||
|
|
||||||
override fun getAllDescriptors(): Collection<DeclarationDescriptor> = allDescriptors.invoke()
|
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
|
||||||
|
nameFilter: (String) -> Boolean): Collection<DeclarationDescriptor> = allDescriptors.invoke()
|
||||||
|
|
||||||
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
|
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> {
|
||||||
val receiver = getImplicitReceiver()
|
val receiver = getImplicitReceiver()
|
||||||
|
|||||||
Reference in New Issue
Block a user