More precise descriptor kind filtering (preparing to optimize smart completion)

This commit is contained in:
Valentin Kipyatkov
2014-11-02 10:12:56 +03:00
parent 5f4220427f
commit 43df891515
7 changed files with 28 additions and 16 deletions
@@ -117,7 +117,7 @@ public class BuiltInsSerializer(val out: PrintStream?) {
})
val classNames = ArrayList<Name>()
val classifierDescriptors = DescriptorSerializer.sort(packageView.getMemberScope().getDescriptors({ it == JetScope.DescriptorKind.CLASSIFIER }))
val classifierDescriptors = DescriptorSerializer.sort(packageView.getMemberScope().getDescriptors({ it == JetScope.DescriptorKind.TYPE }))
ClassSerializationUtil.serializeClasses(classifierDescriptors, serializer, object : ClassSerializationUtil.Sink {
override fun writeClass(classDescriptor: ClassDescriptor, classProto: ProtoBuf.Class) {
@@ -294,7 +294,7 @@ public abstract class LazyJavaMemberScope(
nameFilter: (Name) -> Boolean): List<DeclarationDescriptor> {
val result = LinkedHashSet<DeclarationDescriptor>()
if (kindFilter(JetScope.DescriptorKind.CLASSIFIER)) {
if (kindFilter(JetScope.DescriptorKind.TYPE)) {
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.NON_EXTENSION_FUNCTION)) {
if (kindFilter(JetScope.DescriptorKind.ORDINARY_FUNCTION) || kindFilter(JetScope.DescriptorKind.SAM_CONSTRUCTOR)) {
for (name in getFunctionNames(nameFilter)) {
if (nameFilter(name)) {
result.addAll(getFunctions(name))
@@ -21,6 +21,7 @@ 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
@@ -28,8 +29,8 @@ public class InnerClassesScopeWrapper(override val workerScope: JetScope) : Abst
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
nameFilter: (Name) -> Boolean): List<ClassDescriptor> {
if (!kindFilter(JetScope.DescriptorKind.CLASSIFIER)) return listOf()
return workerScope.getDescriptors({ it == JetScope.DescriptorKind.CLASSIFIER }, nameFilter).filterIsInstance(javaClass<ClassDescriptor>())
if (!descriptorKinds.any { kindFilter(it) }) return listOf()
return workerScope.getDescriptors(JetScope.DescriptorKind.CLASSIFIERS, nameFilter).filterIsInstance(javaClass<ClassDescriptor>())
}
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> = listOf()
@@ -78,10 +78,13 @@ public trait JetScope {
}
public enum class DescriptorKind {
CLASSIFIER
TYPE // class, trait ot type parameter
ENUM_ENTRY
OBJECT
PACKAGE
NON_EXTENSION_FUNCTION
ORDINARY_FUNCTION // not extension and not SAM-constructor
EXTENSION_FUNCTION
SAM_CONSTRUCTOR
NON_EXTENSION_PROPERTY
EXTENSION_PROPERTY
LOCAL_VARIABLE
@@ -89,11 +92,19 @@ public trait JetScope {
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 CALLABLES: (DescriptorKind) -> Boolean = { it != CLASSIFIER && it != PACKAGE }
public val NON_EXTENSION_CALLABLES: (DescriptorKind) -> Boolean = { it == NON_EXTENSION_FUNCTION || it == NON_EXTENSION_PROPERTY || it == LOCAL_VARIABLE }
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 == CLASSIFIER }
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 }
}
@@ -72,7 +72,7 @@ public class DeserializedClassDescriptor(outerContext: DeserializationContext, p
if (classId.isTopLevelClass()) {
val fragments = context.packageFragmentProvider.getPackageFragments(classId.getPackageFqName())
assert(fragments.size() == 1) { "there should be exactly one package: $fragments, class id is $classId" }
return fragments.iterator().next()
return fragments.single()
}
else {
return context.deserializeClass(classId.getOuterClassId()) ?: ErrorUtils.getErrorModule()
@@ -107,7 +107,7 @@ public abstract class DeserializedMemberScope protected(
for (name in membersProtos().keySet()) {
if (nameFilter(name)) {
if (kindFilter(JetScope.DescriptorKind.NON_EXTENSION_FUNCTION) || kindFilter(JetScope.DescriptorKind.EXTENSION_FUNCTION)) {
if (kindFilter(JetScope.DescriptorKind.ORDINARY_FUNCTION) || kindFilter(JetScope.DescriptorKind.EXTENSION_FUNCTION)) {
result.addAll(getFunctions(name))
}
if (kindFilter(JetScope.DescriptorKind.NON_EXTENSION_PROPERTY) || kindFilter(JetScope.DescriptorKind.EXTENSION_PROPERTY)) {
@@ -118,7 +118,7 @@ public abstract class DeserializedMemberScope protected(
addNonDeclaredDescriptors(result)
if (kindFilter(JetScope.DescriptorKind.CLASSIFIER)) {
if (kindFilter(JetScope.DescriptorKind.TYPE) || kindFilter(JetScope.DescriptorKind.OBJECT) || kindFilter(JetScope.DescriptorKind.ENUM_ENTRY)) {
addClassDescriptors(result, nameFilter)
}
@@ -42,11 +42,11 @@ public class StubBasedPackageMemberDeclarationProvider(
override fun getDeclarations(kindFilter: (JetScope.DescriptorKind) -> Boolean, nameFilter: (Name) -> Boolean): List<JetDeclaration> {
val result = ArrayList<JetDeclaration>()
if (kindFilter(JetScope.DescriptorKind.CLASSIFIER)) {
if (kindFilter(JetScope.DescriptorKind.TYPE) || kindFilter(JetScope.DescriptorKind.OBJECT)) {
result.addDeclarations(JetFullClassNameIndex.getInstance(), nameFilter)
}
if (kindFilter(JetScope.DescriptorKind.NON_EXTENSION_FUNCTION) || kindFilter(JetScope.DescriptorKind.EXTENSION_FUNCTION)) {
if (kindFilter(JetScope.DescriptorKind.ORDINARY_FUNCTION) || kindFilter(JetScope.DescriptorKind.EXTENSION_FUNCTION)) {
result.addDeclarations(JetTopLevelFunctionsFqnNameIndex.getInstance(), nameFilter)
}