added more descriptive assertion failure

This commit is contained in:
James Strachan
2012-07-16 13:47:44 +01:00
parent fee8c42885
commit a3d30409d3
@@ -17,11 +17,13 @@
package org.jetbrains.k2js.translate.intrinsic;
import com.google.common.collect.Lists;
import com.google.dart.compiler.Source;
import com.google.dart.compiler.backend.js.ast.JsExpression;
import com.google.dart.compiler.backend.js.ast.JsNameRef;
import com.google.dart.compiler.util.AstUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
import org.jetbrains.k2js.translate.context.TranslationContext;
import java.util.List;
@@ -51,11 +53,24 @@ public final class CallStandardMethodIntrinsic implements Intrinsic {
@NotNull List<JsExpression> arguments,
@NotNull TranslationContext context) {
assert (receiver != null == receiverShouldBeNotNull);
assert arguments.size() == expectedParamsNumber;
assert arguments.size() == expectedParamsNumber : "Incorrect number of arguments " + arguments.size() + " when expected " + expectedParamsNumber + " on method " + methodName + " " + atLocation(receiver, arguments);
JsNameRef iteratorFunName = AstUtil.newQualifiedNameRef(methodName);
return newInvocation(iteratorFunName, composeArguments(receiver, arguments));
}
// TODO move to better helper class
public static String atLocation(JsExpression expression, List<JsExpression> arguments) {
List list = Lists.newArrayList(expression);
list.addAll(arguments);
for (JsExpression value : arguments) {
Source source = value.getSource();
if (source != null) {
return "at " + source + " " + expression.getSourceLine() + ":" + expression.getSourceLine();
}
}
return "at unknown location";
}
@NotNull
private static List<JsExpression> composeArguments(@Nullable JsExpression receiver, @NotNull List<JsExpression> arguments) {
if (receiver != null) {