Change object resolution strategy in lazy resolve
This commit is contained in:
+110
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.lazy.data;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyClassDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class SyntheticClassObjectInfo implements JetClassLikeInfo {
|
||||
private final JetClassLikeInfo classInfo;
|
||||
private final LazyClassDescriptor classDescriptor;
|
||||
|
||||
public SyntheticClassObjectInfo(@NotNull JetClassLikeInfo classInfo, @NotNull LazyClassDescriptor classDescriptor) {
|
||||
this.classInfo = classInfo;
|
||||
this.classDescriptor = classDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public LazyClassDescriptor getClassDescriptor() {
|
||||
return classDescriptor;
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FqName getContainingPackageFqName() {
|
||||
return classInfo.getContainingPackageFqName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetDelegationSpecifier> getDelegationSpecifiers() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JetModifierList getModifierList() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JetClassObject getClassObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiElement getScopeAnchor() {
|
||||
return classInfo.getScopeAnchor();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JetClassOrObject getCorrespondingClassOrObject() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetTypeParameter> getTypeParameters() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends JetParameter> getPrimaryConstructorParameters() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassKind getClassKind() {
|
||||
return ClassKind.CLASS_OBJECT;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetDeclaration> getDeclarations() {
|
||||
// There can be no declarations in a synthetic class object, all its members are fake overrides
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "class object of " + classInfo;
|
||||
}
|
||||
}
|
||||
+7
-13
@@ -198,10 +198,10 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
resolveSession.getInjector().getAnnotationResolver().resolveAnnotationsArguments(propertyDescriptor, resolveSession.getTrace(), resolutionScope);
|
||||
}
|
||||
|
||||
// Objects are also properties
|
||||
// Enum entries are also properties
|
||||
Collection<JetClassOrObject> classOrObjectDeclarations = declarationProvider.getClassOrObjectDeclarations(name);
|
||||
for (JetClassOrObject classOrObjectDeclaration : classOrObjectDeclarations) {
|
||||
if (declaresObjectOrEnumConstant(classOrObjectDeclaration)) {
|
||||
if (classOrObjectDeclaration instanceof JetEnumEntry) {
|
||||
ClassDescriptor classifier = getObjectDescriptor(name);
|
||||
if (classifier == null) {
|
||||
throw new IllegalStateException("Object declaration " + name + " found in the DeclarationProvider " + declarationProvider + " but not in the scope " + this);
|
||||
@@ -259,25 +259,19 @@ public abstract class AbstractLazyMemberScope<D extends DeclarationDescriptor, D
|
||||
if (declaration instanceof JetEnumEntry) {
|
||||
JetEnumEntry jetEnumEntry = (JetEnumEntry) declaration;
|
||||
Name name = safeNameForLazyResolve(jetEnumEntry);
|
||||
if (name != null) {
|
||||
result.all.addAll(getProperties(name));
|
||||
result.objects.add(getObjectDescriptor(name));
|
||||
}
|
||||
result.all.addAll(getProperties(name));
|
||||
result.objects.add(getObjectDescriptor(name));
|
||||
}
|
||||
else if (declaration instanceof JetObjectDeclaration) {
|
||||
JetObjectDeclaration objectDeclaration = (JetObjectDeclaration) declaration;
|
||||
Name name = safeNameForLazyResolve(objectDeclaration.getNameAsDeclaration());
|
||||
if (name != null) {
|
||||
result.all.addAll(getProperties(name));
|
||||
result.objects.add(getObjectDescriptor(name));
|
||||
}
|
||||
result.all.addAll(getProperties(name));
|
||||
result.objects.add(getObjectDescriptor(name));
|
||||
}
|
||||
else if (declaration instanceof JetClassOrObject) {
|
||||
JetClassOrObject classOrObject = (JetClassOrObject) declaration;
|
||||
Name name = safeNameForLazyResolve(classOrObject.getNameAsName());
|
||||
if (name != null) {
|
||||
result.all.addAll(classDescriptors.invoke(name));
|
||||
}
|
||||
result.all.addAll(classDescriptors.invoke(name));
|
||||
}
|
||||
else if (declaration instanceof JetFunction) {
|
||||
JetFunction function = (JetFunction) declaration;
|
||||
|
||||
+33
-24
@@ -40,6 +40,7 @@ import org.jetbrains.jet.lang.resolve.lazy.ScopeProvider;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.data.FilteringClassLikeInfo;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassInfoUtil;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.data.SyntheticClassObjectInfo;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.declarations.ClassMemberDeclarationProvider;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
@@ -52,7 +53,7 @@ import org.jetbrains.jet.storage.StorageManager;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isEnumClassObject;
|
||||
import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isSyntheticClassObject;
|
||||
import static org.jetbrains.jet.lang.resolve.ModifiersChecker.*;
|
||||
import static org.jetbrains.jet.lang.resolve.name.SpecialNames.getClassObjectName;
|
||||
|
||||
@@ -99,8 +100,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
}
|
||||
|
||||
this.originalClassInfo = classLikeInfo;
|
||||
JetClassLikeInfo classLikeInfoForMembers =
|
||||
classLikeInfo.getClassKind() != ClassKind.ENUM_CLASS ? classLikeInfo : noEnumEntries(classLikeInfo);
|
||||
JetClassLikeInfo classLikeInfoForMembers = classLikeInfo.getClassKind() != ClassKind.ENUM_CLASS ? classLikeInfo : noEnumEntries();
|
||||
this.declarationProvider =
|
||||
resolveSession.getDeclarationProviderFactory().getClassMemberDeclarationProvider(classLikeInfoForMembers);
|
||||
|
||||
@@ -118,7 +118,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
Modality defaultModality = kind == ClassKind.TRAIT ? Modality.ABSTRACT : Modality.FINAL;
|
||||
this.modality = resolveModalityFromModifiers(modifierList, defaultModality);
|
||||
}
|
||||
this.visibility = isEnumClassObject(this)
|
||||
this.visibility = isSyntheticClassObject(this)
|
||||
? DescriptorUtils.getSyntheticClassObjectVisibility()
|
||||
: resolveVisibilityFromModifiers(modifierList, getDefaultClassVisibility(this));
|
||||
this.isInner = isInnerClass(modifierList);
|
||||
@@ -271,11 +271,12 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
return JetClassInfoUtil.createClassLikeInfo(objectDeclaration);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (getKind() == ClassKind.ENUM_CLASS) {
|
||||
// Enum classes always have class objects, and enum constants are their members
|
||||
return enumClassObjectInfo(originalClassInfo);
|
||||
}
|
||||
else if (getKind() == ClassKind.OBJECT) {
|
||||
return new SyntheticClassObjectInfo(originalClassInfo, this);
|
||||
}
|
||||
else if (getKind() == ClassKind.ENUM_CLASS) {
|
||||
// Enum classes always have class objects, and enum constants are their members
|
||||
return enumClassObjectInfo();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -358,20 +359,25 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
if (resolveSession.isClassSpecial(DescriptorUtils.getFQName(LazyClassDescriptor.this))) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
else {
|
||||
JetClassOrObject classOrObject = declarationProvider.getOwnerInfo().getCorrespondingClassOrObject();
|
||||
if (classOrObject == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
else {
|
||||
List<JetType> allSupertypes = resolveSession.getInjector().getDescriptorResolver()
|
||||
.resolveSupertypes(getScopeForClassHeaderResolution(),
|
||||
LazyClassDescriptor.this, classOrObject,
|
||||
resolveSession.getTrace());
|
||||
|
||||
return Lists.newArrayList(Collections2.filter(allSupertypes, VALID_SUPERTYPE));
|
||||
JetClassLikeInfo info = declarationProvider.getOwnerInfo();
|
||||
if (info instanceof SyntheticClassObjectInfo) {
|
||||
LazyClassDescriptor descriptor = ((SyntheticClassObjectInfo) info).getClassDescriptor();
|
||||
if (descriptor.getKind().isSingleton()) {
|
||||
return Collections.singleton(descriptor.getDefaultType());
|
||||
}
|
||||
}
|
||||
|
||||
JetClassOrObject classOrObject = info.getCorrespondingClassOrObject();
|
||||
if (classOrObject == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<JetType> allSupertypes = resolveSession.getInjector().getDescriptorResolver()
|
||||
.resolveSupertypes(getScopeForClassHeaderResolution(), LazyClassDescriptor.this, classOrObject,
|
||||
resolveSession.getTrace());
|
||||
|
||||
return Lists.newArrayList(Collections2.filter(allSupertypes, VALID_SUPERTYPE));
|
||||
}
|
||||
},
|
||||
new Function1<Boolean, Collection<JetType>>() {
|
||||
@@ -472,12 +478,14 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
}
|
||||
}
|
||||
|
||||
private JetClassLikeInfo noEnumEntries(JetClassLikeInfo classLikeInfo) {
|
||||
return new FilteringClassLikeInfo(resolveSession.getStorageManager(), classLikeInfo, Predicates.not(ONLY_ENUM_ENTRIES));
|
||||
@NotNull
|
||||
private JetClassLikeInfo noEnumEntries() {
|
||||
return new FilteringClassLikeInfo(resolveSession.getStorageManager(), originalClassInfo, Predicates.not(ONLY_ENUM_ENTRIES));
|
||||
}
|
||||
|
||||
private JetClassLikeInfo enumClassObjectInfo(JetClassLikeInfo classLikeInfo) {
|
||||
return new FilteringClassLikeInfo(resolveSession.getStorageManager(), classLikeInfo, ONLY_ENUM_ENTRIES) {
|
||||
@NotNull
|
||||
private JetClassLikeInfo enumClassObjectInfo() {
|
||||
return new FilteringClassLikeInfo(resolveSession.getStorageManager(), originalClassInfo, ONLY_ENUM_ENTRIES) {
|
||||
@Override
|
||||
public JetClassOrObject getCorrespondingClassOrObject() {
|
||||
return null;
|
||||
@@ -503,6 +511,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ScopeProvider getScopeProvider() {
|
||||
return resolveSession.getInjector().getScopeProvider();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package test
|
||||
|
||||
test.A(a = 12.toInt(): jet.Int, c = "Hello": jet.String) internal val SomeObject: test.SomeObject
|
||||
|
||||
internal final annotation class A : jet.Annotation {
|
||||
/*primary*/ public constructor A(/*0*/ a: jet.Int = ..., /*1*/ b: jet.String = ..., /*2*/ c: jet.String)
|
||||
internal final val a: jet.Int
|
||||
@@ -11,4 +9,8 @@ internal final annotation class A : jet.Annotation {
|
||||
|
||||
test.A(a = 12.toInt(): jet.Int, c = "Hello": jet.String) internal object SomeObject {
|
||||
/*primary*/ private constructor SomeObject()
|
||||
|
||||
public class object <class-object-for-SomeObject> : test.SomeObject {
|
||||
/*primary*/ private constructor <class-object-for-SomeObject>()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package test
|
||||
|
||||
[ERROR : Unresolved annotation type: BadAnnotation]() internal val SomeObject: test.SomeObject
|
||||
internal val some: test.SomeObject
|
||||
|
||||
[ERROR : Unresolved annotation type: BadAnnotation]() internal object SomeObject {
|
||||
/*primary*/ private constructor SomeObject()
|
||||
|
||||
public class object <class-object-for-SomeObject> : test.SomeObject {
|
||||
/*primary*/ private constructor <class-object-for-SomeObject>()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package test
|
||||
|
||||
test.BadAnnotation(s = 1.toInt(): jet.Int) internal val SomeObject: test.SomeObject
|
||||
internal val some: test.SomeObject
|
||||
|
||||
internal final annotation class BadAnnotation : jet.Annotation {
|
||||
@@ -9,4 +8,8 @@ internal final annotation class BadAnnotation : jet.Annotation {
|
||||
|
||||
test.BadAnnotation(s = 1.toInt(): jet.Int) internal object SomeObject {
|
||||
/*primary*/ private constructor SomeObject()
|
||||
|
||||
public class object <class-object-for-SomeObject> : test.SomeObject {
|
||||
/*primary*/ private constructor <class-object-for-SomeObject>()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,14 @@ package test
|
||||
|
||||
internal final class A {
|
||||
/*primary*/ public constructor A()
|
||||
internal final val B: test.A.B
|
||||
|
||||
internal object B {
|
||||
/*primary*/ private constructor B()
|
||||
internal final fun foo(/*0*/ a: jet.Int): jet.String
|
||||
|
||||
public class object <class-object-for-B> : test.A.B {
|
||||
/*primary*/ private constructor <class-object-for-B>()
|
||||
internal final override /*1*/ /*fake_override*/ fun foo(/*0*/ a: jet.Int): jet.String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package test
|
||||
|
||||
internal val SomeObject: test.SomeObject
|
||||
|
||||
internal object SomeObject {
|
||||
/*primary*/ private constructor SomeObject()
|
||||
internal final fun test(/*0*/ a: jet.Int): jet.Int
|
||||
|
||||
public class object <class-object-for-SomeObject> : test.SomeObject {
|
||||
/*primary*/ private constructor <class-object-for-SomeObject>()
|
||||
internal final override /*1*/ /*fake_override*/ fun test(/*0*/ a: jet.Int): jet.Int
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package test
|
||||
|
||||
internal val Bar: test.Bar
|
||||
|
||||
internal object Bar {
|
||||
/*primary*/ private constructor Bar()
|
||||
|
||||
public class object <class-object-for-Bar> : test.Bar {
|
||||
/*primary*/ private constructor <class-object-for-Bar>()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package test
|
||||
|
||||
public val Obj: test.Obj
|
||||
|
||||
public object Obj {
|
||||
/*primary*/ private constructor Obj()
|
||||
public final val v: jet.String
|
||||
public final fun <get-v>(): jet.String
|
||||
public final fun f(): jet.String
|
||||
|
||||
public class object <class-object-for-Obj> : test.Obj {
|
||||
/*primary*/ private constructor <class-object-for-Obj>()
|
||||
public final override /*1*/ /*fake_override*/ val v: jet.String
|
||||
public final override /*1*/ /*fake_override*/ fun <get-v>(): jet.String
|
||||
public final override /*1*/ /*fake_override*/ fun f(): jet.String
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,18 @@ package test
|
||||
|
||||
public final class Outer {
|
||||
/*primary*/ public constructor Outer()
|
||||
public final val Obj: test.Outer.Obj
|
||||
|
||||
public object Obj {
|
||||
/*primary*/ private constructor Obj()
|
||||
public final val v: jet.String
|
||||
public final fun <get-v>(): jet.String
|
||||
public final fun f(): jet.String
|
||||
|
||||
public class object <class-object-for-Obj> : test.Outer.Obj {
|
||||
/*primary*/ private constructor <class-object-for-Obj>()
|
||||
public final override /*1*/ /*fake_override*/ val v: jet.String
|
||||
public final override /*1*/ /*fake_override*/ fun <get-v>(): jet.String
|
||||
public final override /*1*/ /*fake_override*/ fun f(): jet.String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,19 @@ public final class Outer {
|
||||
|
||||
public class object <class-object-for-Outer> {
|
||||
/*primary*/ private constructor <class-object-for-Outer>()
|
||||
public final val Obj: test.Outer.Obj
|
||||
|
||||
public object Obj {
|
||||
/*primary*/ private constructor Obj()
|
||||
public final val v: jet.String
|
||||
public final fun <get-v>(): jet.String
|
||||
public final fun f(): jet.String
|
||||
|
||||
public class object <class-object-for-Obj> : test.Outer.Obj {
|
||||
/*primary*/ private constructor <class-object-for-Obj>()
|
||||
public final override /*1*/ /*fake_override*/ val v: jet.String
|
||||
public final override /*1*/ /*fake_override*/ fun <get-v>(): jet.String
|
||||
public final override /*1*/ /*fake_override*/ fun f(): jet.String
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
package test
|
||||
|
||||
public val Outer: test.Outer
|
||||
|
||||
public object Outer {
|
||||
/*primary*/ private constructor Outer()
|
||||
public final val Obj: test.Outer.Obj
|
||||
|
||||
public class object <class-object-for-Outer> : test.Outer {
|
||||
/*primary*/ private constructor <class-object-for-Outer>()
|
||||
}
|
||||
|
||||
public object Obj {
|
||||
/*primary*/ private constructor Obj()
|
||||
public final val v: jet.String
|
||||
public final fun <get-v>(): jet.String
|
||||
public final fun f(): jet.String
|
||||
|
||||
public class object <class-object-for-Obj> : test.Outer.Obj {
|
||||
/*primary*/ private constructor <class-object-for-Obj>()
|
||||
public final override /*1*/ /*fake_override*/ val v: jet.String
|
||||
public final override /*1*/ /*fake_override*/ fun <get-v>(): jet.String
|
||||
public final override /*1*/ /*fake_override*/ fun f(): jet.String
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package test
|
||||
|
||||
public val Obj: test.Obj
|
||||
internal val x: jet.Int
|
||||
internal fun <get-x>(): jet.Int
|
||||
|
||||
@@ -9,4 +8,11 @@ public object Obj {
|
||||
public final val v: jet.String
|
||||
public final fun <get-v>(): jet.String
|
||||
public final fun f(): jet.String
|
||||
|
||||
public class object <class-object-for-Obj> : test.Obj {
|
||||
/*primary*/ private constructor <class-object-for-Obj>()
|
||||
public final override /*1*/ /*fake_override*/ val v: jet.String
|
||||
public final override /*1*/ /*fake_override*/ fun <get-v>(): jet.String
|
||||
public final override /*1*/ /*fake_override*/ fun f(): jet.String
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,12 +396,7 @@ public class DescriptorValidator {
|
||||
public Void visitClassDescriptor(
|
||||
ClassDescriptor descriptor, JetScope scope
|
||||
) {
|
||||
if (descriptor.getKind().isSingleton()) {
|
||||
assertFound(scope, descriptor, scope.getObjectDescriptor(descriptor.getName()));
|
||||
}
|
||||
else {
|
||||
assertFound(scope, descriptor, scope.getClassifier(descriptor.getName()));
|
||||
}
|
||||
assertFound(scope, descriptor, scope.getClassifier(descriptor.getName()));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -327,6 +327,16 @@ public class DescriptorUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isSyntheticClassObject(@NotNull DeclarationDescriptor descriptor) {
|
||||
if (isClassObject(descriptor)) {
|
||||
DeclarationDescriptor containing = descriptor.getContainingDeclaration();
|
||||
if (containing != null) {
|
||||
return isEnumClass(containing) || isObject(containing) || isEnumEntry(containing);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Visibility getDefaultConstructorVisibility(@NotNull ClassDescriptor classDescriptor) {
|
||||
ClassKind classKind = classDescriptor.getKind();
|
||||
|
||||
Reference in New Issue
Block a user