Track lookups in LazyJavaScope ans LazyJavaPackageScope

This commit is contained in:
Zalim Bashorov
2015-10-28 21:51:05 +03:00
parent 47f1975879
commit c6aa94d30a
4 changed files with 32 additions and 13 deletions
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.PackagePartProvider
import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.load.java.JavaClassFinder
import org.jetbrains.kotlin.load.java.components.ExternalAnnotationResolver
import org.jetbrains.kotlin.load.java.components.ExternalSignatureResolver
@@ -49,7 +50,8 @@ class JavaResolverComponents(
val sourceElementFactory: JavaSourceElementFactory,
val moduleClassResolver: ModuleClassResolver,
val packageMapper: PackagePartProvider,
val supertypeLoopChecker: SupertypeLoopChecker
val supertypeLoopChecker: SupertypeLoopChecker,
val lookupTracker: LookupTracker
)
open class LazyJavaResolverContext(
@@ -16,10 +16,7 @@
package org.jetbrains.kotlin.load.java.lazy.descriptors
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptorKindExclude
@@ -29,7 +26,6 @@ import org.jetbrains.kotlin.load.java.lazy.resolveKotlinBinaryClass
import org.jetbrains.kotlin.load.java.structure.JavaClass
import org.jetbrains.kotlin.load.java.structure.JavaPackage
import org.jetbrains.kotlin.load.kotlin.DeserializedDescriptorResolver
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass
import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.Name
@@ -103,11 +99,21 @@ public class LazyJavaPackageScope(
}
}
override fun getClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? =
if (SpecialNames.isSafeIdentifier(name)) classes(name) else null
override fun getClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? {
if (!SpecialNames.isSafeIdentifier(name)) return null
override fun getProperties(name: Name, location: LookupLocation) = deserializedPackageScope().getProperties(name, location)
override fun getFunctions(name: Name, location: LookupLocation) = deserializedPackageScope().getFunctions(name, location) + super.getFunctions(name, location)
recordLookup(name, location)
return classes(name)
}
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
recordLookup(name, location)
return deserializedPackageScope().getProperties(name, NoLookupLocation.FOR_ALREADY_TRACKED)
}
override fun getFunctions(name: Name, location: LookupLocation): List<FunctionDescriptor> {
recordLookup(name, location)
return deserializedPackageScope().getFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED) + super.getFunctions(name, NoLookupLocation.FOR_ALREADY_TRACKED)
}
override fun addExtraDescriptors(result: MutableSet<DeclarationDescriptor>,
kindFilter: DescriptorKindFilter,
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.incremental.record
import org.jetbrains.kotlin.load.java.components.ExternalSignatureResolver
import org.jetbrains.kotlin.load.java.components.TypeUsage
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
@@ -213,7 +214,10 @@ public abstract class LazyJavaScope(
return ResolvedValueParameters(descriptors, synthesizedNames)
}
override fun getFunctions(name: Name, location: LookupLocation) = functions(name)
override fun getFunctions(name: Name, location: LookupLocation): Collection<FunctionDescriptor> {
recordLookup(name, location)
return functions(name)
}
protected open fun getFunctionNames(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean): Collection<Name>
= memberIndex().getMethodNames(nameFilter)
@@ -294,7 +298,10 @@ public abstract class LazyJavaScope(
return propertyType
}
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> = properties(name)
override fun getProperties(name: Name, location: LookupLocation): Collection<VariableDescriptor> {
recordLookup(name, location)
return properties(name)
}
override fun getOwnDeclaredDescriptors() = getDescriptors()
@@ -357,4 +364,8 @@ public abstract class LazyJavaScope(
p.popIndent()
p.println("}")
}
protected fun recordLookup(name: Name, from: LookupLocation) {
c.components.lookupTracker.record(from, this, name)
}
}