Allow resolve class declarations in class objects
Use INACCESSIBLE_OUTER_CLASS_EXPRESSION error for marking already resolved elements #KT-3261 Fixed
This commit is contained in:
@@ -28,10 +28,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WriteThroughScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.SubstitutionUtils;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
@@ -147,40 +144,6 @@ public class TypeHierarchyResolver {
|
||||
checkTypesInClassHeaders(); // Check bounds in the types used in generic bounds and supertype lists
|
||||
}
|
||||
|
||||
/**
|
||||
* Use nearest class object scope or namespace scope
|
||||
*
|
||||
* @param declarationElement
|
||||
* @param owner
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("SuspiciousMethodCalls")
|
||||
@NotNull
|
||||
private JetScope getStaticScope(PsiElement declarationElement, @NotNull NamespaceLikeBuilder owner) {
|
||||
DeclarationDescriptor ownerDescriptor = owner.getOwnerForChildren();
|
||||
if (ownerDescriptor instanceof NamespaceDescriptorImpl) {
|
||||
return context.getNamespaceScopes().get(declarationElement.getContainingFile());
|
||||
}
|
||||
|
||||
if (ownerDescriptor instanceof MutableClassDescriptor) {
|
||||
MutableClassDescriptor classDescriptor = (MutableClassDescriptor) ownerDescriptor;
|
||||
if (classDescriptor.getKind() == ClassKind.CLASS_OBJECT) {
|
||||
return classDescriptor.getScopeForMemberResolution();
|
||||
}
|
||||
|
||||
DeclarationDescriptor declaration = classDescriptor.getContainingDeclaration();
|
||||
if (declaration instanceof NamespaceDescriptorImpl) {
|
||||
return getStaticScope(declarationElement, ((NamespaceDescriptorImpl) declaration).getBuilder());
|
||||
}
|
||||
|
||||
if (declaration instanceof MutableClassDescriptorLite) {
|
||||
return getStaticScope(declarationElement, ((MutableClassDescriptorLite) declaration).getBuilder());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Collection<JetDeclarationContainer> collectNamespacesAndClassifiers(
|
||||
@NotNull JetScope outerScope,
|
||||
@@ -517,7 +480,7 @@ public class TypeHierarchyResolver {
|
||||
MutableClassDescriptorLite classObjectDescriptor = ownerClassDescriptor.getClassObjectDescriptor();
|
||||
|
||||
assert classObjectDescriptor != null : enumEntry.getParent().getText();
|
||||
createClassDescriptorForEnumEntry(enumEntry, classObjectDescriptor.getBuilder());
|
||||
createClassDescriptorForEnumEntry(enumEntry, classObjectDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -530,9 +493,11 @@ public class TypeHierarchyResolver {
|
||||
JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration();
|
||||
if (objectDeclaration != null) {
|
||||
Name classObjectName = getClassObjectName(owner.getOwnerForChildren().getName());
|
||||
MutableClassDescriptor classObjectDescriptor =
|
||||
createClassDescriptorForObject(objectDeclaration, owner, getStaticScope(classObject, owner),
|
||||
classObjectName, ClassKind.CLASS_OBJECT);
|
||||
|
||||
MutableClassDescriptor classObjectDescriptor = createClassDescriptorForObject(
|
||||
objectDeclaration, owner, outerScope,
|
||||
classObjectName, ClassKind.CLASS_OBJECT);
|
||||
|
||||
NamespaceLikeBuilder.ClassObjectStatus status = owner.setClassObjectDescriptor(classObjectDescriptor);
|
||||
switch (status) {
|
||||
case DUPLICATE:
|
||||
@@ -606,6 +571,7 @@ public class TypeHierarchyResolver {
|
||||
) {
|
||||
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(
|
||||
owner.getOwnerForChildren(), scope, kind, false, name);
|
||||
|
||||
context.getObjects().put(declaration, mutableClassDescriptor);
|
||||
|
||||
JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution();
|
||||
@@ -619,10 +585,13 @@ public class TypeHierarchyResolver {
|
||||
|
||||
private MutableClassDescriptor createClassDescriptorForEnumEntry(
|
||||
@NotNull JetEnumEntry declaration,
|
||||
@NotNull NamespaceLikeBuilder owner
|
||||
@NotNull MutableClassDescriptorLite classObjectDescriptor
|
||||
) {
|
||||
NamespaceLikeBuilder owner = classObjectDescriptor.getBuilder();
|
||||
MutableClassDescriptor mutableClassObjectDescriptor = (MutableClassDescriptor) classObjectDescriptor;
|
||||
|
||||
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(
|
||||
owner.getOwnerForChildren(), getStaticScope(declaration, owner), ClassKind.ENUM_ENTRY,
|
||||
owner.getOwnerForChildren(), mutableClassObjectDescriptor.getScopeForMemberResolution(), ClassKind.ENUM_ENTRY,
|
||||
false, JetPsiUtil.safeName(declaration.getName()));
|
||||
context.getClasses().put(declaration, mutableClassDescriptor);
|
||||
|
||||
|
||||
@@ -165,8 +165,7 @@ public class ScopeProvider {
|
||||
LazyClassDescriptor classObjectDescriptor =
|
||||
(LazyClassDescriptor) resolveSession.getClassObjectDescriptor(classObject).getContainingDeclaration();
|
||||
|
||||
// During class object header resolve there should be no resolution for parent class generic params
|
||||
return new InnerClassesScopeWrapper(classObjectDescriptor.getScopeForMemberDeclarationResolution());
|
||||
return classObjectDescriptor.getScopeForMemberDeclarationResolution();
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Don't call this method for local declarations: " + jetDeclaration + " " + jetDeclaration.getText());
|
||||
|
||||
Reference in New Issue
Block a user