Replace assert with lazy assert, times with repeat.
This commit is contained in:
+3
-3
@@ -63,7 +63,7 @@ public abstract class CoveringTryCatchNodeProcessor(parameterSize: Int) {
|
||||
if (result == 0) {
|
||||
result = instructionIndex(t1.startLabel) - instructionIndex(t2.startLabel)
|
||||
if (result == 0) {
|
||||
assert(false, "Error: support multicatch finallies: ${t1.handler}, ${t2.handler}")
|
||||
assert(false) { "Error: support multicatch finallies: ${t1.handler}, ${t2.handler}" }
|
||||
result = instructionIndex(t1.endLabel) - instructionIndex(t2.endLabel)
|
||||
}
|
||||
}
|
||||
@@ -131,12 +131,12 @@ class IntervalMetaInfo<T : SplittableInterval<T>> {
|
||||
fun processCurrent(curIns: LabelNode, directOrder: Boolean) {
|
||||
getInterval(curIns, directOrder).forEach {
|
||||
val added = currentIntervals.add(it)
|
||||
assert(added, "Wrong interval structure: $curIns, $it")
|
||||
assert(added) { "Wrong interval structure: $curIns, $it" }
|
||||
}
|
||||
|
||||
getInterval(curIns, !directOrder).forEach {
|
||||
val removed = currentIntervals.remove(it)
|
||||
assert(removed, "Wrong interval structure: $curIns, $it")
|
||||
assert(removed) { "Wrong interval structure: $curIns, $it" }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ public open class DefaultSourceMapper(val sourceInfo: SourceInfo, override val p
|
||||
/*Source Mapping*/
|
||||
class SMAP(val fileMappings: List<FileMapping>) {
|
||||
init {
|
||||
assert(fileMappings.isNotEmpty(), "File Mappings shouldn't be empty")
|
||||
assert(fileMappings.isNotEmpty()) { "File Mappings shouldn't be empty" }
|
||||
}
|
||||
|
||||
val default: FileMapping
|
||||
@@ -275,7 +275,7 @@ class RawFileMapping(val name: String, val path: String) {
|
||||
}
|
||||
|
||||
fun initRange(start: Int, end: Int) {
|
||||
assert(lineMappings.isEmpty(), "initRange should only be called for empty mapping")
|
||||
assert(lineMappings.isEmpty()) { "initRange should only be called for empty mapping" }
|
||||
for (index in start..end) {
|
||||
lineMappings.put(index, index)
|
||||
}
|
||||
|
||||
+3
-6
@@ -77,8 +77,7 @@ private fun insertSaveRestoreStackMarkers(
|
||||
doneTryStartLabels.add(tryStartLabel)
|
||||
|
||||
val nopNode = tryStartLabel.findNextOrNull { it.hasOpcode() }!!
|
||||
assert(nopNode.getOpcode() == Opcodes.NOP,
|
||||
"${methodNode.instructions.indexOf(nopNode)}: try block should start with NOP")
|
||||
assert(nopNode.getOpcode() == Opcodes.NOP) { "${methodNode.instructions.indexOf(nopNode)}: try block should start with NOP" }
|
||||
|
||||
val newTryStartLabel = LabelNode(Label())
|
||||
newTryStartLabels[tryStartLabel] = newTryStartLabel
|
||||
@@ -93,8 +92,7 @@ private fun insertSaveRestoreStackMarkers(
|
||||
doneHandlerLabels.add(handlerStartLabel)
|
||||
|
||||
val storeNode = handlerStartLabel.findNextOrNull { it.hasOpcode() }!!
|
||||
assert(storeNode.getOpcode() == Opcodes.ASTORE,
|
||||
"${methodNode.instructions.indexOf(storeNode)}: handler should start with ASTORE")
|
||||
assert(storeNode.getOpcode() == Opcodes.ASTORE) { "${methodNode.instructions.indexOf(storeNode)}: handler should start with ASTORE" }
|
||||
|
||||
methodNode.instructions.insert(storeNode, PseudoInsn.RESTORE_STACK_IN_TRY_CATCH.createInsnNode())
|
||||
}
|
||||
@@ -110,8 +108,7 @@ private fun collectDecompiledTryDescriptors(
|
||||
) {
|
||||
for (tcb in methodNode.tryCatchBlocks) {
|
||||
if (tcb.isDefaultHandlerNode()) {
|
||||
assert(decompiledTryDescriptorForHandler.containsKey(tcb.start),
|
||||
"${methodNode.debugString(tcb)}: default handler should occur after some regular handler")
|
||||
assert(decompiledTryDescriptorForHandler.containsKey(tcb.start)) { "${methodNode.debugString(tcb)}: default handler should occur after some regular handler" }
|
||||
}
|
||||
|
||||
val decompiledTryDescriptor = decompiledTryDescriptorForHandler.getOrPut(tcb.handler) {
|
||||
|
||||
+5
-5
@@ -65,7 +65,7 @@ internal class FixStackContext(val methodNode: MethodNode) {
|
||||
inlineMarkersStack.push(insnNode)
|
||||
}
|
||||
InlineCodegenUtil.isAfterInlineMarker(insnNode) -> {
|
||||
assert(inlineMarkersStack.isNotEmpty(), "Mismatching after inline method marker at ${indexOf(insnNode)}")
|
||||
assert(inlineMarkersStack.isNotEmpty()) { "Mismatching after inline method marker at ${indexOf(insnNode)}" }
|
||||
openingInlineMethodMarker[insnNode] = inlineMarkersStack.pop()
|
||||
}
|
||||
}
|
||||
@@ -78,23 +78,23 @@ internal class FixStackContext(val methodNode: MethodNode) {
|
||||
|
||||
private fun visitFixStackBeforeJump(insnNode: AbstractInsnNode) {
|
||||
val next = insnNode.getNext()
|
||||
assert(next.getOpcode() == Opcodes.GOTO, "${indexOf(insnNode)}: should be followed by GOTO")
|
||||
assert(next.getOpcode() == Opcodes.GOTO) { "${indexOf(insnNode)}: should be followed by GOTO" }
|
||||
breakContinueGotoNodes.add(next as JumpInsnNode)
|
||||
}
|
||||
|
||||
private fun visitFakeAlwaysTrueIfeq(insnNode: AbstractInsnNode) {
|
||||
assert(insnNode.getNext().getOpcode() == Opcodes.IFEQ, "${indexOf(insnNode)}: should be followed by IFEQ")
|
||||
assert(insnNode.getNext().getOpcode() == Opcodes.IFEQ) { "${indexOf(insnNode)}: should be followed by IFEQ" }
|
||||
fakeAlwaysTrueIfeqMarkers.add(insnNode)
|
||||
}
|
||||
|
||||
private fun visitFakeAlwaysFalseIfeq(insnNode: AbstractInsnNode) {
|
||||
assert(insnNode.getNext().getOpcode() == Opcodes.IFEQ, "${indexOf(insnNode)}: should be followed by IFEQ")
|
||||
assert(insnNode.getNext().getOpcode() == Opcodes.IFEQ) { "${indexOf(insnNode)}: should be followed by IFEQ" }
|
||||
fakeAlwaysFalseIfeqMarkers.add(insnNode)
|
||||
}
|
||||
|
||||
private fun visitSaveStackBeforeTry(insnNode: AbstractInsnNode) {
|
||||
val tryStartLabel = insnNode.getNext()
|
||||
assert(tryStartLabel is LabelNode, "${indexOf(insnNode)}: save should be followed by a label")
|
||||
assert(tryStartLabel is LabelNode) { "${indexOf(insnNode)}: save should be followed by a label" }
|
||||
saveStackNodesForTryStartLabel[tryStartLabel as LabelNode] = insnNode
|
||||
}
|
||||
|
||||
|
||||
+2
-3
@@ -77,8 +77,7 @@ public class FixStackMethodTransformer : MethodTransformer() {
|
||||
val expectedStackSize = analyzer.frames[labelIndex]?.getStackSize() ?: DEAD_CODE
|
||||
|
||||
if (actualStackSize != DEAD_CODE && expectedStackSize != DEAD_CODE) {
|
||||
assert(expectedStackSize <= actualStackSize,
|
||||
"Label at $labelIndex, jump at $gotoIndex: stack underflow: $expectedStackSize > $actualStackSize")
|
||||
assert(expectedStackSize <= actualStackSize) { "Label at $labelIndex, jump at $gotoIndex: stack underflow: $expectedStackSize > $actualStackSize" }
|
||||
val frame = analyzer.frames[gotoIndex]!!
|
||||
actions.add({ replaceMarkerWithPops(methodNode, gotoNode.getPrevious(), expectedStackSize, frame) })
|
||||
}
|
||||
@@ -154,7 +153,7 @@ public class FixStackMethodTransformer : MethodTransformer() {
|
||||
val savedStackDescriptor = localVariablesManager.getBeforeInlineDescriptor(inlineMarker)
|
||||
val afterInlineFrame = analyzer.getFrame(inlineMarker) as FixStackAnalyzer.FixStackFrame?
|
||||
if (afterInlineFrame != null && savedStackDescriptor.isNotEmpty()) {
|
||||
assert(afterInlineFrame.getStackSize() <= 1, "Inline method should not leave more than 1 value on stack")
|
||||
assert(afterInlineFrame.getStackSize() <= 1) { "Inline method should not leave more than 1 value on stack" }
|
||||
if (afterInlineFrame.getStackSize() == 1) {
|
||||
val afterInlineStackValues = afterInlineFrame.getStackContent()
|
||||
val returnValue = afterInlineStackValues.last()
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ internal class LocalVariablesManager(val context: FixStackContext, val methodNod
|
||||
numRestoreMarkers == 0
|
||||
|
||||
fun markRestoreNodeEmitted() {
|
||||
assert(numRestoreMarkers > 0, "Emitted more restore markers than expected for $savedStackDescriptor")
|
||||
assert(numRestoreMarkers > 0) { "Emitted more restore markers than expected for $savedStackDescriptor" }
|
||||
numRestoreMarkers--
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -168,7 +168,7 @@ class SamAdapterFunctionsScope(storageManager: StorageManager) : JetScope by Jet
|
||||
}
|
||||
|
||||
original as MyFunctionDescriptor
|
||||
assert(original.original == original, "original in doSubstitute should have no other original")
|
||||
assert(original.original == original) { "original in doSubstitute should have no other original" }
|
||||
|
||||
val substitutionMap = HashMap<TypeConstructor, TypeProjection>()
|
||||
for (typeParameter in original.typeParameters) {
|
||||
|
||||
@@ -266,8 +266,8 @@ public class JetPsiFactory(private val project: Project) {
|
||||
val function = createFunction("fun foo() { when(12) { " + entryText + " } }")
|
||||
val whenEntry = PsiTreeUtil.findChildOfType(function, javaClass<JetWhenEntry>())
|
||||
|
||||
assert(whenEntry != null, "Couldn't generate when entry")
|
||||
assert(entryText == whenEntry!!.getText(), "Generate when entry text differs from the given text")
|
||||
assert(whenEntry != null) { "Couldn't generate when entry" }
|
||||
assert(entryText == whenEntry!!.text) { "Generate when entry text differs from the given text" }
|
||||
|
||||
return whenEntry
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ public class KotlinStringLiteralTextEscaper(host: JetStringTemplateExpression):
|
||||
is JetLiteralStringTemplateEntry -> {
|
||||
val textRange = rangeInsideHost.intersection(childRange)!!.shiftRight(-childRange.getStartOffset())
|
||||
outChars.append(child.getText(), textRange.getStartOffset(), textRange.getEndOffset())
|
||||
textRange.getLength().times {
|
||||
repeat(textRange.length) {
|
||||
sourceOffsetsList.add(sourceOffset++)
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class KotlinStringLiteralTextEscaper(host: JetStringTemplateExpression):
|
||||
}
|
||||
val unescaped = child.getUnescapedValue()
|
||||
outChars.append(unescaped)
|
||||
unescaped.length().times {
|
||||
repeat(unescaped.length()) {
|
||||
sourceOffsetsList.add(sourceOffset)
|
||||
}
|
||||
sourceOffset += child.getTextLength()
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.lexer.JetModifierKeywordToken
|
||||
|
||||
public object ModifierMaskUtils {
|
||||
init {
|
||||
assert(MODIFIER_KEYWORDS_ARRAY.size() <= 32, "Current implementation depends on the ability to represent modifier list as bit mask")
|
||||
assert(MODIFIER_KEYWORDS_ARRAY.size() <= 32) { "Current implementation depends on the ability to represent modifier list as bit mask" }
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -43,7 +43,7 @@ public object ModifierMaskUtils {
|
||||
@JvmStatic
|
||||
public fun maskHasModifier(mask: Int, modifierToken: JetModifierKeywordToken): Boolean {
|
||||
val index = MODIFIER_KEYWORDS_ARRAY.indexOf(modifierToken)
|
||||
assert(index >= 0, "All JetModifierKeywordTokens should be present in MODIFIER_KEYWORDS_ARRAY")
|
||||
assert(index >= 0) { "All JetModifierKeywordTokens should be present in MODIFIER_KEYWORDS_ARRAY" }
|
||||
return (mask and (1 shl index)) != 0
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public class TypeResolver(
|
||||
}
|
||||
|
||||
private fun resolveType(c: TypeResolutionContext, typeReference: JetTypeReference): JetType {
|
||||
assert(!c.allowBareTypes, "Use resolvePossiblyBareType() when bare types are allowed")
|
||||
assert(!c.allowBareTypes) { "Use resolvePossiblyBareType() when bare types are allowed" }
|
||||
return resolvePossiblyBareType(c, typeReference).getActualType()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ public class ResolutionTaskHolder<D : CallableDescriptor, F : D>(
|
||||
}
|
||||
|
||||
private fun assertNotFinished() {
|
||||
assert(internalTasks == null, "Can't add candidates after the resulting tasks were computed.")
|
||||
assert(internalTasks == null) { "Can't add candidates after the resulting tasks were computed." }
|
||||
}
|
||||
|
||||
public fun getTasks(): List<ResolutionTask<D, F>> {
|
||||
|
||||
@@ -328,7 +328,7 @@ public class TaskPrioritizer(
|
||||
// For 'a.foo()' where foo has function type,
|
||||
// a is explicitReceiver, foo is variableReceiver.
|
||||
val variableReceiver = c.context.call.getDispatchReceiver()
|
||||
assert(variableReceiver.exists(), "'Invoke' call hasn't got variable receiver")
|
||||
assert(variableReceiver.exists()) { "'Invoke' call hasn't got variable receiver" }
|
||||
|
||||
// For invocation a.foo() explicit receiver 'a'
|
||||
// can be a receiver for 'foo' variable
|
||||
|
||||
+6
-6
@@ -453,8 +453,8 @@ private class ConstantExpressionEvaluatorVisitor(
|
||||
if (check == emptyUnaryFun) {
|
||||
return result
|
||||
}
|
||||
assert (isIntegerType(receiver.value), "Only integer constants should be checked for overflow")
|
||||
assert (name == "minus", "Only negation should be checked for overflow")
|
||||
assert(isIntegerType(receiver.value)) { "Only integer constants should be checked for overflow" }
|
||||
assert(name == "minus") { "Only negation should be checked for overflow" }
|
||||
|
||||
if (receiver.value == result) {
|
||||
trace.report(Errors.INTEGER_OVERFLOW.on(callExpression.getStrictParentOfType<JetExpression>() ?: callExpression))
|
||||
@@ -790,13 +790,13 @@ private fun parseBoolean(text: String): Boolean {
|
||||
|
||||
private fun createCompileTimeConstantForEquals(result: Any?, operationReference: JetExpression, factory: ConstantValueFactory): ConstantValue<*>? {
|
||||
if (result is Boolean) {
|
||||
assert(operationReference is JetSimpleNameExpression, "This method should be called only for equals operations")
|
||||
assert(operationReference is JetSimpleNameExpression) { "This method should be called only for equals operations" }
|
||||
val operationToken = (operationReference as JetSimpleNameExpression).getReferencedNameElementType()
|
||||
val value: Boolean = when (operationToken) {
|
||||
JetTokens.EQEQ -> result
|
||||
JetTokens.EXCLEQ -> !result
|
||||
JetTokens.IDENTIFIER -> {
|
||||
assert (operationReference.getReferencedNameAsName() == OperatorConventions.EQUALS, "This method should be called only for equals operations")
|
||||
assert(operationReference.getReferencedNameAsName() == OperatorConventions.EQUALS) { "This method should be called only for equals operations" }
|
||||
result
|
||||
}
|
||||
else -> throw IllegalStateException("Unknown equals operation token: $operationToken ${operationReference.getText()}")
|
||||
@@ -808,7 +808,7 @@ private fun createCompileTimeConstantForEquals(result: Any?, operationReference:
|
||||
|
||||
private fun createCompileTimeConstantForCompareTo(result: Any?, operationReference: JetExpression, factory: ConstantValueFactory): ConstantValue<*>? {
|
||||
if (result is Int) {
|
||||
assert(operationReference is JetSimpleNameExpression, "This method should be called only for compareTo operations")
|
||||
assert(operationReference is JetSimpleNameExpression) { "This method should be called only for compareTo operations" }
|
||||
val operationToken = (operationReference as JetSimpleNameExpression).getReferencedNameElementType()
|
||||
return when (operationToken) {
|
||||
JetTokens.LT -> factory.createBooleanValue(result < 0)
|
||||
@@ -816,7 +816,7 @@ private fun createCompileTimeConstantForCompareTo(result: Any?, operationReferen
|
||||
JetTokens.GT -> factory.createBooleanValue(result > 0)
|
||||
JetTokens.GTEQ -> factory.createBooleanValue(result >= 0)
|
||||
JetTokens.IDENTIFIER -> {
|
||||
assert (operationReference.getReferencedNameAsName() == OperatorConventions.COMPARE_TO, "This method should be called only for compareTo operations")
|
||||
assert(operationReference.getReferencedNameAsName() == OperatorConventions.COMPARE_TO) { "This method should be called only for compareTo operations" }
|
||||
return factory.createIntValue(result)
|
||||
}
|
||||
else -> throw IllegalStateException("Unknown compareTo operation token: $operationToken")
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ public class FileBasedPackageMemberDeclarationProvider(
|
||||
override fun doCreateIndex(index: AbstractPsiBasedDeclarationProvider.Index) {
|
||||
for (file in packageFiles) {
|
||||
for (declaration in file.getDeclarations()) {
|
||||
assert(fqName == file.getPackageFqName(), "Files declaration utils contains file with invalid package")
|
||||
assert(fqName == file.getPackageFqName()) { "Files declaration utils contains file with invalid package" }
|
||||
index.putToIndex(declaration)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ public open class LazyClassMemberScope(
|
||||
|
||||
override fun conflict(fromSuper: CallableMemberDescriptor, fromCurrent: CallableMemberDescriptor) {
|
||||
val declaration = DescriptorToSourceUtils.descriptorToDeclaration(fromCurrent) as JetDeclaration?
|
||||
assert(declaration != null, "fromCurrent can not be a fake override")
|
||||
assert(declaration != null) { "fromCurrent can not be a fake override" }
|
||||
trace.report(Errors.CONFLICTING_OVERLOADS.on(declaration, fromCurrent, fromCurrent.getContainingDeclaration().getName().asString()))
|
||||
}
|
||||
})
|
||||
|
||||
@@ -248,7 +248,7 @@ public object LightClassUtil {
|
||||
|
||||
if (declaration is JetPropertyAccessor) {
|
||||
val propertyParent = declaration.parent
|
||||
assert(propertyParent is JetProperty, "JetProperty is expected to be parent of accessor")
|
||||
assert(propertyParent is JetProperty) { "JetProperty is expected to be parent of accessor" }
|
||||
|
||||
declaration = propertyParent as JetProperty
|
||||
}
|
||||
|
||||
+2
-2
@@ -44,7 +44,7 @@ public class CapturedTypeApproximationTest() : JetLiteFixture() {
|
||||
override fun createEnvironment(): KotlinCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY)
|
||||
|
||||
public fun doTest(filePath: String, vararg substitutions: String) {
|
||||
assert(substitutions.size() in 1..2, "Captured type approximation test requires substitutions for (T) or (T, R)")
|
||||
assert(substitutions.size() in 1..2) { "Captured type approximation test requires substitutions for (T) or (T, R)" }
|
||||
val oneTypeVariable = substitutions.size() == 1
|
||||
|
||||
val declarationsText = JetTestUtils.doLoadFile(File(getTestDataPath() + "/declarations.kt"))
|
||||
@@ -141,7 +141,7 @@ public class CapturedTypeApproximationTest() : JetLiteFixture() {
|
||||
fun addRandomVariants(vararg randomVariants: String) {
|
||||
variants.addAll(randomVariants.map { digits -> digits.map { digit -> digit - '0' } })
|
||||
}
|
||||
assert (typePatterns.size() == 5, "Generated random variants below depend on size 5")
|
||||
assert(typePatterns.size() == 5) { "Generated random variants below depend on size 5" }
|
||||
//From 021 the following is generated: In<Inv<Out<T>>>, where In = typePatterns[0], Inv = typePatterns[2], Out = typePatterns[1]
|
||||
addRandomVariants("021", "111", "230", "421", "322", "120", "411", "102", "401", "012")
|
||||
addRandomVariants("4243", "3103", "3043", "2003", "4442", "4143", "1440", "0303", "1302", "1332")
|
||||
|
||||
Reference in New Issue
Block a user