diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt index 6a0ea715837..1215e796203 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/lazy/descriptors/ClassResolutionScopesSupport.kt @@ -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 } } \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/DefaultObjectMixinScope.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/DefaultObjectMixinScope.kt deleted file mode 100644 index 63503b9af2b..00000000000 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/scopes/DefaultObjectMixinScope.kt +++ /dev/null @@ -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()) -} diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt index 86193674c8f..3168e0aaa4c 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/kdoc/KDocReference.kt @@ -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) diff --git a/idea/src/org/jetbrains/kotlin/idea/liveTemplates/macro/BaseJetVariableMacro.java b/idea/src/org/jetbrains/kotlin/idea/liveTemplates/macro/BaseJetVariableMacro.java index 96ec7ac5bf4..a9d6a363b8d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/liveTemplates/macro/BaseJetVariableMacro.java +++ b/idea/src/org/jetbrains/kotlin/idea/liveTemplates/macro/BaseJetVariableMacro.java @@ -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 filteredDescriptors = new ArrayList(); - 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 getAllVariables(JetScope scope) { + Collection 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,