Code simplifications
This commit is contained in:
+16
-33
@@ -17,8 +17,6 @@
|
||||
package org.jetbrains.jet.lang.resolve.lazy.descriptors
|
||||
|
||||
import com.google.common.collect.Sets
|
||||
import com.intellij.util.Function
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jetbrains.jet.lang.descriptors.*
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lang.resolve.AnnotationResolver
|
||||
@@ -26,7 +24,6 @@ import org.jetbrains.jet.lang.resolve.BindingTrace
|
||||
import org.jetbrains.jet.lang.resolve.ScriptNameUtil
|
||||
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession
|
||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo
|
||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetScriptInfo
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.DeclarationProvider
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
@@ -44,42 +41,28 @@ public abstract class AbstractLazyMemberScope<D : DeclarationDescriptor, DP : De
|
||||
protected val thisDescriptor: D,
|
||||
protected val trace: BindingTrace) : JetScope {
|
||||
|
||||
private val classDescriptors: MemoizedFunctionToNotNull<Name, List<ClassDescriptor>>
|
||||
|
||||
private val functionDescriptors: MemoizedFunctionToNotNull<Name, Collection<FunctionDescriptor>>
|
||||
private val propertyDescriptors: MemoizedFunctionToNotNull<Name, Collection<VariableDescriptor>>
|
||||
|
||||
private val descriptorsFromDeclaredElements: NotNullLazyValue<Collection<DeclarationDescriptor>>
|
||||
private val extraDescriptors: NotNullLazyValue<Collection<DeclarationDescriptor>>
|
||||
|
||||
{
|
||||
val storageManager = resolveSession.getStorageManager()
|
||||
this.classDescriptors = storageManager.createMemoizedFunction { resolveClassDescriptor(it) }
|
||||
this.functionDescriptors = storageManager.createMemoizedFunction<Name, Collection<FunctionDescriptor>> { doGetFunctions(it) }
|
||||
this.propertyDescriptors = storageManager.createMemoizedFunction<Name, Collection<VariableDescriptor>> { doGetProperties(it) }
|
||||
this.descriptorsFromDeclaredElements = storageManager.createLazyValue<Collection<DeclarationDescriptor>> { computeDescriptorsFromDeclaredElements() }
|
||||
this.extraDescriptors = storageManager.createLazyValue<Collection<DeclarationDescriptor>> { computeExtraDescriptors() }
|
||||
}
|
||||
private val storageManager = resolveSession.getStorageManager()
|
||||
private val classDescriptors: MemoizedFunctionToNotNull<Name, List<ClassDescriptor>> = storageManager.createMemoizedFunction { resolveClassDescriptor(it) }
|
||||
private val functionDescriptors: MemoizedFunctionToNotNull<Name, Collection<FunctionDescriptor>> = storageManager.createMemoizedFunction { doGetFunctions(it) }
|
||||
private val propertyDescriptors: MemoizedFunctionToNotNull<Name, Collection<VariableDescriptor>> = storageManager.createMemoizedFunction { doGetProperties(it) }
|
||||
private val descriptorsFromDeclaredElements: NotNullLazyValue<Collection<DeclarationDescriptor>> = storageManager.createLazyValue { computeDescriptorsFromDeclaredElements() }
|
||||
private val extraDescriptors: NotNullLazyValue<Collection<DeclarationDescriptor>> = storageManager.createLazyValue { computeExtraDescriptors() }
|
||||
|
||||
private fun resolveClassDescriptor(name: Name): List<ClassDescriptor> {
|
||||
val classOrObjectDeclarations = declarationProvider.getClassOrObjectDeclarations(name)
|
||||
|
||||
return ContainerUtil.mapNotNull<JetClassLikeInfo, ClassDescriptor>(classOrObjectDeclarations, object : Function<JetClassLikeInfo, ClassDescriptor> {
|
||||
override fun `fun`(classLikeInfo: JetClassLikeInfo): ClassDescriptor {
|
||||
// SCRIPT: Creating a script class
|
||||
if (classLikeInfo is JetScriptInfo) {
|
||||
return LazyScriptClassDescriptor(resolveSession, thisDescriptor, name, classLikeInfo)
|
||||
}
|
||||
return LazyClassDescriptor(resolveSession, thisDescriptor, name, classLikeInfo)
|
||||
}
|
||||
}).toReadOnlyList()
|
||||
return declarationProvider.getClassOrObjectDeclarations(name).map {
|
||||
// SCRIPT: Creating a script class
|
||||
if (it is JetScriptInfo)
|
||||
LazyScriptClassDescriptor(resolveSession, thisDescriptor, name, it)
|
||||
else
|
||||
LazyClassDescriptor(resolveSession, thisDescriptor, name, it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getContainingDeclaration() = thisDescriptor
|
||||
|
||||
override fun getClassifier(name: Name): ClassDescriptor? = classDescriptors(name).firstOrNull()
|
||||
|
||||
override fun getFunctions(name: Name): Set<FunctionDescriptor> = functionDescriptors(name)
|
||||
override fun getFunctions(name: Name): Collection<FunctionDescriptor> = functionDescriptors(name)
|
||||
|
||||
private fun doGetFunctions(name: Name): Collection<FunctionDescriptor> {
|
||||
val result = Sets.newLinkedHashSet<FunctionDescriptor>()
|
||||
@@ -106,10 +89,10 @@ public abstract class AbstractLazyMemberScope<D : DeclarationDescriptor, DP : De
|
||||
|
||||
protected abstract fun getNonDeclaredFunctions(name: Name, result: MutableSet<FunctionDescriptor>)
|
||||
|
||||
override fun getProperties(name: Name): Set<VariableDescriptor> = propertyDescriptors(name)
|
||||
override fun getProperties(name: Name): Collection<VariableDescriptor> = propertyDescriptors(name)
|
||||
|
||||
public fun doGetProperties(name: Name): Collection<VariableDescriptor> {
|
||||
val result = Sets.newLinkedHashSet<VariableDescriptor>()
|
||||
val result = LinkedHashSet<VariableDescriptor>()
|
||||
|
||||
val declarations = declarationProvider.getPropertyDeclarations(name)
|
||||
for (propertyDeclaration in declarations) {
|
||||
|
||||
Reference in New Issue
Block a user