Fix JetSimpleNameExpression.getReceiverExpression
The receiver of `in` expressions is on the right, not the left.
This commit is contained in:
committed by
Nikolay Krasko
parent
4f1061c337
commit
1a04b887a4
@@ -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();
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user