Replace assert with lazy assert, times with repeat.

This commit is contained in:
Ilya Gorbunov
2015-10-01 20:13:34 +03:00
parent c1ba30b4bc
commit 3106458cc4
50 changed files with 79 additions and 87 deletions
@@ -73,7 +73,7 @@ public abstract class MultipleModulesTranslationTest(main: String) : BasicTest(m
override fun additionalJsFiles(ecmaVersion: EcmaVersion): List<String> {
val result = super.additionalJsFiles(ecmaVersion)
val dirName = getTestName(true)
assert(dependencies != null, "dependencies should not be null")
assert(dependencies != null) { "dependencies should not be null" }
for (moduleName in dependencies!!.keySet()) {
if (moduleName != MAIN_MODULE_NAME) {
@@ -86,7 +86,7 @@ public abstract class MultipleModulesTranslationTest(main: String) : BasicTest(m
private fun readModuleDependencies(testDataDir: String): Map<String, List<String>> {
val dependenciesTxt = upsearchFile(testDataDir, "dependencies.txt")
assert(dependenciesTxt.isFile(), "moduleDependencies should not be null")
assert(dependenciesTxt.isFile()) { "moduleDependencies should not be null" }
val result = LinkedHashMap<String, List<String>>()
for (line in dependenciesTxt.readLines()) {
@@ -100,7 +100,7 @@ fun TranslationContext.getCallInfo(resolvedCall: ResolvedCall<out FunctionDescri
}
private fun TranslationContext.getDispatchReceiver(receiverValue: ReceiverValue): JsExpression {
assert(receiverValue.exists(), "receiverValue must be exist here")
assert(receiverValue.exists()) { "receiverValue must be exist here" }
return getDispatchReceiver(getReceiverParameterForReceiver(receiverValue))
}
@@ -86,7 +86,7 @@ private fun translateCall(context: TranslationContext,
explicitReceivers: ExplicitReceivers
): JsExpression {
if (resolvedCall is VariableAsFunctionResolvedCall) {
assert(explicitReceivers.extensionReceiver == null, "VariableAsFunctionResolvedCall must have one receiver")
assert(explicitReceivers.extensionReceiver == null) { "VariableAsFunctionResolvedCall must have one receiver" }
val variableCall = resolvedCall.variableCall
if (variableCall.expectedReceivers()) {
val newReceiver = CallTranslator.translateGet(context, variableCall, explicitReceivers.extensionOrDispatchReceiver)
@@ -137,7 +137,7 @@ public class DelegationTranslator(
val jsFunction = JsFunction(context().getScopeForDescriptor(setterDescriptor.getContainingDeclaration()),
"setter for " + setterDescriptor.getName().asString())
assert(setterDescriptor.getValueParameters().size() == 1, "Setter must have 1 parameter")
assert(setterDescriptor.getValueParameters().size() == 1) { "Setter must have 1 parameter" }
val defaultParameter = JsParameter(jsFunction.getScope().declareTemporary())
val defaultParameterRef = defaultParameter.getName().makeRef()
@@ -119,7 +119,7 @@ private class PropertyTranslator(
return generateDelegatedGetterFunction(getterDescriptor, delegatedCall)
}
assert(!descriptor.isExtension, "Unexpected extension property $descriptor}")
assert(!descriptor.isExtension) { "Unexpected extension property $descriptor}" }
val scope = context().getScopeForDescriptor(getterDescriptor.getContainingDeclaration())
val result = backingFieldReference(context(), descriptor)
val body = JsBlock(JsReturn(result))
@@ -157,7 +157,7 @@ private class PropertyTranslator(
val containingScope = context().getScopeForDescriptor(setterDescriptor.getContainingDeclaration())
val function = JsFunction(containingScope, JsBlock(), accessorDescription(setterDescriptor))
assert(setterDescriptor.getValueParameters().size() == 1, "Setter must have 1 parameter")
assert(setterDescriptor.getValueParameters().size() == 1) { "Setter must have 1 parameter" }
val correspondingPropertyName = setterDescriptor.getCorrespondingProperty().getName().asString()
val valueParameter = function.addParameter(correspondingPropertyName).getName()
val withAliased = context().innerContextWithAliased(setterDescriptor.getValueParameters().get(0), valueParameter.makeRef())
@@ -172,7 +172,7 @@ private class PropertyTranslator(
(delegatedJsCall as JsInvocation).getArguments().set(0, receiver.makeRef())
}
} else {
assert(!descriptor.isExtension, "Unexpected extension property $descriptor}")
assert(!descriptor.isExtension) { "Unexpected extension property $descriptor}" }
val assignment = assignmentToBackingField(withAliased, descriptor, valueParameter.makeRef())
function.addStatement(assignment.makeStmt())
}
@@ -143,8 +143,8 @@ public class CallArgumentTranslator private constructor(
}
if (isNativeFunctionCall && hasSpreadOperator) {
assert(argsBeforeVararg != null, "argsBeforeVararg should not be null")
assert(concatArguments != null, "concatArguments should not be null")
assert(argsBeforeVararg != null) { "argsBeforeVararg should not be null" }
assert(concatArguments != null) { "concatArguments should not be null" }
concatArguments!!.addAll(result)
@@ -269,7 +269,7 @@ public class CallArgumentTranslator private constructor(
}
private fun concatArgumentsIfNeeded(concatArguments: List<JsExpression>): JsExpression {
assert(concatArguments.size() > 0, "concatArguments.size should not be 0")
assert(concatArguments.size() > 0) { "concatArguments.size should not be 0" }
if (concatArguments.size() > 1) {
return JsInvocation(JsNameRef("concat", concatArguments.get(0)), concatArguments.subList(1, concatArguments.size()))
@@ -281,7 +281,7 @@ public class CallArgumentTranslator private constructor(
}
private fun prepareConcatArguments(arguments: List<ValueArgument>, list: List<JsExpression>): MutableList<JsExpression> {
assert(arguments.size() != 0, "arguments.size should not be 0")
assert(arguments.size() != 0) { "arguments.size should not be 0" }
assert(arguments.size() == list.size()) { "arguments.size: " + arguments.size() + " != list.size: " + list.size() }
val concatArguments = SmartList<JsExpression>()
@@ -127,7 +127,7 @@ object CallableReferenceTranslator {
private fun translateForExtensionFunction(descriptor: FunctionDescriptor, context: TranslationContext): JsExpression {
val receiverParameterDescriptor = descriptor.getExtensionReceiverParameter()
assert(receiverParameterDescriptor != null, "receiverParameter for extension should not be null")
assert(receiverParameterDescriptor != null) { "receiverParameter for extension should not be null" }
val jsFunctionRef = ReferenceTranslator.translateAsFQReference(descriptor, context)
if (descriptor.getVisibility() == Visibilities.LOCAL) {