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