Mix class object scope to member resolution scope in lazy resolve
This commit is contained in:
+2
-15
@@ -26,7 +26,6 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -224,7 +223,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull final MutableClassDescriptorLite classObjectDescriptor) {
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
ClassObjectStatus r = superBuilder.setClassObjectDescriptor(classObjectDescriptor);
|
||||
if (r != ClassObjectStatus.OK) {
|
||||
return r;
|
||||
@@ -232,19 +231,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
|
||||
|
||||
// Members of the class object are accessible from the class
|
||||
// The scope must be lazy, because classObjectDescriptor may not by fully built yet
|
||||
scopeForMemberResolution.importScope(new AbstractScopeAdapter() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected JetScope getWorkerScope() {
|
||||
return classObjectDescriptor.getDefaultType().getMemberScope();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
|
||||
return Collections.singletonList(classObjectDescriptor.getThisAsReceiverParameter());
|
||||
}
|
||||
});
|
||||
scopeForMemberResolution.importScope(new ClassObjectMixinScope(classObjectDescriptor));
|
||||
|
||||
return ClassObjectStatus.OK;
|
||||
}
|
||||
|
||||
+5
-1
@@ -206,12 +206,16 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
thisScope.addLabeledDeclaration(this);
|
||||
thisScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
ClassDescriptor classObject = getClassObjectDescriptor();
|
||||
JetScope classObjectAdapterScope = (classObject != null) ? new ClassObjectMixinScope(classObject) : JetScope.EMPTY;
|
||||
|
||||
return new ChainedScope(
|
||||
this,
|
||||
"ScopeForMemberDeclarationResolution: " + getName(),
|
||||
thisScope,
|
||||
getScopeForMemberLookup(),
|
||||
getScopeForClassHeaderResolution());
|
||||
getScopeForClassHeaderResolution(),
|
||||
classObjectAdapterScope);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.jet.lang.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Members of the class object are accessible from the class.
|
||||
* Scope lazily delegates requests to class object scope.
|
||||
*/
|
||||
public class ClassObjectMixinScope extends AbstractScopeAdapter {
|
||||
private final ClassDescriptor classObjectDescriptor;
|
||||
|
||||
public ClassObjectMixinScope(ClassDescriptor classObjectDescriptor) {
|
||||
this.classObjectDescriptor = classObjectDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JetScope getWorkerScope() {
|
||||
return classObjectDescriptor.getDefaultType().getMemberScope();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
|
||||
return Collections.singletonList(classObjectDescriptor.getThisAsReceiverParameter());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user