Introduce ResolutionScope::definitelyDoesNotContainName

Also add some obvious implementations

This method might be used in resolution to filter out
inapplicable scopes
This commit is contained in:
Denis Zharkov
2017-08-15 12:27:21 +07:00
parent 7b5842a088
commit 94356e891b
7 changed files with 28 additions and 1 deletions
@@ -124,4 +124,7 @@ abstract class LexicalScopeStorage(
} while (rest != null)
return result
}
override fun definitelyDoesNotContainName(name: Name) =
functionsByName?.get(name) == null && variablesAndClassifiersByName?.get(name) == null
}
@@ -55,6 +55,8 @@ interface LexicalScope : HierarchicalScope {
override val kind: LexicalScopeKind
get() = LexicalScopeKind.EMPTY
override fun definitelyDoesNotContainName(name: Name) = true
override fun printStructure(p: Printer) {
p.println("Base lexical scope with owner = $ownerDescriptor and parent = $parent")
}
@@ -123,6 +125,8 @@ interface ImportingScope : HierarchicalScope {
override fun printStructure(p: Printer) {
p.println("ImportingScope.Empty")
}
override fun definitelyDoesNotContainName(name: Name) = true
}
}
@@ -40,5 +40,7 @@ class InnerClassesScopeWrapper(val workerScope: MemberScope) : MemberScopeImpl()
workerScope.printScopeStructure(p)
}
override fun definitelyDoesNotContainName(name: Name) = workerScope.definitelyDoesNotContainName(name)
override fun toString() = "Classes from $workerScope"
}
@@ -16,7 +16,10 @@
package org.jetbrains.kotlin.resolve.scopes
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.VariableDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.Name
@@ -36,4 +39,6 @@ interface ResolutionScope {
kindFilter: DescriptorKindFilter = DescriptorKindFilter.ALL,
nameFilter: (Name) -> Boolean = MemberScope.ALL_NAME_FILTER
): Collection<DeclarationDescriptor>
fun definitelyDoesNotContainName(name: Name): Boolean = false
}
@@ -82,6 +82,8 @@ class SubstitutingScope(private val workerScope: MemberScope, givenSubstitutor:
override fun getFunctionNames() = workerScope.getFunctionNames()
override fun getVariableNames() = workerScope.getVariableNames()
override fun definitelyDoesNotContainName(name: Name) = workerScope.definitelyDoesNotContainName(name)
override fun printScopeStructure(p: Printer) {
p.println(this::class.java.simpleName, " {")
p.pushIndent()
@@ -219,6 +219,11 @@ public class ErrorUtils {
return Collections.emptyList();
}
@Override
public boolean definitelyDoesNotContainName(@NotNull Name name) {
return false;
}
@Override
public String toString() {
return "ErrorScope{" + debugMessage + '}';
@@ -279,6 +284,11 @@ public class ErrorUtils {
throw new IllegalStateException();
}
@Override
public boolean definitelyDoesNotContainName(@NotNull Name name) {
return false;
}
@Override
public String toString() {
return "ThrowingScope{" + debugMessage + '}';
@@ -106,6 +106,7 @@ class MetadataPackageFragment(
containerSource = null, components = components, classNames = { emptyList() }
) {
override fun hasClass(name: Name): Boolean = hasTopLevelClass(name)
override fun definitelyDoesNotContainName(name: Name) = false
})
return ChainedMemberScope.create("Metadata scope", scopes)