From 5003da67f658d4a0f7b04f90d6b7753c916f91ac Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Thu, 7 Jun 2012 17:05:51 +0400 Subject: [PATCH] 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 --- .../src/org/jetbrains/jet/lang/psi/Call.java | 7 +++ .../org/jetbrains/jet/lang/psi/CallKey.java | 60 +++++++++++++++++++ .../jet/lang/resolve/calls/CallMaker.java | 45 ++++++++++++-- .../lang/resolve/calls/DelegatingCall.java | 6 ++ .../BasicExpressionTypingVisitor.java | 4 +- 5 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/jet/lang/psi/CallKey.java diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/Call.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/Call.java index d3c46683dbb..bf57fc1d0ec 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/Call.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/Call.java @@ -59,4 +59,11 @@ public interface Call { @NotNull PsiElement getCallElement(); + + enum CallType { + DEFAULT, ARRAY_GET_METHOD, ARRAY_SET_METHOD + } + + @NotNull + Call.CallType getCallType(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/CallKey.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/CallKey.java new file mode 100644 index 00000000000..61e4b7ecd47 --- /dev/null +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/CallKey.java @@ -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; + } +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallMaker.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallMaker.java index 98e42503e85..ed2af126de9 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallMaker.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallMaker.java @@ -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 valueArguments; + private final Call.CallType callType; protected CallImpl(@Nullable PsiElement callElement, @NotNull ReceiverDescriptor explicitReceiver, @Nullable ASTNode callOperationNode, @NotNull JetExpression calleeExpression, @NotNull List 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 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 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 argumentExpressions, @NotNull CallType callType) { List 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 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 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.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 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; + } }; } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/DelegatingCall.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/DelegatingCall.java index 9c82f0829d8..0f310da9966 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/DelegatingCall.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/DelegatingCall.java @@ -95,4 +95,10 @@ public class DelegatingCall implements Call { public PsiElement getCallElement() { return delegate.getCallElement(); } + + @NotNull + @Override + public CallType getCallType() { + return delegate.getCallType(); + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index 37dafad2743..61b97cf14f1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -1178,8 +1178,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { if (!isGet) assert rightHandSide != null; OverloadResolutionResults 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()) {