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.name.Name;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -224,7 +223,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull final MutableClassDescriptorLite classObjectDescriptor) {
|
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||||
ClassObjectStatus r = superBuilder.setClassObjectDescriptor(classObjectDescriptor);
|
ClassObjectStatus r = superBuilder.setClassObjectDescriptor(classObjectDescriptor);
|
||||||
if (r != ClassObjectStatus.OK) {
|
if (r != ClassObjectStatus.OK) {
|
||||||
return r;
|
return r;
|
||||||
@@ -232,19 +231,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
|
|||||||
|
|
||||||
// Members of the class object are accessible from the class
|
// Members of the class object are accessible from the class
|
||||||
// The scope must be lazy, because classObjectDescriptor may not by fully built yet
|
// The scope must be lazy, because classObjectDescriptor may not by fully built yet
|
||||||
scopeForMemberResolution.importScope(new AbstractScopeAdapter() {
|
scopeForMemberResolution.importScope(new ClassObjectMixinScope(classObjectDescriptor));
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
protected JetScope getWorkerScope() {
|
|
||||||
return classObjectDescriptor.getDefaultType().getMemberScope();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
|
|
||||||
return Collections.singletonList(classObjectDescriptor.getThisAsReceiverParameter());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return ClassObjectStatus.OK;
|
return ClassObjectStatus.OK;
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -206,12 +206,16 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
|||||||
thisScope.addLabeledDeclaration(this);
|
thisScope.addLabeledDeclaration(this);
|
||||||
thisScope.changeLockLevel(WritableScope.LockLevel.READING);
|
thisScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||||
|
|
||||||
|
ClassDescriptor classObject = getClassObjectDescriptor();
|
||||||
|
JetScope classObjectAdapterScope = (classObject != null) ? new ClassObjectMixinScope(classObject) : JetScope.EMPTY;
|
||||||
|
|
||||||
return new ChainedScope(
|
return new ChainedScope(
|
||||||
this,
|
this,
|
||||||
"ScopeForMemberDeclarationResolution: " + getName(),
|
"ScopeForMemberDeclarationResolution: " + getName(),
|
||||||
thisScope,
|
thisScope,
|
||||||
getScopeForMemberLookup(),
|
getScopeForMemberLookup(),
|
||||||
getScopeForClassHeaderResolution());
|
getScopeForClassHeaderResolution(),
|
||||||
|
classObjectAdapterScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class ConstructorTypeParamClassObjectTypeConflict<test> {
|
||||||
|
class object {
|
||||||
|
trait test
|
||||||
|
}
|
||||||
|
|
||||||
|
val some: test? = null
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConstructorTypeParamClassObjectConflict<test> {
|
||||||
|
class object {
|
||||||
|
val test = 12
|
||||||
|
}
|
||||||
|
|
||||||
|
val some = test
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestConstructorParamClassObjectConflict(test: String) {
|
||||||
|
class object {
|
||||||
|
val test = 12
|
||||||
|
}
|
||||||
|
|
||||||
|
val some = test
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class TestConstructorValClassObjectConflict(val test: String) {
|
||||||
|
class object {
|
||||||
|
val test = 12
|
||||||
|
}
|
||||||
|
|
||||||
|
val some = test
|
||||||
|
}
|
||||||
|
|
||||||
|
class TestClassObjectAndClassConflict {
|
||||||
|
class object {
|
||||||
|
val bla = 12
|
||||||
|
}
|
||||||
|
|
||||||
|
val bla = "More"
|
||||||
|
|
||||||
|
val some = bla
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
internal final class ConstructorTypeParamClassObjectConflict</*0*/ test> {
|
||||||
|
/*primary*/ public constructor ConstructorTypeParamClassObjectConflict</*0*/ test>()
|
||||||
|
internal final val some: jet.Int
|
||||||
|
internal final fun <get-some>(): jet.Int
|
||||||
|
|
||||||
|
internal class object <class-object-for-ConstructorTypeParamClassObjectConflict> {
|
||||||
|
/*primary*/ private constructor <class-object-for-ConstructorTypeParamClassObjectConflict>()
|
||||||
|
internal final val test: jet.Int
|
||||||
|
internal final fun <get-test>(): jet.Int
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal final class ConstructorTypeParamClassObjectTypeConflict</*0*/ test> {
|
||||||
|
/*primary*/ public constructor ConstructorTypeParamClassObjectTypeConflict</*0*/ test>()
|
||||||
|
internal final val some: test?
|
||||||
|
internal final fun <get-some>(): test?
|
||||||
|
|
||||||
|
internal class object <class-object-for-ConstructorTypeParamClassObjectTypeConflict> {
|
||||||
|
/*primary*/ private constructor <class-object-for-ConstructorTypeParamClassObjectTypeConflict>()
|
||||||
|
|
||||||
|
internal trait test {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal final class TestClassObjectAndClassConflict {
|
||||||
|
/*primary*/ public constructor TestClassObjectAndClassConflict()
|
||||||
|
internal final val bla: jet.String
|
||||||
|
internal final fun <get-bla>(): jet.String
|
||||||
|
internal final val some: jet.String
|
||||||
|
internal final fun <get-some>(): jet.String
|
||||||
|
|
||||||
|
internal class object <class-object-for-TestClassObjectAndClassConflict> {
|
||||||
|
/*primary*/ private constructor <class-object-for-TestClassObjectAndClassConflict>()
|
||||||
|
internal final val bla: jet.Int
|
||||||
|
internal final fun <get-bla>(): jet.Int
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal final class TestConstructorParamClassObjectConflict {
|
||||||
|
/*primary*/ public constructor TestConstructorParamClassObjectConflict(/*0*/ test: jet.String)
|
||||||
|
internal final val some: jet.String
|
||||||
|
internal final fun <get-some>(): jet.String
|
||||||
|
|
||||||
|
internal class object <class-object-for-TestConstructorParamClassObjectConflict> {
|
||||||
|
/*primary*/ private constructor <class-object-for-TestConstructorParamClassObjectConflict>()
|
||||||
|
internal final val test: jet.Int
|
||||||
|
internal final fun <get-test>(): jet.Int
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal final class TestConstructorValClassObjectConflict {
|
||||||
|
/*primary*/ public constructor TestConstructorValClassObjectConflict(/*0*/ test: jet.String)
|
||||||
|
internal final val some: jet.String
|
||||||
|
internal final fun <get-some>(): jet.String
|
||||||
|
internal final val test: jet.String
|
||||||
|
internal final fun <get-test>(): jet.String
|
||||||
|
|
||||||
|
internal class object <class-object-for-TestConstructorValClassObjectConflict> {
|
||||||
|
/*primary*/ private constructor <class-object-for-TestConstructorValClassObjectConflict>()
|
||||||
|
internal final val test: jet.Int
|
||||||
|
internal final fun <get-test>(): jet.Int
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
class A {
|
||||||
|
class object {
|
||||||
|
val some = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
val other = some
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
internal final class A {
|
||||||
|
/*primary*/ public constructor A()
|
||||||
|
internal final val other: jet.Int
|
||||||
|
internal final fun <get-other>(): jet.Int
|
||||||
|
|
||||||
|
internal class object <class-object-for-A> {
|
||||||
|
/*primary*/ private constructor <class-object-for-A>()
|
||||||
|
internal final val some: jet.Int
|
||||||
|
internal final fun <get-some>(): jet.Int
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -58,6 +58,11 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
|||||||
doTestWithAccessors("compiler/testData/loadKotlin/class/ClassInnerClass.kt");
|
doTestWithAccessors("compiler/testData/loadKotlin/class/ClassInnerClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ClassMemberConflict.kt")
|
||||||
|
public void testClassMemberConflict() throws Exception {
|
||||||
|
doTestWithAccessors("compiler/testData/loadKotlin/class/ClassMemberConflict.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ClassOutParam.kt")
|
@TestMetadata("ClassOutParam.kt")
|
||||||
public void testClassOutParam() throws Exception {
|
public void testClassOutParam() throws Exception {
|
||||||
doTestWithAccessors("compiler/testData/loadKotlin/class/ClassOutParam.kt");
|
doTestWithAccessors("compiler/testData/loadKotlin/class/ClassOutParam.kt");
|
||||||
@@ -259,6 +264,11 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT
|
|||||||
doTestWithAccessors("compiler/testData/loadKotlin/classObject/ClassObjectExtendsTraitWithTP.kt");
|
doTestWithAccessors("compiler/testData/loadKotlin/classObject/ClassObjectExtendsTraitWithTP.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ClassObjectPropertyInClass.kt")
|
||||||
|
public void testClassObjectPropertyInClass() throws Exception {
|
||||||
|
doTestWithAccessors("compiler/testData/loadKotlin/classObject/ClassObjectPropertyInClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("InnerClassInClassObject.kt")
|
@TestMetadata("InnerClassInClassObject.kt")
|
||||||
public void testInnerClassInClassObject() throws Exception {
|
public void testInnerClassInClassObject() throws Exception {
|
||||||
doTestWithAccessors("compiler/testData/loadKotlin/classObject/InnerClassInClassObject.kt");
|
doTestWithAccessors("compiler/testData/loadKotlin/classObject/InnerClassInClassObject.kt");
|
||||||
|
|||||||
+10
@@ -60,6 +60,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
|||||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/class/ClassInnerClass.kt");
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/class/ClassInnerClass.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ClassMemberConflict.kt")
|
||||||
|
public void testClassMemberConflict() throws Exception {
|
||||||
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/class/ClassMemberConflict.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ClassOutParam.kt")
|
@TestMetadata("ClassOutParam.kt")
|
||||||
public void testClassOutParam() throws Exception {
|
public void testClassOutParam() throws Exception {
|
||||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/class/ClassOutParam.kt");
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/class/ClassOutParam.kt");
|
||||||
@@ -261,6 +266,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso
|
|||||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/classObject/ClassObjectExtendsTraitWithTP.kt");
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/classObject/ClassObjectExtendsTraitWithTP.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ClassObjectPropertyInClass.kt")
|
||||||
|
public void testClassObjectPropertyInClass() throws Exception {
|
||||||
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/classObject/ClassObjectPropertyInClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("InnerClassInClassObject.kt")
|
@TestMetadata("InnerClassInClassObject.kt")
|
||||||
public void testInnerClassInClassObject() throws Exception {
|
public void testInnerClassInClassObject() throws Exception {
|
||||||
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/classObject/InnerClassInClassObject.kt");
|
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadKotlin/classObject/InnerClassInClassObject.kt");
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
class Some {
|
||||||
|
class object {
|
||||||
|
val coProp = 12
|
||||||
|
|
||||||
|
fun coFun = 12
|
||||||
|
}
|
||||||
|
|
||||||
|
fun some() {
|
||||||
|
val a = co<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EXIST: coProp, coFun
|
||||||
@@ -79,6 +79,11 @@ public class JetBasicJSCompletionTestGenerated extends AbstractJetJSCompletionTe
|
|||||||
doTest("idea/testData/completion/basic/common/CallLocalLambda.kt");
|
doTest("idea/testData/completion/basic/common/CallLocalLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("classObjectElementsInClass.kt")
|
||||||
|
public void testClassObjectElementsInClass() throws Exception {
|
||||||
|
doTest("idea/testData/completion/basic/common/classObjectElementsInClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ClassRedeclaration1.kt")
|
@TestMetadata("ClassRedeclaration1.kt")
|
||||||
public void testClassRedeclaration1() throws Exception {
|
public void testClassRedeclaration1() throws Exception {
|
||||||
doTest("idea/testData/completion/basic/common/ClassRedeclaration1.kt");
|
doTest("idea/testData/completion/basic/common/ClassRedeclaration1.kt");
|
||||||
|
|||||||
@@ -79,6 +79,11 @@ public class JetBasicJavaCompletionTestGenerated extends AbstractJavaCompletionT
|
|||||||
doTest("idea/testData/completion/basic/common/CallLocalLambda.kt");
|
doTest("idea/testData/completion/basic/common/CallLocalLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("classObjectElementsInClass.kt")
|
||||||
|
public void testClassObjectElementsInClass() throws Exception {
|
||||||
|
doTest("idea/testData/completion/basic/common/classObjectElementsInClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("ClassRedeclaration1.kt")
|
@TestMetadata("ClassRedeclaration1.kt")
|
||||||
public void testClassRedeclaration1() throws Exception {
|
public void testClassRedeclaration1() throws Exception {
|
||||||
doTest("idea/testData/completion/basic/common/ClassRedeclaration1.kt");
|
doTest("idea/testData/completion/basic/common/ClassRedeclaration1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user