[KT-10614] Fix passing of inline.kt test
This commit is contained in:
@@ -19,23 +19,31 @@ package org.jetbrains.kotlin.js.test.utils;
|
||||
import com.google.dart.compiler.backend.js.ast.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
public class CallCounter extends RecursiveJsVisitor {
|
||||
|
||||
private final List<JsNameRef> callsNameRefs = new ArrayList<JsNameRef>();
|
||||
|
||||
@NotNull
|
||||
private final Set<String> exceptFunctionNames;
|
||||
|
||||
@NotNull
|
||||
public static CallCounter countCalls(@NotNull JsNode node) {
|
||||
CallCounter visitor = new CallCounter();
|
||||
return countCalls(node, Collections.<String>emptySet());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static CallCounter countCalls(@NotNull JsNode node, @NotNull Set<String> exceptFunctionNames) {
|
||||
CallCounter visitor = new CallCounter(new HashSet<String>(exceptFunctionNames));
|
||||
node.accept(visitor);
|
||||
|
||||
return visitor;
|
||||
}
|
||||
|
||||
CallCounter() {}
|
||||
CallCounter(@NotNull Set<String> exceptFunctionNames) {
|
||||
this.exceptFunctionNames = exceptFunctionNames;
|
||||
}
|
||||
|
||||
public int getTotalCallsCount() {
|
||||
return callsNameRefs.size();
|
||||
@@ -61,7 +69,10 @@ public class CallCounter extends RecursiveJsVisitor {
|
||||
JsExpression qualifier = invocation.getQualifier();
|
||||
|
||||
if (qualifier instanceof JsNameRef) {
|
||||
callsNameRefs.add((JsNameRef) qualifier);
|
||||
JsNameRef nameRef = (JsNameRef) qualifier;
|
||||
if (!exceptFunctionNames.contains(nameRef.getIdent())) {
|
||||
callsNameRefs.add(nameRef);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,15 @@ public class DirectiveTestUtils {
|
||||
private static final DirectiveHandler FUNCTION_CONTAINS_NO_CALLS = new DirectiveHandler("CHECK_CONTAINS_NO_CALLS") {
|
||||
@Override
|
||||
void processEntry(@NotNull JsNode ast, @NotNull ArgumentsHelper arguments) throws Exception {
|
||||
checkFunctionContainsNoCalls(ast, arguments.getFirst());
|
||||
Set<String> exceptNames = new HashSet<String>();
|
||||
String exceptNamesArg = arguments.findNamedArgument("except");
|
||||
if (exceptNamesArg != null) {
|
||||
for (String exceptName : exceptNamesArg.split(";")) {
|
||||
exceptNames.add(exceptName.trim());
|
||||
}
|
||||
}
|
||||
|
||||
checkFunctionContainsNoCalls(ast, arguments.getFirst(), exceptNames);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -179,9 +187,10 @@ public class DirectiveTestUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static void checkFunctionContainsNoCalls(JsNode node, String functionName) throws Exception {
|
||||
public static void checkFunctionContainsNoCalls(JsNode node, String functionName, @NotNull Set<String> exceptFunctionNames)
|
||||
throws Exception {
|
||||
JsFunction function = AstSearchUtil.getFunction(node, functionName);
|
||||
CallCounter counter = CallCounter.countCalls(function);
|
||||
CallCounter counter = CallCounter.countCalls(function, exceptFunctionNames);
|
||||
int callsCount = counter.getTotalCallsCount();
|
||||
|
||||
String errorMessage = functionName + " contains calls";
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ package foo
|
||||
|
||||
// CHECK_CONTAINS_NO_CALLS: test1
|
||||
// CHECK_CONTAINS_NO_CALLS: test2
|
||||
// CHECK_CONTAINS_NO_CALLS: test3
|
||||
// CHECK_CONTAINS_NO_CALLS: test3 except=slice
|
||||
|
||||
internal inline fun concat(vararg strings: String): String {
|
||||
var result = ""
|
||||
|
||||
Reference in New Issue
Block a user