LazyClassContext introduced
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* 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.lazy
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
|
||||
public trait DeclarationScopeProvider {
|
||||
fun getResolutionScopeForDeclaration(elementOfDeclaration: PsiElement): JetScope
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.lazy
|
||||
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.resolve.DescriptorResolver
|
||||
import org.jetbrains.kotlin.resolve.TypeResolver
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.resolve.AnnotationResolver
|
||||
|
||||
public trait LazyClassContext {
|
||||
val scopeProvider: DeclarationScopeProvider
|
||||
|
||||
val storageManager: StorageManager
|
||||
val trace: BindingTrace
|
||||
val moduleDescriptor: ModuleDescriptor
|
||||
val descriptorResolver: DescriptorResolver
|
||||
val typeResolver: TypeResolver
|
||||
val declarationProviderFactory: DeclarationProviderFactory
|
||||
val annotationResolver: AnnotationResolver
|
||||
}
|
||||
@@ -48,7 +48,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
|
||||
private final LazyResolveStorageManager storageManager;
|
||||
private final ExceptionTracker exceptionTracker;
|
||||
|
||||
@@ -221,13 +221,12 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
//@Override
|
||||
@Override
|
||||
public LazyResolveStorageManager getStorageManager() {
|
||||
return storageManager;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
//@Override
|
||||
public ExceptionTracker getExceptionTracker() {
|
||||
return exceptionTracker;
|
||||
}
|
||||
@@ -297,7 +296,6 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
return (ClassDescriptor) classifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public ScriptDescriptor getScriptDescriptor(@NotNull JetScript script) {
|
||||
return scriptDescriptors.invoke(script);
|
||||
@@ -334,11 +332,13 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
return trace.getBindingContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public BindingTrace getTrace() {
|
||||
return trace;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public DeclarationProviderFactory getDeclarationProviderFactory() {
|
||||
return declarationProviderFactory;
|
||||
@@ -507,16 +507,19 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
return jetImportFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public AnnotationResolver getAnnotationResolver() {
|
||||
return annotationResolve;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public DescriptorResolver getDescriptorResolver() {
|
||||
return descriptorResolver;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public TypeResolver getTypeResolver() {
|
||||
return typeResolver;
|
||||
|
||||
@@ -35,7 +35,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ScopeProvider {
|
||||
public class ScopeProvider implements DeclarationScopeProvider {
|
||||
public static class AdditionalFileScopeProvider {
|
||||
@NotNull
|
||||
public List<JetScope> scopes(@NotNull JetFile file) {
|
||||
@@ -101,6 +101,7 @@ public class ScopeProvider {
|
||||
"LazyFileScope for file " + file.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetScope getResolutionScopeForDeclaration(@NotNull PsiElement elementOfDeclaration) {
|
||||
JetDeclaration jetDeclaration = JetStubbedPsiUtil.getPsiOrStubParent(elementOfDeclaration, JetDeclaration.class, false);
|
||||
|
||||
+8
-8
@@ -22,8 +22,6 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.AnnotationResolver
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||
import org.jetbrains.kotlin.resolve.ScriptNameUtil
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.JetScriptInfo
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProvider
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -35,14 +33,16 @@ import java.util.*
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyClassContext
|
||||
|
||||
public abstract class AbstractLazyMemberScope<D : DeclarationDescriptor, DP : DeclarationProvider> protected(
|
||||
protected val resolveSession: ResolveSession,
|
||||
protected val c: LazyClassContext,
|
||||
protected val declarationProvider: DP,
|
||||
protected val thisDescriptor: D,
|
||||
protected val trace: BindingTrace) : JetScope {
|
||||
|
||||
protected val storageManager: StorageManager = resolveSession.getStorageManager()
|
||||
protected val storageManager: StorageManager = c.storageManager
|
||||
private val classDescriptors: MemoizedFunctionToNotNull<Name, List<ClassDescriptor>> = storageManager.createMemoizedFunction { resolveClassDescriptor(it) }
|
||||
private val functionDescriptors: MemoizedFunctionToNotNull<Name, Collection<FunctionDescriptor>> = storageManager.createMemoizedFunction { doGetFunctions(it) }
|
||||
private val propertyDescriptors: MemoizedFunctionToNotNull<Name, Collection<VariableDescriptor>> = storageManager.createMemoizedFunction { doGetProperties(it) }
|
||||
@@ -51,9 +51,9 @@ public abstract class AbstractLazyMemberScope<D : DeclarationDescriptor, DP : De
|
||||
return declarationProvider.getClassOrObjectDeclarations(name).map {
|
||||
// SCRIPT: Creating a script class
|
||||
if (it is JetScriptInfo)
|
||||
LazyScriptClassDescriptor(resolveSession, thisDescriptor, name, it)
|
||||
LazyScriptClassDescriptor(c as ResolveSession, thisDescriptor, name, it)
|
||||
else
|
||||
LazyClassDescriptor(resolveSession, thisDescriptor, name, it)
|
||||
LazyClassDescriptor(c, thisDescriptor, name, it)
|
||||
}.toReadOnlyList()
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public abstract class AbstractLazyMemberScope<D : DeclarationDescriptor, DP : De
|
||||
val declarations = declarationProvider.getFunctionDeclarations(name)
|
||||
for (functionDeclaration in declarations) {
|
||||
val resolutionScope = getScopeForMemberDeclarationResolution(functionDeclaration)
|
||||
result.add(resolveSession.getDescriptorResolver().resolveFunctionDescriptorWithAnnotationArguments(
|
||||
result.add(c.descriptorResolver.resolveFunctionDescriptorWithAnnotationArguments(
|
||||
thisDescriptor,
|
||||
resolutionScope,
|
||||
functionDeclaration,
|
||||
@@ -96,7 +96,7 @@ public abstract class AbstractLazyMemberScope<D : DeclarationDescriptor, DP : De
|
||||
val declarations = declarationProvider.getPropertyDeclarations(name)
|
||||
for (propertyDeclaration in declarations) {
|
||||
val resolutionScope = getScopeForMemberDeclarationResolution(propertyDeclaration)
|
||||
val propertyDescriptor = resolveSession.getDescriptorResolver().resolvePropertyDescriptor(
|
||||
val propertyDescriptor = c.descriptorResolver.resolvePropertyDescriptor(
|
||||
thisDescriptor,
|
||||
resolutionScope,
|
||||
propertyDeclaration,
|
||||
|
||||
+33
-40
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve.lazy.descriptors;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import kotlin.Function0;
|
||||
import kotlin.Function1;
|
||||
import kotlin.KotlinPackage;
|
||||
@@ -28,6 +27,7 @@ import org.jetbrains.annotations.Mutable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyClassContext;
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
@@ -40,8 +40,6 @@ import org.jetbrains.kotlin.resolve.ModifiersChecker;
|
||||
import org.jetbrains.kotlin.resolve.TypeHierarchyResolver;
|
||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyEntity;
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.kotlin.resolve.lazy.ScopeProvider;
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.JetClassInfoUtil;
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.JetClassLikeInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.SyntheticClassObjectInfo;
|
||||
@@ -73,7 +71,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
return TypeUtils.getClassDescriptor(type) != null;
|
||||
}
|
||||
};
|
||||
private final ResolveSession resolveSession;
|
||||
private final LazyClassContext c;
|
||||
|
||||
private final JetClassLikeInfo originalClassInfo;
|
||||
private final ClassMemberDeclarationProvider declarationProvider;
|
||||
@@ -99,25 +97,25 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
private final NullableLazyValue<Void> forceResolveAllContents;
|
||||
|
||||
public LazyClassDescriptor(
|
||||
@NotNull final ResolveSession resolveSession,
|
||||
@NotNull LazyClassContext c,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull Name name,
|
||||
@NotNull JetClassLikeInfo classLikeInfo
|
||||
) {
|
||||
super(resolveSession.getStorageManager(), containingDeclaration, name,
|
||||
super(c.getStorageManager(), containingDeclaration, name,
|
||||
toSourceElement(classLikeInfo.getCorrespondingClassOrObject())
|
||||
);
|
||||
this.resolveSession = resolveSession;
|
||||
this.c = c;
|
||||
|
||||
if (classLikeInfo.getCorrespondingClassOrObject() != null) {
|
||||
this.resolveSession.getTrace().record(BindingContext.CLASS, classLikeInfo.getCorrespondingClassOrObject(), this);
|
||||
this.c.getTrace().record(BindingContext.CLASS, classLikeInfo.getCorrespondingClassOrObject(), this);
|
||||
}
|
||||
this.resolveSession.getTrace().record(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, DescriptorUtils.getFqName(this), this);
|
||||
this.c.getTrace().record(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, DescriptorUtils.getFqName(this), this);
|
||||
|
||||
this.originalClassInfo = classLikeInfo;
|
||||
this.declarationProvider = resolveSession.getDeclarationProviderFactory().getClassMemberDeclarationProvider(classLikeInfo);
|
||||
this.declarationProvider = c.getDeclarationProviderFactory().getClassMemberDeclarationProvider(classLikeInfo);
|
||||
|
||||
this.unsubstitutedMemberScope = createMemberScope(resolveSession, this.declarationProvider);
|
||||
this.unsubstitutedMemberScope = createMemberScope(c, this.declarationProvider);
|
||||
|
||||
this.typeConstructor = new LazyClassTypeConstructor();
|
||||
|
||||
@@ -136,21 +134,20 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
: resolveVisibilityFromModifiers(modifierList, getDefaultClassVisibility(this));
|
||||
this.isInner = isInnerClass(modifierList) && !ModifiersChecker.isIllegalInner(this);
|
||||
|
||||
StorageManager storageManager = resolveSession.getStorageManager();
|
||||
StorageManager storageManager = c.getStorageManager();
|
||||
|
||||
|
||||
if (modifierList != null) {
|
||||
this.annotations = new LazyAnnotations(
|
||||
new LazyAnnotationsContext(
|
||||
resolveSession.getAnnotationResolver(),
|
||||
c.getAnnotationResolver(),
|
||||
storageManager,
|
||||
resolveSession.getTrace()
|
||||
c.getTrace()
|
||||
) {
|
||||
@NotNull
|
||||
@Override
|
||||
public JetScope getScope() {
|
||||
JetClassLikeInfo ownerInfo = declarationProvider.getOwnerInfo();
|
||||
return resolveSession.getScopeProvider().getResolutionScopeForDeclaration(ownerInfo.getScopeAnchor());
|
||||
return getOuterScope();
|
||||
}
|
||||
},
|
||||
modifierList.getAnnotationEntries()
|
||||
@@ -168,9 +165,9 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
else {
|
||||
this.danglingAnnotations = new LazyAnnotations(
|
||||
new LazyAnnotationsContext(
|
||||
resolveSession.getAnnotationResolver(),
|
||||
c.getAnnotationResolver(),
|
||||
storageManager,
|
||||
resolveSession.getTrace()
|
||||
c.getTrace()
|
||||
) {
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -224,10 +221,10 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
// NOTE: Called from constructor!
|
||||
@NotNull
|
||||
protected LazyClassMemberScope createMemberScope(
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull LazyClassContext c,
|
||||
@NotNull ClassMemberDeclarationProvider declarationProvider
|
||||
) {
|
||||
return new LazyClassMemberScope(resolveSession, declarationProvider, this, resolveSession.getTrace());
|
||||
return new LazyClassMemberScope(c, declarationProvider, this, c.getTrace());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -250,11 +247,12 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
PsiElement scopeAnchor = declarationProvider.getOwnerInfo().getScopeAnchor();
|
||||
return new ChainedScope(this, "ScopeForClassHeaderResolution: " + getName(), scope, getOuterScope());
|
||||
}
|
||||
|
||||
return new ChainedScope(this, "ScopeForClassHeaderResolution: " + getName(),
|
||||
scope,
|
||||
getScopeProvider().getResolutionScopeForDeclaration(scopeAnchor));
|
||||
@NotNull
|
||||
protected JetScope getOuterScope() {
|
||||
return c.getScopeProvider().getResolutionScopeForDeclaration(declarationProvider.getOwnerInfo().getScopeAnchor());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -382,7 +380,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
private LazyClassDescriptor computeClassObjectDescriptor(@Nullable JetClassObject classObject) {
|
||||
JetClassLikeInfo classObjectInfo = getClassObjectInfo(classObject);
|
||||
if (classObjectInfo != null) {
|
||||
return new LazyClassDescriptor(resolveSession, this, getClassObjectName(getName()), classObjectInfo);
|
||||
return new LazyClassDescriptor(c, this, getClassObjectName(getName()), classObjectInfo);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -391,7 +389,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
private JetClassLikeInfo getClassObjectInfo(@Nullable JetClassObject classObject) {
|
||||
if (classObject != null) {
|
||||
if (!isClassObjectAllowed()) {
|
||||
resolveSession.getTrace().report(CLASS_OBJECT_NOT_ALLOWED.on(classObject));
|
||||
c.getTrace().report(CLASS_OBJECT_NOT_ALLOWED.on(classObject));
|
||||
}
|
||||
|
||||
return JetClassInfoUtil.createClassLikeInfo(classObject.getObjectDeclaration());
|
||||
@@ -524,7 +522,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
|
||||
private class LazyClassTypeConstructor extends AbstractClassTypeConstructor implements LazyEntity {
|
||||
private final NotNullLazyValue<Supertypes> supertypes = resolveSession.getStorageManager().createLazyValueWithPostCompute(
|
||||
private final NotNullLazyValue<Supertypes> supertypes = c.getStorageManager().createLazyValueWithPostCompute(
|
||||
new Function0<Supertypes>() {
|
||||
@Override
|
||||
public Supertypes invoke() {
|
||||
@@ -542,12 +540,12 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
|
||||
JetClassOrObject classOrObject = info.getCorrespondingClassOrObject();
|
||||
if (classOrObject == null) {
|
||||
return new Supertypes(Collections.singleton(resolveSession.getModuleDescriptor().getBuiltIns().getAnyType()));
|
||||
return new Supertypes(Collections.singleton(c.getModuleDescriptor().getBuiltIns().getAnyType()));
|
||||
}
|
||||
|
||||
List<JetType> allSupertypes = resolveSession.getDescriptorResolver()
|
||||
List<JetType> allSupertypes = c.getDescriptorResolver()
|
||||
.resolveSupertypes(getScopeForClassHeaderResolution(), LazyClassDescriptor.this, classOrObject,
|
||||
resolveSession.getTrace());
|
||||
c.getTrace());
|
||||
|
||||
return new Supertypes(Lists.newArrayList(Collections2.filter(allSupertypes, VALID_SUPERTYPE)));
|
||||
}
|
||||
@@ -567,7 +565,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
);
|
||||
|
||||
private final NotNullLazyValue<List<TypeParameterDescriptor>> parameters = resolveSession.getStorageManager().createLazyValue(new Function0<List<TypeParameterDescriptor>>() {
|
||||
private final NotNullLazyValue<List<TypeParameterDescriptor>> parameters = c.getStorageManager().createLazyValue(new Function0<List<TypeParameterDescriptor>>() {
|
||||
@Override
|
||||
public List<TypeParameterDescriptor> invoke() {
|
||||
JetClassLikeInfo classInfo = declarationProvider.getOwnerInfo();
|
||||
@@ -575,13 +573,13 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
if (typeParameterList == null) return Collections.emptyList();
|
||||
|
||||
if (classInfo.getClassKind() == ClassKind.ENUM_CLASS) {
|
||||
resolveSession.getTrace().report(TYPE_PARAMETERS_IN_ENUM.on(typeParameterList));
|
||||
c.getTrace().report(TYPE_PARAMETERS_IN_ENUM.on(typeParameterList));
|
||||
}
|
||||
|
||||
List<JetTypeParameter> typeParameters = typeParameterList.getParameters();
|
||||
List<TypeParameterDescriptor> parameters = new ArrayList<TypeParameterDescriptor>(typeParameters.size());
|
||||
for (int i = 0; i < typeParameters.size(); i++) {
|
||||
parameters.add(new LazyTypeParameterDescriptor(resolveSession, LazyClassDescriptor.this, typeParameters.get(i), i));
|
||||
parameters.add(new LazyTypeParameterDescriptor(c, LazyClassDescriptor.this, typeParameters.get(i), i));
|
||||
}
|
||||
|
||||
return parameters;
|
||||
@@ -589,7 +587,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
});
|
||||
|
||||
private final NullableLazyValue<Void> forceResolveAllContents =
|
||||
resolveSession.getStorageManager().createRecursionTolerantNullableLazyValue(new Function0<Void>() {
|
||||
c.getStorageManager().createRecursionTolerantNullableLazyValue(new Function0<Void>() {
|
||||
@Override
|
||||
public Void invoke() {
|
||||
doForceResolveAllContents();
|
||||
@@ -619,7 +617,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
ClassifierDescriptor supertypeDescriptor = supertype.getConstructor().getDeclarationDescriptor();
|
||||
if (supertypeDescriptor instanceof ClassDescriptor) {
|
||||
ClassDescriptor superclass = (ClassDescriptor) supertypeDescriptor;
|
||||
TypeHierarchyResolver.reportCyclicInheritanceHierarchyError(resolveSession.getTrace(), LazyClassDescriptor.this,
|
||||
TypeHierarchyResolver.reportCyclicInheritanceHierarchyError(c.getTrace(), LazyClassDescriptor.this,
|
||||
superclass);
|
||||
}
|
||||
}
|
||||
@@ -695,9 +693,4 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
ForceResolveUtil.forceResolveAllContents(getParameters());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ScopeProvider getScopeProvider() {
|
||||
return resolveSession.getScopeProvider();
|
||||
}
|
||||
}
|
||||
|
||||
+13
-11
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.dataClassUtils.*
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
@@ -40,12 +39,15 @@ import org.jetbrains.kotlin.resolve.DelegationResolver.generateDelegatedMembers
|
||||
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.varianceChecker.VarianceChecker
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyClassContext
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isObjectLiteral
|
||||
|
||||
public open class LazyClassMemberScope(resolveSession: ResolveSession,
|
||||
declarationProvider: ClassMemberDeclarationProvider,
|
||||
thisClass: LazyClassDescriptor,
|
||||
trace: BindingTrace)
|
||||
: AbstractLazyMemberScope<LazyClassDescriptor, ClassMemberDeclarationProvider>(resolveSession, declarationProvider, thisClass, trace) {
|
||||
public open class LazyClassMemberScope(
|
||||
c: LazyClassContext,
|
||||
declarationProvider: ClassMemberDeclarationProvider,
|
||||
thisClass: LazyClassDescriptor,
|
||||
trace: BindingTrace
|
||||
) : AbstractLazyMemberScope<LazyClassDescriptor, ClassMemberDeclarationProvider>(c, declarationProvider, thisClass, trace) {
|
||||
|
||||
private val descriptorsFromDeclaredElements = storageManager.createLazyValue {
|
||||
computeDescriptorsFromDeclaredElements(DescriptorKindFilter.ALL, JetScope.ALL_NAME_FILTER)
|
||||
@@ -86,7 +88,7 @@ public open class LazyClassMemberScope(resolveSession: ResolveSession,
|
||||
}
|
||||
|
||||
private val primaryConstructor: NullableLazyValue<ConstructorDescriptor>
|
||||
= resolveSession.getStorageManager().createNullableLazyValue { resolvePrimaryConstructor() }
|
||||
= c.storageManager.createNullableLazyValue { resolvePrimaryConstructor() }
|
||||
|
||||
override fun getScopeForMemberDeclarationResolution(declaration: JetDeclaration): JetScope {
|
||||
if (declaration is JetProperty) {
|
||||
@@ -219,7 +221,7 @@ public open class LazyClassMemberScope(resolveSession: ResolveSession,
|
||||
|
||||
val parameter = primaryConstructorParameters.get(valueParameterDescriptor.getIndex())
|
||||
if (parameter.hasValOrVarNode()) {
|
||||
val propertyDescriptor = resolveSession.getDescriptorResolver().resolvePrimaryConstructorParameterToAProperty(
|
||||
val propertyDescriptor = c.descriptorResolver.resolvePrimaryConstructorParameterToAProperty(
|
||||
thisDescriptor, valueParameterDescriptor, thisDescriptor.getScopeForClassHeaderResolution(), parameter, trace)
|
||||
result.add(propertyDescriptor)
|
||||
}
|
||||
@@ -231,7 +233,7 @@ public open class LazyClassMemberScope(resolveSession: ResolveSession,
|
||||
?: return setOf() // Enum class objects do not have delegated members
|
||||
|
||||
val lazyTypeResolver = DelegationResolver.TypeResolver { reference ->
|
||||
resolveSession.getTypeResolver().resolveType(thisDescriptor.getScopeForClassHeaderResolution(), reference, trace, false)
|
||||
c.typeResolver.resolveType(thisDescriptor.getScopeForClassHeaderResolution(), reference, trace, false)
|
||||
}
|
||||
val lazyMemberExtractor = DelegationResolver.MemberExtractor<T> {
|
||||
type -> extractor.extract(type, name)
|
||||
@@ -274,7 +276,7 @@ public open class LazyClassMemberScope(resolveSession: ResolveSession,
|
||||
if (!thisDescriptor.getKind().isSingleton()) {
|
||||
assert(classOrObject is JetClass) { "No JetClass for $thisDescriptor" }
|
||||
classOrObject as JetClass
|
||||
val constructor = resolveSession.getDescriptorResolver().resolvePrimaryConstructorDescriptor(
|
||||
val constructor = c.descriptorResolver.resolvePrimaryConstructorDescriptor(
|
||||
thisDescriptor.getScopeForClassHeaderResolution(), thisDescriptor, classOrObject, trace)
|
||||
assert(constructor != null) { "No constructor created for $thisDescriptor" }
|
||||
setDeferredReturnType(constructor)
|
||||
@@ -290,7 +292,7 @@ public open class LazyClassMemberScope(resolveSession: ResolveSession,
|
||||
}
|
||||
|
||||
protected fun setDeferredReturnType(descriptor: ConstructorDescriptorImpl) {
|
||||
descriptor.setReturnType(DeferredType.create(resolveSession.getStorageManager(), trace, { thisDescriptor.getDefaultType() }))
|
||||
descriptor.setReturnType(DeferredType.create(c.storageManager, trace, { thisDescriptor.getDefaultType() }))
|
||||
}
|
||||
|
||||
// Do not add details here, they may compromise the laziness during debugging
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
|
||||
public class LazyPackageMemberScope(
|
||||
resolveSession: ResolveSession,
|
||||
private val resolveSession: ResolveSession,
|
||||
declarationProvider: PackageMemberDeclarationProvider,
|
||||
thisPackage: PackageFragmentDescriptor)
|
||||
: AbstractLazyMemberScope<PackageFragmentDescriptor, PackageMemberDeclarationProvider>(resolveSession, declarationProvider, thisPackage, resolveSession.getTrace()) {
|
||||
|
||||
+6
-3
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.lazy.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyClassContext;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities;
|
||||
import org.jetbrains.kotlin.descriptors.Visibility;
|
||||
@@ -39,13 +40,15 @@ public class LazyScriptClassDescriptor extends LazyClassDescriptor {
|
||||
@NotNull
|
||||
@Override
|
||||
protected LazyScriptClassMemberScope createMemberScope(
|
||||
@NotNull ResolveSession resolveSession, @NotNull ClassMemberDeclarationProvider declarationProvider
|
||||
@NotNull LazyClassContext c,
|
||||
@NotNull ClassMemberDeclarationProvider declarationProvider
|
||||
) {
|
||||
return new LazyScriptClassMemberScope(
|
||||
resolveSession,
|
||||
// Must be a ResolveSession for scripts
|
||||
(ResolveSession) c,
|
||||
declarationProvider,
|
||||
this,
|
||||
TemporaryBindingTrace.create(resolveSession.getTrace(), "A trace for script class, needed to avoid rewrites on members")
|
||||
TemporaryBindingTrace.create(c.getTrace(), "A trace for script class, needed to avoid rewrites on members")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+15
-15
@@ -1,18 +1,18 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
* 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.lazy.descriptors
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
|
||||
// SCRIPT: Members of a script class
|
||||
public class LazyScriptClassMemberScope protected(
|
||||
resolveSession: ResolveSession,
|
||||
private val resolveSession: ResolveSession,
|
||||
declarationProvider: ClassMemberDeclarationProvider,
|
||||
thisClass: LazyClassDescriptor,
|
||||
trace: BindingTrace)
|
||||
|
||||
+11
-11
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.lazy.descriptors;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyClassContext;
|
||||
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
@@ -25,7 +26,6 @@ import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorResolver;
|
||||
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyEntity;
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -33,17 +33,17 @@ import java.util.Set;
|
||||
import static org.jetbrains.kotlin.resolve.source.SourcePackage.toSourceElement;
|
||||
|
||||
public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescriptor implements LazyEntity {
|
||||
private final ResolveSession resolveSession;
|
||||
private final LazyClassContext c;
|
||||
|
||||
private final JetTypeParameter jetTypeParameter;
|
||||
|
||||
public LazyTypeParameterDescriptor(
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull LazyClassContext c,
|
||||
@NotNull LazyClassDescriptor containingDeclaration,
|
||||
@NotNull JetTypeParameter jetTypeParameter,
|
||||
int index) {
|
||||
super(
|
||||
resolveSession.getStorageManager(),
|
||||
c.getStorageManager(),
|
||||
containingDeclaration,
|
||||
jetTypeParameter.getNameAsSafeName(),
|
||||
jetTypeParameter.getVariance(),
|
||||
@@ -51,10 +51,10 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
|
||||
index,
|
||||
toSourceElement(jetTypeParameter)
|
||||
);
|
||||
this.resolveSession = resolveSession;
|
||||
this.c = c;
|
||||
this.jetTypeParameter = jetTypeParameter;
|
||||
|
||||
this.resolveSession.getTrace().record(BindingContext.TYPE_PARAMETER, jetTypeParameter, this);
|
||||
this.c.getTrace().record(BindingContext.TYPE_PARAMETER, jetTypeParameter, this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -72,7 +72,7 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
|
||||
resolveUpperBoundsFromWhereClause(upperBounds);
|
||||
|
||||
if (upperBounds.isEmpty()) {
|
||||
upperBounds.add(resolveSession.getModuleDescriptor().getBuiltIns().getDefaultBound());
|
||||
upperBounds.add(c.getModuleDescriptor().getBuiltIns().getDefaultBound());
|
||||
}
|
||||
|
||||
return upperBounds;
|
||||
@@ -83,12 +83,12 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
|
||||
if (classOrObject instanceof JetClass) {
|
||||
JetClass jetClass = (JetClass) classOrObject;
|
||||
for (JetTypeConstraint jetTypeConstraint : jetClass.getTypeConstraints()) {
|
||||
DescriptorResolver.reportUnsupportedClassObjectConstraint(resolveSession.getTrace(), jetTypeConstraint);
|
||||
DescriptorResolver.reportUnsupportedClassObjectConstraint(c.getTrace(), jetTypeConstraint);
|
||||
|
||||
JetSimpleNameExpression constrainedParameterName = jetTypeConstraint.getSubjectTypeParameterName();
|
||||
if (constrainedParameterName != null) {
|
||||
if (getName().equals(constrainedParameterName.getReferencedNameAsName())) {
|
||||
resolveSession.getTrace().record(BindingContext.REFERENCE_TARGET, constrainedParameterName, this);
|
||||
c.getTrace().record(BindingContext.REFERENCE_TARGET, constrainedParameterName, this);
|
||||
|
||||
JetTypeReference boundTypeReference = jetTypeConstraint.getBoundTypeReference();
|
||||
if (boundTypeReference != null) {
|
||||
@@ -105,9 +105,9 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
|
||||
}
|
||||
|
||||
private JetType resolveBoundType(@NotNull JetTypeReference boundTypeReference) {
|
||||
return resolveSession.getTypeResolver()
|
||||
return c.getTypeResolver()
|
||||
.resolveType(getContainingDeclaration().getScopeForClassHeaderResolution(), boundTypeReference,
|
||||
resolveSession.getTrace(), false);
|
||||
c.getTrace(), false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user