Move error reporting util from CallStandardMethodIntrinsic to ErrorReportingUtils.
This commit is contained in:
+6
-14
@@ -17,17 +17,16 @@
|
||||
package org.jetbrains.k2js.translate.intrinsic.functions.basic;
|
||||
|
||||
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;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.ErrorReportingUtils.atLocation;
|
||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.newInvocation;
|
||||
|
||||
/**
|
||||
@@ -53,22 +52,15 @@ public final class CallStandardMethodIntrinsic extends FunctionIntrinsic {
|
||||
@NotNull List<JsExpression> arguments,
|
||||
@NotNull TranslationContext context) {
|
||||
assert (receiver != null == receiverShouldBeNotNull);
|
||||
assert arguments.size() == expectedParamsNumber : "Incorrect number of arguments " + arguments.size() + " when expected " + expectedParamsNumber + " on method " + methodName + " " + atLocation(receiver, arguments);
|
||||
assert arguments.size() == expectedParamsNumber : errorMessage(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 String errorMessage(@Nullable JsExpression receiver, @NotNull List<JsExpression> arguments) {
|
||||
return "Incorrect number of arguments " + arguments.size() + " when expected " + expectedParamsNumber + " on method " + methodName + " " +
|
||||
atLocation(receiver, arguments);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -16,13 +16,19 @@
|
||||
|
||||
package org.jetbrains.k2js.translate.utils;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.dart.compiler.Source;
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
@@ -63,4 +69,17 @@ public final class ErrorReportingUtils {
|
||||
@NotNull BindingContext bindingContext) {
|
||||
throw reportErrorWithLocation(e, DiagnosticUtils.atLocation(bindingContext, descriptor));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String atLocation(@Nullable JsExpression expression, @NotNull List<JsExpression> arguments) {
|
||||
List<JsExpression> list = Lists.newArrayList(expression);
|
||||
list.addAll(arguments);
|
||||
for (JsExpression value : arguments) {
|
||||
Source source = value.getSource();
|
||||
if (source != null) {
|
||||
return "at " + source + " " + value.getSourceLine() + ":" + value.getSourceColumn();
|
||||
}
|
||||
}
|
||||
return "at unknown location";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user