Replaced usages of JetScope.getAllDescriptors() with JetScope.getDescriptors() (where makes sense)

This commit is contained in:
Valentin Kipyatkov
2014-10-30 13:42:46 +03:00
parent 2dd41028fd
commit 1983a9f3da
22 changed files with 48 additions and 36 deletions
@@ -25,6 +25,7 @@ import org.jetbrains.jet.utils.keysToMapExceptNulls
import org.jetbrains.jet.lang.resolve.DescriptorUtils
import org.jetbrains.jet.lang.resolve.MemberComparator
import java.util.Comparator
import org.jetbrains.jet.lang.resolve.scopes.JetScope
public object CodegenUtilKt {
@@ -39,7 +40,7 @@ public object CodegenUtilKt {
delegateExpressionType: JetType? = null
): Map<CallableMemberDescriptor, CallableDescriptor> {
return descriptor.getDefaultType().getMemberScope().getAllDescriptors().stream()
return descriptor.getDefaultType().getMemberScope().getDescriptors().stream()
.filterIsInstance(javaClass<CallableMemberDescriptor>())
.filter { it.getKind() == CallableMemberDescriptor.Kind.DELEGATION }
.toList()
@@ -54,6 +54,7 @@ import org.jetbrains.jet.lang.resolve.java.jvmSignature.JvmMethodSignature;
import org.jetbrains.jet.lang.resolve.kotlin.PackagePartClassUtils;
import org.jetbrains.jet.lang.resolve.kotlin.incremental.IncrementalPackageFragmentProvider;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.org.objectweb.asm.AnnotationVisitor;
import org.jetbrains.org.objectweb.asm.MethodVisitor;
import org.jetbrains.org.objectweb.asm.Type;
@@ -150,7 +151,7 @@ public class PackageCodegen {
return Collections.emptyList();
}
List<DeserializedCallableMemberDescriptor> callables = Lists.newArrayList();
for (DeclarationDescriptor member : packageFragment.getMemberScope().getAllDescriptors()) {
for (DeclarationDescriptor member : packageFragment.getMemberScope().getDescriptors(JetScope.DescriptorKind.CALLABLES, JetScope.ALL_NAME_FILTER)) {
if (member instanceof DeserializedCallableMemberDescriptor) {
callables.add((DeserializedCallableMemberDescriptor) member);
}
@@ -31,6 +31,7 @@ import org.jetbrains.jet.codegen.ClassBuilderMode
import org.jetbrains.jet.lang.resolve.java.descriptor.SamAdapterDescriptor
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
import org.jetbrains.jet.lang.diagnostics.DiagnosticSink
import org.jetbrains.jet.lang.resolve.scopes.JetScope
class BuilderFactoryForDuplicateSignatureDiagnostics(
builderFactory: ClassBuilderFactory,
@@ -127,7 +128,7 @@ class BuilderFactoryForDuplicateSignatureDiagnostics(
}
}
for (member in descriptor.getDefaultType().getMemberScope().getAllDescriptors()) {
for (member in descriptor.getDefaultType().getMemberScope().getDescriptors()) {
processMember(member)
}
@@ -47,6 +47,7 @@ import org.jetbrains.jet.analyzer.ModuleInfo
import org.jetbrains.jet.lang.resolve.java.JvmPlatformParameters
import org.jetbrains.jet.analyzer.ModuleContent
import org.jetbrains.jet.lang.resolve.kotlin.DeserializedResolverUtils
import org.jetbrains.jet.lang.resolve.scopes.JetScope
public class BuiltInsSerializer(val out: PrintStream?) {
private var totalSize = 0
@@ -116,9 +117,9 @@ public class BuiltInsSerializer(val out: PrintStream?) {
})
val classNames = ArrayList<Name>()
val allDescriptors = DescriptorSerializer.sort(packageView.getMemberScope().getAllDescriptors())
val classifierDescriptors = DescriptorSerializer.sort(packageView.getMemberScope().getDescriptors({ it == JetScope.DescriptorKind.CLASSIFIER }))
ClassSerializationUtil.serializeClasses(allDescriptors, serializer, object : ClassSerializationUtil.Sink {
ClassSerializationUtil.serializeClasses(classifierDescriptors, serializer, object : ClassSerializationUtil.Sink {
override fun writeClass(classDescriptor: ClassDescriptor, classProto: ProtoBuf.Class) {
val stream = ByteArrayOutputStream()
classProto.writeTo(stream)
@@ -20,6 +20,7 @@ import org.jetbrains.jet.descriptors.serialization.DescriptorSerializer
import org.jetbrains.jet.descriptors.serialization.ProtoBuf
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.lang.resolve.scopes.JetScope
public object ClassSerializationUtil {
public trait Sink {
@@ -30,7 +31,7 @@ public object ClassSerializationUtil {
val classProto = serializer.classProto(classDescriptor).build() ?: error("Class not serialized: $classDescriptor")
sink.writeClass(classDescriptor, classProto)
serializeClasses(classDescriptor.getUnsubstitutedInnerClassesScope().getAllDescriptors(), serializer, sink)
serializeClasses(classDescriptor.getUnsubstitutedInnerClassesScope().getDescriptors(), serializer, sink)
val classObjectDescriptor = classDescriptor.getClassObjectDescriptor()
if (classObjectDescriptor != null) {
@@ -42,6 +42,7 @@ import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.java.TopDownAnalyzerFacadeForJVM;
import org.jetbrains.jet.lang.resolve.java.JvmAbi;
import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
@@ -215,7 +216,7 @@ public class CliLightClassGenerationSupport extends LightClassGenerationSupport
PackageViewDescriptor packageView = getModule().getPackage(fqn);
if (packageView == null) return Collections.emptyList();
Collection<DeclarationDescriptor> members = packageView.getMemberScope().getAllDescriptors();
Collection<DeclarationDescriptor> members = packageView.getMemberScope().getDescriptors(JetScope.DescriptorKind.PACKAGES, JetScope.ALL_NAME_FILTER);
return ContainerUtil.mapNotNull(members, new Function<DeclarationDescriptor, FqName>() {
@Override
public FqName fun(DeclarationDescriptor member) {
@@ -37,7 +37,6 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil;
import org.jetbrains.jet.lang.resolve.dataClassUtils.DataClassUtilsPackage;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
@@ -318,14 +317,14 @@ public class OverrideResolver {
private static List<CallableMemberDescriptor> getCallableMembersFromSupertypes(ClassDescriptor classDescriptor) {
Set<CallableMemberDescriptor> r = Sets.newLinkedHashSet();
for (JetType supertype : classDescriptor.getTypeConstructor().getSupertypes()) {
r.addAll(getCallableMembersFromType(supertype.getMemberScope()));
r.addAll(getCallableMembersFromType(supertype));
}
return new ArrayList<CallableMemberDescriptor>(r);
}
private static List<CallableMemberDescriptor> getCallableMembersFromType(JetScope scope) {
private static List<CallableMemberDescriptor> getCallableMembersFromType(JetType type) {
List<CallableMemberDescriptor> r = Lists.newArrayList();
for (DeclarationDescriptor decl : scope.getAllDescriptors()) {
for (DeclarationDescriptor decl : type.getMemberScope().getAllDescriptors()) {
if (decl instanceof PropertyDescriptor || decl instanceof SimpleFunctionDescriptor) {
r.add((CallableMemberDescriptor) decl);
}
@@ -183,7 +183,7 @@ public abstract class AbstractLazyMemberScope<D : DeclarationDescriptor, DP : De
// a generic implementation can't do this properly
abstract override fun toString(): String
override fun getOwnDeclaredDescriptors() = getAllDescriptors()
override fun getOwnDeclaredDescriptors() = getDescriptors()
override fun printScopeStructure(p: Printer) {
p.println(javaClass.getSimpleName(), " {")
@@ -206,7 +206,7 @@ public open class LazyClassMemberScope(resolveSession: ResolveSession,
override fun computeExtraDescriptors(): Collection<DeclarationDescriptor> {
val result = ArrayList<DeclarationDescriptor>()
for (supertype in thisDescriptor.getTypeConstructor().getSupertypes()) {
for (descriptor in supertype.getMemberScope().getAllDescriptors()) {
for (descriptor in supertype.getMemberScope().getDescriptors()) {
if (descriptor is FunctionDescriptor) {
result.addAll(getFunctions(descriptor.getName()))
}
@@ -61,7 +61,7 @@ public final class JetScopeUtils {
public static Collection<CallableDescriptor> getAllExtensions(@NotNull JetScope scope) {
Set<CallableDescriptor> result = Sets.newHashSet();
for (DeclarationDescriptor descriptor : scope.getAllDescriptors()) {
for (DeclarationDescriptor descriptor : scope.getDescriptors(JetScope.DescriptorKind.EXTENSIONS, JetScope.ALL_NAME_FILTER)) {
if (descriptor instanceof CallableDescriptor) {
CallableDescriptor callDescriptor = (CallableDescriptor) descriptor;
if (callDescriptor.getExtensionReceiverParameter() != null) {
@@ -109,9 +109,9 @@ public class WritableScopeImpl(scope: JetScope,
// make sure no descriptors added to allDescriptors collection
changeLockLevel(WritableScope.LockLevel.READING)
allDescriptors.addAll(workerScope.getAllDescriptors())
allDescriptors.addAll(workerScope.getDescriptors())
for (imported in getImports()) {
allDescriptors.addAll(imported.getAllDescriptors())
allDescriptors.addAll(imported.getDescriptors())
}
}
return allDescriptors
@@ -170,10 +170,10 @@ public class WriteThroughScope(outerScope: JetScope, private val writableWorker:
if (_allDescriptors == null) {
_allDescriptors = Lists.newArrayList<DeclarationDescriptor>()
_allDescriptors!!.addAll(workerScope.getAllDescriptors())
_allDescriptors!!.addAll(workerScope.getDescriptors())
for (imported in getImports()) {
_allDescriptors!!.addAll(imported.getAllDescriptors())
_allDescriptors!!.addAll(imported.getDescriptors())
}
}
return _allDescriptors!!
@@ -282,7 +282,7 @@ public abstract class LazyJavaMemberScope(
override fun getLocalVariable(name: Name): VariableDescriptor? = null
override fun getDeclarationsByLabel(labelName: Name) = listOf<DeclarationDescriptor>()
override fun getOwnDeclaredDescriptors() = getAllDescriptors()
override fun getOwnDeclaredDescriptors() = getDescriptors()
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
nameFilter: (String) -> Boolean) = allDescriptors()
@@ -102,7 +102,7 @@ public class LazyPackageFragmentScopeForJavaPackage(
override fun getFunctions(name: Name) = deserializedPackageScope().getFunctions(name) + super.getFunctions(name)
override fun addExtraDescriptors(result: MutableSet<DeclarationDescriptor>) {
result.addAll(deserializedPackageScope().getAllDescriptors())
result.addAll(deserializedPackageScope().getDescriptors())
}
override fun computeMemberIndex(): MemberIndex = object : MemberIndex by EMPTY_MEMBER_INDEX {
@@ -77,7 +77,7 @@ public class ChainedScope(private val containingDeclaration: DeclarationDescript
if (_allDescriptors == null) {
_allDescriptors = HashSet<DeclarationDescriptor>()
for (scope in scopeChain) {
_allDescriptors!!.addAll(scope.getAllDescriptors())
_allDescriptors!!.addAll(scope.getDescriptors())
}
}
return _allDescriptors!!
@@ -17,11 +17,8 @@
package org.jetbrains.jet.lang.resolve.scopes
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
import org.jetbrains.jet.lang.descriptors.ClassifierDescriptor
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor
import org.jetbrains.jet.lang.resolve.name.Name
import java.util.Collections
public class InnerClassesScopeWrapper(override val workerScope: JetScope) : AbstractScopeAdapter() {
@@ -30,7 +27,10 @@ public class InnerClassesScopeWrapper(override val workerScope: JetScope) : Abst
override fun getDeclarationsByLabel(labelName: Name) = workerScope.getDeclarationsByLabel(labelName).filterIsInstance(javaClass<ClassDescriptor>())
override fun getDescriptors(kindFilter: (JetScope.DescriptorKind) -> Boolean,
nameFilter: (String) -> Boolean) = workerScope.getDescriptors(kindFilter, nameFilter).filterIsInstance(javaClass<ClassDescriptor>())
nameFilter: (String) -> Boolean): List<ClassDescriptor> {
if (!kindFilter(JetScope.DescriptorKind.CLASSIFIER)) return listOf()
return workerScope.getDescriptors({ it == JetScope.DescriptorKind.CLASSIFIER }, nameFilter).filterIsInstance(javaClass<ClassDescriptor>())
}
override fun getImplicitReceiversHierarchy(): List<ReceiverParameterDescriptor> = listOf()
@@ -44,7 +44,7 @@ public trait JetScope {
*
* @return All visible descriptors from current scope.
*/
public fun getAllDescriptors(): Collection<DeclarationDescriptor> = getDescriptors(DescriptorKind.ALL, {true})
public fun getAllDescriptors(): Collection<DeclarationDescriptor> = getDescriptors()
/**
* All visible descriptors from current scope possibly filtered by the given name and kind filters
@@ -90,7 +90,12 @@ public trait JetScope {
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 NON_EXTENSIONS: (DescriptorKind) -> Boolean = { it != EXTENSION_FUNCTION && it != EXTENSION_PROPERTY }
public val CLASSIFIERS: (DescriptorKind) -> Boolean = { it == CLASSIFIER }
public val PACKAGES: (DescriptorKind) -> Boolean = { it == PACKAGE }
public val VARIABLES_AND_PROPERTIES: (DescriptorKind) -> Boolean = { it == LOCAL_VARIABLE || it == NON_EXTENSION_PROPERTY || it == EXTENSION_PROPERTY }
}
}
@@ -28,7 +28,7 @@ public class SubstitutingScope(private val workerScope: JetScope, private val su
private var substitutedDescriptors: MutableMap<DeclarationDescriptor, DeclarationDescriptor?>? = null
private val _allDescriptors by Delegates.lazy { substitute(workerScope.getAllDescriptors()) }
private val _allDescriptors by Delegates.lazy { substitute(workerScope.getDescriptors()) }
private fun <D : DeclarationDescriptor> substitute(descriptor: D?): D? {
if (descriptor == null) return null
@@ -56,8 +56,9 @@ public object TipsManager{
val qualifier = context[BindingContext.QUALIFIER, receiverExpression]
if (qualifier != null) {
//TODO: filter out extensions!
// It's impossible to add extension function for package or class (if it's class object, expression type is not null)
qualifier.scope.getAllDescriptors().filterTo(descriptors, ::filterIfInfix)
qualifier.scope.getDescriptors(JetScope.DescriptorKind.NON_EXTENSIONS).filterTo(descriptors, ::filterIfInfix)
}
val expressionType = context[BindingContext.EXPRESSION_TYPE, receiverExpression]
@@ -66,7 +67,8 @@ public object TipsManager{
val dataFlowInfo = context.getDataFlowInfo(expression)
for (variant in SmartCastUtils.getSmartCastVariants(receiverValue, context, dataFlowInfo)) {
variant.getMemberScope().getAllDescriptors().filterTo(descriptors) { filterIfInfix(it) && !it.isExtension }
//TODO: filter out nested classes!
variant.getMemberScope().getDescriptors().filterTo(descriptors) { filterIfInfix(it) && !it.isExtension }
}
JetScopeUtils.getAllExtensions(resolutionScope).filterTo(descriptors) {
@@ -79,16 +81,16 @@ public object TipsManager{
}
if (parent is JetImportDirective || parent is JetPackageDirective) {
return excludeNonPackageDescriptors(resolutionScope.getAllDescriptors())
return excludeNonPackageDescriptors(resolutionScope.getDescriptors({ it == JetScope.DescriptorKind.PACKAGE }))
}
else {
val descriptorsSet = HashSet<DeclarationDescriptor>()
for (receiverDescriptor in resolutionScope.getImplicitReceiversHierarchy()) {
receiverDescriptor.getType().getMemberScope().getAllDescriptors().filterTo(descriptorsSet) { !it.isExtension }
receiverDescriptor.getType().getMemberScope().getDescriptors().filterTo(descriptorsSet) { !it.isExtension }
}
descriptorsSet.addAll(resolutionScope.getAllDescriptors())
descriptorsSet.addAll(resolutionScope.getDescriptors())
descriptorsSet.excludeNotCallableExtensions(resolutionScope, context, context.getDataFlowInfo(expression))
@@ -98,7 +100,7 @@ public object TipsManager{
public fun getPackageReferenceVariants(expression: JetSimpleNameExpression, context: BindingContext): Collection<DeclarationDescriptor> {
val resolutionScope = context[BindingContext.RESOLUTION_SCOPE, expression] ?: return listOf()
return excludeNonPackageDescriptors(resolutionScope.getAllDescriptors())
return excludeNonPackageDescriptors(resolutionScope.getDescriptors({ it == JetScope.DescriptorKind.PACKAGE }))
}
public fun excludeNotCallableExtensions(descriptors: Collection<DeclarationDescriptor>,
@@ -75,7 +75,7 @@ public abstract class BaseJetVariableMacro extends Macro {
new InjectorForMacros(project, resolveSession.getModuleDescriptor()).getExpressionTypingComponents();
List<VariableDescriptor> filteredDescriptors = new ArrayList<VariableDescriptor>();
for (DeclarationDescriptor declarationDescriptor : scope.getAllDescriptors()) {
for (DeclarationDescriptor declarationDescriptor : scope.getDescriptors(JetScope.DescriptorKind.VARIABLES_AND_PROPERTIES, JetScope.ALL_NAME_FILTER)) {
if (declarationDescriptor instanceof VariableDescriptor) {
VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor;
if (isSuitable(variableDescriptor, scope, project, components)) {
@@ -96,7 +96,7 @@ public class JetAnonymousSuperMacro extends Macro {
List<PsiNamedElement> result = new ArrayList<PsiNamedElement>();
for (DeclarationDescriptor descriptor : scope.getAllDescriptors()) {
for (DeclarationDescriptor descriptor : scope.getDescriptors(JetScope.DescriptorKind.CLASSIFIERS, JetScope.ALL_NAME_FILTER)) {
if (!(descriptor instanceof ClassDescriptor)) continue;
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
if (!classDescriptor.getModality().isOverridable()) continue;
@@ -144,7 +144,7 @@ public class ManglingUtils {
int counter = 0;
if (jetScope != null) {
Collection<DeclarationDescriptor> declarations = jetScope.getAllDescriptors();
Collection<DeclarationDescriptor> declarations = jetScope.getDescriptors(JetScope.DescriptorKind.CALLABLES, JetScope.ALL_NAME_FILTER);
List<CallableMemberDescriptor>
overloadedFunctions = ContainerUtil.mapNotNull(declarations, new Function<DeclarationDescriptor, CallableMemberDescriptor>() {
@Override