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
|
||||
}
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||
import org.jetbrains.kotlin.resolve.scopes.ChainedScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
@@ -95,7 +96,7 @@ public class CodeFragmentAnalyzer(
|
||||
is JetClassOrObject -> {
|
||||
val descriptor = resolveSession.getClassDescriptor(context, NoLookupLocation.FROM_IDE) as ClassDescriptorWithResolutionScopes
|
||||
|
||||
scopeForContextElement = descriptor.getScopeForMemberDeclarationResolution()
|
||||
scopeForContextElement = descriptor.getScopeForMemberDeclarationResolution().asJetScope()
|
||||
dataFlowInfo = DataFlowInfo.EMPTY
|
||||
}
|
||||
is JetExpression -> {
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.jetbrains.kotlin.frontend.di.createContainerForBodyResolve
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.CodeFragmentAnalyzer
|
||||
import org.jetbrains.kotlin.idea.stubindex.JetProbablyNothingFunctionShortNameIndex
|
||||
import org.jetbrains.kotlin.idea.stubindex.JetProbablyNothingPropertyShortNameIndex
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||
@@ -43,10 +42,9 @@ import org.jetbrains.kotlin.resolve.*
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.lazy.*
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyPackageDescriptor
|
||||
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.utils.addToStdlib.check
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
|
||||
public class ResolveElementCache(
|
||||
private val resolveSession: ResolveSession,
|
||||
@@ -409,15 +407,15 @@ public class ResolveElementCache(
|
||||
classOrObject,
|
||||
descriptor,
|
||||
descriptor.getUnsubstitutedPrimaryConstructor(),
|
||||
descriptor.getScopeForClassHeaderResolution(),
|
||||
descriptor.getScopeForMemberDeclarationResolution())
|
||||
descriptor.getScopeForClassHeaderResolution().asJetScope(),
|
||||
descriptor.getScopeForMemberDeclarationResolution().asJetScope())
|
||||
|
||||
return trace
|
||||
}
|
||||
|
||||
private fun propertyAdditionalResolve(resolveSession: ResolveSession, jetProperty: JetProperty, file: JetFile, statementFilter: StatementFilter): BindingTrace {
|
||||
val trace = createDelegatingTrace(jetProperty)
|
||||
val propertyResolutionScope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(jetProperty)
|
||||
val propertyResolutionScope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(jetProperty).asJetScope()
|
||||
|
||||
val bodyResolver = createBodyResolver(resolveSession, trace, file, statementFilter)
|
||||
val descriptor = resolveSession.resolveToDescriptor(jetProperty) as PropertyDescriptor
|
||||
@@ -450,7 +448,7 @@ public class ResolveElementCache(
|
||||
private fun functionAdditionalResolve(resolveSession: ResolveSession, namedFunction: JetNamedFunction, file: JetFile, statementFilter: StatementFilter): BindingTrace {
|
||||
val trace = createDelegatingTrace(namedFunction)
|
||||
|
||||
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(namedFunction)
|
||||
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(namedFunction).asJetScope()
|
||||
val functionDescriptor = resolveSession.resolveToDescriptor(namedFunction) as FunctionDescriptor
|
||||
ForceResolveUtil.forceResolveAllContents(functionDescriptor)
|
||||
|
||||
@@ -463,7 +461,7 @@ public class ResolveElementCache(
|
||||
private fun secondaryConstructorAdditionalResolve(resolveSession: ResolveSession, constructor: JetSecondaryConstructor, file: JetFile, statementFilter: StatementFilter): BindingTrace {
|
||||
val trace = createDelegatingTrace(constructor)
|
||||
|
||||
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(constructor)
|
||||
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(constructor).asJetScope()
|
||||
val constructorDescriptor = resolveSession.resolveToDescriptor(constructor) as ConstructorDescriptor
|
||||
ForceResolveUtil.forceResolveAllContents(constructorDescriptor)
|
||||
|
||||
@@ -475,7 +473,7 @@ public class ResolveElementCache(
|
||||
|
||||
private fun constructorAdditionalResolve(resolveSession: ResolveSession, klass: JetClass, file: JetFile): BindingTrace {
|
||||
val trace = createDelegatingTrace(klass)
|
||||
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(klass)
|
||||
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(klass).asJetScope()
|
||||
|
||||
val classDescriptor = resolveSession.resolveToDescriptor(klass) as ClassDescriptor
|
||||
val constructorDescriptor = classDescriptor.getUnsubstitutedPrimaryConstructor()
|
||||
@@ -523,7 +521,7 @@ public class ResolveElementCache(
|
||||
|
||||
private class BodyResolveContextForLazy(
|
||||
private val topDownAnalysisMode: TopDownAnalysisMode,
|
||||
private val declaringScopes: Function1<JetDeclaration, JetScope?>
|
||||
private val declaringScopes: Function1<JetDeclaration, LexicalScope?>
|
||||
) : BodiesResolveContext {
|
||||
override fun getFiles(): Collection<JetFile> = setOf()
|
||||
|
||||
@@ -537,7 +535,7 @@ public class ResolveElementCache(
|
||||
|
||||
override fun getFunctions(): MutableMap<JetNamedFunction, SimpleFunctionDescriptor> = hashMapOf()
|
||||
|
||||
override fun getDeclaringScope(declaration: JetDeclaration): JetScope? = declaringScopes(declaration)
|
||||
override fun getDeclaringScope(declaration: JetDeclaration): LexicalScope? = declaringScopes(declaration)
|
||||
|
||||
override fun getScripts(): MutableMap<JetScript, ScriptDescriptor> = hashMapOf()
|
||||
|
||||
|
||||
@@ -20,15 +20,16 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getFileTopLevelScope
|
||||
import org.jetbrains.kotlin.idea.resolve.ResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.util.getImplicitReceiversWithInstanceToExpression
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import java.util.HashMap
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import java.util.*
|
||||
|
||||
public fun Call.mapArgumentsToParameters(targetDescriptor: CallableDescriptor): Map<ValueArgument, ValueParameterDescriptor> {
|
||||
val parameters = targetDescriptor.getValueParameters()
|
||||
@@ -89,7 +90,7 @@ public fun PsiElement.getResolutionScope(bindingContext: BindingContext, resolut
|
||||
if (parent is JetClassBody) {
|
||||
val classDescriptor = bindingContext[BindingContext.CLASS, parent.getParent()] as? ClassDescriptorWithResolutionScopes
|
||||
if (classDescriptor != null) {
|
||||
return classDescriptor.getScopeForMemberDeclarationResolution()
|
||||
return classDescriptor.getScopeForMemberDeclarationResolution().asJetScope()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSupport
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsFileScope
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
@@ -177,11 +179,12 @@ object ReplaceWithAnnotationAnalyzer {
|
||||
descriptor.memberScope
|
||||
|
||||
is ClassDescriptorWithResolutionScopes ->
|
||||
descriptor.getScopeForMemberDeclarationResolution()
|
||||
descriptor.getScopeForMemberDeclarationResolution().asJetScope()
|
||||
|
||||
is ClassDescriptor -> {
|
||||
val outerScope = getResolutionScope(descriptor.getContainingDeclaration())
|
||||
ClassResolutionScopesSupport(descriptor, LockBasedStorageManager.NO_LOCKS, { outerScope }).getScopeForMemberDeclarationResolution()
|
||||
ClassResolutionScopesSupport(descriptor, LockBasedStorageManager.NO_LOCKS, { outerScope.memberScopeAsFileScope() })
|
||||
.scopeForMemberDeclarationResolution().asJetScope()
|
||||
}
|
||||
|
||||
is FunctionDescriptor ->
|
||||
|
||||
+2
-2
@@ -54,7 +54,6 @@ import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.util.ShortenReferences
|
||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.lexer.JetTokens
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
@@ -66,6 +65,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.scopes.*
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
@@ -341,7 +341,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
}
|
||||
|
||||
if (receiverClassDescriptor is ClassDescriptorWithResolutionScopes) {
|
||||
return receiverClassDescriptor.getScopeForMemberDeclarationResolution()
|
||||
return receiverClassDescriptor.getScopeForMemberDeclarationResolution().asJetScope()
|
||||
}
|
||||
|
||||
assert (receiverClassDescriptor is JavaClassDescriptor) { "Unexpected receiver class: $receiverClassDescriptor" }
|
||||
|
||||
+3
-2
@@ -37,10 +37,11 @@ import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElement
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import java.util.LinkedHashSet
|
||||
import java.util.*
|
||||
|
||||
object CreateParameterByRefActionFactory : CreateParameterFromUsageFactory<JetSimpleNameExpression>() {
|
||||
override fun getElementOfInterest(diagnostic: Diagnostic): JetSimpleNameExpression? {
|
||||
@@ -126,7 +127,7 @@ fun JetType.hasTypeParametersToAdd(functionDescriptor: FunctionDescriptor, conte
|
||||
val scope =
|
||||
when (functionDescriptor) {
|
||||
is ConstructorDescriptor -> {
|
||||
(functionDescriptor.containingDeclaration as? ClassDescriptorWithResolutionScopes)?.scopeForClassHeaderResolution
|
||||
(functionDescriptor.containingDeclaration as? ClassDescriptorWithResolutionScopes)?.scopeForClassHeaderResolution?.asJetScope()
|
||||
}
|
||||
|
||||
is FunctionDescriptor -> {
|
||||
|
||||
@@ -43,8 +43,8 @@ import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.OverrideResolver
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope
|
||||
import java.util.Collections
|
||||
import java.util.HashSet
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
|
||||
import java.util.*
|
||||
|
||||
public abstract class CallableRefactoring<T: CallableDescriptor>(
|
||||
val project: Project,
|
||||
@@ -192,7 +192,7 @@ fun DeclarationDescriptor.getContainingScope(bindingContext: BindingContext): Je
|
||||
else {
|
||||
val containingDescriptor = getContainingDeclaration() ?: return null
|
||||
return when (containingDescriptor) {
|
||||
is ClassDescriptorWithResolutionScopes -> containingDescriptor.getScopeForInitializerResolution()
|
||||
is ClassDescriptorWithResolutionScopes -> containingDescriptor.getScopeForInitializerResolution().asJetScope()
|
||||
is PackageFragmentDescriptor -> containingDescriptor.getMemberScope()
|
||||
else -> null
|
||||
}
|
||||
|
||||
+2
-1
@@ -74,6 +74,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver;
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
|
||||
import org.jetbrains.kotlin.types.JetType;
|
||||
|
||||
import java.util.*;
|
||||
@@ -609,7 +610,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
|
||||
|
||||
JetScope parametersScope = null;
|
||||
if (oldDescriptor instanceof ConstructorDescriptor && containingDeclaration instanceof ClassDescriptorWithResolutionScopes)
|
||||
parametersScope = ((ClassDescriptorWithResolutionScopes) containingDeclaration).getScopeForInitializerResolution();
|
||||
parametersScope = UtilsPackage.asJetScope(((ClassDescriptorWithResolutionScopes) containingDeclaration).getScopeForInitializerResolution());
|
||||
else if (function instanceof JetFunction)
|
||||
parametersScope = org.jetbrains.kotlin.idea.refactoring.RefactoringPackage.getBodyScope((JetFunction) function, bindingContext);
|
||||
|
||||
|
||||
@@ -6,28 +6,28 @@ import bar.*
|
||||
val a = 1
|
||||
var b = ""
|
||||
|
||||
val c: /*c:foo.A p:foo*/String
|
||||
get() = /*c:foo.A p:foo p:bar c:foo.A.Companion*/b
|
||||
val c: /*c:foo.A c:foo.A.Companion p:foo*/String
|
||||
get() = /*p:foo p:bar c:foo.A c:foo.A.Companion*/b
|
||||
|
||||
var d: /*c:foo.A p:foo*/String = "ddd"
|
||||
get() = /*c:foo.A p:foo p:bar c:foo.A.Companion*/$d
|
||||
set(v) { /*c:foo.A p:foo p:bar c:foo.A.Companion*/$d = v }
|
||||
var d: /*c:foo.A c:foo.A.Companion p:foo*/String = "ddd"
|
||||
get() = /*p:foo p:bar c:foo.A c:foo.A.Companion*/$d
|
||||
set(v) { /*p:foo p:bar c:foo.A c:foo.A.Companion*/$d = v }
|
||||
|
||||
fun foo() {
|
||||
/*c:foo.A p:foo p:bar c:foo.A.Companion*/a
|
||||
/*c:foo.A p:foo p:bar c:foo.A.Companion*/foo()
|
||||
/*p:foo p:bar c:foo.A c:foo.A.Companion*/a
|
||||
/*p:foo p:bar c:foo.A c:foo.A.Companion*/foo()
|
||||
this./*c:foo.A*/a
|
||||
this./*c:foo.A*/foo()
|
||||
/*c:foo.A p:foo p:bar c:foo.A.Companion*/baz()
|
||||
/*c:foo.A p:foo p:bar c:foo.A.Companion*/Companion./*c:foo.A.Companion*/a
|
||||
/*c:foo.A p:foo p:bar c:foo.A.Companion*/O./*c:foo.A.O*/v = "OK"
|
||||
/*p:foo p:bar c:foo.A c:foo.A.Companion*/baz()
|
||||
/*p:foo p:bar c:foo.A c:foo.A.Companion*/Companion./*c:foo.A.Companion*/a
|
||||
/*p:foo p:bar c:foo.A c:foo.A.Companion*/O./*c:foo.A.O*/v = "OK"
|
||||
}
|
||||
|
||||
class B {
|
||||
val a = 1
|
||||
|
||||
companion object CO {
|
||||
fun bar(a: /*c:foo.A.B.CO c:foo.A.B c:foo.A p:foo*/Int) {}
|
||||
fun bar(a: /*c:foo.A.B.CO c:foo.A.B c:foo.A c:foo.A.Companion p:foo*/Int) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,10 +59,10 @@ import bar.*
|
||||
|
||||
val a = 1
|
||||
fun foo() {
|
||||
/*c:foo.E p:foo p:bar*/a
|
||||
/*c:foo.E p:foo p:bar*/Y./*c:foo.E*/a
|
||||
/*c:foo.E p:foo p:bar*/foo()
|
||||
/*c:foo.E p:foo p:bar*/X./*c:foo.E*/foo()
|
||||
/*p:foo p:bar c:foo.E*/a
|
||||
/*p:foo p:bar c:foo.E*/Y./*c:foo.E*/a
|
||||
/*p:foo p:bar c:foo.E*/foo()
|
||||
/*p:foo p:bar c:foo.E*/X./*c:foo.E*/foo()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user