Fix JetSimpleNameExpression#getReceiver
Correct behaviour for unary, binary expressions and type references Add instanceof checks in TipsManager so it's clear it only takes care of certain types of JetSimpleNameExpression
This commit is contained in:
@@ -35,10 +35,6 @@ public class JetSimpleNameExpression extends JetReferenceExpression {
|
|||||||
super(node);
|
super(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* null if it's not a code expression
|
|
||||||
* @return receiver expression
|
|
||||||
*/
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public JetExpression getReceiverExpression() {
|
public JetExpression getReceiverExpression() {
|
||||||
PsiElement parent = getParent();
|
PsiElement parent = getParent();
|
||||||
@@ -55,10 +51,24 @@ public class JetSimpleNameExpression extends JetReferenceExpression {
|
|||||||
parent = callExpression.getParent();
|
parent = callExpression.getParent();
|
||||||
if (parent instanceof JetQualifiedExpression) {
|
if (parent instanceof JetQualifiedExpression) {
|
||||||
JetQualifiedExpression qualifiedExpression = (JetQualifiedExpression) parent;
|
JetQualifiedExpression qualifiedExpression = (JetQualifiedExpression) parent;
|
||||||
return qualifiedExpression.getReceiverExpression();
|
JetExpression parentsReceiver = qualifiedExpression.getReceiverExpression();
|
||||||
|
if (parentsReceiver != callExpression) {
|
||||||
|
return parentsReceiver;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (parent instanceof JetBinaryExpression && ((JetBinaryExpression) parent).getOperationReference() == this) {
|
||||||
|
return ((JetBinaryExpression) parent).getLeft();
|
||||||
|
}
|
||||||
|
else if (parent instanceof JetUnaryExpression && ((JetUnaryExpression) parent).getOperationReference() == this) {
|
||||||
|
return ((JetUnaryExpression) parent).getBaseExpression();
|
||||||
|
}
|
||||||
|
else if (parent instanceof JetUserType) {
|
||||||
|
JetUserType qualifier = ((JetUserType) parent).getQualifier();
|
||||||
|
if (qualifier != null) {
|
||||||
|
return qualifier.getReferenceExpression();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -292,8 +292,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
|||||||
@NotNull GlobalSearchScope searchScope
|
@NotNull GlobalSearchScope searchScope
|
||||||
) {
|
) {
|
||||||
BindingContext context = resolveSession.resolveToElement(expression);
|
BindingContext context = resolveSession.resolveToElement(expression);
|
||||||
JetExpression receiverExpression = getReceiverForExtensionCall(expression);
|
JetExpression receiverExpression = expression.getReceiverExpression();
|
||||||
|
|
||||||
if (receiverExpression == null) {
|
if (receiverExpression == null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
@@ -325,18 +324,6 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
|||||||
return resultDescriptors;
|
return resultDescriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private static JetExpression getReceiverForExtensionCall(@NotNull JetSimpleNameExpression expression) {
|
|
||||||
PsiElement parent = expression.getParent();
|
|
||||||
if (parent instanceof JetBinaryExpression && ((JetBinaryExpression) parent).getOperationReference() == expression) {
|
|
||||||
return ((JetBinaryExpression) parent).getLeft();
|
|
||||||
}
|
|
||||||
else if (parent instanceof JetUnaryExpression && ((JetUnaryExpression) parent).getOperationReference() == expression) {
|
|
||||||
return ((JetUnaryExpression) parent).getBaseExpression();
|
|
||||||
}
|
|
||||||
return expression.getReceiverExpression();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private Set<FqName> extensionFunctionsFromSourceFqNames(
|
private Set<FqName> extensionFunctionsFromSourceFqNames(
|
||||||
@NotNull Condition<String> acceptedNameCondition,
|
@NotNull Condition<String> acceptedNameCondition,
|
||||||
|
|||||||
@@ -20,16 +20,14 @@ import com.google.common.base.Predicate;
|
|||||||
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.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
import org.jetbrains.jet.lang.descriptors.PackageViewDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetPackageDirective;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastUtils;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||||
@@ -54,7 +52,9 @@ public final class TipsManager {
|
|||||||
@NotNull BindingContext context
|
@NotNull BindingContext context
|
||||||
) {
|
) {
|
||||||
JetExpression receiverExpression = expression.getReceiverExpression();
|
JetExpression receiverExpression = expression.getReceiverExpression();
|
||||||
if (receiverExpression != null) {
|
PsiElement parent = expression.getParent();
|
||||||
|
boolean inPositionForCompletionWithReceiver = parent instanceof JetCallExpression || parent instanceof JetQualifiedExpression;
|
||||||
|
if (receiverExpression != null && inPositionForCompletionWithReceiver) {
|
||||||
// Process as call expression
|
// Process as call expression
|
||||||
JetScope resolutionScope = context.get(BindingContext.RESOLUTION_SCOPE, expression);
|
JetScope resolutionScope = context.get(BindingContext.RESOLUTION_SCOPE, expression);
|
||||||
JetType expressionType = context.get(BindingContext.EXPRESSION_TYPE, receiverExpression);
|
JetType expressionType = context.get(BindingContext.EXPRESSION_TYPE, receiverExpression);
|
||||||
|
|||||||
Reference in New Issue
Block a user