Remove member scope from scopeForMemberDeclarationResolution
This commit is contained in:
+14
-5
@@ -47,22 +47,31 @@ class ClassResolutionScopesSupport(
|
||||
}
|
||||
|
||||
private fun computeScopeForMemberDeclarationResolution(): JetScope {
|
||||
val thisScope = WritableScopeImpl(JetScope.Empty, classDescriptor, RedeclarationHandler.DO_NOTHING,
|
||||
"Scope with 'this' for " + classDescriptor.getName(), classDescriptor.getThisAsReceiverParameter(), classDescriptor)
|
||||
thisScope.changeLockLevel(WritableScope.LockLevel.READING)
|
||||
val thisScope = scopeWithThis(classDescriptor)
|
||||
|
||||
return ChainedScope(
|
||||
classDescriptor,
|
||||
"ScopeForMemberDeclarationResolution: " + classDescriptor.getName(),
|
||||
thisScope,
|
||||
classDescriptor.getUnsubstitutedMemberScope(),
|
||||
classDescriptor.unsubstitutedInnerClassesScope,
|
||||
getScopeForClassHeaderResolution(),
|
||||
getCompanionObjectScope(),
|
||||
classDescriptor.getStaticScope())
|
||||
}
|
||||
|
||||
private fun scopeWithThis(descriptor: ClassDescriptor): WritableScopeImpl {
|
||||
val thisScope = WritableScopeImpl(JetScope.Empty, descriptor, RedeclarationHandler.DO_NOTHING,
|
||||
"Scope with 'this' for " + descriptor.getName(), descriptor.getThisAsReceiverParameter(), descriptor)
|
||||
thisScope.changeLockLevel(WritableScope.LockLevel.READING)
|
||||
return thisScope
|
||||
}
|
||||
|
||||
private fun getCompanionObjectScope(): JetScope {
|
||||
val companionObjectDescriptor = classDescriptor.getCompanionObjectDescriptor()
|
||||
return if ((companionObjectDescriptor != null)) CompanionObjectMixinScope(companionObjectDescriptor) else JetScope.Empty
|
||||
return if (companionObjectDescriptor != null) {
|
||||
ChainedScope(companionObjectDescriptor, "Companion object scope for class: ${classDescriptor.getName()}",
|
||||
scopeWithThis(companionObjectDescriptor), companionObjectDescriptor.unsubstitutedInnerClassesScope)
|
||||
}
|
||||
else JetScope.Empty
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.resolve.scopes
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
|
||||
/**
|
||||
* Members of the companion object are accessible from the class.
|
||||
* Scope lazily delegates requests to companion object scope.
|
||||
*/
|
||||
public class CompanionObjectMixinScope(private val companionObjectDescriptor: ClassDescriptor) : AbstractScopeAdapter() {
|
||||
override val workerScope: JetScope
|
||||
get() = companionObjectDescriptor.getDefaultType().getMemberScope()
|
||||
|
||||
override fun getImplicitReceiversHierarchy() = listOf(companionObjectDescriptor.getThisAsReceiverParameter())
|
||||
}
|
||||
@@ -133,7 +133,8 @@ private fun getPackageInnerScope(descriptor: PackageFragmentDescriptor): JetScop
|
||||
private fun getClassInnerScope(outerScope: JetScope, descriptor: ClassDescriptor): JetScope {
|
||||
val redeclarationHandler = RedeclarationHandler.DO_NOTHING
|
||||
|
||||
val headerScope = WritableScopeImpl(outerScope, descriptor, redeclarationHandler, "Class ${descriptor.getName()} header scope")
|
||||
val headerScope = WritableScopeImpl(outerScope, descriptor, redeclarationHandler, "Class ${descriptor.getName()} header scope",
|
||||
descriptor.thisAsReceiverParameter)
|
||||
for (typeParameter in descriptor.getTypeConstructor().getParameters()) {
|
||||
headerScope.addClassifierDescriptor(typeParameter)
|
||||
}
|
||||
@@ -154,9 +155,6 @@ public fun getResolutionScope(resolutionFacade: ResolutionFacade, descriptor: De
|
||||
is PackageViewDescriptor ->
|
||||
descriptor.memberScope
|
||||
|
||||
is ClassDescriptorWithResolutionScopes ->
|
||||
descriptor.getScopeForMemberDeclarationResolution()
|
||||
|
||||
is ClassDescriptor ->
|
||||
getClassInnerScope(getOuterScope(descriptor, resolutionFacade), descriptor)
|
||||
|
||||
|
||||
@@ -27,10 +27,12 @@ import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiNamedElement;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.analyzer.AnalysisResult;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor;
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
|
||||
import org.jetbrains.kotlin.idea.core.IterableTypesDetector;
|
||||
@@ -42,10 +44,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilPackage.getDataFlowInfo;
|
||||
|
||||
@@ -76,7 +75,7 @@ public abstract class BaseJetVariableMacro extends Macro {
|
||||
DataFlowInfo dataFlowInfo = getDataFlowInfo(bindingContext, contextExpression);
|
||||
|
||||
List<VariableDescriptor> filteredDescriptors = new ArrayList<VariableDescriptor>();
|
||||
for (DeclarationDescriptor declarationDescriptor : scope.getDescriptors(DescriptorKindFilter.VARIABLES, JetScope.ALL_NAME_FILTER)) {
|
||||
for (DeclarationDescriptor declarationDescriptor : getAllVariables(scope)) {
|
||||
if (declarationDescriptor instanceof VariableDescriptor) {
|
||||
VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor;
|
||||
|
||||
@@ -106,6 +105,15 @@ public abstract class BaseJetVariableMacro extends Macro {
|
||||
return declarations.toArray(new JetNamedDeclaration[declarations.size()]);
|
||||
}
|
||||
|
||||
private static Collection<DeclarationDescriptor> getAllVariables(JetScope scope) {
|
||||
Collection<DeclarationDescriptor> result = ContainerUtil.newArrayList();
|
||||
result.addAll(scope.getDescriptors(DescriptorKindFilter.VARIABLES, JetScope.ALL_NAME_FILTER));
|
||||
for (ReceiverParameterDescriptor implicitReceiver : scope.getImplicitReceiversHierarchy()) {
|
||||
result.addAll(implicitReceiver.getType().getMemberScope().getDescriptors(DescriptorKindFilter.VARIABLES, JetScope.ALL_NAME_FILTER));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
protected abstract boolean isSuitable(
|
||||
@NotNull VariableDescriptor variableDescriptor,
|
||||
@NotNull Project project,
|
||||
|
||||
Reference in New Issue
Block a user