added CallType
callElement in not unique for the call, for example: for 'set' and 'get' array methods resolve the same callElement is used, so callType with callElement is the unique key
This commit is contained in:
@@ -59,4 +59,11 @@ public interface Call {
|
||||
|
||||
@NotNull
|
||||
PsiElement getCallElement();
|
||||
|
||||
enum CallType {
|
||||
DEFAULT, ARRAY_GET_METHOD, ARRAY_SET_METHOD
|
||||
}
|
||||
|
||||
@NotNull
|
||||
Call.CallType getCallType();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import org.jetbrains.jet.lang.psi.Call.CallType;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
public class CallKey {
|
||||
private final CallType callType;
|
||||
private final JetExpression element;
|
||||
|
||||
public CallKey(CallType callType, JetExpression element) {
|
||||
this.callType = callType;
|
||||
this.element = element;
|
||||
}
|
||||
|
||||
public static CallKey create(CallType callType, JetExpression element) {
|
||||
return new CallKey(callType, element);
|
||||
}
|
||||
|
||||
public static CallKey create(JetExpression element) {
|
||||
return new CallKey(CallType.DEFAULT, element);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof CallKey)) return false;
|
||||
|
||||
CallKey key = (CallKey) o;
|
||||
|
||||
if (callType != key.callType) return false;
|
||||
if (element != null ? !element.equals(key.element) : key.element != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = callType != null ? callType.hashCode() : 0;
|
||||
result = 31 * result + (element != null ? element.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.Call.CallType;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -78,13 +79,20 @@ public class CallMaker {
|
||||
private ASTNode callOperationNode;
|
||||
private final JetExpression calleeExpression;
|
||||
private final List<? extends ValueArgument> valueArguments;
|
||||
private final Call.CallType callType;
|
||||
|
||||
protected CallImpl(@Nullable PsiElement callElement, @NotNull ReceiverDescriptor explicitReceiver, @Nullable ASTNode callOperationNode, @NotNull JetExpression calleeExpression, @NotNull List<? extends ValueArgument> valueArguments) {
|
||||
this(callElement, explicitReceiver, callOperationNode, calleeExpression, valueArguments, CallType.DEFAULT);
|
||||
}
|
||||
|
||||
protected CallImpl(@Nullable PsiElement callElement, @NotNull ReceiverDescriptor explicitReceiver, @Nullable ASTNode callOperationNode,
|
||||
@NotNull JetExpression calleeExpression, @NotNull List<? extends ValueArgument> valueArguments, @NotNull CallType callType) {
|
||||
this.callElement = callElement;
|
||||
this.explicitReceiver = explicitReceiver;
|
||||
this.callOperationNode = callOperationNode;
|
||||
this.calleeExpression = calleeExpression;
|
||||
this.valueArguments = valueArguments;
|
||||
this.callType = callType;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,20 +154,37 @@ public class CallMaker {
|
||||
public String toString() {
|
||||
return getCallElement().getText();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CallType getCallType() {
|
||||
return callType;
|
||||
}
|
||||
}
|
||||
|
||||
public static Call makeCallWithExpressions(@NotNull JetElement callElement, @NotNull ReceiverDescriptor explicitReceiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull JetExpression calleeExpression,
|
||||
@NotNull List<JetExpression> argumentExpressions) {
|
||||
return makeCallWithExpressions(callElement, explicitReceiver, callOperationNode, calleeExpression, argumentExpressions, CallType.DEFAULT);
|
||||
}
|
||||
|
||||
public static Call makeCallWithExpressions(@NotNull JetElement callElement, @NotNull ReceiverDescriptor explicitReceiver,
|
||||
@Nullable ASTNode callOperationNode, @NotNull JetExpression calleeExpression,
|
||||
@NotNull List<JetExpression> argumentExpressions, @NotNull CallType callType) {
|
||||
List<ValueArgument> arguments = Lists.newArrayList();
|
||||
for (JetExpression argumentExpression : argumentExpressions) {
|
||||
arguments.add(makeValueArgument(argumentExpression, calleeExpression));
|
||||
}
|
||||
return makeCall(callElement, explicitReceiver, callOperationNode, calleeExpression, arguments);
|
||||
return makeCall(callElement, explicitReceiver, callOperationNode, calleeExpression, arguments, callType);
|
||||
}
|
||||
|
||||
public static Call makeCall(JetElement callElement, ReceiverDescriptor explicitReceiver, @Nullable ASTNode callOperationNode, JetExpression calleeExpression, List<? extends ValueArgument> arguments) {
|
||||
return new CallImpl(callElement, explicitReceiver, callOperationNode, calleeExpression, arguments);
|
||||
return makeCall(callElement, explicitReceiver, callOperationNode, calleeExpression, arguments, CallType.DEFAULT);
|
||||
}
|
||||
|
||||
public static Call makeCall(JetElement callElement, ReceiverDescriptor explicitReceiver, @Nullable ASTNode callOperationNode,
|
||||
JetExpression calleeExpression, List<? extends ValueArgument> arguments, CallType callType) {
|
||||
return new CallImpl(callElement, explicitReceiver, callOperationNode, calleeExpression, arguments, callType);
|
||||
}
|
||||
|
||||
public static Call makeCall(@NotNull ReceiverDescriptor leftAsReceiver, JetBinaryExpression expression) {
|
||||
@@ -170,14 +195,16 @@ public class CallMaker {
|
||||
return makeCall(expression, baseAsReceiver, null, expression.getOperationReference(), Collections.<ValueArgument>emptyList());
|
||||
}
|
||||
|
||||
public static Call makeArraySetCall(@NotNull ReceiverDescriptor arrayAsReceiver, @NotNull JetArrayAccessExpression arrayAccessExpression, @NotNull JetExpression rightHandSide) {
|
||||
public static Call makeArraySetCall(@NotNull ReceiverDescriptor arrayAsReceiver, @NotNull JetArrayAccessExpression arrayAccessExpression,
|
||||
@NotNull JetExpression rightHandSide, @NotNull CallType callType) {
|
||||
List<JetExpression> arguments = Lists.newArrayList(arrayAccessExpression.getIndexExpressions());
|
||||
arguments.add(rightHandSide);
|
||||
return makeCallWithExpressions(arrayAccessExpression, arrayAsReceiver, null, arrayAccessExpression, arguments);
|
||||
return makeCallWithExpressions(arrayAccessExpression, arrayAsReceiver, null, arrayAccessExpression, arguments, callType);
|
||||
}
|
||||
|
||||
public static Call makeArrayGetCall(@NotNull ReceiverDescriptor arrayAsReceiver, @NotNull JetArrayAccessExpression arrayAccessExpression) {
|
||||
return makeCallWithExpressions(arrayAccessExpression, arrayAsReceiver, null, arrayAccessExpression, arrayAccessExpression.getIndexExpressions());
|
||||
public static Call makeArrayGetCall(@NotNull ReceiverDescriptor arrayAsReceiver, @NotNull JetArrayAccessExpression arrayAccessExpression,
|
||||
@NotNull CallType callType) {
|
||||
return makeCallWithExpressions(arrayAccessExpression, arrayAsReceiver, null, arrayAccessExpression, arrayAccessExpression.getIndexExpressions(), callType);
|
||||
}
|
||||
|
||||
public static ValueArgument makeValueArgument(@NotNull JetExpression expression) {
|
||||
@@ -251,6 +278,12 @@ public class CallMaker {
|
||||
public String toString() {
|
||||
return callElement.getText();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CallType getCallType() {
|
||||
return CallType.DEFAULT;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,4 +95,10 @@ public class DelegatingCall implements Call {
|
||||
public PsiElement getCallElement() {
|
||||
return delegate.getCallElement();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CallType getCallType() {
|
||||
return delegate.getCallType();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -1178,8 +1178,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (!isGet) assert rightHandSide != null;
|
||||
OverloadResolutionResults<FunctionDescriptor> functionResults = context.resolveCallWithGivenName(
|
||||
isGet
|
||||
? CallMaker.makeArrayGetCall(receiver, arrayAccessExpression)
|
||||
: CallMaker.makeArraySetCall(receiver, arrayAccessExpression, rightHandSide),
|
||||
? CallMaker.makeArrayGetCall(receiver, arrayAccessExpression, Call.CallType.ARRAY_GET_METHOD)
|
||||
: CallMaker.makeArraySetCall(receiver, arrayAccessExpression, rightHandSide, Call.CallType.ARRAY_SET_METHOD),
|
||||
arrayAccessExpression,
|
||||
Name.identifier(isGet ? "get" : "set"));
|
||||
if (!functionResults.isSuccess()) {
|
||||
|
||||
Reference in New Issue
Block a user