Global replace JetScope to LexicalScope

This commit is contained in:
Stanislav Erokhin
2015-08-28 17:41:20 +03:00
parent 1b1fae8899
commit 4c7bafce45
80 changed files with 518 additions and 504 deletions
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import static org.jetbrains.kotlin.resolve.BindingContext.NEED_SYNTHETIC_ACCESSOR;
@@ -43,9 +44,9 @@ public class NeedSyntheticChecker implements CallChecker {
//Necessary synthetic accessors in outer classes generated via old logic: CodegenContext.getAccessor
//Generation of accessors in nested classes (to invoke from outer,
// e.g.: from class to companion object) controlled via NEED_SYNTHETIC_ACCESSOR slice
private boolean needSyntheticAccessor(JetScope invokationScope, CallableDescriptor targetDescriptor) {
private boolean needSyntheticAccessor(LexicalScope invokationScope, CallableDescriptor targetDescriptor) {
return targetDescriptor instanceof CallableMemberDescriptor &&
Visibilities.isPrivate(targetDescriptor.getVisibility()) &&
targetDescriptor.getContainingDeclaration() != invokationScope.getContainingDeclaration().getContainingDeclaration();
targetDescriptor.getContainingDeclaration() != invokationScope.getOwnerDescriptor().getContainingDeclaration();
}
}
@@ -38,7 +38,7 @@ public class TraitDefaultMethodCallChecker : CallChecker {
if (containerDescriptor is JavaClassDescriptor && DescriptorUtils.isTrait(containerDescriptor)) {
//is java interface default method called from trait
val classifier = DescriptorUtils.getParentOfType(context.scope.getContainingDeclaration(), javaClass<ClassifierDescriptor>())
val classifier = DescriptorUtils.getParentOfType(context.scope.ownerDescriptor, javaClass<ClassifierDescriptor>())
if (classifier != null && DescriptorUtils.isTrait(classifier)) {
context.trace.report(
@@ -38,7 +38,7 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluat
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationDescriptor;
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationsContextImpl;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.storage.StorageManager;
import org.jetbrains.kotlin.types.ErrorUtils;
@@ -74,7 +74,7 @@ public class AnnotationResolver {
@NotNull
public Annotations resolveAnnotationsWithoutArguments(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@Nullable JetModifierList modifierList,
@NotNull BindingTrace trace
) {
@@ -83,7 +83,7 @@ public class AnnotationResolver {
@NotNull
public Annotations resolveAnnotationsWithArguments(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@Nullable JetModifierList modifierList,
@NotNull BindingTrace trace
) {
@@ -92,7 +92,7 @@ public class AnnotationResolver {
@NotNull
public Annotations resolveAnnotationsWithoutArguments(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull List<JetAnnotationEntry> annotationEntries,
@NotNull BindingTrace trace
) {
@@ -101,7 +101,7 @@ public class AnnotationResolver {
@NotNull
public Annotations resolveAnnotationsWithArguments(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull List<JetAnnotationEntry> annotationEntries,
@NotNull BindingTrace trace
) {
@@ -109,7 +109,7 @@ public class AnnotationResolver {
}
private Annotations resolveAnnotations(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@Nullable JetModifierList modifierList,
@NotNull BindingTrace trace,
boolean shouldResolveArguments
@@ -124,7 +124,7 @@ public class AnnotationResolver {
}
private Annotations resolveAnnotationEntries(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull List<JetAnnotationEntry> annotationEntryElements,
@NotNull BindingTrace trace,
boolean shouldResolveArguments
@@ -146,7 +146,7 @@ public class AnnotationResolver {
}
@NotNull
public JetType resolveAnnotationType(@NotNull JetScope scope, @NotNull JetAnnotationEntry entryElement) {
public JetType resolveAnnotationType(@NotNull LexicalScope scope, @NotNull JetAnnotationEntry entryElement) {
JetTypeReference typeReference = entryElement.getTypeReference();
if (typeReference == null) {
return ErrorUtils.createErrorType("No type reference: " + entryElement.getText());
@@ -183,7 +183,7 @@ public class AnnotationResolver {
@NotNull
public OverloadResolutionResults<FunctionDescriptor> resolveAnnotationCall(
JetAnnotationEntry annotationEntry,
JetScope scope,
LexicalScope scope,
BindingTrace trace
) {
return callResolver.resolveFunctionCall(
@@ -20,6 +20,7 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.intellij.psi.PsiElement;
import com.intellij.util.containers.Queue;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -117,7 +118,7 @@ public class BodyResolver {
for (Map.Entry<JetSecondaryConstructor, ConstructorDescriptor> entry : c.getSecondaryConstructors().entrySet()) {
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(), asJetScope(declaringScope));
resolveSecondaryConstructorBody(c.getOuterDataFlowInfo(), trace, entry.getKey(), entry.getValue(), declaringScope);
}
if (c.getSecondaryConstructors().isEmpty()) return;
Set<ConstructorDescriptor> visitedConstructors = Sets.newHashSet();
@@ -131,15 +132,15 @@ public class BodyResolver {
@NotNull final BindingTrace trace,
@NotNull final JetSecondaryConstructor constructor,
@NotNull final ConstructorDescriptor descriptor,
@NotNull JetScope declaringScope
@NotNull LexicalScope declaringScope
) {
ForceResolveUtil.forceResolveAllContents(descriptor.getAnnotations());
final CallChecker callChecker = new ConstructorHeaderCallChecker(descriptor);
resolveFunctionBody(outerDataFlowInfo, trace, constructor, descriptor, declaringScope,
new Function1<JetScope, DataFlowInfo>() {
new Function1<LexicalScope, DataFlowInfo>() {
@Override
public DataFlowInfo invoke(@NotNull JetScope headerInnerScope) {
public DataFlowInfo invoke(@NotNull LexicalScope headerInnerScope) {
return resolveSecondaryConstructorDelegationCall(outerDataFlowInfo, trace, headerInnerScope, constructor, descriptor,
callChecker);
}
@@ -151,7 +152,7 @@ public class BodyResolver {
private DataFlowInfo resolveSecondaryConstructorDelegationCall(
@NotNull DataFlowInfo outerDataFlowInfo,
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetSecondaryConstructor constructor,
@NotNull ConstructorDescriptor descriptor,
@NotNull CallChecker callChecker
@@ -237,8 +238,8 @@ public class BodyResolver {
resolveDelegationSpecifierList(c.getOuterDataFlowInfo(), classOrObject, descriptor,
descriptor.getUnsubstitutedPrimaryConstructor(),
asJetScope(descriptor.getScopeForClassHeaderResolution()),
asJetScope(descriptor.getScopeForMemberDeclarationResolution()));
descriptor.getScopeForClassHeaderResolution(),
descriptor.getScopeForMemberDeclarationResolution());
}
}
@@ -247,10 +248,10 @@ public class BodyResolver {
@NotNull JetClassOrObject jetClass,
@NotNull final ClassDescriptor descriptor,
@Nullable final ConstructorDescriptor primaryConstructor,
@NotNull JetScope scopeForSupertypeResolution,
@NotNull final JetScope scopeForMemberResolution
@NotNull LexicalScope scopeForSupertypeResolution,
@NotNull final LexicalScope scopeForMemberResolution
) {
final JetScope scopeForConstructor = primaryConstructor == null
final LexicalScope scopeForConstructor = primaryConstructor == null
? null
: FunctionDescriptorUtil.getFunctionInnerScope(scopeForSupertypeResolution, primaryConstructor, trace);
final ExpressionTypingServices typeInferrer = expressionTypingServices; // TODO : flow
@@ -281,7 +282,7 @@ public class BodyResolver {
}
JetExpression delegateExpression = specifier.getDelegateExpression();
if (delegateExpression != null) {
JetScope scope = scopeForConstructor == null ? scopeForMemberResolution : scopeForConstructor;
LexicalScope scope = scopeForConstructor == null ? scopeForMemberResolution : scopeForConstructor;
JetType expectedType = supertype != null ? supertype : NO_EXPECTED_TYPE;
typeInferrer.getType(scope, delegateExpression, expectedType, outerDataFlowInfo, trace);
}
@@ -492,7 +493,7 @@ public class BodyResolver {
@NotNull JetClassInitializer anonymousInitializer,
@NotNull ClassDescriptorWithResolutionScopes classDescriptor
) {
JetScope scopeForInitializers = asJetScope(classDescriptor.getScopeForInitializerResolution());
LexicalScope scopeForInitializers = classDescriptor.getScopeForInitializerResolution();
if (!classDescriptor.getConstructors().isEmpty()) {
JetExpression body = anonymousInitializer.getBody();
if (body != null) {
@@ -506,7 +507,7 @@ public class BodyResolver {
}
}
private void processModifiersOnInitializer(@NotNull JetModifierListOwner owner, @NotNull JetScope scope) {
private void processModifiersOnInitializer(@NotNull JetModifierListOwner owner, @NotNull LexicalScope scope) {
annotationChecker.check(owner, trace, null);
ModifierCheckerCore.INSTANCE$.check(owner, trace, null);
JetModifierList modifierList = owner.getModifierList();
@@ -523,8 +524,8 @@ public class BodyResolver {
if (unsubstitutedPrimaryConstructor != null) {
ForceResolveUtil.forceResolveAllContents(unsubstitutedPrimaryConstructor.getAnnotations());
JetScope parameterScope = getPrimaryConstructorParametersScope(asJetScope(classDescriptor.getScopeForClassHeaderResolution()),
unsubstitutedPrimaryConstructor);
LexicalScope parameterScope = getPrimaryConstructorParametersScope(classDescriptor.getScopeForClassHeaderResolution(),
unsubstitutedPrimaryConstructor);
valueParameterResolver.resolveValueParameters(klass.getPrimaryConstructorParameters(),
unsubstitutedPrimaryConstructor.getValueParameters(),
parameterScope, c.getOuterDataFlowInfo(), trace);
@@ -532,32 +533,33 @@ public class BodyResolver {
}
}
private static JetScope getPrimaryConstructorParametersScope(
JetScope originalScope,
ConstructorDescriptor unsubstitutedPrimaryConstructor
private static LexicalScope getPrimaryConstructorParametersScope(
LexicalScope originalScope,
final ConstructorDescriptor unsubstitutedPrimaryConstructor
) {
WritableScope parameterScope = new WritableScopeImpl(
originalScope,
unsubstitutedPrimaryConstructor,
RedeclarationHandler.DO_NOTHING, "Scope with value parameters of a constructor"
);
for (ValueParameterDescriptor valueParameterDescriptor : unsubstitutedPrimaryConstructor.getValueParameters()) {
parameterScope.addVariableDescriptor(valueParameterDescriptor);
}
parameterScope.changeLockLevel(WritableScope.LockLevel.READING);
return parameterScope;
return new LexicalScopeImpl(originalScope, unsubstitutedPrimaryConstructor, false, null,
"Scope with value parameters of a constructor", RedeclarationHandler.DO_NOTHING,
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
for (ValueParameterDescriptor valueParameterDescriptor : unsubstitutedPrimaryConstructor.getValueParameters()) {
handler.addVariableDescriptor(valueParameterDescriptor);
}
return Unit.INSTANCE$;
}
});
}
private void resolveProperty(
@NotNull BodiesResolveContext c,
@Nullable JetScope parentScope,
@Nullable LexicalScope parentScope,
@NotNull JetProperty property,
@NotNull PropertyDescriptor propertyDescriptor
) {
computeDeferredType(propertyDescriptor.getReturnType());
JetExpression initializer = property.getInitializer();
JetScope propertyScope = getScopeForProperty(c, property);
LexicalScope propertyScope = getScopeForProperty(c, property);
if (parentScope == null) {
parentScope = propertyScope;
}
@@ -587,7 +589,7 @@ public class BodyResolver {
PropertyDescriptor propertyDescriptor = c.getProperties().get(property);
assert propertyDescriptor != null;
resolveProperty(c, asJetScope(classDescriptor.getScopeForMemberDeclarationResolution()), property, propertyDescriptor);
resolveProperty(c, classDescriptor.getScopeForMemberDeclarationResolution(), property, propertyDescriptor);
processed.add(property);
}
}
@@ -603,10 +605,12 @@ public class BodyResolver {
}
}
private JetScope makeScopeForPropertyAccessor(@NotNull BodiesResolveContext c, @NotNull JetPropertyAccessor accessor, @NotNull PropertyDescriptor descriptor) {
private LexicalScope makeScopeForPropertyAccessor(
@NotNull BodiesResolveContext c, @NotNull JetPropertyAccessor accessor, @NotNull PropertyDescriptor descriptor
) {
LexicalScope accessorDeclaringScope = c.getDeclaringScope(accessor);
assert accessorDeclaringScope != null : "Scope for accessor " + accessor.getText() + " should exists";
return JetScopeUtils.makeScopeForPropertyAccessor(descriptor, asJetScope(accessorDeclaringScope), trace);
return JetScopeUtils.makeScopeForPropertyAccessor(descriptor, accessorDeclaringScope, trace);
}
public void resolvePropertyAccessors(
@@ -619,7 +623,7 @@ public class BodyResolver {
JetPropertyAccessor getter = property.getGetter();
PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter();
if (getter != null && getterDescriptor != null) {
JetScope accessorScope = makeScopeForPropertyAccessor(c, getter, propertyDescriptor);
LexicalScope accessorScope = makeScopeForPropertyAccessor(c, getter, propertyDescriptor);
ForceResolveUtil.forceResolveAllContents(getterDescriptor.getAnnotations());
resolveFunctionBody(c.getOuterDataFlowInfo(), fieldAccessTrackingTrace, getter, getterDescriptor, accessorScope);
}
@@ -627,7 +631,7 @@ public class BodyResolver {
JetPropertyAccessor setter = property.getSetter();
PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter();
if (setter != null && setterDescriptor != null) {
JetScope accessorScope = makeScopeForPropertyAccessor(c, setter, propertyDescriptor);
LexicalScope accessorScope = makeScopeForPropertyAccessor(c, setter, propertyDescriptor);
ForceResolveUtil.forceResolveAllContents(setterDescriptor.getAnnotations());
resolveFunctionBody(c.getOuterDataFlowInfo(), fieldAccessTrackingTrace, setter, setterDescriptor, accessorScope);
}
@@ -655,8 +659,8 @@ public class BodyResolver {
@NotNull JetProperty jetProperty,
@NotNull PropertyDescriptor propertyDescriptor,
@NotNull JetExpression delegateExpression,
@NotNull JetScope parentScopeForAccessor,
@NotNull JetScope propertyScope
@NotNull LexicalScope parentScopeForAccessor,
@NotNull LexicalScope propertyScope
) {
JetPropertyAccessor getter = jetProperty.getGetter();
if (getter != null && getter.hasBody()) {
@@ -668,9 +672,9 @@ public class BodyResolver {
trace.report(ACCESSOR_FOR_DELEGATED_PROPERTY.on(setter));
}
JetScope propertyDeclarationInnerScope = JetScopeUtils.getPropertyDeclarationInnerScopeForInitializer(
LexicalScope propertyDeclarationInnerScope = JetScopeUtils.getPropertyDeclarationInnerScopeForInitializer(
propertyDescriptor, propertyScope, propertyDescriptor.getTypeParameters(), null, trace);
JetScope accessorScope = JetScopeUtils.makeScopeForPropertyAccessor(
LexicalScope accessorScope = JetScopeUtils.makeScopeForPropertyAccessor(
propertyDescriptor, parentScopeForAccessor, trace);
JetType delegateType = delegatedPropertyResolver.resolveDelegateExpression(
@@ -694,9 +698,9 @@ public class BodyResolver {
@NotNull JetProperty property,
@NotNull PropertyDescriptor propertyDescriptor,
@NotNull JetExpression initializer,
@NotNull JetScope scope
@NotNull LexicalScope scope
) {
JetScope propertyDeclarationInnerScope = JetScopeUtils.getPropertyDeclarationInnerScopeForInitializer(
LexicalScope propertyDeclarationInnerScope = JetScopeUtils.getPropertyDeclarationInnerScopeForInitializer(
propertyDescriptor, scope, propertyDescriptor.getTypeParameters(), null, trace);
JetType expectedTypeForInitializer = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
if (propertyDescriptor.getCompileTimeInitializer() == null) {
@@ -706,10 +710,10 @@ public class BodyResolver {
}
@NotNull
private static JetScope getScopeForProperty(@NotNull BodiesResolveContext c, @NotNull JetProperty property) {
private static LexicalScope getScopeForProperty(@NotNull BodiesResolveContext c, @NotNull JetProperty property) {
LexicalScope scope = c.getDeclaringScope(property);
assert scope != null : "Scope for property " + property.getText() + " should exists";
return asJetScope(scope);
return scope;
}
private void resolveFunctionBodies(@NotNull BodiesResolveContext c) {
@@ -724,7 +728,7 @@ public class BodyResolver {
bodyResolveCache.resolveFunctionBody(declaration).addOwnDataTo(trace, true);
}
else {
resolveFunctionBody(c.getOuterDataFlowInfo(), trace, declaration, entry.getValue(), asJetScope(scope));
resolveFunctionBody(c.getOuterDataFlowInfo(), trace, declaration, entry.getValue(), scope);
}
}
}
@@ -734,7 +738,7 @@ public class BodyResolver {
@NotNull BindingTrace trace,
@NotNull JetDeclarationWithBody function,
@NotNull FunctionDescriptor functionDescriptor,
@NotNull JetScope declaringScope
@NotNull LexicalScope declaringScope
) {
computeDeferredType(functionDescriptor.getReturnType());
@@ -748,11 +752,11 @@ public class BodyResolver {
@NotNull BindingTrace trace,
@NotNull JetDeclarationWithBody function,
@NotNull FunctionDescriptor functionDescriptor,
@NotNull JetScope scope,
@Nullable Function1<JetScope, DataFlowInfo> beforeBlockBody,
@NotNull LexicalScope scope,
@Nullable Function1<LexicalScope, DataFlowInfo> beforeBlockBody,
@NotNull CallChecker callChecker
) {
JetScope innerScope = FunctionDescriptorUtil.getFunctionInnerScope(scope, functionDescriptor, trace);
LexicalScope innerScope = FunctionDescriptorUtil.getFunctionInnerScope(scope, functionDescriptor, trace);
List<JetParameter> valueParameters = function.getValueParameters();
List<ValueParameterDescriptor> valueParameterDescriptors = functionDescriptor.getValueParameters();
@@ -781,12 +785,12 @@ public class BodyResolver {
@NotNull BindingTrace trace,
@NotNull JetClass klass,
@NotNull ConstructorDescriptor constructorDescriptor,
@NotNull JetScope declaringScope
@NotNull LexicalScope declaringScope
) {
List<JetParameter> valueParameters = klass.getPrimaryConstructorParameters();
List<ValueParameterDescriptor> valueParameterDescriptors = constructorDescriptor.getValueParameters();
JetScope scope = getPrimaryConstructorParametersScope(declaringScope, constructorDescriptor);
LexicalScope scope = getPrimaryConstructorParametersScope(declaringScope, constructorDescriptor);
valueParameterResolver.resolveValueParameters(valueParameters, valueParameterDescriptors, scope, outerDataFlowInfo, trace);
}
@@ -27,7 +27,6 @@ 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;
@@ -81,7 +80,7 @@ public class DeclarationsChecker {
JetClass jetClass = (JetClass) classOrObject;
checkClass(bodiesResolveContext, jetClass, classDescriptor);
descriptorResolver.checkNamesInConstraints(
jetClass, classDescriptor, UtilsPackage.asJetScope(classDescriptor.getScopeForClassHeaderResolution()), trace);
jetClass, classDescriptor, classDescriptor.getScopeForClassHeaderResolution(), trace);
}
else if (classOrObject instanceof JetObjectDeclaration) {
checkObject((JetObjectDeclaration) classOrObject, classDescriptor);
@@ -32,7 +32,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator;
import org.jetbrains.kotlin.types.DeferredType;
@@ -81,7 +81,7 @@ public class DelegatedPropertyResolver {
@NotNull JetExpression delegateExpression,
@NotNull JetType delegateType,
@NotNull BindingTrace trace,
@NotNull JetScope scope
@NotNull LexicalScope scope
) {
resolveDelegatedPropertyConventionMethod(propertyDescriptor, delegateExpression, delegateType, trace, scope, true);
ResolvedCall<FunctionDescriptor> resolvedCall =
@@ -94,7 +94,7 @@ public class DelegatedPropertyResolver {
@NotNull JetExpression delegateExpression,
@NotNull JetType delegateType,
@NotNull BindingTrace trace,
@NotNull JetScope scope
@NotNull LexicalScope scope
) {
JetType returnType = getDelegatedPropertyGetMethodReturnType(
propertyDescriptor, delegateExpression, delegateType, trace, scope);
@@ -114,7 +114,7 @@ public class DelegatedPropertyResolver {
@NotNull JetExpression delegateExpression,
@NotNull JetType delegateType,
@NotNull BindingTrace trace,
@NotNull JetScope scope
@NotNull LexicalScope scope
) {
resolveDelegatedPropertyConventionMethod(propertyDescriptor, delegateExpression, delegateType, trace, scope, false);
}
@@ -136,7 +136,7 @@ public class DelegatedPropertyResolver {
@NotNull JetExpression delegateExpression,
@NotNull JetType delegateType,
@NotNull BindingTrace trace,
@NotNull JetScope scope
@NotNull LexicalScope scope
) {
TemporaryBindingTrace traceToResolvePDMethod = TemporaryBindingTrace.create(trace, "Trace to resolve propertyDelegated method in delegated property");
ExpressionTypingContext context = ExpressionTypingContext.newContext(
@@ -174,7 +174,7 @@ public class DelegatedPropertyResolver {
@NotNull JetExpression delegateExpression,
@NotNull JetType delegateType,
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
boolean isGet
) {
PropertyAccessorDescriptor accessor = isGet ? propertyDescriptor.getGetter() : propertyDescriptor.getSetter();
@@ -226,7 +226,7 @@ public class DelegatedPropertyResolver {
@NotNull JetExpression delegateExpression,
@NotNull JetType delegateType,
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
boolean isGet,
boolean isComplete
) {
@@ -287,8 +287,8 @@ public class DelegatedPropertyResolver {
@NotNull JetExpression delegateExpression,
@NotNull JetProperty jetProperty,
@NotNull PropertyDescriptor propertyDescriptor,
@NotNull JetScope propertyDeclarationInnerScope,
@NotNull JetScope accessorScope,
@NotNull LexicalScope propertyDeclarationInnerScope,
@NotNull LexicalScope accessorScope,
@NotNull BindingTrace trace,
@NotNull DataFlowInfo dataFlowInfo
) {
@@ -315,7 +315,7 @@ public class DelegatedPropertyResolver {
@NotNull JetProperty property,
@NotNull final PropertyDescriptor propertyDescriptor,
@NotNull final JetExpression delegateExpression,
@NotNull final JetScope accessorScope,
@NotNull final LexicalScope accessorScope,
@NotNull final BindingTrace trace
) {
final JetType expectedType = property.getTypeReference() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
@@ -39,10 +39,7 @@ import org.jetbrains.kotlin.resolve.constants.ConstantValue;
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
import org.jetbrains.kotlin.resolve.dataClassUtils.DataClassUtilsPackage;
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils;
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl;
import org.jetbrains.kotlin.resolve.scopes.*;
import org.jetbrains.kotlin.storage.StorageManager;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
@@ -57,6 +54,7 @@ import static org.jetbrains.kotlin.resolve.BindingContext.*;
import static org.jetbrains.kotlin.resolve.DescriptorUtils.*;
import static org.jetbrains.kotlin.resolve.ModifiersChecker.resolveModalityFromModifiers;
import static org.jetbrains.kotlin.resolve.ModifiersChecker.resolveVisibilityFromModifiers;
import static org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage.asJetScope;
import static org.jetbrains.kotlin.resolve.source.SourcePackage.toSourceElement;
public class DescriptorResolver {
@@ -89,7 +87,7 @@ public class DescriptorResolver {
}
public List<JetType> resolveSupertypes(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull ClassDescriptor classDescriptor,
@NotNull JetClassOrObject jetClass,
BindingTrace trace
@@ -153,7 +151,7 @@ public class DescriptorResolver {
}
public Collection<JetType> resolveDelegationSpecifiers(
JetScope extensibleScope,
LexicalScope extensibleScope,
List<JetDelegationSpecifier> delegationSpecifiers,
@NotNull TypeResolver resolver,
BindingTrace trace,
@@ -322,7 +320,7 @@ public class DescriptorResolver {
@NotNull
public ValueParameterDescriptorImpl resolveValueParameterDescriptor(
JetScope scope, FunctionDescriptor owner, JetParameter valueParameter, int index, JetType type, BindingTrace trace
LexicalScope scope, FunctionDescriptor owner, JetParameter valueParameter, int index, JetType type, BindingTrace trace
) {
JetType varargElementType = null;
JetType variableType = type;
@@ -357,7 +355,7 @@ public class DescriptorResolver {
public List<TypeParameterDescriptorImpl> resolveTypeParametersForCallableDescriptor(
DeclarationDescriptor containingDescriptor,
WritableScope extensibleScope,
LexicalWritableScope extensibleScope,
List<JetTypeParameter> typeParameters,
BindingTrace trace
) {
@@ -371,7 +369,7 @@ public class DescriptorResolver {
private TypeParameterDescriptorImpl resolveTypeParameterForCallableDescriptor(
DeclarationDescriptor containingDescriptor,
WritableScope extensibleScope,
LexicalWritableScope extensibleScope,
JetTypeParameter typeParameter,
int index,
BindingTrace trace
@@ -426,7 +424,7 @@ public class DescriptorResolver {
public JetType resolveTypeParameterExtendsBound(
@NotNull TypeParameterDescriptor typeParameterDescriptor,
@NotNull JetTypeReference extendsBound,
JetScope scope,
LexicalScope scope,
BindingTrace trace
) {
JetType type = typeResolver.resolveType(scope, extendsBound, trace, false);
@@ -440,7 +438,7 @@ public class DescriptorResolver {
public void resolveGenericBounds(
@NotNull JetTypeParameterListOwner declaration,
@NotNull DeclarationDescriptor descriptor,
JetScope scope,
LexicalScope scope,
List<TypeParameterDescriptorImpl> parameters,
BindingTrace trace
) {
@@ -513,7 +511,7 @@ public class DescriptorResolver {
public void checkNamesInConstraints(
@NotNull JetTypeParameterListOwner declaration,
@NotNull DeclarationDescriptor descriptor,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull BindingTrace trace
) {
for (JetTypeConstraint constraint : declaration.getTypeConstraints()) {
@@ -522,7 +520,7 @@ public class DescriptorResolver {
Name name = nameExpression.getReferencedNameAsName();
ClassifierDescriptor classifier = scope.getClassifier(name, NoLookupLocation.UNSORTED);
ClassifierDescriptor classifier = asJetScope(scope).getClassifier(name, NoLookupLocation.UNSORTED);
if (classifier instanceof TypeParameterDescriptor && classifier.getContainingDeclaration() == descriptor) continue;
if (classifier != null) {
@@ -556,7 +554,7 @@ public class DescriptorResolver {
@NotNull
public VariableDescriptor resolveLocalVariableDescriptor(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetParameter parameter,
BindingTrace trace
) {
@@ -564,7 +562,7 @@ public class DescriptorResolver {
return resolveLocalVariableDescriptor(parameter, type, trace, scope);
}
private JetType resolveParameterType(JetScope scope, JetParameter parameter, BindingTrace trace) {
private JetType resolveParameterType(LexicalScope scope, JetParameter parameter, BindingTrace trace) {
JetTypeReference typeReference = parameter.getTypeReference();
JetType type;
if (typeReference != null) {
@@ -584,10 +582,10 @@ public class DescriptorResolver {
@NotNull JetParameter parameter,
@NotNull JetType type,
BindingTrace trace,
@NotNull JetScope scope
@NotNull LexicalScope scope
) {
VariableDescriptor variableDescriptor = new LocalVariableDescriptor(
scope.getContainingDeclaration(),
scope.getOwnerDescriptor(),
annotationResolver.resolveAnnotationsWithArguments(scope, parameter.getModifierList(), trace),
JetPsiUtil.safeName(parameter.getName()),
type,
@@ -602,12 +600,12 @@ public class DescriptorResolver {
@NotNull
public VariableDescriptor resolveLocalVariableDescriptor(
JetScope scope,
LexicalScope scope,
JetVariableDeclaration variable,
DataFlowInfo dataFlowInfo,
BindingTrace trace
) {
DeclarationDescriptor containingDeclaration = scope.getContainingDeclaration();
DeclarationDescriptor containingDeclaration = scope.getOwnerDescriptor();
VariableDescriptor result;
JetType type;
// SCRIPT: Create property descriptors
@@ -660,13 +658,13 @@ public class DescriptorResolver {
@NotNull
public LocalVariableDescriptor resolveLocalVariableDescriptorWithType(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetVariableDeclaration variable,
@Nullable JetType type,
@NotNull BindingTrace trace
) {
LocalVariableDescriptor variableDescriptor = new LocalVariableDescriptor(
scope.getContainingDeclaration(),
scope.getOwnerDescriptor(),
annotationResolver.resolveAnnotationsWithArguments(scope, variable.getModifierList(), trace),
JetPsiUtil.safeName(variable.getName()),
type,
@@ -680,7 +678,7 @@ public class DescriptorResolver {
@NotNull
public PropertyDescriptor resolvePropertyDescriptor(
@NotNull DeclarationDescriptor containingDeclaration,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetProperty property,
@NotNull BindingTrace trace,
@NotNull DataFlowInfo dataFlowInfo
@@ -705,7 +703,7 @@ public class DescriptorResolver {
);
List<TypeParameterDescriptorImpl> typeParameterDescriptors;
JetScope scopeWithTypeParameters;
LexicalScope scopeWithTypeParameters;
JetType receiverType = null;
{
@@ -715,8 +713,8 @@ public class DescriptorResolver {
typeParameterDescriptors = Collections.emptyList();
}
else {
WritableScope writableScope = new WritableScopeImpl(
scope, containingDeclaration, new TraceBasedRedeclarationHandler(trace),
LexicalWritableScope writableScope = new LexicalWritableScope(
scope, containingDeclaration, false, null, new TraceBasedRedeclarationHandler(trace),
"Scope with type parameters of a property");
typeParameterDescriptors = resolveTypeParametersForCallableDescriptor(propertyDescriptor, writableScope, typeParameters,
trace);
@@ -736,8 +734,8 @@ public class DescriptorResolver {
ReceiverParameterDescriptor implicitInitializerReceiver = property.hasDelegate() ? null : receiverDescriptor;
JetScope propertyScope = JetScopeUtils.getPropertyDeclarationInnerScope(propertyDescriptor, scope, typeParameterDescriptors,
implicitInitializerReceiver, trace);
LexicalScope propertyScope = JetScopeUtils.getPropertyDeclarationInnerScope(propertyDescriptor, scope, typeParameterDescriptors,
implicitInitializerReceiver, trace);
JetType type = getVariableType(propertyDescriptor, propertyScope, property, dataFlowInfo, true, trace);
@@ -772,7 +770,7 @@ public class DescriptorResolver {
@NotNull
private JetType getVariableType(
@NotNull final VariableDescriptorWithInitializerImpl variableDescriptor,
@NotNull final JetScope scope,
@NotNull final LexicalScope scope,
@NotNull final JetVariableDeclaration variable,
@NotNull final DataFlowInfo dataFlowInfo,
boolean notLocal,
@@ -834,7 +832,7 @@ public class DescriptorResolver {
private void setConstantForVariableIfNeeded(
@NotNull VariableDescriptorWithInitializerImpl variableDescriptor,
@NotNull final JetScope scope,
@NotNull final LexicalScope scope,
@NotNull final JetVariableDeclaration variable,
@NotNull final DataFlowInfo dataFlowInfo,
@NotNull final JetType variableType,
@@ -861,12 +859,12 @@ public class DescriptorResolver {
private JetType resolveDelegatedPropertyType(
@NotNull JetProperty property,
@NotNull PropertyDescriptor propertyDescriptor,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetExpression delegateExpression,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull BindingTrace trace
) {
JetScope accessorScope = JetScopeUtils.makeScopeForPropertyAccessor(propertyDescriptor, scope, trace);
LexicalScope accessorScope = JetScopeUtils.makeScopeForPropertyAccessor(propertyDescriptor, scope, trace);
JetType type = delegatedPropertyResolver.resolveDelegateExpression(
delegateExpression, property, propertyDescriptor, scope, accessorScope, trace, dataFlowInfo);
@@ -912,7 +910,7 @@ public class DescriptorResolver {
@NotNull
private JetType resolveInitializerType(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetExpression initializer,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull BindingTrace trace
@@ -922,7 +920,7 @@ public class DescriptorResolver {
@Nullable
private PropertySetterDescriptor resolvePropertySetterDescriptor(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetProperty property,
@NotNull PropertyDescriptor propertyDescriptor,
BindingTrace trace
@@ -989,7 +987,7 @@ public class DescriptorResolver {
@Nullable
private PropertyGetterDescriptorImpl resolvePropertyGetterDescriptor(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetProperty property,
@NotNull PropertyDescriptor propertyDescriptor,
BindingTrace trace
@@ -1029,7 +1027,7 @@ public class DescriptorResolver {
public PropertyDescriptor resolvePrimaryConstructorParameterToAProperty(
@NotNull ClassDescriptor classDescriptor,
@NotNull ValueParameterDescriptor valueParameter,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetParameter parameter, BindingTrace trace
) {
JetType type = resolveParameterType(scope, parameter, trace);
@@ -1124,7 +1122,7 @@ public class DescriptorResolver {
}
public static boolean checkHasOuterClassInstance(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull BindingTrace trace,
@NotNull PsiElement reportErrorsOn,
@NotNull ClassDescriptor target
@@ -1158,8 +1156,8 @@ public class DescriptorResolver {
}
@Nullable
public static ClassDescriptor getContainingClass(@NotNull JetScope scope) {
return getParentOfType(scope.getContainingDeclaration(), ClassDescriptor.class, false);
public static ClassDescriptor getContainingClass(@NotNull LexicalScope scope) {
return getParentOfType(scope.getOwnerDescriptor(), ClassDescriptor.class, false);
}
public static void resolvePackageHeader(
@@ -28,14 +28,17 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticUtils
import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.ModifiersChecker.*
import org.jetbrains.kotlin.resolve.DescriptorUtils.*
import org.jetbrains.kotlin.resolve.DescriptorResolver.*
import org.jetbrains.kotlin.resolve.DescriptorUtils.getDispatchReceiverParameterIfNeeded
import org.jetbrains.kotlin.resolve.DescriptorUtils.isFunctionExpression
import org.jetbrains.kotlin.resolve.DescriptorUtils.isFunctionLiteral
import org.jetbrains.kotlin.resolve.ModifiersChecker.resolveModalityFromModifiers
import org.jetbrains.kotlin.resolve.ModifiersChecker.resolveVisibilityFromModifiers
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope
import org.jetbrains.kotlin.resolve.scopes.WritableScope
import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl
import org.jetbrains.kotlin.resolve.source.toSourceElement
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.DeferredType
@@ -45,7 +48,7 @@ import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.checker.JetTypeChecker
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
import java.util.ArrayList
import java.util.*
class FunctionDescriptorResolver(
private val typeResolver: TypeResolver,
@@ -58,7 +61,7 @@ class FunctionDescriptorResolver(
) {
public fun resolveFunctionDescriptor(
containingDescriptor: DeclarationDescriptor,
scope: JetScope,
scope: LexicalScope,
function: JetNamedFunction,
trace: BindingTrace,
dataFlowInfo: DataFlowInfo
@@ -72,7 +75,7 @@ class FunctionDescriptorResolver(
public fun resolveFunctionExpressionDescriptor(
containingDescriptor: DeclarationDescriptor,
scope: JetScope,
scope: LexicalScope,
function: JetNamedFunction,
trace: BindingTrace,
dataFlowInfo: DataFlowInfo,
@@ -83,7 +86,7 @@ class FunctionDescriptorResolver(
private fun resolveFunctionDescriptor(
functionConstructor: (DeclarationDescriptor, Annotations, Name, CallableMemberDescriptor.Kind, SourceElement) -> SimpleFunctionDescriptorImpl,
containingDescriptor: DeclarationDescriptor,
scope: JetScope,
scope: LexicalScope,
function: JetNamedFunction,
trace: BindingTrace,
dataFlowInfo: DataFlowInfo,
@@ -103,7 +106,7 @@ class FunctionDescriptorResolver(
}
private fun initializeFunctionReturnTypeBasedOnFunctionBody(
scope: JetScope,
scope: LexicalScope,
function: JetNamedFunction,
functionDescriptor: SimpleFunctionDescriptorImpl,
trace: BindingTrace,
@@ -130,17 +133,14 @@ class FunctionDescriptorResolver(
fun initializeFunctionDescriptorAndExplicitReturnType(
containingDescriptor: DeclarationDescriptor,
scope: JetScope,
scope: LexicalScope,
function: JetFunction,
functionDescriptor: SimpleFunctionDescriptorImpl,
trace: BindingTrace,
expectedFunctionType: JetType
) {
val innerScope = WritableScopeImpl(scope,
functionDescriptor,
TraceBasedRedeclarationHandler(trace),
"Function descriptor header scope",
labeledDeclaration = functionDescriptor)
val innerScope = LexicalWritableScope(scope, functionDescriptor, true, null,
TraceBasedRedeclarationHandler(trace), "Function descriptor header scope")
val typeParameterDescriptors = descriptorResolver.
resolveTypeParametersForCallableDescriptor(functionDescriptor, innerScope, function.getTypeParameters(), trace)
@@ -181,7 +181,7 @@ class FunctionDescriptorResolver(
private fun createValueParameterDescriptors(
function: JetFunction,
functionDescriptor: SimpleFunctionDescriptorImpl,
innerScope: WritableScopeImpl,
innerScope: LexicalWritableScope,
trace: BindingTrace,
expectedFunctionType: JetType
): List<ValueParameterDescriptor> {
@@ -218,7 +218,7 @@ class FunctionDescriptorResolver(
if (functionTypeExpected()) KotlinBuiltIns.getValueParameters(owner, this) else null
public fun resolvePrimaryConstructorDescriptor(
scope: JetScope,
scope: LexicalScope,
classDescriptor: ClassDescriptor,
classElement: JetClassOrObject,
trace: BindingTrace
@@ -237,7 +237,7 @@ class FunctionDescriptorResolver(
}
public fun resolveSecondaryConstructorDescriptor(
scope: JetScope,
scope: LexicalScope,
classDescriptor: ClassDescriptor,
constructor: JetSecondaryConstructor,
trace: BindingTrace
@@ -255,7 +255,7 @@ class FunctionDescriptorResolver(
}
private fun createConstructorDescriptor(
scope: JetScope,
scope: LexicalScope,
classDescriptor: ClassDescriptor,
isPrimary: Boolean,
modifierList: JetModifierList?,
@@ -271,9 +271,10 @@ class FunctionDescriptorResolver(
declarationToTrace.toSourceElement()
)
trace.record(BindingContext.CONSTRUCTOR, declarationToTrace, constructorDescriptor)
val parameterScope = WritableScopeImpl(
val parameterScope = LexicalWritableScope(
scope,
constructorDescriptor,
false, null,
TraceBasedRedeclarationHandler(trace),
"Scope with value parameters of a constructor"
)
@@ -294,7 +295,7 @@ class FunctionDescriptorResolver(
private fun resolveValueParameters(
functionDescriptor: FunctionDescriptor,
parameterScope: WritableScope,
parameterScope: LexicalWritableScope,
valueParameters: List<JetParameter>,
trace: BindingTrace,
expectedValueParameters: List<ValueParameterDescriptor>?
@@ -16,6 +16,8 @@
package org.jetbrains.kotlin.resolve;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
@@ -24,14 +26,13 @@ import org.jetbrains.kotlin.descriptors.impl.FunctionDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl;
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.RedeclarationHandler;
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl;
import org.jetbrains.kotlin.resolve.scopes.*;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.typeUtil.TypeUtilPackage;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class FunctionDescriptorUtil {
private static final TypeSubstitutor MAKE_TYPE_PARAMETERS_FRESH = TypeSubstitutor.create(new TypeSubstitution() {
@@ -60,27 +61,31 @@ public class FunctionDescriptorUtil {
}
@NotNull
public static JetScope getFunctionInnerScope(@NotNull JetScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) {
public static LexicalScope getFunctionInnerScope(@NotNull LexicalScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) {
TraceBasedRedeclarationHandler redeclarationHandler = new TraceBasedRedeclarationHandler(trace);
return getFunctionInnerScope(outerScope, descriptor, redeclarationHandler);
}
@NotNull
public static JetScope getFunctionInnerScope(
@NotNull JetScope outerScope,
@NotNull FunctionDescriptor descriptor,
public static LexicalScope getFunctionInnerScope(
@NotNull LexicalScope outerScope,
@NotNull final FunctionDescriptor descriptor,
@NotNull RedeclarationHandler redeclarationHandler
) {
ReceiverParameterDescriptor receiver = descriptor.getExtensionReceiverParameter();
WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, redeclarationHandler, "Function inner scope", receiver, descriptor);
for (TypeParameterDescriptor typeParameter : descriptor.getTypeParameters()) {
parameterScope.addClassifierDescriptor(typeParameter);
}
for (ValueParameterDescriptor valueParameterDescriptor : descriptor.getValueParameters()) {
parameterScope.addVariableDescriptor(valueParameterDescriptor);
}
parameterScope.changeLockLevel(WritableScope.LockLevel.READING);
return parameterScope;
return new LexicalScopeImpl(outerScope, descriptor, true, receiver, "Function inner scope", redeclarationHandler,
new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
for (TypeParameterDescriptor typeParameter : descriptor.getTypeParameters()) {
handler.addClassifierDescriptor(typeParameter);
}
for (ValueParameterDescriptor valueParameterDescriptor : descriptor.getValueParameters()) {
handler.addVariableDescriptor(valueParameterDescriptor);
}
return Unit.INSTANCE$;
}
});
}
public static void initializeFromFunctionType(
@@ -17,21 +17,21 @@
package org.jetbrains.kotlin.resolve;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
public class TypeResolutionContext {
public final JetScope scope;
public final LexicalScope scope;
public final BindingTrace trace;
public final boolean checkBounds;
public final boolean allowBareTypes;
public final boolean forceResolveLazyTypes;
public TypeResolutionContext(@NotNull JetScope scope, @NotNull BindingTrace trace, boolean checkBounds, boolean allowBareTypes) {
public TypeResolutionContext(@NotNull LexicalScope scope, @NotNull BindingTrace trace, boolean checkBounds, boolean allowBareTypes) {
this(scope, trace, checkBounds, allowBareTypes, allowBareTypes);
}
private TypeResolutionContext(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull BindingTrace trace,
boolean checkBounds,
boolean allowBareTypes,
@@ -32,6 +32,8 @@ import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
import org.jetbrains.kotlin.resolve.lazy.LazyEntity
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.LazyScopeAdapter
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.*
@@ -58,7 +60,7 @@ public class TypeResolver(
}
}
public fun resolveType(scope: JetScope, typeReference: JetTypeReference, trace: BindingTrace, checkBounds: Boolean): JetType {
public fun resolveType(scope: LexicalScope, typeReference: JetTypeReference, trace: BindingTrace, checkBounds: Boolean): JetType {
// bare types are not allowed
return resolveType(TypeResolutionContext(scope, trace, checkBounds, false), typeReference)
}
@@ -108,7 +110,7 @@ public class TypeResolver(
val typeElement = typeReference.getTypeElement()
val type = resolveTypeElement(c, annotations, typeElement)
c.trace.record(BindingContext.TYPE_RESOLUTION_SCOPE, typeReference, c.scope)
c.trace.record(BindingContext.TYPE_RESOLUTION_SCOPE, typeReference, c.scope.asJetScope())
if (!type.isBare) {
for (argument in type.actualType.arguments) {
@@ -307,7 +309,7 @@ public class TypeResolver(
}
}
public fun resolveClass(scope: JetScope, userType: JetUserType, trace: BindingTrace): ClassifierDescriptor? {
public fun resolveClass(scope: LexicalScope, userType: JetUserType, trace: BindingTrace): ClassifierDescriptor? {
if (userType.qualifier != null) { // we must resolve all type references in arguments of qualifier type
for (typeArgument in userType.qualifier!!.typeArguments) {
typeArgument.typeReference?.let {
@@ -316,7 +318,7 @@ public class TypeResolver(
}
}
val classifierDescriptor = qualifiedExpressionResolver.lookupDescriptorsForUserType(userType, scope, trace, true)
val classifierDescriptor = qualifiedExpressionResolver.lookupDescriptorsForUserType(userType, scope.asJetScope(), trace, true)
.firstIsInstanceOrNull<ClassifierDescriptor>()
if (classifierDescriptor != null) {
PlatformTypesMappedToKotlinChecker.reportPlatformClassMappedToKotlin(moduleDescriptor, trace, userType, classifierDescriptor)
@@ -16,35 +16,43 @@
package org.jetbrains.kotlin.resolve.callableReferences
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.ReflectionTypes
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
import org.jetbrains.kotlin.diagnostics.Errors.CALLABLE_REFERENCE_LHS_NOT_A_CLASS
import org.jetbrains.kotlin.diagnostics.Errors.EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED
import org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.JetCallableReferenceExpression
import org.jetbrains.kotlin.psi.JetExpression
import org.jetbrains.kotlin.psi.JetSimpleNameExpression
import org.jetbrains.kotlin.psi.ValueArgument
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
import org.jetbrains.kotlin.resolve.TypeResolver
import org.jetbrains.kotlin.resolve.calls.CallResolver
import org.jetbrains.kotlin.resolve.calls.context.*
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
import org.jetbrains.kotlin.resolve.calls.context.TemporaryTraceAndCache
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil
import org.jetbrains.kotlin.resolve.calls.util.CallMaker
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
import org.jetbrains.kotlin.utils.ThrowingList
import org.jetbrains.kotlin.diagnostics.Errors.*
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsFileScope
import org.jetbrains.kotlin.resolve.source.toSourceElement
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.expressions.ExpressionTypingComponents
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
import org.jetbrains.kotlin.utils.ThrowingList
public fun resolveCallableReferenceReceiverType(
callableReferenceExpression: JetCallableReferenceExpression,
@@ -95,9 +103,9 @@ public fun resolvePossiblyAmbiguousCallableReference(
): OverloadResolutionResults<CallableDescriptor>? {
val reference = callableReferenceExpression.getCallableReference()
fun resolveInScope(traceTitle: String, scope: JetScope): OverloadResolutionResults<CallableDescriptor> {
fun resolveInScope(traceTitle: String, staticScope: JetScope): OverloadResolutionResults<CallableDescriptor> {
val temporaryTraceAndCache = TemporaryTraceAndCache.create(context, traceTitle, reference)
val newContext = context.replaceTraceAndCache(temporaryTraceAndCache).replaceScope(scope)
val newContext = context.replaceTraceAndCache(temporaryTraceAndCache).replaceScope(staticScope.memberScopeAsFileScope())
val results = resolvePossiblyAmbiguousCallableReference(reference, ReceiverValue.NO_RECEIVER, newContext, resolutionMode, callResolver)
resolutionMode.acceptResolution(results, temporaryTraceAndCache)
return results
@@ -177,7 +185,7 @@ private fun createReflectionTypeForProperty(
private fun bindFunctionReference(expression: JetCallableReferenceExpression, referenceType: JetType, context: ResolutionContext<*>) {
val functionDescriptor = AnonymousFunctionDescriptor(
context.scope.getContainingDeclaration(),
context.scope.ownerDescriptor,
Annotations.EMPTY,
CallableMemberDescriptor.Kind.DECLARATION,
expression.toSourceElement())
@@ -188,7 +196,7 @@ private fun bindFunctionReference(expression: JetCallableReferenceExpression, re
}
private fun bindPropertyReference(expression: JetCallableReferenceExpression, referenceType: JetType, context: ResolutionContext<*>) {
val localVariable = LocalVariableDescriptor(context.scope.getContainingDeclaration(), Annotations.EMPTY, Name.special("<anonymous>"),
val localVariable = LocalVariableDescriptor(context.scope.ownerDescriptor, Annotations.EMPTY, Name.special("<anonymous>"),
referenceType, /* mutable = */ false, expression.toSourceElement())
context.trace.record(BindingContext.VARIABLE, expression, localVariable)
@@ -25,7 +25,9 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.diagnostics.Errors;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.*;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace;
import org.jetbrains.kotlin.resolve.TypeResolver;
import org.jetbrains.kotlin.resolve.callableReferences.CallableReferencesPackage;
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode;
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
@@ -39,7 +41,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory;
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor;
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.receivers.QualifierReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.types.ErrorUtils;
@@ -265,7 +267,7 @@ public class ArgumentTypeResolver {
@Nullable
public JetType getShapeTypeOfFunctionLiteral(
@NotNull JetFunction function,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull BindingTrace trace,
boolean expectedTypeIsUnknown
) {
@@ -294,7 +296,7 @@ public class ArgumentTypeResolver {
@Nullable
public JetType resolveTypeRefWithDefault(
@Nullable JetTypeReference returnTypeRef,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull BindingTrace trace,
@Nullable JetType defaultValue
) {
@@ -44,9 +44,10 @@ import org.jetbrains.kotlin.resolve.calls.tasks.*;
import org.jetbrains.kotlin.resolve.calls.tasks.collectors.CallableDescriptorCollectors;
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.TypeSubstitutor;
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext;
@@ -255,7 +256,7 @@ public class CallResolver {
@NotNull
public OverloadResolutionResults<FunctionDescriptor> resolveFunctionCall(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull Call call,
@NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo,
@@ -326,14 +327,14 @@ public class CallResolver {
return checkArgumentTypesAndFail(context);
}
Collection<ResolutionCandidate<CallableDescriptor>> candidates =
taskPrioritizer.<CallableDescriptor>convertWithImpliedThisAndNoReceiver(context.scope, constructors, context.call);
taskPrioritizer.<CallableDescriptor>convertWithImpliedThisAndNoReceiver(UtilsPackage.asJetScope(context.scope), constructors, context.call);
return computeTasksFromCandidatesAndResolvedCall(context, functionReference, candidates, CallTransformer.FUNCTION_CALL_TRANSFORMER);
}
@Nullable
public OverloadResolutionResults<FunctionDescriptor> resolveConstructorDelegationCall(
@NotNull BindingTrace trace, @NotNull JetScope scope, @NotNull DataFlowInfo dataFlowInfo,
@NotNull BindingTrace trace, @NotNull LexicalScope scope, @NotNull DataFlowInfo dataFlowInfo,
@NotNull ConstructorDescriptor constructorDescriptor,
@NotNull JetConstructorDelegationCall call, @NotNull CallChecker callChecker
) {
@@ -55,9 +55,8 @@ import org.jetbrains.kotlin.types.TypeSubstitutor
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.TypeUtils.noExpectedType
import org.jetbrains.kotlin.types.checker.JetTypeChecker
import org.jetbrains.kotlin.types.checker.TypeCheckingProcedure
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
import java.util.ArrayList
import java.util.*
public class CandidateResolver(
private val argumentTypeResolver: ArgumentTypeResolver,
@@ -181,7 +180,7 @@ public class CandidateResolver(
private fun CallCandidateResolutionContext<*>.checkVisibility() = checkAndReport {
val receiverValue = ExpressionTypingUtils.normalizeReceiverValueForVisibility(candidateCall.getDispatchReceiver(),
trace.getBindingContext())
val invisibleMember = Visibilities.findInvisibleMember(receiverValue, candidateDescriptor, scope.getContainingDeclaration())
val invisibleMember = Visibilities.findInvisibleMember(receiverValue, candidateDescriptor, scope.ownerDescriptor)
if (invisibleMember != null) {
tracing.invisibleMember(trace, invisibleMember)
OTHER_ERROR
@@ -480,7 +479,7 @@ public class CandidateResolver(
}
val bindingContext = trace.bindingContext
val receiverValue = DataFlowValueFactory.createDataFlowValue(receiverArgument, bindingContext, scope.getContainingDeclaration())
val receiverValue = DataFlowValueFactory.createDataFlowValue(receiverArgument, bindingContext, scope.ownerDescriptor)
if (safeAccess && !dataFlowInfo.getNullability(receiverValue).canBeNull()) {
tracing.unnecessarySafeCall(trace, receiverArgument.type)
}
@@ -18,19 +18,15 @@ package org.jetbrains.kotlin.resolve.calls.checkers
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.psi.JetFunction
import org.jetbrains.kotlin.psi.JetFunctionLiteral
import org.jetbrains.kotlin.psi.JetFunctionLiteralExpression
import org.jetbrains.kotlin.psi.JetNamedFunction
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingContext.CAPTURED_IN_CLOSURE
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getParentResolvedCall
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.kotlin.resolve.inline.InlineUtil
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.types.expressions.CaptureKind
class CapturingInClosureChecker : CallChecker {
@@ -42,9 +38,9 @@ class CapturingInClosureChecker : CallChecker {
}
}
private fun checkCapturingInClosure(variable: VariableDescriptor, trace: BindingTrace, scope: JetScope) {
private fun checkCapturingInClosure(variable: VariableDescriptor, trace: BindingTrace, scope: LexicalScope) {
val variableParent = variable.getContainingDeclaration()
val scopeContainer = scope.getContainingDeclaration()
val scopeContainer = scope.ownerDescriptor
if (isCapturedVariable(variableParent, scopeContainer)) {
if (trace.get(CAPTURED_IN_CLOSURE, variable) != CaptureKind.NOT_INLINE) {
val inline = isCapturedInInline(trace.getBindingContext(), scopeContainer, variableParent)
@@ -30,7 +30,7 @@ public class InlineCheckerWrapper : CallChecker {
override fun <F : CallableDescriptor> check(resolvedCall: ResolvedCall<F>, context: BasicCallResolutionContext) {
if (context.isAnnotationContext) return
var parentDescriptor: DeclarationDescriptor? = context.scope.getContainingDeclaration()
var parentDescriptor: DeclarationDescriptor? = context.scope.ownerDescriptor
while (parentDescriptor != null) {
if (InlineUtil.isInline(parentDescriptor)) {
@@ -25,13 +25,13 @@ import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.types.JetType;
public class BasicCallResolutionContext extends CallResolutionContext<BasicCallResolutionContext> {
private BasicCallResolutionContext(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull Call call,
@NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo,
@@ -52,7 +52,7 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
@NotNull
public static BasicCallResolutionContext create(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull Call call,
@NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo,
@@ -88,7 +88,7 @@ public class BasicCallResolutionContext extends CallResolutionContext<BasicCallR
@Override
protected BasicCallResolutionContext create(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType,
@NotNull ContextDependency contextDependency,
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.types.JetType;
@@ -45,7 +45,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
@NotNull MutableResolvedCall<D> candidateCall,
@NotNull TracingStrategy tracing,
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull Call call,
@NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo,
@@ -98,7 +98,7 @@ public final class CallCandidateResolutionContext<D extends CallableDescriptor>
@Override
protected CallCandidateResolutionContext<D> create(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType,
@NotNull ContextDependency contextDependency,
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
import org.jetbrains.kotlin.resolve.calls.model.DataFlowInfoForArgumentsImpl;
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.types.JetType;
public abstract class CallResolutionContext<Context extends CallResolutionContext<Context>> extends ResolutionContext<Context> {
@@ -38,7 +38,7 @@ public abstract class CallResolutionContext<Context extends CallResolutionContex
protected CallResolutionContext(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull Call call,
@NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo,
@@ -21,9 +21,8 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.StatementFilter;
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.TypeUtils;
@@ -37,7 +36,7 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
@NotNull
public final BindingTrace trace;
@NotNull
public final JetScope scope;
public final LexicalScope scope;
@NotNull
public final JetType expectedType;
@NotNull
@@ -60,7 +59,7 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
protected ResolutionContext(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull ContextDependency contextDependency,
@@ -86,7 +85,7 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
protected abstract Context create(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType,
@NotNull ContextDependency contextDependency,
@@ -125,7 +124,7 @@ public abstract class ResolutionContext<Context extends ResolutionContext<Contex
}
@NotNull
public Context replaceScope(@NotNull JetScope newScope) {
public Context replaceScope(@NotNull LexicalScope newScope) {
if (newScope == scope) return self();
return create(trace, newScope, dataFlowInfo, expectedType, contextDependency, resolutionResultsCache, statementFilter,
collectAllCandidates, insideCallChain);
@@ -54,7 +54,7 @@ public class DataFlowValueFactory {
@NotNull ResolutionContext resolutionContext
) {
return createDataFlowValue(expression, type, resolutionContext.trace.getBindingContext(),
resolutionContext.scope.getContainingDeclaration());
resolutionContext.scope.getOwnerDescriptor());
}
@NotNull
@@ -106,7 +106,7 @@ public class DataFlowValueFactory {
@NotNull ResolutionContext resolutionContext
) {
return createDataFlowValue(receiverValue, resolutionContext.trace.getBindingContext(),
resolutionContext.scope.getContainingDeclaration());
resolutionContext.scope.getOwnerDescriptor());
}
@NotNull
@@ -55,7 +55,7 @@ public class SmartCastManager {
@NotNull ReceiverValue receiverToCast,
@NotNull ResolutionContext context
) {
return getSmartCastVariants(receiverToCast, context.trace.getBindingContext(), context.scope.getContainingDeclaration(), context.dataFlowInfo);
return getSmartCastVariants(receiverToCast, context.trace.getBindingContext(), context.scope.getOwnerDescriptor(), context.dataFlowInfo);
}
@NotNull
@@ -102,7 +102,7 @@ public class SmartCastManager {
@NotNull ReceiverValue receiverToCast
) {
return getSmartCastVariantsExcludingReceiver(context.trace.getBindingContext(),
context.scope.getContainingDeclaration(),
context.scope.getOwnerDescriptor(),
context.dataFlowInfo,
receiverToCast);
}
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.resolve.calls.context.*;
import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
import org.jetbrains.kotlin.resolve.calls.model.MutableResolvedCall;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.types.JetType;
import java.util.Collection;
@@ -46,7 +46,7 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
@NotNull Function0<Collection<ResolutionCandidate<D>>> lazyCandidates,
@NotNull TracingStrategy tracing,
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull Call call,
@NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo,
@@ -99,7 +99,7 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
@Override
protected ResolutionTask<D, F> create(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType,
@NotNull ContextDependency contextDependency,
@@ -41,6 +41,7 @@ import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils
import org.jetbrains.kotlin.resolve.scopes.receivers.QualifierReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.JetType
@@ -77,7 +78,7 @@ public class TaskPrioritizer(
): List<ResolutionTask<D, F>> {
val explicitReceiver = context.call.getExplicitReceiver()
val result = ResolutionTaskHolder<D, F>(storageManager, context, PriorityProviderImpl<D>(context), tracing)
val taskPrioritizerContext = TaskPrioritizerContext(name, result, context, context.scope, callableDescriptorCollectors)
val taskPrioritizerContext = TaskPrioritizerContext(name, result, context, context.scope.asJetScope(), callableDescriptorCollectors)
if (explicitReceiver is QualifierReceiver) {
val qualifierReceiver: QualifierReceiver = explicitReceiver
@@ -445,7 +446,7 @@ public class TaskPrioritizer(
val candidateDescriptor = candidate.getDescriptor()
if (ErrorUtils.isError(candidateDescriptor)) return true
val receiverValue = ExpressionTypingUtils.normalizeReceiverValueForVisibility(candidate.getDispatchReceiver(), context.trace.getBindingContext())
return Visibilities.isVisible(receiverValue, candidateDescriptor, context.scope.getContainingDeclaration())
return Visibilities.isVisible(receiverValue, candidateDescriptor, context.scope.ownerDescriptor)
}
private fun isSynthesized(candidate: ResolutionCandidate<D>): Boolean {
@@ -22,7 +22,6 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.resolve.AnnotationResolver;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.TypeConstructor;
@@ -213,8 +213,9 @@ public class ResolveSession implements KotlinCodeAnalyzer, LazyClassContext {
}
private LazyAnnotations createAnnotations(JetFile file, List<JetAnnotationEntry> annotationEntries) {
JetScope scope = fileScopeProvider.getFileScope(file);
LazyAnnotationsContextImpl lazyAnnotationContext = new LazyAnnotationsContextImpl(annotationResolve, storageManager, trace, scope);
LazyFileScope scope = fileScopeProvider.getFileScope(file);
LazyAnnotationsContextImpl lazyAnnotationContext =
new LazyAnnotationsContextImpl(annotationResolve, storageManager, trace, scope);
return new LazyAnnotations(lazyAnnotationContext, annotationEntries);
}
@@ -34,7 +34,6 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.DeclarationProvider
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
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
@@ -81,7 +80,7 @@ protected constructor(
val declarations = declarationProvider.getFunctionDeclarations(name)
for (functionDeclaration in declarations) {
val resolutionScope = getScopeForMemberDeclarationResolution(functionDeclaration).asJetScope()
val resolutionScope = getScopeForMemberDeclarationResolution(functionDeclaration)
result.add(c.functionDescriptorResolver.resolveFunctionDescriptor(
thisDescriptor,
resolutionScope,
@@ -109,7 +108,7 @@ protected constructor(
val declarations = declarationProvider.getPropertyDeclarations(name)
for (propertyDeclaration in declarations) {
val resolutionScope = getScopeForMemberDeclarationResolution(propertyDeclaration).asJetScope()
val resolutionScope = getScopeForMemberDeclarationResolution(propertyDeclaration)
val propertyDescriptor = c.descriptorResolver.resolvePropertyDescriptor(
thisDescriptor,
resolutionScope,
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.constants.ConstantValue
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
import org.jetbrains.kotlin.resolve.lazy.LazyEntity
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.source.toSourceElement
import org.jetbrains.kotlin.storage.StorageManager
@@ -37,14 +37,14 @@ abstract class LazyAnnotationsContext(
val storageManager: StorageManager,
val trace: BindingTrace
) {
abstract val scope: JetScope
abstract val scope: LexicalScope
}
class LazyAnnotationsContextImpl(
annotationResolver: AnnotationResolver,
storageManager: StorageManager,
trace: BindingTrace,
override val scope: JetScope
override val scope: LexicalScope
) : LazyAnnotationsContext(annotationResolver, storageManager, trace)
public class LazyAnnotations(
@@ -48,7 +48,6 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProv
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;
@@ -170,8 +169,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
) {
@NotNull
@Override
public JetScope getScope() {
return UtilsPackage.asJetScope(getOuterScope());
public LexicalScope getScope() {
return getOuterScope();
}
},
modifierList.getAnnotationEntries()
@@ -195,8 +194,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
) {
@NotNull
@Override
public JetScope getScope() {
return UtilsPackage.asJetScope(getScopeForMemberDeclarationResolution());
public LexicalScope getScope() {
return getScopeForMemberDeclarationResolution();
}
},
jetDanglingAnnotations
@@ -510,7 +509,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
}
List<JetType> allSupertypes = c.getDescriptorResolver()
.resolveSupertypes(UtilsPackage.asJetScope(getScopeForClassHeaderResolution()), LazyClassDescriptor.this, classOrObject,
.resolveSupertypes(getScopeForClassHeaderResolution(), LazyClassDescriptor.this, classOrObject,
c.getTrace());
return new Supertypes(Lists.newArrayList(Collections2.filter(allSupertypes, VALID_SUPERTYPE)));
@@ -37,7 +37,6 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProv
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
@@ -224,7 +223,7 @@ public open class LazyClassMemberScope(
val parameter = primaryConstructorParameters.get(valueParameterDescriptor.getIndex())
if (parameter.hasValOrVar()) {
val propertyDescriptor = c.descriptorResolver.resolvePrimaryConstructorParameterToAProperty(
thisDescriptor, valueParameterDescriptor, thisDescriptor.getScopeForClassHeaderResolution().asJetScope(), parameter, trace)
thisDescriptor, valueParameterDescriptor, thisDescriptor.getScopeForClassHeaderResolution(), parameter, trace)
result.add(propertyDescriptor)
}
}
@@ -235,7 +234,7 @@ public open class LazyClassMemberScope(
?: return setOf()
val lazyTypeResolver = DelegationResolver.TypeResolver { reference ->
c.typeResolver.resolveType(thisDescriptor.getScopeForClassHeaderResolution().asJetScope(), reference, trace, false)
c.typeResolver.resolveType(thisDescriptor.getScopeForClassHeaderResolution(), reference, trace, false)
}
val lazyMemberExtractor = DelegationResolver.MemberExtractor<T> {
type -> extractor.extract(type, name)
@@ -284,7 +283,7 @@ public open class LazyClassMemberScope(
if (DescriptorUtils.canHaveDeclaredConstructors(thisDescriptor) || hasPrimaryConstructor) {
val constructor = c.functionDescriptorResolver.resolvePrimaryConstructorDescriptor(
thisDescriptor.getScopeForClassHeaderResolution().asJetScope(), thisDescriptor, classOrObject, trace)
thisDescriptor.getScopeForClassHeaderResolution(), thisDescriptor, classOrObject, trace)
constructor ?: return null
setDeferredReturnType(constructor)
return constructor
@@ -301,7 +300,7 @@ public open class LazyClassMemberScope(
return classOrObject.getSecondaryConstructors().map { constructor ->
val descriptor = c.functionDescriptorResolver.resolveSecondaryConstructorDescriptor(
thisDescriptor.getScopeForClassHeaderResolution().asJetScope(), thisDescriptor, constructor, trace
thisDescriptor.getScopeForClassHeaderResolution(), thisDescriptor, constructor, trace
)
setDeferredReturnType(descriptor)
descriptor
@@ -90,19 +90,13 @@ public class LazyScriptDescriptor(
override fun getScriptCodeDescriptor() = scriptCodeDescriptor()
override fun getScopeForBodyResolution(): JetScope {
val parametersScope = WritableScopeImpl(JetScope.Empty, this, RedeclarationHandler.DO_NOTHING, "Parameters of $this", implicitReceiver)
for (valueParameterDescriptor in getScriptCodeDescriptor().getValueParameters()) {
parametersScope.addVariableDescriptor(valueParameterDescriptor)
override fun getScopeForBodyResolution(): LexicalScope {
return LexicalScopeImpl(resolveSession.fileScopeProvider.getFileScope(jetScript.getContainingJetFile()),
this, false, implicitReceiver, "Scope for body resolution for " + this) {
for (valueParameterDescriptor in getScriptCodeDescriptor().valueParameters) {
addVariableDescriptor(valueParameterDescriptor)
}
}
parametersScope.changeLockLevel(WritableScope.LockLevel.READING)
return ChainedScope(
this,
"Scope for body resolution for " + this,
resolveSession.getFileScopeProvider().getFileScope(jetScript.getContainingJetFile()),
parametersScope
)
}
override fun forceResolveAllContents() {
@@ -25,7 +25,6 @@ import org.jetbrains.kotlin.resolve.BindingContext;
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.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.types.JetType;
import java.util.Set;
@@ -67,7 +66,7 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
JetTypeReference extendsBound = jetTypeParameter.getExtendsBound();
if (extendsBound != null) {
JetType boundType = c.getDescriptorResolver().resolveTypeParameterExtendsBound(
this, extendsBound, UtilsPackage.asJetScope(getContainingDeclaration().getScopeForClassHeaderResolution()), c.getTrace());
this, extendsBound, getContainingDeclaration().getScopeForClassHeaderResolution(), c.getTrace());
upperBounds.add(boundType);
}
@@ -104,7 +103,7 @@ public class LazyTypeParameterDescriptor extends AbstractLazyTypeParameterDescri
private JetType resolveBoundType(@NotNull JetTypeReference boundTypeReference) {
return c.getTypeResolver()
.resolveType(UtilsPackage.asJetScope(getContainingDeclaration().getScopeForClassHeaderResolution()), boundTypeReference,
.resolveType(getContainingDeclaration().getScopeForClassHeaderResolution(), boundTypeReference,
c.getTrace(), false);
}
@@ -19,14 +19,14 @@ package org.jetbrains.kotlin.resolve.scopes;
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.intellij.psi.PsiElement;
import com.intellij.psi.util.PsiTreeUtil;
import kotlin.Unit;
import kotlin.jvm.functions.Function1;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.descriptors.PropertyDescriptor;
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor;
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
import org.jetbrains.kotlin.resolve.BindingTrace;
import org.jetbrains.kotlin.resolve.TraceBasedRedeclarationHandler;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
@@ -53,25 +53,21 @@ public final class JetScopeUtils {
);
}
public static JetScope makeScopeForPropertyAccessor(
public static LexicalScope makeScopeForPropertyAccessor(
@NotNull PropertyDescriptor propertyDescriptor,
@NotNull JetScope parentScope,
@NotNull LexicalScope parentScope,
@NotNull BindingTrace trace
) {
JetScope propertyDeclarationInnerScope =
LexicalScope propertyDeclarationInnerScope =
getPropertyDeclarationInnerScope(propertyDescriptor, parentScope,
propertyDescriptor.getTypeParameters(),
propertyDescriptor.getExtensionReceiverParameter(), trace);
WritableScope accessorScope = new WritableScopeImpl(propertyDeclarationInnerScope, parentScope.getContainingDeclaration(),
new TraceBasedRedeclarationHandler(trace), "Accessor Scope");
accessorScope.changeLockLevel(WritableScope.LockLevel.READING);
return accessorScope;
return new LexicalScopeImpl(propertyDeclarationInnerScope, parentScope.getOwnerDescriptor(), false, null, "Accessor Scope");
}
public static JetScope getPropertyDeclarationInnerScope(
public static LexicalScope getPropertyDeclarationInnerScope(
@NotNull PropertyDescriptor propertyDescriptor,
@NotNull JetScope outerScope,
@NotNull LexicalScope outerScope,
@NotNull RedeclarationHandler redeclarationHandler
) {
return getPropertyDeclarationInnerScope(propertyDescriptor,
@@ -82,9 +78,9 @@ public final class JetScopeUtils {
true);
}
public static JetScope getPropertyDeclarationInnerScope(
public static LexicalScope getPropertyDeclarationInnerScope(
@NotNull PropertyDescriptor propertyDescriptor,
@NotNull JetScope outerScope,
@NotNull LexicalScope outerScope,
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
@Nullable ReceiverParameterDescriptor receiver,
BindingTrace trace
@@ -92,9 +88,9 @@ public final class JetScopeUtils {
return getPropertyDeclarationInnerScope(propertyDescriptor, outerScope, typeParameters, receiver, trace, true);
}
public static JetScope getPropertyDeclarationInnerScopeForInitializer(
public static LexicalScope getPropertyDeclarationInnerScopeForInitializer(
@NotNull PropertyDescriptor propertyDescriptor,
@NotNull JetScope outerScope,
@NotNull LexicalScope outerScope,
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
@Nullable ReceiverParameterDescriptor receiver,
BindingTrace trace
@@ -102,9 +98,9 @@ public final class JetScopeUtils {
return getPropertyDeclarationInnerScope(propertyDescriptor, outerScope, typeParameters, receiver, trace, false);
}
private static JetScope getPropertyDeclarationInnerScope(
private static LexicalScope getPropertyDeclarationInnerScope(
@NotNull PropertyDescriptor propertyDescriptor,
@NotNull JetScope outerScope,
@NotNull LexicalScope outerScope,
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
@Nullable ReceiverParameterDescriptor receiver,
BindingTrace trace,
@@ -116,24 +112,26 @@ public final class JetScopeUtils {
}
@NotNull
private static JetScope getPropertyDeclarationInnerScope(
private static LexicalScope getPropertyDeclarationInnerScope(
@NotNull PropertyDescriptor propertyDescriptor,
@NotNull JetScope outerScope,
@NotNull List<? extends TypeParameterDescriptor> typeParameters,
@NotNull LexicalScope outerScope,
@NotNull final List<? extends TypeParameterDescriptor> typeParameters,
@Nullable ReceiverParameterDescriptor receiver,
@NotNull RedeclarationHandler redeclarationHandler,
boolean addLabelForProperty
) {
WritableScopeImpl result = new WritableScopeImpl(
outerScope, propertyDescriptor, redeclarationHandler,
return new LexicalScopeImpl(
outerScope, propertyDescriptor, addLabelForProperty, receiver,
"Property declaration inner scope",
receiver,
addLabelForProperty ? propertyDescriptor : null);
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
result.addClassifierDescriptor(typeParameterDescriptor);
}
result.changeLockLevel(WritableScope.LockLevel.READING);
return result;
redeclarationHandler, new Function1<LexicalScopeImpl.InitializeHandler, Unit>() {
@Override
public Unit invoke(LexicalScopeImpl.InitializeHandler handler) {
for (TypeParameterDescriptor typeParameterDescriptor : typeParameters) {
handler.addClassifierDescriptor(typeParameterDescriptor);
}
return Unit.INSTANCE$;
}
});
}
@TestOnly
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.hasClassObjectType
import org.jetbrains.kotlin.resolve.scopes.ChainedScope
import org.jetbrains.kotlin.resolve.scopes.FilteringScope
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
@@ -114,7 +115,7 @@ fun createQualifier(
context: ExpressionTypingContext
): QualifierReceiver? {
val receiverScope = when {
!receiver.exists() -> context.scope
!receiver.exists() -> context.scope.asJetScope()
receiver is QualifierReceiver -> receiver.scope
else -> receiver.getType().getMemberScope()
}
@@ -55,8 +55,9 @@ import org.jetbrains.kotlin.resolve.calls.tasks.ResolutionCandidate;
import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
import org.jetbrains.kotlin.resolve.constants.*;
import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl;
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryPackage;
@@ -76,6 +77,7 @@ import static org.jetbrains.kotlin.resolve.calls.context.ContextDependency.DEPEN
import static org.jetbrains.kotlin.resolve.calls.context.ContextDependency.INDEPENDENT;
import static org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory.createDataFlowValue;
import static org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue.NO_RECEIVER;
import static org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage.asJetScope;
import static org.jetbrains.kotlin.types.TypeUtils.NO_EXPECTED_TYPE;
import static org.jetbrains.kotlin.types.TypeUtils.noExpectedType;
import static org.jetbrains.kotlin.types.expressions.ControlStructureTypingUtils.createCallForSpecialConstruction;
@@ -426,7 +428,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
context.trace.record(BindingContext.REFERENCE_TARGET, expression.getInstanceReference(), result.getConstructor().getDeclarationDescriptor());
}
if (superTypeQualifier != null) {
context.trace.record(BindingContext.TYPE_RESOLUTION_SCOPE, superTypeQualifier, context.scope);
context.trace.record(BindingContext.TYPE_RESOLUTION_SCOPE, superTypeQualifier, asJetScope(context.scope));
}
return result;
}
@@ -452,7 +454,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
}
else {
ReceiverParameterDescriptor result = null;
List<ReceiverParameterDescriptor> receivers = context.scope.getImplicitReceiversHierarchy();
List<ReceiverParameterDescriptor> receivers = UtilsPackage.getImplicitReceiversHierarchy(context.scope);
if (onlyClassReceivers) {
for (ReceiverParameterDescriptor receiver : receivers) {
if (isDeclaredInClass(receiver)) {
@@ -660,7 +662,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
traceAdapter.addHandler(CLASS, handler);
components.localClassifierAnalyzer.processClassOrObject(null, // don't need to add classifier of object literal to any scope
context.replaceBindingTrace(traceAdapter).replaceContextDependency(INDEPENDENT),
context.scope.getContainingDeclaration(),
context.scope.getOwnerDescriptor(),
expression.getObjectDeclaration());
temporaryTrace.commit();
DataFlowInfo resultFlowInfo = context.dataFlowInfo;
@@ -1115,11 +1117,11 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
JetTypeInfo leftTypeInfo = getTypeInfoOrNullType(left, context.replaceExpectedType(booleanType), facade);
DataFlowInfo dataFlowInfo = leftTypeInfo.getDataFlowInfo();
WritableScopeImpl leftScope = newWritableScopeImpl(context, "Left scope of && or ||");
LexicalWritableScope leftScope = newWritableScopeImpl(context, "Left scope of && or ||");
// TODO: This gets computed twice: here and in extractDataFlowInfoFromCondition() for the whole condition
boolean isAnd = operationType == JetTokens.ANDAND;
DataFlowInfo flowInfoLeft = components.dataFlowAnalyzer.extractDataFlowInfoFromCondition(left, isAnd, context).and(dataFlowInfo);
WritableScopeImpl rightScope = isAnd ? leftScope : newWritableScopeImpl(context, "Right scope of && or ||");
LexicalWritableScope rightScope = isAnd ? leftScope : newWritableScopeImpl(context, "Right scope of && or ||");
ExpressionTypingContext contextForRightExpr =
context.replaceDataFlowInfo(flowInfoLeft).replaceScope(rightScope).replaceExpectedType(booleanType);
@@ -1382,8 +1384,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
}
public JetTypeInfo visitAnnotatedExpression(JetAnnotatedExpression expression, ExpressionTypingContext context, boolean isStatement) {
components.annotationResolver.resolveAnnotationsWithArguments(
context.scope, expression.getAnnotationEntries(), context.trace);
components.annotationResolver.resolveAnnotationsWithArguments(context.scope, expression.getAnnotationEntries(), context.trace);
JetExpression baseExpression = expression.getBaseExpression();
if (baseExpression == null) {
@@ -31,11 +31,11 @@ import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.inline.InlineUtil;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.types.CommonSupertypes;
import org.jetbrains.kotlin.types.ErrorUtils;
import org.jetbrains.kotlin.types.JetType;
@@ -66,7 +66,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
}
@NotNull
private DataFlowInfo checkCondition(@NotNull JetScope scope, @Nullable JetExpression condition, ExpressionTypingContext context) {
private DataFlowInfo checkCondition(@NotNull LexicalScope scope, @Nullable JetExpression condition, ExpressionTypingContext context) {
if (condition != null) {
JetTypeInfo typeInfo = facade.getTypeInfo(condition, context.replaceScope(scope)
.replaceExpectedType(components.builtIns.getBooleanType()).replaceContextDependency(INDEPENDENT));
@@ -97,8 +97,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
JetExpression elseBranch = ifExpression.getElse();
JetExpression thenBranch = ifExpression.getThen();
WritableScopeImpl thenScope = newWritableScopeImpl(context, "Then scope");
WritableScopeImpl elseScope = newWritableScopeImpl(context, "Else scope");
LexicalWritableScope thenScope = newWritableScopeImpl(context, "Then scope");
LexicalWritableScope elseScope = newWritableScopeImpl(context, "Else scope");
DataFlowInfo thenInfo = components.dataFlowAnalyzer.extractDataFlowInfoFromCondition(condition, true, context).and(conditionDataFlowInfo);
DataFlowInfo elseInfo = components.dataFlowAnalyzer.extractDataFlowInfoFromCondition(condition, false, context).and(conditionDataFlowInfo);
@@ -172,7 +172,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
@NotNull
private JetTypeInfo getTypeInfoWhenOnlyOneBranchIsPresent(
@NotNull JetExpression presentBranch,
@NotNull WritableScopeImpl presentScope,
@NotNull LexicalWritableScope presentScope,
@NotNull DataFlowInfo presentInfo,
@NotNull DataFlowInfo otherInfo,
@NotNull ExpressionTypingContext context,
@@ -226,7 +226,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
JetTypeInfo bodyTypeInfo;
DataFlowInfo conditionInfo = components.dataFlowAnalyzer.extractDataFlowInfoFromCondition(condition, true, context).and(dataFlowInfo);
if (body != null) {
WritableScopeImpl scopeToExtend = newWritableScopeImpl(context, "Scope extended in while's condition");
LexicalWritableScope scopeToExtend = newWritableScopeImpl(context, "Scope extended in while's condition");
bodyTypeInfo = components.expressionTypingServices.getBlockReturnedTypeWithWritableScope(
scopeToExtend, Collections.singletonList(body),
CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(conditionInfo));
@@ -304,7 +304,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
ExpressionTypingContext context =
contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE).replaceContextDependency(INDEPENDENT);
JetExpression body = expression.getBody();
JetScope conditionScope = context.scope;
LexicalScope conditionScope = context.scope;
// Preliminary analysis
PreliminaryLoopVisitor loopVisitor = PreliminaryLoopVisitor.visitLoop(expression);
context = context.replaceDataFlowInfo(
@@ -319,7 +319,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
bodyTypeInfo = facade.getTypeInfo(body, context.replaceScope(context.scope));
}
else if (body != null) {
WritableScope writableScope = newWritableScopeImpl(context, "do..while body scope");
LexicalWritableScope writableScope = newWritableScopeImpl(context, "do..while body scope");
conditionScope = writableScope;
List<JetExpression> block;
if (body instanceof JetBlockExpression) {
@@ -387,7 +387,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
loopRangeInfo = TypeInfoFactoryPackage.noTypeInfo(context);
}
WritableScope loopScope = newWritableScopeImpl(context, "Scope with for-loop index");
LexicalWritableScope loopScope = newWritableScopeImpl(context, "Scope with for-loop index");
JetParameter loopParameter = expression.getLoopParameter();
if (loopParameter != null) {
@@ -432,7 +432,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
JetTypeReference typeReference = loopParameter.getTypeReference();
VariableDescriptor variableDescriptor;
if (typeReference != null) {
variableDescriptor = components.descriptorResolver.resolveLocalVariableDescriptor(context.scope, loopParameter, context.trace);
variableDescriptor = components.descriptorResolver.
resolveLocalVariableDescriptor(context.scope, loopParameter, context.trace);
JetType actualParameterType = variableDescriptor.getType();
if (expectedParameterType != null &&
!JetTypeChecker.DEFAULT.isSubtypeOf(expectedParameterType, actualParameterType)) {
@@ -443,14 +444,15 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
if (expectedParameterType == null) {
expectedParameterType = ErrorUtils.createErrorType("Error");
}
variableDescriptor = components.descriptorResolver.resolveLocalVariableDescriptor(loopParameter, expectedParameterType, context.trace, context.scope);
variableDescriptor = components.descriptorResolver.
resolveLocalVariableDescriptor(loopParameter, expectedParameterType, context.trace, context.scope);
}
{
// http://youtrack.jetbrains.net/issue/KT-527
VariableDescriptor olderVariable = context.scope.getLocalVariable(variableDescriptor.getName());
if (olderVariable != null && isLocal(context.scope.getContainingDeclaration(), olderVariable)) {
VariableDescriptor olderVariable = UtilsPackage.getLocalVariable(context.scope, variableDescriptor.getName());
if (olderVariable != null && isLocal(context.scope.getOwnerDescriptor(), olderVariable)) {
PsiElement declaration = DescriptorToSourceUtils.descriptorToDeclaration(variableDescriptor);
context.trace.report(Errors.NAME_SHADOWING.on(declaration, variableDescriptor.getName().asString()));
}
@@ -478,7 +480,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
JetType throwableType = components.builtIns.getThrowable().getDefaultType();
components.dataFlowAnalyzer.checkType(variableDescriptor.getType(), catchParameter, context.replaceExpectedType(throwableType));
if (catchBody != null) {
WritableScope catchScope = newWritableScopeImpl(context, "Catch scope");
LexicalWritableScope catchScope = newWritableScopeImpl(context, "Catch scope");
catchScope.addVariableDescriptor(variableDescriptor);
JetType type = facade.getTypeInfo(catchBody, context.replaceScope(catchScope)).getType();
if (type != null) {
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.calls.context.ResolutionResultsCache;
import org.jetbrains.kotlin.resolve.calls.context.ResolutionResultsCacheImpl;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstantChecker;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.types.JetType;
public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingContext> {
@@ -34,7 +34,7 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull
public static ExpressionTypingContext newContext(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType
) {
@@ -44,7 +44,7 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull
public static ExpressionTypingContext newContext(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType,
@NotNull CallChecker callChecker
@@ -69,7 +69,7 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@NotNull
public static ExpressionTypingContext newContext(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType,
@NotNull ContextDependency contextDependency,
@@ -87,7 +87,7 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
private ExpressionTypingContext(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType,
@NotNull ContextDependency contextDependency,
@@ -106,7 +106,7 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
@Override
protected ExpressionTypingContext create(
@NotNull BindingTrace trace,
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull JetType expectedType,
@NotNull ContextDependency contextDependency,
@@ -29,9 +29,10 @@ import org.jetbrains.kotlin.resolve.*;
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency;
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.types.ErrorUtils;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryPackage;
@@ -69,7 +70,7 @@ public class ExpressionTypingServices {
@NotNull
public JetType safeGetType(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetExpression expression,
@NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo,
@@ -82,7 +83,7 @@ public class ExpressionTypingServices {
@NotNull
public JetTypeInfo getTypeInfo(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetExpression expression,
@NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo,
@@ -102,7 +103,7 @@ public class ExpressionTypingServices {
@Nullable
public JetType getType(
@NotNull JetScope scope,
@NotNull LexicalScope scope,
@NotNull JetExpression expression,
@NotNull JetType expectedType,
@NotNull DataFlowInfo dataFlowInfo,
@@ -114,7 +115,7 @@ public class ExpressionTypingServices {
/////////////////////////////////////////////////////////
public void checkFunctionReturnType(
@NotNull JetScope functionInnerScope,
@NotNull LexicalScope functionInnerScope,
@NotNull JetDeclarationWithBody function,
@NotNull FunctionDescriptor functionDescriptor,
@NotNull DataFlowInfo dataFlowInfo,
@@ -160,7 +161,7 @@ public class ExpressionTypingServices {
List<JetExpression> block = ResolvePackage.filterStatements(statementFilter, expression);
// SCRIPT: get code descriptor for script declaration
DeclarationDescriptor containingDescriptor = context.scope.getContainingDeclaration();
DeclarationDescriptor containingDescriptor = context.scope.getOwnerDescriptor();
if (containingDescriptor instanceof ScriptDescriptor) {
if (!(expression.getParent() instanceof JetScript)) {
// top level script declarations should have ScriptDescriptor parent
@@ -168,8 +169,8 @@ public class ExpressionTypingServices {
containingDescriptor = ((ScriptDescriptor) containingDescriptor).getScriptCodeDescriptor();
}
}
WritableScope scope = new WritableScopeImpl(
context.scope, containingDescriptor, new TraceBasedRedeclarationHandler(context.trace), "getBlockReturnedType");
LexicalWritableScope scope = new LexicalWritableScope(context.scope, containingDescriptor, false, null,
new TraceBasedRedeclarationHandler(context.trace), "getBlockReturnedType");
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
JetTypeInfo r;
@@ -184,7 +185,7 @@ public class ExpressionTypingServices {
scope.changeLockLevel(WritableScope.LockLevel.READING);
if (containingDescriptor instanceof ScriptDescriptor) {
context.trace.record(BindingContext.SCRIPT_SCOPE, (ScriptDescriptor) containingDescriptor, scope);
context.trace.record(BindingContext.SCRIPT_SCOPE, (ScriptDescriptor) containingDescriptor, UtilsPackage.asJetScope(scope));
}
return r;
@@ -193,14 +194,14 @@ public class ExpressionTypingServices {
@NotNull
public JetType getBodyExpressionType(
@NotNull BindingTrace trace,
@NotNull JetScope outerScope,
@NotNull LexicalScope outerScope,
@NotNull DataFlowInfo dataFlowInfo,
@NotNull JetDeclarationWithBody function,
@NotNull FunctionDescriptor functionDescriptor
) {
JetExpression bodyExpression = function.getBodyExpression();
assert bodyExpression != null;
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace);
LexicalScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace);
ExpressionTypingContext context = ExpressionTypingContext.newContext(
trace, functionInnerScope, dataFlowInfo, NO_EXPECTED_TYPE
@@ -222,7 +223,7 @@ public class ExpressionTypingServices {
* at the nearest jump point from the block beginning.
*/
/*package*/ JetTypeInfo getBlockReturnedTypeWithWritableScope(
@NotNull WritableScope scope,
@NotNull LexicalWritableScope scope,
@NotNull List<? extends JetElement> block,
@NotNull CoercionStrategy coercionStrategyForLastExpression,
@NotNull ExpressionTypingContext context
@@ -29,12 +29,8 @@ import org.jetbrains.kotlin.diagnostics.Errors;
import org.jetbrains.kotlin.lexer.JetTokens;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.*;
import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver;
import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant;
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant;
import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant;
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl;
import org.jetbrains.kotlin.resolve.scopes.receivers.ClassReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
@@ -47,7 +43,6 @@ import java.util.List;
import static org.jetbrains.kotlin.diagnostics.Errors.*;
import static org.jetbrains.kotlin.psi.PsiPackage.JetPsiFactory;
import static org.jetbrains.kotlin.resolve.BindingContext.PROCESSED;
import static org.jetbrains.kotlin.resolve.calls.context.ContextDependency.INDEPENDENT;
public class ExpressionTypingUtils {
@@ -106,9 +101,9 @@ public class ExpressionTypingUtils {
}
@NotNull
public static WritableScopeImpl newWritableScopeImpl(ExpressionTypingContext context, @NotNull String scopeDebugName) {
WritableScopeImpl scope = new WritableScopeImpl(
context.scope, context.scope.getContainingDeclaration(), new TraceBasedRedeclarationHandler(context.trace), scopeDebugName);
public static LexicalWritableScope newWritableScopeImpl(ExpressionTypingContext context, @NotNull String scopeDebugName) {
LexicalWritableScope scope = new LexicalWritableScope(
context.scope, context.scope.getOwnerDescriptor(), false, null, new TraceBasedRedeclarationHandler(context.trace), scopeDebugName);
scope.changeLockLevel(WritableScope.LockLevel.BOTH);
return scope;
}
@@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.AnnotationChecker;
import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.BindingContextUtils;
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
import org.jetbrains.kotlin.types.DeferredType;
import org.jetbrains.kotlin.types.ErrorUtils;
import org.jetbrains.kotlin.types.JetType;
@@ -65,7 +65,7 @@ public abstract class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTy
public ForBlock(
@NotNull ExpressionTypingComponents components,
@NotNull AnnotationChecker annotationChecker,
@NotNull WritableScope writableScope
@NotNull LexicalWritableScope writableScope
) {
super(components, annotationChecker);
this.visitorForBlock = new ExpressionTypingVisitorForStatements(
@@ -40,8 +40,9 @@ import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResultsUtil;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory;
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.TypeUtils;
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
@@ -59,7 +60,7 @@ import static org.jetbrains.kotlin.types.TypeUtils.noExpectedType;
@SuppressWarnings("SuspiciousMethodCalls")
public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisitor {
private final WritableScope scope;
private final LexicalWritableScope scope;
private final BasicExpressionTypingVisitor basic;
private final ControlStructureTypingVisitor controlStructures;
private final PatternMatchingTypingVisitor patterns;
@@ -67,7 +68,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
public ExpressionTypingVisitorForStatements(
@NotNull ExpressionTypingInternals facade,
@NotNull WritableScope scope,
@NotNull LexicalWritableScope scope,
@NotNull BasicExpressionTypingVisitor basic,
@NotNull ControlStructureTypingVisitor controlStructures,
@NotNull PatternMatchingTypingVisitor patterns,
@@ -99,7 +100,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
public JetTypeInfo visitObjectDeclaration(@NotNull JetObjectDeclaration declaration, ExpressionTypingContext context) {
components.localClassifierAnalyzer.processClassOrObject(
scope, context.replaceScope(scope).replaceContextDependency(INDEPENDENT),
scope.getContainingDeclaration(),
scope.getOwnerDescriptor(),
declaration);
return TypeInfoFactoryPackage.createTypeInfo(components.dataFlowAnalyzer.checkStatementType(declaration, context), context);
}
@@ -147,7 +148,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
if (property.getTypeReference() == null && type != null) {
DataFlowValue variableDataFlowValue = DataFlowValueFactory.createDataFlowValue(
propertyDescriptor, context.trace.getBindingContext(),
DescriptorUtils.getContainingModuleOrNull(scope.getContainingDeclaration()));
DescriptorUtils.getContainingModuleOrNull(scope.getOwnerDescriptor()));
DataFlowValue initializerDataFlowValue = DataFlowValueFactory.createDataFlowValue(initializer, type, context);
// We cannot say here anything new about initializerDataFlowValue
// except it has the same value as variableDataFlowValue
@@ -159,7 +160,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
}
{
VariableDescriptor olderVariable = scope.getLocalVariable(propertyDescriptor.getName());
VariableDescriptor olderVariable = UtilsPackage.getLocalVariable(scope, propertyDescriptor.getName());
ExpressionTypingUtils.checkVariableShadowing(context, propertyDescriptor, olderVariable);
}
@@ -170,8 +171,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
@Override
public JetTypeInfo visitMultiDeclaration(@NotNull JetMultiDeclaration multiDeclaration, ExpressionTypingContext context) {
components.annotationResolver.resolveAnnotationsWithArguments(
scope, multiDeclaration.getModifierList(), context.trace);
components.annotationResolver.resolveAnnotationsWithArguments(scope, multiDeclaration.getModifierList(), context.trace);
JetExpression initializer = multiDeclaration.getInitializer();
if (initializer == null) {
@@ -197,7 +197,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
public JetTypeInfo visitClass(@NotNull JetClass klass, ExpressionTypingContext context) {
components.localClassifierAnalyzer.processClassOrObject(
scope, context.replaceScope(scope).replaceContextDependency(INDEPENDENT),
scope.getContainingDeclaration(),
scope.getOwnerDescriptor(),
klass);
return TypeInfoFactoryPackage.createTypeInfo(components.dataFlowAnalyzer.checkStatementType(klass, context), context);
}
@@ -33,7 +33,7 @@ import org.jetbrains.kotlin.resolve.BindingContextUtils
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
import org.jetbrains.kotlin.resolve.scopes.WritableScope
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope
import org.jetbrains.kotlin.resolve.source.toSourceElement
import org.jetbrains.kotlin.types.CommonSupertypes
import org.jetbrains.kotlin.types.JetType
@@ -55,7 +55,7 @@ public class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Express
function: JetNamedFunction,
context: ExpressionTypingContext,
isStatement: Boolean,
statementScope: WritableScope? // must be not null if isStatement
statementScope: LexicalWritableScope? // must be not null if isStatement
): JetTypeInfo {
if (!isStatement) {
// function expression
@@ -80,7 +80,7 @@ public class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Express
val functionDescriptor: SimpleFunctionDescriptor
if (isStatement) {
functionDescriptor = components.functionDescriptorResolver.resolveFunctionDescriptor(
context.scope.getContainingDeclaration(), context.scope, function, context.trace, context.dataFlowInfo)
context.scope.ownerDescriptor, context.scope, function, context.trace, context.dataFlowInfo)
assert(statementScope != null) {
"statementScope must be not null for function: " + function.getName() + " at location " + DiagnosticUtils.atLocation(function)
}
@@ -88,7 +88,7 @@ public class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Express
}
else {
functionDescriptor = components.functionDescriptorResolver.resolveFunctionExpressionDescriptor(
context.scope.getContainingDeclaration(), context.scope, function,
context.scope.ownerDescriptor, context.scope, function,
context.trace, context.dataFlowInfo, context.expectedType
)
}
@@ -161,12 +161,12 @@ public class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Express
): AnonymousFunctionDescriptor {
val functionLiteral = expression.getFunctionLiteral()
val functionDescriptor = AnonymousFunctionDescriptor(
context.scope.getContainingDeclaration(),
context.scope.ownerDescriptor,
components.annotationResolver.resolveAnnotationsWithArguments(context.scope, expression.getAnnotationEntries(), context.trace),
CallableMemberDescriptor.Kind.DECLARATION, functionLiteral.toSourceElement()
)
components.functionDescriptorResolver.
initializeFunctionDescriptorAndExplicitReturnType(context.scope.getContainingDeclaration(), context.scope, functionLiteral,
initializeFunctionDescriptorAndExplicitReturnType(context.scope.ownerDescriptor, context.scope, functionLiteral,
functionDescriptor, context.trace, context.expectedType)
for (parameterDescriptor in functionDescriptor.getValueParameters()) {
ForceResolveUtil.forceResolveAllContents(parameterDescriptor.getAnnotations())
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.types.expressions;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
@@ -27,9 +25,9 @@ import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.*;
import org.jetbrains.kotlin.resolve.*;
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import static org.jetbrains.kotlin.diagnostics.Errors.LABEL_NAME_CLASH;
@@ -143,7 +141,7 @@ public class LabelResolver {
Name labelName = expression.getLabelNameAsName();
if (labelElement == null || labelName == null) return null;
Collection<DeclarationDescriptor> declarationsByLabel = context.scope.getDeclarationsByLabel(labelName);
Collection<DeclarationDescriptor> declarationsByLabel = UtilsPackage.getDeclarationsByLabel(context.scope, labelName);
int size = declarationsByLabel.size();
if (size > 1) {
@@ -196,7 +194,7 @@ public class LabelResolver {
JetSimpleNameExpression targetLabel = expression.getTargetLabel();
assert targetLabel != null : expression;
Collection<DeclarationDescriptor> declarationsByLabel = context.scope.getDeclarationsByLabel(labelName);
Collection<DeclarationDescriptor> declarationsByLabel = UtilsPackage.getDeclarationsByLabel(context.scope, labelName);
int size = declarationsByLabel.size();
if (size == 1) {
DeclarationDescriptor declarationDescriptor = declarationsByLabel.iterator().next();
@@ -42,8 +42,7 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.PackageMemberDeclarationPr
import org.jetbrains.kotlin.resolve.lazy.declarations.PsiBasedClassMemberDeclarationProvider
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
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.resolve.scopes.LexicalWritableScope
import org.jetbrains.kotlin.storage.StorageManager
import org.jetbrains.kotlin.types.DynamicTypesSettings
@@ -58,7 +57,7 @@ public class LocalClassifierAnalyzer(
private val dynamicTypesSettings: DynamicTypesSettings
) {
fun processClassOrObject(
scope: WritableScope?,
scope: LexicalWritableScope?,
context: ExpressionTypingContext,
containingDeclaration: DeclarationDescriptor,
classOrObject: JetClassOrObject
@@ -92,7 +91,7 @@ public class LocalClassifierAnalyzer(
}
class LocalClassDescriptorHolder(
val writableScope: WritableScope?,
val writableScope: LexicalWritableScope?,
val myClass: JetClassOrObject,
val containingDeclaration: DeclarationDescriptor,
val storageManager: StorageManager,
@@ -147,7 +146,7 @@ class LocalClassDescriptorHolder(
fun getResolutionScopeForClass(classOrObject: JetClassOrObject): LexicalScope {
assert (isMyClass(classOrObject)) { "Called on a wrong class: ${classOrObject.getDebugText()}" }
return expressionTypingContext.scope.memberScopeAsFileScope()
return expressionTypingContext.scope
}
}
@@ -24,8 +24,9 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorResolver
import org.jetbrains.kotlin.resolve.TypeResolver
import org.jetbrains.kotlin.resolve.dataClassUtils.createComponentName
import org.jetbrains.kotlin.resolve.scopes.WritableScope
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.utils.getLocalVariable
import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.JetType
@@ -39,7 +40,7 @@ public class MultiDeclarationResolver(
private val symbolUsageValidator: SymbolUsageValidator
) {
public fun defineLocalVariablesFromMultiDeclaration(
writableScope: WritableScope,
writableScope: LexicalWritableScope,
multiDeclaration: JetMultiDeclaration,
receiver: ReceiverValue,
reportErrorsOn: JetExpression,
@@ -33,7 +33,8 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValue;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory;
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.checker.JetTypeChecker;
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.TypeInfoFactoryPackage;
@@ -113,7 +114,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
JetExpression bodyExpression = whenEntry.getExpression();
if (bodyExpression != null) {
WritableScope scopeToExtend = newWritableScopeImpl(context, "Scope extended in when entry");
LexicalWritableScope scopeToExtend = newWritableScopeImpl(context, "Scope extended in when entry");
ExpressionTypingContext newContext = contextWithExpectedType
.replaceScope(scopeToExtend).replaceDataFlowInfo(infosForCondition.thenInfo).replaceContextDependency(INDEPENDENT);
CoercionStrategy coercionStrategy = isStatement ? CoercionStrategy.COERCION_TO_UNIT : CoercionStrategy.NO_COERCION;
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.types.TypeUtils
public class ValueParameterResolver(
@@ -35,7 +35,7 @@ public class ValueParameterResolver(
public fun resolveValueParameters(
valueParameters: List<JetParameter>,
valueParameterDescriptors: List<ValueParameterDescriptor>,
declaringScope: JetScope,
declaringScope: LexicalScope,
dataFlowInfo: DataFlowInfo,
trace: BindingTrace
) {
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage;
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.tests.di.ContainerForTests;
import org.jetbrains.kotlin.tests.di.DiPackage;
@@ -134,7 +135,7 @@ public class JetExpectedResolveDataUtil {
emptyModule.initialize(PackageFragmentProvider.Empty.INSTANCE$);
ExpressionTypingContext context = ExpressionTypingContext.newContext(
new BindingTraceContext(), classDescriptor.getDefaultType().getMemberScope(),
new BindingTraceContext(), UtilsPackage.memberScopeAsFileScope(classDescriptor.getDefaultType().getMemberScope()),
DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE);
OverloadResolutionResults<FunctionDescriptor> functions = container.getFakeCallResolver().resolveFakeCall(
@@ -29,6 +29,7 @@ import java.util.regex.Pattern
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor
import org.jetbrains.kotlin.types.JetTypeImpl
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
public class ConstraintSystemTestData(
context: BindingContext,
@@ -36,14 +37,14 @@ public class ConstraintSystemTestData(
private val typeResolver: TypeResolver
) {
private val functionFoo: FunctionDescriptor
private val scopeToResolveTypeParameters: JetScope
private val scopeToResolveTypeParameters: LexicalScope
init {
val functions = context.getSliceContents(BindingContext.FUNCTION)
functionFoo = findFunctionByName(functions.values(), "foo")
val function = DescriptorToSourceUtils.descriptorToDeclaration(functionFoo) as JetFunction
val fooBody = function.getBodyExpression()
scopeToResolveTypeParameters = context.get(BindingContext.RESOLUTION_SCOPE, fooBody)!!
scopeToResolveTypeParameters = context.get(BindingContext.LEXICAL_SCOPE, fooBody)!!
}
private fun findFunctionByName(functions: Collection<FunctionDescriptor>, name: String): FunctionDescriptor {
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.RedeclarationHandler;
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.JetLiteFixture;
import org.jetbrains.kotlin.test.JetTestUtils;
@@ -126,9 +127,9 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
List<JetDeclaration> declarations = aClass.getDeclarations();
JetNamedFunction function = (JetNamedFunction) declarations.get(0);
SimpleFunctionDescriptor functionDescriptor = functionDescriptorResolver.resolveFunctionDescriptor(classDescriptor, scope, function,
JetTestUtils.DUMMY_TRACE,
DataFlowInfo.EMPTY);
SimpleFunctionDescriptor functionDescriptor =
functionDescriptorResolver.resolveFunctionDescriptor(classDescriptor, UtilsPackage.asLexicalScope(scope), function,
JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
assertEquals(expectedFunctionModality, functionDescriptor.getModality());
}
@@ -140,7 +141,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
List<JetDeclaration> declarations = aClass.getDeclarations();
JetProperty property = (JetProperty) declarations.get(0);
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(
classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
classDescriptor, UtilsPackage.asLexicalScope(scope), property, JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
assertEquals(expectedPropertyModality, propertyDescriptor.getModality());
}
@@ -153,7 +154,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
List<JetDeclaration> declarations = aClass.getDeclarations();
JetProperty property = (JetProperty) declarations.get(0);
PropertyDescriptor propertyDescriptor = descriptorResolver.resolvePropertyDescriptor(
classDescriptor, scope, property, JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
classDescriptor, UtilsPackage.asLexicalScope(scope), property, JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
PropertyAccessorDescriptor propertyAccessor = isGetter
? propertyDescriptor.getGetter()
: propertyDescriptor.getSetter();
@@ -24,10 +24,11 @@ import org.jetbrains.kotlin.psi.JetNamedFunction;
import org.jetbrains.kotlin.resolve.FunctionDescriptorResolver;
import org.jetbrains.kotlin.resolve.OverloadUtil;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.scopes.FileScope;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.JetLiteFixture;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.tests.di.ContainerForTests;
import org.jetbrains.kotlin.tests.di.DiPackage;
import static org.jetbrains.kotlin.psi.PsiPackage.JetPsiFactory;
@@ -173,7 +174,7 @@ public class JetOverloadTest extends JetLiteFixture {
private FunctionDescriptor makeFunction(String funDecl) {
JetNamedFunction function = JetPsiFactory(getProject()).createFunction(funDecl);
return functionDescriptorResolver.resolveFunctionDescriptor(root, KotlinBuiltIns.getInstance().getBuiltInsPackageScope(), function,
JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
FileScope scope = UtilsPackage.memberScopeAsFileScope(KotlinBuiltIns.getInstance().getBuiltInsPackageScope());
return functionDescriptorResolver.resolveFunctionDescriptor(root, scope, function, JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
}
}
@@ -24,6 +24,8 @@ import org.jetbrains.kotlin.psi.JetNamedFunction;
import org.jetbrains.kotlin.resolve.FunctionDescriptorResolver;
import org.jetbrains.kotlin.resolve.OverridingUtil;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.JetLiteFixture;
import org.jetbrains.kotlin.test.JetTestUtils;
@@ -163,7 +165,8 @@ public class JetOverridingTest extends JetLiteFixture {
private FunctionDescriptor makeFunction(String funDecl) {
JetNamedFunction function = JetPsiFactory(getProject()).createFunction(funDecl);
return functionDescriptorResolver.resolveFunctionDescriptor(root, KotlinBuiltIns.getInstance().getBuiltInsPackageScope(), function,
JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
LexicalScope scope = UtilsPackage.asLexicalScope(KotlinBuiltIns.getInstance().getBuiltInsPackageScope());
return functionDescriptorResolver.resolveFunctionDescriptor(root, scope, function,
JetTestUtils.DUMMY_TRACE, DataFlowInfo.EMPTY);
}
}
@@ -52,6 +52,7 @@ import java.io.IOException;
import java.util.*;
import static org.jetbrains.kotlin.psi.PsiPackage.JetPsiFactory;
import static org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage.asLexicalScope;
public class JetTypeCheckerTest extends JetLiteFixture {
@@ -550,14 +551,14 @@ public class JetTypeCheckerTest extends JetLiteFixture {
private void assertType(String expression, JetType expectedType) {
Project project = getProject();
JetExpression jetExpression = JetPsiFactory(project).createExpression(expression);
JetType type = expressionTypingServices.getType(scopeWithImports, jetExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, JetTestUtils.DUMMY_TRACE);
JetType type = expressionTypingServices.getType(asLexicalScope(scopeWithImports), jetExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, JetTestUtils.DUMMY_TRACE);
assertTrue(type + " != " + expectedType, type.equals(expectedType));
}
private void assertErrorType(String expression) {
Project project = getProject();
JetExpression jetExpression = JetPsiFactory(project).createExpression(expression);
JetType type = expressionTypingServices.safeGetType(scopeWithImports, jetExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, JetTestUtils.DUMMY_TRACE);
JetType type = expressionTypingServices.safeGetType(asLexicalScope(scopeWithImports), jetExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, JetTestUtils.DUMMY_TRACE);
assertTrue("Error type expected but " + type + " returned", type.isError());
}
@@ -590,7 +591,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
Project project = getProject();
JetExpression jetExpression = JetPsiFactory(project).createExpression(expression);
JetType type = expressionTypingServices.getType(
addImports(scope), jetExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, new BindingTraceContext());
asLexicalScope(addImports(scope)), jetExpression, TypeUtils.NO_EXPECTED_TYPE, DataFlowInfo.EMPTY, new BindingTraceContext());
JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
assertEquals(expectedType, type);
}
@@ -637,6 +638,6 @@ public class JetTypeCheckerTest extends JetLiteFixture {
}
private JetType makeType(JetScope scope, String typeStr) {
return typeResolver.resolveType(scope, JetPsiFactory(getProject()).createType(typeStr), JetTestUtils.DUMMY_TRACE, true);
return typeResolver.resolveType(asLexicalScope(scope), JetPsiFactory(getProject()).createType(typeStr), JetTestUtils.DUMMY_TRACE, true);
}
}
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.resolve.BindingTraceContext;
import org.jetbrains.kotlin.resolve.lazy.KotlinTestWithEnvironment;
import org.jetbrains.kotlin.resolve.lazy.LazyResolveTestUtil;
import org.jetbrains.kotlin.resolve.scopes.*;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.JetTestUtils;
import org.jetbrains.kotlin.tests.di.ContainerForTests;
@@ -142,7 +143,7 @@ public class TypeSubstitutorTest extends KotlinTestWithEnvironment {
JetTypeReference jetTypeReference = JetPsiFactory(getProject()).createType(typeStr);
AnalyzingUtils.checkForSyntacticErrors(jetTypeReference);
BindingTrace trace = new BindingTraceContext();
JetType type = container.getTypeResolver().resolveType(scope, jetTypeReference, trace, true);
JetType type = container.getTypeResolver().resolveType(UtilsPackage.asLexicalScope(scope), jetTypeReference, trace, true);
if (!trace.getBindingContext().getDiagnostics().isEmpty()) {
fail("Errors:\n" + StringUtil.join(
trace.getBindingContext().getDiagnostics(),
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.RedeclarationHandler;
import org.jetbrains.kotlin.resolve.scopes.WritableScope;
import org.jetbrains.kotlin.resolve.scopes.WritableScopeImpl;
import org.jetbrains.kotlin.resolve.scopes.utils.UtilsPackage;
import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.JetLiteFixture;
import org.jetbrains.kotlin.test.JetTestUtils;
@@ -211,7 +212,7 @@ public class TypeUnifierTest extends JetLiteFixture {
JetTypeReference typeReference = projection.getTypeReference();
assert typeReference != null;
JetType type = typeResolver.resolveType(withX, typeReference, JetTestUtils.DUMMY_TRACE, true);
JetType type = typeResolver.resolveType(UtilsPackage.asLexicalScope(withX), typeReference, JetTestUtils.DUMMY_TRACE, true);
return new TypeProjectionImpl(getProjectionKind(typeStr, projection), type);
}
@@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.descriptors.impl.ScriptCodeDescriptor;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
public interface ScriptDescriptor extends DeclarationDescriptorNonRoot {
String LAST_EXPRESSION_VALUE_FIELD_NAME = "rv";
@@ -37,7 +38,7 @@ public interface ScriptDescriptor extends DeclarationDescriptorNonRoot {
ClassDescriptor getClassDescriptor();
@NotNull
JetScope getScopeForBodyResolution();
LexicalScope getScopeForBodyResolution();
@NotNull
PropertyDescriptor getScriptResultProperty();
@@ -30,8 +30,8 @@ import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
import org.jetbrains.kotlin.resolve.calls.context.CheckArgumentTypesMode
import org.jetbrains.kotlin.resolve.calls.context.ContextDependency
import org.jetbrains.kotlin.resolve.scopes.ChainedScope
import org.jetbrains.kotlin.resolve.scopes.ExplicitImportsScope
import org.jetbrains.kotlin.resolve.scopes.LexicalChainedScope
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.types.TypeUtils
@@ -164,11 +164,12 @@ public class ShadowedDeclarationsFilter(
override fun getCallType() = Call.CallType.DEFAULT
}
var resolutionScope = bindingContext[BindingContext.RESOLUTION_SCOPE, context] ?: return descriptors
var resolutionScope = bindingContext[BindingContext.LEXICAL_SCOPE, context] ?: return descriptors
if (descriptorsToImport.isNotEmpty()) {
resolutionScope = ChainedScope(resolutionScope.getContainingDeclaration(), "Scope with explicitly imported descriptors",
ExplicitImportsScope(descriptorsToImport), resolutionScope)
resolutionScope = LexicalChainedScope(resolutionScope, resolutionScope.ownerDescriptor, false, null,
"Scope with explicitly imported descriptors",
ExplicitImportsScope(descriptorsToImport))
}
val dataFlowInfo = bindingContext.getDataFlowInfo(context)
@@ -27,6 +27,8 @@ import org.jetbrains.kotlin.load.java.JvmAnnotationNames.JETBRAINS_READONLY_ANNO
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.platform.JavaToKotlinClassMap
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.utils.getClassifier
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typeUtil.makeNotNullable
import org.jetbrains.kotlin.types.typeUtil.substitute
@@ -75,7 +77,7 @@ private fun JetType.hasAnnotationMaybeExternal(fqName: FqName) = with (getAnnota
findAnnotation(fqName) ?: findExternalAnnotation(fqName)
} != null
fun JetType.isResolvableInScope(scope: JetScope?, checkTypeParameters: Boolean): Boolean {
fun JetType.isResolvableInScope(scope: LexicalScope?, checkTypeParameters: Boolean): Boolean {
if (canBeReferencedViaImport()) return true
val descriptor = getConstructor().getDeclarationDescriptor()
@@ -85,7 +87,7 @@ fun JetType.isResolvableInScope(scope: JetScope?, checkTypeParameters: Boolean):
return scope != null && scope.getClassifier(descriptor.name, NoLookupLocation.FROM_IDE) == descriptor
}
public fun JetType.approximateWithResolvableType(scope: JetScope?, checkTypeParameters: Boolean): JetType {
public fun JetType.approximateWithResolvableType(scope: LexicalScope?, checkTypeParameters: Boolean): JetType {
if (isError() || isResolvableInScope(scope, checkTypeParameters)) return this
return supertypes().firstOrNull { it.isResolvableInScope(scope, checkTypeParameters) }
?: KotlinBuiltIns.getInstance().getAnyType()
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.BindingTraceContext
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.utils.asLexicalScope
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
@@ -39,7 +40,7 @@ public fun JetExpression.computeTypeInfoInContext(
isStatement: Boolean = false
): JetTypeInfo {
return contextExpression.getResolutionFacade().frontendService<ExpressionTypingServices>()
.getTypeInfo(scope, this, expectedType, dataFlowInfo, trace, isStatement)
.getTypeInfo(scope.asLexicalScope(), this, expectedType, dataFlowInfo, trace, isStatement)
}
jvmOverloads
@@ -28,9 +28,9 @@ import org.jetbrains.kotlin.resolve.bindingContextUtil.getDataFlowInfo
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
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.resolve.scopes.LexicalChainedScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
@@ -85,18 +85,18 @@ public class CodeFragmentAnalyzer(
private fun getScopeAndDataFlowForAnalyzeFragment(
codeFragment: JetCodeFragment,
resolveToElement: (JetElement) -> BindingContext
): Pair<JetScope, DataFlowInfo>? {
): Pair<LexicalScope, DataFlowInfo>? {
val context = codeFragment.getContext()
if (context !is JetExpression) return null
val scopeForContextElement: JetScope?
val scopeForContextElement: LexicalScope?
val dataFlowInfo: DataFlowInfo
when (context) {
is JetClassOrObject -> {
val descriptor = resolveSession.getClassDescriptor(context, NoLookupLocation.FROM_IDE) as ClassDescriptorWithResolutionScopes
scopeForContextElement = descriptor.getScopeForMemberDeclarationResolution().asJetScope()
scopeForContextElement = descriptor.getScopeForMemberDeclarationResolution()
dataFlowInfo = DataFlowInfo.EMPTY
}
is JetExpression -> {
@@ -104,7 +104,7 @@ public class CodeFragmentAnalyzer(
val contextForElement = resolveToElement(correctedContext)
scopeForContextElement = contextForElement[BindingContext.RESOLUTION_SCOPE, correctedContext]
scopeForContextElement = contextForElement[BindingContext.LEXICAL_SCOPE, correctedContext]
dataFlowInfo = contextForElement.getDataFlowInfo(correctedContext)
}
is JetFile -> {
@@ -117,10 +117,11 @@ public class CodeFragmentAnalyzer(
if (scopeForContextElement == null) return null
val codeFragmentScope = resolveSession.getFileScopeProvider().getFileScope(codeFragment)
val chainedScope = ChainedScope(
scopeForContextElement.getContainingDeclaration(),
val chainedScope = LexicalChainedScope(
scopeForContextElement, scopeForContextElement.ownerDescriptor,
false, null,
"Scope for resolve code fragment",
scopeForContextElement, codeFragmentScope)
codeFragmentScope)
return chainedScope to dataFlowInfo
}
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.idea.caches.resolve
import com.intellij.openapi.project.Project
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
@@ -34,7 +33,7 @@ import org.jetbrains.kotlin.resolve.ImportPath
import org.jetbrains.kotlin.resolve.QualifiedExpressionResolver
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.lazy.FileScopeProvider
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.lazy.LazyFileScope
public fun JetElement.getResolutionFacade(): ResolutionFacade {
return KotlinCacheService.getInstance(getProject()).getResolutionFacade(listOf(this))
@@ -96,6 +95,6 @@ public fun getResolveScope(file: JetFile): GlobalSearchScope {
}
}
public fun ResolutionFacade.getFileTopLevelScope(file: JetFile): JetScope {
public fun ResolutionFacade.getFileTopLevelScope(file: JetFile): LazyFileScope {
return frontendService<FileScopeProvider>().getFileScope(file)
}
@@ -32,6 +32,8 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.FunctionDescriptorUtil
import org.jetbrains.kotlin.resolve.scopes.*
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsFileScope
import org.jetbrains.kotlin.resolve.source.PsiSourceElement
public class KDocReference(element: KDocName): JetMultiReference<KDocName>(element) {
@@ -84,7 +86,7 @@ public fun resolveKDocLink(resolutionFacade: ResolutionFacade,
var result: Collection<DeclarationDescriptor> = listOf(fromDescriptor)
qualifiedName.forEach { nameComponent ->
if (result.size() != 1) return listOf()
val scope = getResolutionScope(resolutionFacade, result.first())
val scope = getResolutionScope(resolutionFacade, result.first()).asJetScope()
result = scope.getDescriptors().filter { it.getName().asString() == nameComponent }
}
@@ -94,7 +96,7 @@ public fun resolveKDocLink(resolutionFacade: ResolutionFacade,
private fun resolveInLocalScope(fromDescriptor: DeclarationDescriptor,
name: String,
resolutionFacade: ResolutionFacade): List<DeclarationDescriptor> {
val scope = getResolutionScope(resolutionFacade, fromDescriptor)
val scope = getResolutionScope(resolutionFacade, fromDescriptor).asJetScope()
return scope.getDescriptors().filter {
it.getName().asString() == name && it.getContainingDeclaration() == fromDescriptor
}
@@ -129,30 +131,28 @@ private fun getPackageInnerScope(descriptor: PackageFragmentDescriptor): JetScop
return descriptor.getContainingDeclaration().getPackage(descriptor.fqName).memberScope
}
private fun getClassInnerScope(outerScope: JetScope, descriptor: ClassDescriptor): JetScope {
val redeclarationHandler = RedeclarationHandler.DO_NOTHING
private fun getClassInnerScope(outerScope: LexicalScope, descriptor: ClassDescriptor): LexicalScope {
val headerScope = WritableScopeImpl(outerScope, descriptor, redeclarationHandler, "Class ${descriptor.getName()} header scope",
descriptor.thisAsReceiverParameter)
for (typeParameter in descriptor.getTypeConstructor().getParameters()) {
headerScope.addClassifierDescriptor(typeParameter)
val headerScope = LexicalScopeImpl(outerScope, descriptor, false, descriptor.thisAsReceiverParameter,
"Class ${descriptor.getName()} header scope") {
for (typeParameter in descriptor.getTypeConstructor().getParameters()) {
addClassifierDescriptor(typeParameter)
}
for (constructor in descriptor.getConstructors()) {
addFunctionDescriptor(constructor)
}
}
for (constructor in descriptor.getConstructors()) {
headerScope.addFunctionDescriptor(constructor)
}
headerScope.changeLockLevel(WritableScope.LockLevel.READING)
val classScope = ChainedScope(descriptor, "Class ${descriptor.getName()} scope", descriptor.getDefaultType().getMemberScope(), headerScope)
return classScope
return LexicalChainedScope(headerScope, descriptor, false, null,
"Class ${descriptor.getName()} scope", descriptor.getDefaultType().getMemberScope())
}
public fun getResolutionScope(resolutionFacade: ResolutionFacade, descriptor: DeclarationDescriptor): JetScope {
public fun getResolutionScope(resolutionFacade: ResolutionFacade, descriptor: DeclarationDescriptor): LexicalScope {
return when (descriptor) {
is PackageFragmentDescriptor ->
getPackageInnerScope(descriptor)
getPackageInnerScope(descriptor).memberScopeAsFileScope()
is PackageViewDescriptor ->
descriptor.memberScope
descriptor.memberScope.memberScopeAsFileScope()
is ClassDescriptor ->
getClassInnerScope(getOuterScope(descriptor, resolutionFacade), descriptor)
@@ -173,7 +173,7 @@ public fun getResolutionScope(resolutionFacade: ResolutionFacade, descriptor: De
}
}
private fun getOuterScope(descriptor: DeclarationDescriptorWithSource, resolutionFacade: ResolutionFacade): JetScope {
private fun getOuterScope(descriptor: DeclarationDescriptorWithSource, resolutionFacade: ResolutionFacade): LexicalScope {
val parent = descriptor.getContainingDeclaration()
if (parent is PackageFragmentDescriptor) {
val containingFile = (descriptor.getSource() as? PsiSourceElement)?.psi?.getContainingFile() as? JetFile
@@ -43,7 +43,6 @@ 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.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
import org.jetbrains.kotlin.utils.addToStdlib.check
public class ResolveElementCache(
@@ -407,15 +406,15 @@ public class ResolveElementCache(
classOrObject,
descriptor,
descriptor.getUnsubstitutedPrimaryConstructor(),
descriptor.getScopeForClassHeaderResolution().asJetScope(),
descriptor.getScopeForMemberDeclarationResolution().asJetScope())
descriptor.getScopeForClassHeaderResolution(),
descriptor.getScopeForMemberDeclarationResolution())
return trace
}
private fun propertyAdditionalResolve(resolveSession: ResolveSession, jetProperty: JetProperty, file: JetFile, statementFilter: StatementFilter): BindingTrace {
val trace = createDelegatingTrace(jetProperty)
val propertyResolutionScope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(jetProperty).asJetScope()
val propertyResolutionScope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(jetProperty)
val bodyResolver = createBodyResolver(resolveSession, trace, file, statementFilter)
val descriptor = resolveSession.resolveToDescriptor(jetProperty) as PropertyDescriptor
@@ -448,7 +447,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).asJetScope()
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(namedFunction)
val functionDescriptor = resolveSession.resolveToDescriptor(namedFunction) as FunctionDescriptor
ForceResolveUtil.forceResolveAllContents(functionDescriptor)
@@ -461,7 +460,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).asJetScope()
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(constructor)
val constructorDescriptor = resolveSession.resolveToDescriptor(constructor) as ConstructorDescriptor
ForceResolveUtil.forceResolveAllContents(constructorDescriptor)
@@ -473,7 +472,7 @@ public class ResolveElementCache(
private fun constructorAdditionalResolve(resolveSession: ResolveSession, klass: JetClass, file: JetFile): BindingTrace {
val trace = createDelegatingTrace(klass)
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(klass).asJetScope()
val scope = resolveSession.getDeclarationScopeProvider().getResolutionScopeForDeclaration(klass)
val classDescriptor = resolveSession.resolveToDescriptor(klass) as ClassDescriptor
val constructorDescriptor = classDescriptor.getUnsubstitutedPrimaryConstructor()
@@ -97,7 +97,7 @@ abstract class CompletionSession(protected val configuration: CompletionSessionC
}
protected val bindingContext: BindingContext = resolutionFacade.analyze(position.parentsWithSelf.firstIsInstance<JetElement>(), BodyResolveMode.PARTIAL_FOR_COMPLETION)
protected val inDescriptor: DeclarationDescriptor = position.getResolutionScope(bindingContext, resolutionFacade).getContainingDeclaration()
protected val inDescriptor: DeclarationDescriptor = position.getResolutionScope(bindingContext, resolutionFacade).ownerDescriptor
private val kotlinIdentifierStartPattern: ElementPattern<Char>
private val kotlinIdentifierPartPattern: ElementPattern<Char>
@@ -234,7 +234,7 @@ class ExpectedInfos(
override fun getFunctionLiteralArguments() = emptyList<FunctionLiteralArgument>()
override fun getValueArgumentList() = null
}
val resolutionScope = bindingContext[BindingContext.RESOLUTION_SCOPE, call.calleeExpression] ?: return emptyList() //TODO: discuss it
val resolutionScope = bindingContext[BindingContext.LEXICAL_SCOPE, call.calleeExpression] ?: return emptyList() //TODO: discuss it
val dataFlowInfo = bindingContext.getDataFlowInfo(call.calleeExpression)
val bindingTrace = DelegatingBindingTrace(bindingContext, "Temporary trace for completion")
@@ -257,7 +257,7 @@ class ExpectedInfos(
if (descriptor.valueParameters.isEmpty()) continue
val thisReceiver = ExpressionTypingUtils.normalizeReceiverValueForVisibility(candidate.getDispatchReceiver(), bindingContext)
if (!Visibilities.isVisible(thisReceiver, descriptor, resolutionScope.getContainingDeclaration())) continue
if (!Visibilities.isVisible(thisReceiver, descriptor, resolutionScope.ownerDescriptor)) continue
var argumentToParameter = call.mapArgumentsToParameters(descriptor)
var parameter = argumentToParameter[argument] ?: continue
@@ -22,20 +22,19 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.descriptors.impl.SubpackagesScope
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.JetPsiFactory
import org.jetbrains.kotlin.resolve.BindingTraceContext
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.TypeResolver
import org.jetbrains.kotlin.resolve.scopes.ChainedScope
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsFileScope
import org.jetbrains.kotlin.types.IndexedParametersSubstitution
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.SubstitutionUtils
import org.jetbrains.kotlin.types.Variance
import java.util.HashMap
import java.util.*
public class HeuristicSignatures(
private val moduleDescriptor: ModuleDescriptor,
@@ -77,20 +76,15 @@ public class HeuristicSignatures(
private fun typeFromText(text: String, typeParameters: Collection<TypeParameterDescriptor>): JetType {
val typeRef = JetPsiFactory(project).createType(text)
val rootPackagesScope = SubpackagesScope(moduleDescriptor, FqName.ROOT)
val typeParametersScope = TypeParametersScope(typeParameters)
val scope = ChainedScope(moduleDescriptor, "Root packages + type parameters", typeParametersScope, rootPackagesScope)
val rootPackagesScope = SubpackagesScope(moduleDescriptor, FqName.ROOT).memberScopeAsFileScope()
val scope = LexicalScopeImpl(rootPackagesScope, moduleDescriptor, false, null, "Root packages + type parameters") {
typeParameters.forEach { addClassifierDescriptor(it) }
}
val type = typeResolver.resolveType(scope, typeRef, BindingTraceContext(), false)
assert(!type.isError()) { "No type resolved from '$text'" }
return type
}
private class TypeParametersScope(params: Collection<TypeParameterDescriptor>) : JetScope by JetScope.Empty {
private val paramsByName = params.map { it.getName() to it }.toMap()
override fun getClassifier(name: Name, location: LookupLocation) = paramsByName[name]
}
companion object {
private val signatures = HashMap<Pair<FqName, Name>, List<String>>()
@@ -38,7 +38,8 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
class KDocCompletionContributor(): CompletionContributor() {
init {
@@ -42,7 +42,7 @@ import org.jetbrains.kotlin.psi.JetParameter
import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.getDescriptorsFiltered
import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFiltered
import org.jetbrains.kotlin.types.JetType
import java.util.*
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.resolve.BindingTraceContext
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.utils.asLexicalScope
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.expressions.ExpressionTypingContext
@@ -73,7 +74,7 @@ public class IterableTypesDetection(
val expression = JetPsiFactory(project).createExpression("fake")
val expressionReceiver = ExpressionReceiver(expression, type.type)
val context = ExpressionTypingContext.newContext(BindingTraceContext(), scope, DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE)
val context = ExpressionTypingContext.newContext(BindingTraceContext(), scope.asLexicalScope(), DataFlowInfo.EMPTY, TypeUtils.NO_EXPECTED_TYPE)
val elementType = forLoopConventionsChecker.checkIterableConvention(expressionReceiver, context)
return elementType?.let { FuzzyType(it, type.freeParameters) }
}
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.psi.psiUtil.siblings
import org.jetbrains.kotlin.resolve.descriptorUtil.isExtension
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
import java.util.Collections
import java.util.HashSet
@@ -79,7 +80,7 @@ public class NewDeclarationNameValidator(
if (visibleDeclarationsContext != null) {
val bindingContext = visibleDeclarationsContext.analyze(BodyResolveMode.PARTIAL_FOR_COMPLETION)
val resolutionScope = visibleDeclarationsContext.getResolutionScope(bindingContext, visibleDeclarationsContext.getResolutionFacade())
if (resolutionScope.hasConflict(identifier)) return false
if (resolutionScope.asJetScope().hasConflict(identifier)) return false
}
return checkDeclarationsIn.none {
@@ -27,8 +27,9 @@ 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.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
import org.jetbrains.kotlin.resolve.scopes.utils.asLexicalScope
import java.util.*
public fun Call.mapArgumentsToParameters(targetDescriptor: CallableDescriptor): Map<ValueArgument, ValueParameterDescriptor> {
@@ -80,17 +81,18 @@ public fun ThisReceiver.asExpression(resolutionScope: JetScope, psiFactory: JetP
return expressionFactory.createExpression(psiFactory)
}
public fun PsiElement.getResolutionScope(bindingContext: BindingContext, resolutionFacade: ResolutionFacade): JetScope {
public fun PsiElement.getResolutionScope(bindingContext: BindingContext, resolutionFacade: ResolutionFacade): LexicalScope {
for (parent in parentsWithSelf) {
if (parent is JetExpression) {
val scope = bindingContext[BindingContext.RESOLUTION_SCOPE, parent]
val scope = bindingContext[BindingContext.LEXICAL_SCOPE, parent] ?:
bindingContext[BindingContext.RESOLUTION_SCOPE, parent]?.asLexicalScope() // todo remove this hack
if (scope != null) return scope
}
if (parent is JetClassBody) {
val classDescriptor = bindingContext[BindingContext.CLASS, parent.getParent()] as? ClassDescriptorWithResolutionScopes
if (classDescriptor != null) {
return classDescriptor.getScopeForMemberDeclarationResolution().asJetScope()
return classDescriptor.getScopeForMemberDeclarationResolution()
}
}
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.idea.inspections
import com.intellij.codeInspection.*
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.codegen.SamCodegenUtil
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
@@ -33,7 +32,6 @@ import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptor
import org.jetbrains.kotlin.load.java.sam.SingleAbstractMethodUtils
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.BindingTraceContext
@@ -42,6 +40,7 @@ import org.jetbrains.kotlin.resolve.calls.CallResolver
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.utils.getFileScope
import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.utils.addToStdlib.check
@@ -114,7 +113,7 @@ public class RedundantSamConstructorInspection : AbstractKotlinInspection() {
val context = parentCall.analyze(BodyResolveMode.PARTIAL)
val calleeExpression = parentCall.calleeExpression ?: return false
val scope = context[BindingContext.RESOLUTION_SCOPE, calleeExpression] ?: return false
val scope = context[BindingContext.LEXICAL_SCOPE, calleeExpression] ?: return false
val originalCall = parentCall.getResolvedCall(context) ?: return false
@@ -178,7 +177,7 @@ public class RedundantSamConstructorInspection : AbstractKotlinInspection() {
}
// SAM adapters for member functions
val resolutionScope = functionCall.getResolutionScope(bindingContext, functionCall.getResolutionFacade())
val resolutionScope = functionCall.getResolutionScope(bindingContext, functionCall.getResolutionFacade()).getFileScope()
val syntheticExtensions = resolutionScope.getSyntheticExtensionFunctions(
containingClass.defaultType.singletonList(),
functionResolvedCall.resultingDescriptor.name,
@@ -47,7 +47,7 @@ public class RemoveExplicitTypeArgumentsIntention : JetSelfTargetingOffsetIndepe
val resolutionFacade = callExpression.getResolutionFacade()
val context = resolutionFacade.analyze(callExpression, BodyResolveMode.PARTIAL)
val calleeExpression = callExpression.getCalleeExpression() ?: return false
val scope = context[BindingContext.RESOLUTION_SCOPE, calleeExpression/*TODO: discuss it*/] ?: return false
val scope = context[BindingContext.LEXICAL_SCOPE, calleeExpression/*TODO: discuss it*/] ?: return false
val originalCall = callExpression.getResolvedCall(context) ?: return false
val untypedCall = CallWithoutTypeArgs(originalCall.getCall())
@@ -47,6 +47,8 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.kotlin.resolve.calls.util.DelegatingCall
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
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.synthetic.SyntheticJavaPropertyDescriptor
import org.jetbrains.kotlin.types.JetType
import org.jetbrains.kotlin.types.TypeUtils
@@ -83,7 +85,7 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
val function = resolvedCall.getResultingDescriptor() as? FunctionDescriptor ?: return null
val resolutionScope = callExpression.getResolutionScope(bindingContext, resolutionFacade)
val property = findSyntheticProperty(function, resolutionScope) ?: return null
val property = findSyntheticProperty(function, resolutionScope.asJetScope()) ?: return null
val dataFlowInfo = bindingContext.getDataFlowInfo(callee)
val qualifiedExpression = callExpression.getQualifiedExpressionForSelectorOrThis()
@@ -98,7 +100,7 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
val newExpression = applyTo(callExpressionCopy, property.name)
val bindingTrace = DelegatingBindingTrace(bindingContext, "Temporary trace")
val newBindingContext = newExpression.analyzeInContext(
resolutionScope,
resolutionScope.asJetScope(),
contextExpression = callExpression,
trace = bindingTrace,
dataFlowInfo = dataFlowInfo,
@@ -115,7 +117,7 @@ class UsePropertyAccessSyntaxIntention : JetSelfTargetingOffsetIndependentIntent
resolvedCall: ResolvedCall<out CallableDescriptor>,
property: SyntheticJavaPropertyDescriptor,
bindingContext: BindingContext,
resolutionScope: JetScope,
resolutionScope: LexicalScope,
dataFlowInfo: DataFlowInfo,
expectedType: JetType,
facade: ResolutionFacade
@@ -37,7 +37,7 @@ import org.jetbrains.kotlin.resolve.BindingContext;
import org.jetbrains.kotlin.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.kotlin.resolve.calls.callUtil.CallUtilPackage;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.scopes.JetScope;
import org.jetbrains.kotlin.resolve.scopes.LexicalScope;
import org.jetbrains.kotlin.types.JetType;
import org.jetbrains.kotlin.types.typeUtil.TypeUtilPackage;
@@ -104,7 +104,7 @@ public class QuickFixFactoryForTypeMismatchError extends JetIntentionActionsFact
JetExpression initializer = property.getInitializer();
if (QuickFixUtil.canEvaluateTo(initializer, expression) ||
(getter != null && QuickFixUtil.canFunctionOrGetterReturnExpression(property.getGetter(), expression))) {
JetScope scope = CorePackage.getResolutionScope(property, context, ResolvePackage.getResolutionFacade(property));
LexicalScope scope = CorePackage.getResolutionScope(property, context, ResolvePackage.getResolutionFacade(property));
JetType typeToInsert = UtilPackage.approximateWithResolvableType(expressionType, scope, false);
actions.add(new ChangeVariableTypeFix(property, typeToInsert));
}
@@ -118,7 +118,7 @@ public class QuickFixFactoryForTypeMismatchError extends JetIntentionActionsFact
? BindingContextUtilPackage.getTargetFunction((JetReturnExpression) expressionParent, context)
: PsiTreeUtil.getParentOfType(expression, JetFunction.class, true);
if (function instanceof JetFunction && QuickFixUtil.canFunctionOrGetterReturnExpression(function, expression)) {
JetScope scope = CorePackage.getResolutionScope(function, context, ResolvePackage.getResolutionFacade(function));
LexicalScope scope = CorePackage.getResolutionScope(function, context, ResolvePackage.getResolutionFacade(function));
JetType typeToInsert = UtilPackage.approximateWithResolvableType(expressionType, scope, false);
actions.add(new ChangeFunctionReturnTypeFix((JetFunction) function, typeToInsert));
}
@@ -159,7 +159,7 @@ public class QuickFixFactoryForTypeMismatchError extends JetIntentionActionsFact
: context.getType(valueArgument.getArgumentExpression());
if (correspondingParameter != null && valueArgumentType != null) {
JetCallableDeclaration callable = PsiTreeUtil.getParentOfType(correspondingParameter, JetCallableDeclaration.class, true);
JetScope scope = callable != null ? CorePackage.getResolutionScope(callable, context, ResolvePackage.getResolutionFacade(callable)) : null;
LexicalScope scope = callable != null ? CorePackage.getResolutionScope(callable, context, ResolvePackage.getResolutionFacade(callable)) : null;
JetType typeToInsert = UtilPackage.approximateWithResolvableType(valueArgumentType, scope, true);
actions.add(new ChangeParameterTypeFix(correspondingParameter, typeToInsert));
}
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.resolve.lazy.descriptors.ClassResolutionScopesSuppor
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.asLexicalScope
import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsFileScope
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.TypeUtils
@@ -91,7 +92,8 @@ object ReplaceWithAnnotationAnalyzer {
val explicitlyImportedSymbols = importFqNames.flatMap { resolutionFacade.resolveImportReference(symbolDescriptor.module, it) }
val symbolScope = getResolutionScope(symbolDescriptor)
val scope = ChainedScope(symbolDescriptor, "ReplaceWith resolution scope", ExplicitImportsScope(explicitlyImportedSymbols), symbolScope)
val scope = LexicalChainedScope(symbolScope, symbolDescriptor, false, null, "ReplaceWith resolution scope",
ExplicitImportsScope(explicitlyImportedSymbols))
var bindingContext = analyzeInContext(expression, symbolDescriptor, scope, resolutionFacade)
@@ -135,7 +137,7 @@ object ReplaceWithAnnotationAnalyzer {
else
resolvedCall.getDispatchReceiver()
if (receiver is ThisReceiver) {
val receiverExpression = receiver.asExpression(symbolScope, psiFactory)
val receiverExpression = receiver.asExpression(symbolScope.asJetScope(), psiFactory)
if (receiverExpression != null) {
receiversToAdd.add(expression to receiverExpression)
}
@@ -159,7 +161,7 @@ object ReplaceWithAnnotationAnalyzer {
private fun analyzeInContext(
expression: JetExpression,
symbolDescriptor: CallableDescriptor,
scope: ChainedScope,
scope: LexicalScope,
resolutionFacade: ResolutionFacade
): BindingContext {
val traceContext = BindingTraceContext()
@@ -168,7 +170,7 @@ object ReplaceWithAnnotationAnalyzer {
return traceContext.bindingContext
}
private fun getResolutionScope(descriptor: DeclarationDescriptor): JetScope {
private fun getResolutionScope(descriptor: DeclarationDescriptor): LexicalScope {
return when (descriptor) {
is PackageFragmentDescriptor -> {
val moduleDescriptor = descriptor.getContainingDeclaration()
@@ -176,15 +178,15 @@ object ReplaceWithAnnotationAnalyzer {
}
is PackageViewDescriptor ->
descriptor.memberScope
descriptor.memberScope.memberScopeAsFileScope()
is ClassDescriptorWithResolutionScopes ->
descriptor.getScopeForMemberDeclarationResolution().asJetScope()
descriptor.getScopeForMemberDeclarationResolution()
is ClassDescriptor -> {
val outerScope = getResolutionScope(descriptor.getContainingDeclaration())
ClassResolutionScopesSupport(descriptor, LockBasedStorageManager.NO_LOCKS, { outerScope.memberScopeAsFileScope() })
.scopeForMemberDeclarationResolution().asJetScope()
ClassResolutionScopesSupport(descriptor, LockBasedStorageManager.NO_LOCKS, { outerScope })
.scopeForMemberDeclarationResolution()
}
is FunctionDescriptor ->
@@ -197,7 +199,7 @@ object ReplaceWithAnnotationAnalyzer {
RedeclarationHandler.DO_NOTHING)
is LocalVariableDescriptor -> {
val declaration = DescriptorToSourceUtils.descriptorToDeclaration(descriptor) as JetDeclaration
declaration.analyze()[BindingContext.RESOLUTION_SCOPE, declaration]!!
declaration.analyze()[BindingContext.RESOLUTION_SCOPE, declaration]!!.asLexicalScope()
}
//TODO?
@@ -72,10 +72,11 @@ import org.jetbrains.kotlin.resolve.calls.tasks.isSynthesizedInvoke
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.getImportableDescriptor
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
import org.jetbrains.kotlin.resolve.scopes.utils.asJetScope
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.JetTypeChecker
import org.jetbrains.kotlin.types.typeUtil.makeNullable
@@ -142,7 +143,7 @@ private fun List<Instruction>.getExitPoints(): List<Instruction> =
private fun List<Instruction>.getResultTypeAndExpressions(
bindingContext: BindingContext,
targetScope: JetScope?,
targetScope: LexicalScope?,
options: ExtractionOptions
): Pair<JetType, List<JetExpression>> {
fun instructionToExpression(instruction: Instruction, unwrapReturn: Boolean): JetExpression? {
@@ -239,7 +240,7 @@ private fun ExtractionData.analyzeControlFlow(
bindingContext: BindingContext,
modifiedVarDescriptors: Map<VariableDescriptor, List<JetExpression>>,
options: ExtractionOptions,
targetScope: JetScope?,
targetScope: LexicalScope?,
parameters: Set<Parameter>
): Pair<ControlFlow, ErrorMessage?> {
val exitPoints = localInstructions.getExitPoints()
@@ -444,7 +445,7 @@ fun TypeParameter.collectReferencedTypes(bindingContext: BindingContext): List<J
.filterNotNull()
}
private fun JetType.isExtractable(targetScope: JetScope?): Boolean {
private fun JetType.isExtractable(targetScope: LexicalScope?): Boolean {
return collectReferencedTypes(true).fold(true) { extractable, typeToCheck ->
val parameterTypeDescriptor = typeToCheck.getConstructor().getDeclarationDescriptor() as? TypeParameterDescriptor
val typeParameter = parameterTypeDescriptor?.let {
@@ -459,7 +460,7 @@ private fun JetType.processTypeIfExtractable(
typeParameters: MutableSet<TypeParameter>,
nonDenotableTypes: MutableSet<JetType>,
options: ExtractionOptions,
targetScope: JetScope?,
targetScope: LexicalScope?,
processTypeArguments: Boolean = true
): Boolean {
return collectReferencedTypes(processTypeArguments).fold(true) { extractable, typeToCheck ->
@@ -495,7 +496,7 @@ private class MutableParameter(
override val argumentText: String,
override val originalDescriptor: DeclarationDescriptor,
override val receiverCandidate: Boolean,
private val targetScope: JetScope?
private val targetScope: LexicalScope?
): Parameter {
// All modifications happen in the same thread
private var writable: Boolean = true
@@ -585,7 +586,7 @@ private fun ExtractionData.inferParametersInfo(
commonParent: PsiElement,
pseudocode: Pseudocode,
bindingContext: BindingContext,
targetScope: JetScope?,
targetScope: LexicalScope?,
modifiedVarDescriptors: Set<VariableDescriptor>
): ParametersInfo {
val info = ParametersInfo()
@@ -652,7 +653,7 @@ private fun ExtractionData.inferParametersInfo(
options.captureLocalFunctions
&& originalRef.getReferencedName() == originalDescriptor.getName().asString() // to forbid calls by convention
&& originalDeclaration is JetNamedFunction && originalDeclaration.isLocal()
&& (targetScope == null || originalDescriptor !in targetScope.getFunctions(originalDescriptor.name, NoLookupLocation.FROM_IDE))
&& (targetScope == null || originalDescriptor !in targetScope.asJetScope().getFunctions(originalDescriptor.name, NoLookupLocation.FROM_IDE))
val descriptorToExtract = (if (extractThis) thisDescriptor else null) ?: originalDescriptor
@@ -23,30 +23,23 @@ import com.intellij.openapi.project.Project
import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiReference
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.refactoring.BaseRefactoringProcessor
import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer
import com.intellij.refactoring.listeners.RefactoringEventListener
import com.intellij.usageView.BaseUsageViewDescriptor
import com.intellij.usageView.UsageInfo
import com.intellij.usageView.UsageViewDescriptor
import com.intellij.util.containers.MultiMap
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.core.getResolutionScope
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
import org.jetbrains.kotlin.idea.core.refactoring.runRefactoringWithPostprocessing
import org.jetbrains.kotlin.idea.core.NewDeclarationNameValidator
import org.jetbrains.kotlin.idea.core.getResolutionScope
import org.jetbrains.kotlin.idea.core.refactoring.runRefactoringWithPostprocessing
import org.jetbrains.kotlin.idea.refactoring.JetRefactoringBundle
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*
import org.jetbrains.kotlin.idea.refactoring.introduce.KotlinIntroduceHandlerBase
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.*
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceVariable.KotlinInplaceVariableIntroducer
import org.jetbrains.kotlin.idea.refactoring.introduce.selectElementsWithTargetParent
import org.jetbrains.kotlin.idea.refactoring.introduce.showErrorHint
import org.jetbrains.kotlin.idea.refactoring.introduce.showErrorHintByKey
@@ -54,9 +47,10 @@ import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.search.usagesSearch.DefaultSearchHelper
import org.jetbrains.kotlin.idea.search.usagesSearch.UsagesSearchTarget
import org.jetbrains.kotlin.idea.search.usagesSearch.search
import org.jetbrains.kotlin.idea.util.*
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.idea.util.application.executeCommand
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.idea.util.approximateWithResolvableType
import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiRange
import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiUnifier
import org.jetbrains.kotlin.idea.util.psi.patternMatching.toRange
@@ -64,7 +58,6 @@ import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.scopes.JetScopeUtils
import org.jetbrains.kotlin.resolve.scopes.receivers.ThisReceiver
import org.jetbrains.kotlin.types.typeUtil.isNothing
import org.jetbrains.kotlin.types.typeUtil.isUnit
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.psi.JetClassOrObject
import org.jetbrains.kotlin.psi.JetNamedDeclaration
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.utils.getDescriptorsFiltered
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.types.TypeProjection
import org.jetbrains.kotlin.types.TypeProjectionImpl
@@ -50,7 +51,7 @@ class KotlinPullUpData(val sourceClass: JetClassOrObject,
val typeParametersInSourceClassContext by lazy {
sourceClassDescriptor.typeConstructor.parameters + sourceClass.getResolutionScope(sourceClassContext, resolutionFacade)
.getDescriptors(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS)
.getDescriptorsFiltered(DescriptorKindFilter.NON_SINGLETON_CLASSIFIERS)
.filterIsInstance<TypeParameterDescriptor>()
}