KT-962: Function is called two times

safecall expression now compute receiver only once.
This commit is contained in:
Pavel Talanov
2012-01-17 17:37:40 +04:00
parent b89cb4a9df
commit 0d89e5d01f
9 changed files with 101 additions and 44 deletions
@@ -309,6 +309,28 @@ public class AstUtil {
throw new AssertionError("Set qualifier should be applied only to JsInvocation or JsNameRef instances");
}
public static JsExpression getQualifier(JsExpression expression) {
if (expression instanceof JsInvocation) {
return ((JsInvocation) expression).getQualifier();
}
if (expression instanceof JsNameRef) {
return ((JsNameRef) expression).getQualifier();
}
throw new AssertionError("Get qualifier should be applied only to JsInvocation or JsNameRef instances");
}
public static void substituteTopLevelQualifier(JsExpression expression, JsExpression substitutor) {
assert expression != null;
JsExpression previous = expression;
JsExpression current = getQualifier(expression);
assert current != null : "Cannot be applied to unqualified expression";
while (getQualifier(current) != null) {
previous = current;
current = getQualifier(current);
}
setQualifier(previous, substitutor);
}
//TODO: look for should-be-usages
public static JsNameRef qualified(JsName selector, JsExpression qualifier) {
JsNameRef reference = selector.makeRef();