Changed JetScope to LexicalScope in ClassDescriptorWithResolutionScopes and DeclarationScopeProvider
This commit is contained in:
+7
-4
@@ -19,19 +19,22 @@ package org.jetbrains.kotlin.descriptors;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.ReadOnly;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface ClassDescriptorWithResolutionScopes extends ClassDescriptor {
|
||||
@NotNull
|
||||
JetScope getScopeForClassHeaderResolution();
|
||||
LexicalScope getScopeForClassHeaderResolution();
|
||||
|
||||
@NotNull
|
||||
JetScope getScopeForMemberDeclarationResolution();
|
||||
LexicalScope getScopeForMemberDeclarationResolution();
|
||||
|
||||
@NotNull
|
||||
JetScope getScopeForInitializerResolution();
|
||||
LexicalScope getScopeForStaticMemberDeclarationResolution();
|
||||
|
||||
@NotNull
|
||||
LexicalScope getScopeForInitializerResolution();
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.annotations.ReadOnly;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
@@ -47,7 +47,7 @@ public interface BodiesResolveContext {
|
||||
Map<JetNamedFunction, SimpleFunctionDescriptor> getFunctions();
|
||||
|
||||
@Nullable
|
||||
JetScope getDeclaringScope(@NotNull JetDeclaration declaration);
|
||||
LexicalScope getDeclaringScope(@NotNull JetDeclaration declaration);
|
||||
|
||||
@NotNull
|
||||
DataFlowInfo getOuterDataFlowInfo();
|
||||
|
||||
@@ -49,6 +49,7 @@ import java.util.*;
|
||||
|
||||
import static org.jetbrains.kotlin.diagnostics.Errors.*;
|
||||
import static org.jetbrains.kotlin.resolve.BindingContext.*;
|
||||
import static org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage.asJetScope;
|
||||
import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
|
||||
public class BodyResolver {
|
||||
@@ -114,9 +115,9 @@ public class BodyResolver {
|
||||
|
||||
private void resolveSecondaryConstructors(@NotNull BodiesResolveContext c) {
|
||||
for (Map.Entry<JetSecondaryConstructor, ConstructorDescriptor> entry : c.getSecondaryConstructors().entrySet()) {
|
||||
JetScope declaringScope = c.getDeclaringScope(entry.getKey());
|
||||
LexicalScope declaringScope = c.getDeclaringScope(entry.getKey());
|
||||
assert declaringScope != null : "Declaring scope should be registered before body resolve";
|
||||
resolveSecondaryConstructorBody(c.getOuterDataFlowInfo(), trace, entry.getKey(), entry.getValue(), declaringScope);
|
||||
resolveSecondaryConstructorBody(c.getOuterDataFlowInfo(), trace, entry.getKey(), entry.getValue(), asJetScope(declaringScope));
|
||||
}
|
||||
if (c.getSecondaryConstructors().isEmpty()) return;
|
||||
Set<ConstructorDescriptor> visitedConstructors = Sets.newHashSet();
|
||||
@@ -236,8 +237,8 @@ public class BodyResolver {
|
||||
|
||||
resolveDelegationSpecifierList(c.getOuterDataFlowInfo(), classOrObject, descriptor,
|
||||
descriptor.getUnsubstitutedPrimaryConstructor(),
|
||||
descriptor.getScopeForClassHeaderResolution(),
|
||||
descriptor.getScopeForMemberDeclarationResolution());
|
||||
asJetScope(descriptor.getScopeForClassHeaderResolution()),
|
||||
asJetScope(descriptor.getScopeForMemberDeclarationResolution()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -491,7 +492,7 @@ public class BodyResolver {
|
||||
@NotNull JetClassInitializer anonymousInitializer,
|
||||
@NotNull ClassDescriptorWithResolutionScopes classDescriptor
|
||||
) {
|
||||
JetScope scopeForInitializers = classDescriptor.getScopeForInitializerResolution();
|
||||
JetScope scopeForInitializers = asJetScope(classDescriptor.getScopeForInitializerResolution());
|
||||
if (!classDescriptor.getConstructors().isEmpty()) {
|
||||
JetExpression body = anonymousInitializer.getBody();
|
||||
if (body != null) {
|
||||
@@ -522,7 +523,7 @@ public class BodyResolver {
|
||||
if (unsubstitutedPrimaryConstructor != null) {
|
||||
ForceResolveUtil.forceResolveAllContents(unsubstitutedPrimaryConstructor.getAnnotations());
|
||||
|
||||
JetScope parameterScope = getPrimaryConstructorParametersScope(classDescriptor.getScopeForClassHeaderResolution(),
|
||||
JetScope parameterScope = getPrimaryConstructorParametersScope(asJetScope(classDescriptor.getScopeForClassHeaderResolution()),
|
||||
unsubstitutedPrimaryConstructor);
|
||||
valueParameterResolver.resolveValueParameters(klass.getPrimaryConstructorParameters(),
|
||||
unsubstitutedPrimaryConstructor.getValueParameters(),
|
||||
@@ -586,7 +587,7 @@ public class BodyResolver {
|
||||
PropertyDescriptor propertyDescriptor = c.getProperties().get(property);
|
||||
assert propertyDescriptor != null;
|
||||
|
||||
resolveProperty(c, classDescriptor.getScopeForMemberDeclarationResolution(), property, propertyDescriptor);
|
||||
resolveProperty(c, asJetScope(classDescriptor.getScopeForMemberDeclarationResolution()), property, propertyDescriptor);
|
||||
processed.add(property);
|
||||
}
|
||||
}
|
||||
@@ -603,9 +604,9 @@ public class BodyResolver {
|
||||
}
|
||||
|
||||
private JetScope makeScopeForPropertyAccessor(@NotNull BodiesResolveContext c, @NotNull JetPropertyAccessor accessor, @NotNull PropertyDescriptor descriptor) {
|
||||
JetScope accessorDeclaringScope = c.getDeclaringScope(accessor);
|
||||
LexicalScope accessorDeclaringScope = c.getDeclaringScope(accessor);
|
||||
assert accessorDeclaringScope != null : "Scope for accessor " + accessor.getText() + " should exists";
|
||||
return JetScopeUtils.makeScopeForPropertyAccessor(descriptor, accessorDeclaringScope, trace);
|
||||
return JetScopeUtils.makeScopeForPropertyAccessor(descriptor, asJetScope(accessorDeclaringScope), trace);
|
||||
}
|
||||
|
||||
public void resolvePropertyAccessors(
|
||||
@@ -706,16 +707,16 @@ public class BodyResolver {
|
||||
|
||||
@NotNull
|
||||
private static JetScope getScopeForProperty(@NotNull BodiesResolveContext c, @NotNull JetProperty property) {
|
||||
JetScope scope = c.getDeclaringScope(property);
|
||||
LexicalScope scope = c.getDeclaringScope(property);
|
||||
assert scope != null : "Scope for property " + property.getText() + " should exists";
|
||||
return scope;
|
||||
return asJetScope(scope);
|
||||
}
|
||||
|
||||
private void resolveFunctionBodies(@NotNull BodiesResolveContext c) {
|
||||
for (Map.Entry<JetNamedFunction, SimpleFunctionDescriptor> entry : c.getFunctions().entrySet()) {
|
||||
JetNamedFunction declaration = entry.getKey();
|
||||
|
||||
JetScope scope = c.getDeclaringScope(declaration);
|
||||
LexicalScope scope = c.getDeclaringScope(declaration);
|
||||
assert scope != null : "Scope is null: " + PsiUtilPackage.getElementTextWithContext(declaration);
|
||||
|
||||
if (!c.getTopDownAnalysisMode().getIsLocalDeclarations() && !(bodyResolveCache instanceof BodyResolveCache.ThrowException) &&
|
||||
@@ -723,7 +724,7 @@ public class BodyResolver {
|
||||
bodyResolveCache.resolveFunctionBody(declaration).addOwnDataTo(trace, true);
|
||||
}
|
||||
else {
|
||||
resolveFunctionBody(c.getOuterDataFlowInfo(), trace, declaration, entry.getValue(), scope);
|
||||
resolveFunctionBody(c.getOuterDataFlowInfo(), trace, declaration, entry.getValue(), asJetScope(scope));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.lexer.JetModifierKeywordToken;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
import org.jetbrains.kotlin.types.SubstitutionUtils;
|
||||
import org.jetbrains.kotlin.types.TypeConstructor;
|
||||
@@ -80,7 +81,7 @@ public class DeclarationsChecker {
|
||||
JetClass jetClass = (JetClass) classOrObject;
|
||||
checkClass(bodiesResolveContext, jetClass, classDescriptor);
|
||||
descriptorResolver.checkNamesInConstraints(
|
||||
jetClass, classDescriptor, classDescriptor.getScopeForClassHeaderResolution(), trace);
|
||||
jetClass, classDescriptor, UtilsPackage.asJetScope(classDescriptor.getScopeForClassHeaderResolution()), trace);
|
||||
}
|
||||
else if (classOrObject instanceof JetObjectDeclaration) {
|
||||
checkObject((JetObjectDeclaration) classOrObject, classDescriptor);
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.DeclarationScopeProvider;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.Collection;
|
||||
@@ -130,7 +130,7 @@ public class TopDownAnalysisContext implements BodiesResolveContext {
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JetScope getDeclaringScope(@NotNull JetDeclaration declaration) {
|
||||
public LexicalScope getDeclaringScope(@NotNull JetDeclaration declaration) {
|
||||
return declarationScopeProvider.getResolutionScopeForDeclaration(declaration);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -19,11 +19,11 @@ package org.jetbrains.kotlin.resolve.lazy;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
|
||||
public interface DeclarationScopeProvider {
|
||||
@NotNull
|
||||
JetScope getResolutionScopeForDeclaration(@NotNull PsiElement elementOfDeclaration);
|
||||
LexicalScope getResolutionScopeForDeclaration(@NotNull PsiElement elementOfDeclaration);
|
||||
|
||||
@NotNull
|
||||
DataFlowInfo getOuterDataFlowInfoForDeclaration(@NotNull PsiElement elementOfDeclaration);
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.psi.psiUtil.PsiUtilPackage;
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
|
||||
public class DeclarationScopeProviderImpl implements DeclarationScopeProvider {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class DeclarationScopeProviderImpl implements DeclarationScopeProvider {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetScope getResolutionScopeForDeclaration(@NotNull PsiElement elementOfDeclaration) {
|
||||
public LexicalScope getResolutionScopeForDeclaration(@NotNull PsiElement elementOfDeclaration) {
|
||||
JetDeclaration jetDeclaration = JetStubbedPsiUtil.getPsiOrStubParent(elementOfDeclaration, JetDeclaration.class, false);
|
||||
|
||||
assert !(elementOfDeclaration instanceof JetDeclaration) || jetDeclaration == elementOfDeclaration :
|
||||
|
||||
+5
-4
@@ -32,8 +32,9 @@ 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.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScopeImpl
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
@@ -80,7 +81,7 @@ protected constructor(
|
||||
|
||||
val declarations = declarationProvider.getFunctionDeclarations(name)
|
||||
for (functionDeclaration in declarations) {
|
||||
val resolutionScope = getScopeForMemberDeclarationResolution(functionDeclaration)
|
||||
val resolutionScope = getScopeForMemberDeclarationResolution(functionDeclaration).asJetScope()
|
||||
result.add(c.functionDescriptorResolver.resolveFunctionDescriptor(
|
||||
thisDescriptor,
|
||||
resolutionScope,
|
||||
@@ -94,7 +95,7 @@ protected constructor(
|
||||
return result.toReadOnlyList()
|
||||
}
|
||||
|
||||
protected abstract fun getScopeForMemberDeclarationResolution(declaration: JetDeclaration): JetScope
|
||||
protected abstract fun getScopeForMemberDeclarationResolution(declaration: JetDeclaration): LexicalScope
|
||||
|
||||
protected abstract fun getNonDeclaredFunctions(name: Name, result: MutableSet<FunctionDescriptor>)
|
||||
|
||||
@@ -108,7 +109,7 @@ protected constructor(
|
||||
|
||||
val declarations = declarationProvider.getPropertyDeclarations(name)
|
||||
for (propertyDeclaration in declarations) {
|
||||
val resolutionScope = getScopeForMemberDeclarationResolution(propertyDeclaration)
|
||||
val resolutionScope = getScopeForMemberDeclarationResolution(propertyDeclaration).asJetScope()
|
||||
val propertyDescriptor = c.descriptorResolver.resolvePropertyDescriptor(
|
||||
thisDescriptor,
|
||||
resolutionScope,
|
||||
|
||||
+52
-52
@@ -17,73 +17,73 @@
|
||||
package org.jetbrains.kotlin.resolve.lazy.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
import org.jetbrains.kotlin.psi.JetParameter
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalChainedScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
class ClassResolutionScopesSupport(
|
||||
private val classDescriptor: ClassDescriptor,
|
||||
storageManager: StorageManager,
|
||||
private val getOuterScope: () -> JetScope
|
||||
private val getOuterScope: () -> LexicalScope,
|
||||
private val primaryConstructorParameters: List<JetParameter>? = null
|
||||
) {
|
||||
private val scopeForClassHeaderResolution = storageManager.createLazyValue { computeScopeForClassHeaderResolution() }
|
||||
private val scopeForMemberDeclarationResolution = storageManager.createLazyValue { computeScopeForMemberDeclarationResolution() }
|
||||
private val scopeForStaticMemberDeclarationResolution = storageManager.createLazyValue { computeScopeForStaticMemberDeclarationResolution() }
|
||||
|
||||
|
||||
fun getScopeForClassHeaderResolution(): JetScope = scopeForClassHeaderResolution()
|
||||
|
||||
fun getScopeForMemberDeclarationResolution(): JetScope = scopeForMemberDeclarationResolution()
|
||||
|
||||
fun getScopeForStaticMemberDeclarationResolution(): JetScope = scopeForStaticMemberDeclarationResolution()
|
||||
|
||||
private fun computeScopeForClassHeaderResolution(): JetScope {
|
||||
val scope = WritableScopeImpl(JetScope.Empty, classDescriptor, RedeclarationHandler.DO_NOTHING, "Scope with type parameters for " + classDescriptor.getName())
|
||||
for (typeParameterDescriptor in classDescriptor.getTypeConstructor().getParameters()) {
|
||||
scope.addClassifierDescriptor(typeParameterDescriptor)
|
||||
private fun scopeWithGenerics(parent: LexicalScope, debugName: String): LexicalScopeImpl {
|
||||
return LexicalScopeImpl(parent, classDescriptor, false, null, debugName) {
|
||||
classDescriptor.typeConstructor.parameters.forEach { addClassifierDescriptor(it) }
|
||||
}
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING)
|
||||
|
||||
return ChainedScope(classDescriptor, "ScopeForClassHeaderResolution: " + classDescriptor.getName(), scope, getOuterScope())
|
||||
}
|
||||
|
||||
private fun computeScopeForMemberDeclarationResolution(): JetScope {
|
||||
val thisScope = scopeWithThis(classDescriptor)
|
||||
|
||||
return ChainedScope(
|
||||
classDescriptor,
|
||||
"ScopeForMemberDeclarationResolution: " + classDescriptor.getName(),
|
||||
thisScope,
|
||||
classDescriptor.unsubstitutedInnerClassesScope,
|
||||
getScopeForClassHeaderResolution(),
|
||||
getCompanionObjectScope(),
|
||||
classDescriptor.getStaticScope())
|
||||
public val scopeForClassHeaderResolution: () -> LexicalScope = storageManager.createLazyValue {
|
||||
scopeWithGenerics(getOuterScope(), "Scope for class header resolution for ${classDescriptor.name}")
|
||||
}
|
||||
|
||||
private fun scopeWithThis(descriptor: ClassDescriptor): WritableScopeImpl {
|
||||
val thisScope = WritableScopeImpl(JetScope.Empty, descriptor, RedeclarationHandler.DO_NOTHING,
|
||||
"Scope with 'this' for " + descriptor.getName(), descriptor.getThisAsReceiverParameter(), descriptor)
|
||||
thisScope.changeLockLevel(WritableScope.LockLevel.READING)
|
||||
return thisScope
|
||||
private val scopeWithStaticMembersAndCompanionObjectReceiver = storageManager.createLazyValue {
|
||||
val staticScopes = classDescriptor.companionObjectDescriptor?.let {
|
||||
arrayOf(classDescriptor.staticScope, it.unsubstitutedInnerClassesScope)
|
||||
} ?: arrayOf(classDescriptor.staticScope)
|
||||
|
||||
LexicalChainedScope(getOuterScope(), classDescriptor, false,
|
||||
classDescriptor.companionObjectDescriptor?.thisAsReceiverParameter,
|
||||
"Scope with static members and companion object for ${classDescriptor.name}",
|
||||
memberScopes = *staticScopes)
|
||||
}
|
||||
|
||||
private fun computeScopeForStaticMemberDeclarationResolution(): JetScope {
|
||||
if (classDescriptor.getKind().isSingleton) return scopeForMemberDeclarationResolution()
|
||||
|
||||
return ChainedScope(
|
||||
classDescriptor,
|
||||
"ScopeForStaticMemberDeclarationResolution: " + classDescriptor.getName(),
|
||||
classDescriptor.unsubstitutedInnerClassesScope,
|
||||
getOuterScope(),
|
||||
getCompanionObjectScope(),
|
||||
classDescriptor.getStaticScope())
|
||||
public val scopeForMemberDeclarationResolution: () -> LexicalScope = storageManager.createLazyValue {
|
||||
val scopeWithGenerics = scopeWithGenerics(scopeWithStaticMembersAndCompanionObjectReceiver(),
|
||||
"Scope with generics for ${classDescriptor.name}")
|
||||
LexicalChainedScope(scopeWithGenerics, classDescriptor, true, classDescriptor.thisAsReceiverParameter,
|
||||
"Scope for member declaration resolution: ${classDescriptor.name}",
|
||||
classDescriptor.unsubstitutedInnerClassesScope)
|
||||
}
|
||||
|
||||
private fun getCompanionObjectScope(): JetScope {
|
||||
val companionObjectDescriptor = classDescriptor.getCompanionObjectDescriptor()
|
||||
return if (companionObjectDescriptor != null) {
|
||||
ChainedScope(companionObjectDescriptor, "Companion object scope for class: ${classDescriptor.getName()}",
|
||||
scopeWithThis(companionObjectDescriptor), companionObjectDescriptor.unsubstitutedInnerClassesScope)
|
||||
public val scopeForStaticMemberDeclarationResolution: () -> LexicalScope = storageManager.createLazyValue {
|
||||
if (classDescriptor.kind.isSingleton) {
|
||||
scopeForMemberDeclarationResolution()
|
||||
}
|
||||
else {
|
||||
LexicalChainedScope(scopeWithStaticMembersAndCompanionObjectReceiver(), classDescriptor, false, null,
|
||||
"Scope for static member declaration resolution: ${classDescriptor.name}",
|
||||
classDescriptor.unsubstitutedInnerClassesScope)
|
||||
}
|
||||
else JetScope.Empty
|
||||
}
|
||||
|
||||
public val scopeForInitializerResolution: () -> LexicalScope = storageManager.createLazyValue {
|
||||
val primaryConstructor = classDescriptor.unsubstitutedPrimaryConstructor ?:
|
||||
return@createLazyValue scopeForMemberDeclarationResolution()
|
||||
assert(primaryConstructorParameters != null) {
|
||||
"primary constructor parameters must be not null, because primary constructor exist: $primaryConstructor"
|
||||
}
|
||||
LexicalScopeImpl(scopeForMemberDeclarationResolution(), primaryConstructor, false, null,
|
||||
"Scope for initializer resolution: ${classDescriptor.name}") {
|
||||
primaryConstructorParameters!!.forEachIndexed {
|
||||
index, parameter ->
|
||||
if (!parameter.hasValOrVar()) {
|
||||
addVariableDescriptor(primaryConstructor.valueParameters[index])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+27
-53
@@ -45,7 +45,10 @@ import org.jetbrains.kotlin.resolve.lazy.data.JetClassLikeInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.JetClassOrObjectInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.data.JetObjectInfo;
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider;
|
||||
import org.jetbrains.kotlin.resolve.scopes.*;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.StaticScopeForKotlinClass;
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
|
||||
import org.jetbrains.kotlin.storage.MemoizedFunctionToNotNull;
|
||||
import org.jetbrains.kotlin.storage.NotNullLazyValue;
|
||||
import org.jetbrains.kotlin.storage.NullableLazyValue;
|
||||
@@ -74,7 +77,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
};
|
||||
private final LazyClassContext c;
|
||||
|
||||
private final JetClassLikeInfo originalClassInfo;
|
||||
private final ClassMemberDeclarationProvider declarationProvider;
|
||||
|
||||
private final LazyClassTypeConstructor typeConstructor;
|
||||
@@ -91,8 +93,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
private final LazyClassMemberScope unsubstitutedMemberScope;
|
||||
private final JetScope staticScope;
|
||||
|
||||
private final NotNullLazyValue<JetScope> scopeForPropertyInitializerResolution;
|
||||
|
||||
private final NullableLazyValue<Void> forceResolveAllContents;
|
||||
private final boolean isCompanionObject;
|
||||
|
||||
@@ -115,7 +115,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
this.c.getTrace().record(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, DescriptorUtils.getFqName(this), this);
|
||||
|
||||
this.originalClassInfo = classLikeInfo;
|
||||
this.declarationProvider = c.getDeclarationProviderFactory().getClassMemberDeclarationProvider(classLikeInfo);
|
||||
|
||||
this.unsubstitutedMemberScope = createMemberScope(c, this.declarationProvider);
|
||||
@@ -172,7 +171,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
@NotNull
|
||||
@Override
|
||||
public JetScope getScope() {
|
||||
return getOuterScope();
|
||||
return UtilsPackage.asJetScope(getOuterScope());
|
||||
}
|
||||
},
|
||||
modifierList.getAnnotationEntries()
|
||||
@@ -197,7 +196,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
@NotNull
|
||||
@Override
|
||||
public JetScope getScope() {
|
||||
return getScopeForMemberDeclarationResolution();
|
||||
return UtilsPackage.asJetScope(getScopeForMemberDeclarationResolution());
|
||||
}
|
||||
},
|
||||
jetDanglingAnnotations
|
||||
@@ -216,12 +215,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
return computeCompanionObjectDescriptor(companionObject);
|
||||
}
|
||||
});
|
||||
this.scopeForPropertyInitializerResolution = storageManager.createLazyValue(new Function0<JetScope>() {
|
||||
@Override
|
||||
public JetScope invoke() {
|
||||
return computeScopeForPropertyInitializerResolution();
|
||||
}
|
||||
});
|
||||
this.forceResolveAllContents = storageManager.createRecursionTolerantNullableLazyValue(new Function0<Void>() {
|
||||
@Override
|
||||
public Void invoke() {
|
||||
@@ -230,12 +223,12 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
}, null);
|
||||
|
||||
this.resolutionScopesSupport = new ClassResolutionScopesSupport(this, storageManager, new Function0<JetScope>() {
|
||||
this.resolutionScopesSupport = new ClassResolutionScopesSupport(this, storageManager, new Function0<LexicalScope>() {
|
||||
@Override
|
||||
public JetScope invoke() {
|
||||
public LexicalScope invoke() {
|
||||
return getOuterScope();
|
||||
}
|
||||
});
|
||||
}, classLikeInfo.getPrimaryConstructorParameters());
|
||||
}
|
||||
|
||||
// NOTE: Called from constructor!
|
||||
@@ -253,31 +246,33 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
return unsubstitutedMemberScope;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetScope getScopeForClassHeaderResolution() {
|
||||
return resolutionScopesSupport.getScopeForClassHeaderResolution();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected JetScope getOuterScope() {
|
||||
protected LexicalScope getOuterScope() {
|
||||
return c.getDeclarationScopeProvider().getResolutionScopeForDeclaration(declarationProvider.getOwnerInfo().getScopeAnchor());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetScope getScopeForMemberDeclarationResolution() {
|
||||
return resolutionScopesSupport.getScopeForMemberDeclarationResolution();
|
||||
}
|
||||
|
||||
public JetScope getScopeForStaticMemberDeclarationResolution() {
|
||||
return resolutionScopesSupport.getScopeForStaticMemberDeclarationResolution();
|
||||
public LexicalScope getScopeForClassHeaderResolution() {
|
||||
return resolutionScopesSupport.getScopeForClassHeaderResolution().invoke();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public JetScope getScopeForInitializerResolution() {
|
||||
return scopeForPropertyInitializerResolution.invoke();
|
||||
public LexicalScope getScopeForMemberDeclarationResolution() {
|
||||
return resolutionScopesSupport.getScopeForMemberDeclarationResolution().invoke();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public LexicalScope getScopeForStaticMemberDeclarationResolution() {
|
||||
return resolutionScopesSupport.getScopeForStaticMemberDeclarationResolution().invoke();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public LexicalScope getScopeForInitializerResolution() {
|
||||
return resolutionScopesSupport.getScopeForInitializerResolution().invoke();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -296,27 +291,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JetScope computeScopeForPropertyInitializerResolution() {
|
||||
ConstructorDescriptor primaryConstructor = getUnsubstitutedPrimaryConstructor();
|
||||
if (primaryConstructor == null) return getScopeForMemberDeclarationResolution();
|
||||
|
||||
WritableScopeImpl scope = new WritableScopeImpl(JetScope.Empty.INSTANCE$, primaryConstructor, RedeclarationHandler.DO_NOTHING, "Scope with constructor parameters in " + getName());
|
||||
for (int i = 0; i < originalClassInfo.getPrimaryConstructorParameters().size(); i++) {
|
||||
JetParameter jetParameter = originalClassInfo.getPrimaryConstructorParameters().get(i);
|
||||
if (!jetParameter.hasValOrVar()) {
|
||||
scope.addVariableDescriptor(primaryConstructor.getValueParameters().get(i));
|
||||
}
|
||||
}
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
return new ChainedScope(
|
||||
primaryConstructor,
|
||||
"ScopeForPropertyInitializerResolution: " + getName(),
|
||||
scope, getScopeForMemberDeclarationResolution());
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public JetScope getStaticScope() {
|
||||
@@ -536,7 +510,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
|
||||
}
|
||||
|
||||
List<JetType> allSupertypes = c.getDescriptorResolver()
|
||||
.resolveSupertypes(getScopeForClassHeaderResolution(), LazyClassDescriptor.this, classOrObject,
|
||||
.resolveSupertypes(UtilsPackage.asJetScope(getScopeForClassHeaderResolution()), LazyClassDescriptor.this, classOrObject,
|
||||
c.getTrace());
|
||||
|
||||
return new Supertypes(Lists.newArrayList(Collections2.filter(allSupertypes, VALID_SUPERTYPE)));
|
||||
|
||||
+7
-5
@@ -36,6 +36,8 @@ import org.jetbrains.kotlin.resolve.lazy.LazyClassContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.varianceChecker.VarianceChecker
|
||||
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
||||
import org.jetbrains.kotlin.storage.NullableLazyValue
|
||||
@@ -91,7 +93,7 @@ public open class LazyClassMemberScope(
|
||||
private val primaryConstructor: NullableLazyValue<ConstructorDescriptor>
|
||||
= c.storageManager.createNullableLazyValue { resolvePrimaryConstructor() }
|
||||
|
||||
override fun getScopeForMemberDeclarationResolution(declaration: JetDeclaration): JetScope {
|
||||
override fun getScopeForMemberDeclarationResolution(declaration: JetDeclaration): LexicalScope {
|
||||
if (declaration is JetProperty) {
|
||||
return thisDescriptor.getScopeForInitializerResolution()
|
||||
}
|
||||
@@ -222,7 +224,7 @@ public open class LazyClassMemberScope(
|
||||
val parameter = primaryConstructorParameters.get(valueParameterDescriptor.getIndex())
|
||||
if (parameter.hasValOrVar()) {
|
||||
val propertyDescriptor = c.descriptorResolver.resolvePrimaryConstructorParameterToAProperty(
|
||||
thisDescriptor, valueParameterDescriptor, thisDescriptor.getScopeForClassHeaderResolution(), parameter, trace)
|
||||
thisDescriptor, valueParameterDescriptor, thisDescriptor.getScopeForClassHeaderResolution().asJetScope(), parameter, trace)
|
||||
result.add(propertyDescriptor)
|
||||
}
|
||||
}
|
||||
@@ -233,7 +235,7 @@ public open class LazyClassMemberScope(
|
||||
?: return setOf()
|
||||
|
||||
val lazyTypeResolver = DelegationResolver.TypeResolver { reference ->
|
||||
c.typeResolver.resolveType(thisDescriptor.getScopeForClassHeaderResolution(), reference, trace, false)
|
||||
c.typeResolver.resolveType(thisDescriptor.getScopeForClassHeaderResolution().asJetScope(), reference, trace, false)
|
||||
}
|
||||
val lazyMemberExtractor = DelegationResolver.MemberExtractor<T> {
|
||||
type -> extractor.extract(type, name)
|
||||
@@ -282,7 +284,7 @@ public open class LazyClassMemberScope(
|
||||
|
||||
if (DescriptorUtils.canHaveDeclaredConstructors(thisDescriptor) || hasPrimaryConstructor) {
|
||||
val constructor = c.functionDescriptorResolver.resolvePrimaryConstructorDescriptor(
|
||||
thisDescriptor.getScopeForClassHeaderResolution(), thisDescriptor, classOrObject, trace)
|
||||
thisDescriptor.getScopeForClassHeaderResolution().asJetScope(), thisDescriptor, classOrObject, trace)
|
||||
constructor ?: return null
|
||||
setDeferredReturnType(constructor)
|
||||
return constructor
|
||||
@@ -299,7 +301,7 @@ public open class LazyClassMemberScope(
|
||||
|
||||
return classOrObject.getSecondaryConstructors().map { constructor ->
|
||||
val descriptor = c.functionDescriptorResolver.resolveSecondaryConstructorDescriptor(
|
||||
thisDescriptor.getScopeForClassHeaderResolution(), thisDescriptor, constructor, trace
|
||||
thisDescriptor.getScopeForClassHeaderResolution().asJetScope(), thisDescriptor, constructor, trace
|
||||
)
|
||||
setDeferredReturnType(descriptor)
|
||||
descriptor
|
||||
|
||||
+3
-5
@@ -19,15 +19,13 @@ package org.jetbrains.kotlin.resolve.lazy.descriptors;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
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.LazyClassContext;
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyEntity;
|
||||
import org.jetbrains.kotlin.types.ErrorUtils;
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -69,7 +67,7 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
|
||||
JetTypeReference extendsBound = jetTypeParameter.getExtendsBound();
|
||||
if (extendsBound != null) {
|
||||
JetType boundType = c.getDescriptorResolver().resolveTypeParameterExtendsBound(
|
||||
this, extendsBound, getContainingDeclaration().getScopeForClassHeaderResolution(), c.getTrace());
|
||||
this, extendsBound, UtilsPackage.asJetScope(getContainingDeclaration().getScopeForClassHeaderResolution()), c.getTrace());
|
||||
upperBounds.add(boundType);
|
||||
}
|
||||
|
||||
@@ -106,7 +104,7 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
|
||||
|
||||
private JetType resolveBoundType(@NotNull JetTypeReference boundTypeReference) {
|
||||
return c.getTypeResolver()
|
||||
.resolveType(getContainingDeclaration().getScopeForClassHeaderResolution(), boundTypeReference,
|
||||
.resolveType(UtilsPackage.asJetScope(getContainingDeclaration().getScopeForClassHeaderResolution()), boundTypeReference,
|
||||
c.getTrace(), false);
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -41,8 +41,9 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProviderFactory
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.PackageMemberDeclarationProvider
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.PsiBasedClassMemberDeclarationProvider
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.WritableScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsFileScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.DynamicTypesSettings
|
||||
|
||||
@@ -144,9 +145,9 @@ class LocalClassDescriptorHolder(
|
||||
return classDescriptor!!
|
||||
}
|
||||
|
||||
fun getResolutionScopeForClass(classOrObject: JetClassOrObject): JetScope {
|
||||
fun getResolutionScopeForClass(classOrObject: JetClassOrObject): LexicalScope {
|
||||
assert (isMyClass(classOrObject)) { "Called on a wrong class: ${classOrObject.getDebugText()}" }
|
||||
return expressionTypingContext.scope
|
||||
return expressionTypingContext.scope.memberScopeAsFileScope()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +172,7 @@ class DeclarationScopeProviderForLocalClassifierAnalyzer(
|
||||
fileScopeProvider: FileScopeProvider,
|
||||
private val localClassDescriptorManager: LocalClassDescriptorHolder
|
||||
) : DeclarationScopeProviderImpl(lazyDeclarationResolver, fileScopeProvider) {
|
||||
override fun getResolutionScopeForDeclaration(elementOfDeclaration: PsiElement): JetScope {
|
||||
override fun getResolutionScopeForDeclaration(elementOfDeclaration: PsiElement): LexicalScope {
|
||||
if (localClassDescriptorManager.isMyClass(elementOfDeclaration)) {
|
||||
return localClassDescriptorManager.getResolutionScopeForClass(elementOfDeclaration as JetClassOrObject)
|
||||
}
|
||||
|
||||
@@ -9,8 +9,7 @@ class WithClassObject {
|
||||
class ~class-object~TestClass
|
||||
}
|
||||
|
||||
// TODO: Isn't it a bug?
|
||||
val a2: `testing`TestClass? = null
|
||||
val a2: `class-object`TestClass? = null
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user