diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetSimpleNameExpression.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetSimpleNameExpression.java index 238736e3d9c..0a9c3bf3671 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetSimpleNameExpression.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetSimpleNameExpression.java @@ -24,6 +24,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.lang.parsing.JetExpressionParsing; import org.jetbrains.jet.lang.resolve.name.Name; +import org.jetbrains.jet.lang.types.expressions.OperatorConventions; import org.jetbrains.jet.lexer.JetTokens; import static org.jetbrains.jet.lexer.JetTokens.*; @@ -58,7 +59,11 @@ public class JetSimpleNameExpression extends JetReferenceExpression { } } else if (parent instanceof JetBinaryExpression && ((JetBinaryExpression) parent).getOperationReference() == this) { - return ((JetBinaryExpression) parent).getLeft(); + JetBinaryExpression expr = (JetBinaryExpression) parent; + //noinspection SuspiciousMethodCalls + return OperatorConventions.IN_OPERATIONS.contains(expr.getOperationToken()) + ? expr.getRight() + : expr.getLeft(); } else if (parent instanceof JetUnaryExpression && ((JetUnaryExpression) parent).getOperationReference() == this) { return ((JetUnaryExpression) parent).getBaseExpression(); diff --git a/compiler/tests/org/jetbrains/jet/lang/psi/JetSimpleNameExpressionTest.kt b/compiler/tests/org/jetbrains/jet/lang/psi/JetSimpleNameExpressionTest.kt new file mode 100644 index 00000000000..f3261b3a260 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/lang/psi/JetSimpleNameExpressionTest.kt @@ -0,0 +1,39 @@ +/* + * Copyright 2010-2014 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.junit.Assert +import org.jetbrains.jet.JetLiteFixture +import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment +import org.jetbrains.jet.config.CompilerConfiguration + +public class JetSimpleNameExpressionTest() : JetLiteFixture() { + public fun testGetReceiverExpressionIdentifier() { + // Binary Expressions + assertReceiver("1 + 2", "1") + assertReceiver("1 in array(1)", "array(1)") + assertReceiver("1 !in array(1)", "array(1)") + assertReceiver("1 to 2", "1") + } + private fun assertReceiver(exprString: String, expected: String) { + val expression = JetPsiFactory.createExpression(getProject(), exprString) as JetBinaryExpression + Assert.assertEquals(expected, expression.getOperationReference().getReceiverExpression()!!.getText()) + } + override fun createEnvironment(): JetCoreEnvironment { + return JetCoreEnvironment.createForTests(getTestRootDisposable()!!, CompilerConfiguration()) + } +}