Use throwNoSuchSlot consistently.

This commit is contained in:
Dmitry Petrov
2016-09-08 17:22:07 +03:00
committed by Dmitry Petrov
parent 40a60e430f
commit d6a3246586
14 changed files with 30 additions and 18 deletions
@@ -55,6 +55,7 @@ class IrAnonymousInitializerImpl(
override fun replaceChild(slot: Int, newChild: IrElement) {
when (slot) {
ANONYMOUS_INITIALIZER_BODY_SLOT -> body = newChild.assertCast()
else -> throwNoSuchSlot(slot)
}
}
@@ -66,6 +66,7 @@ class IrEnumEntryImpl(
when (slot) {
ENUM_ENTRY_CLASS_SLOT -> correspondingClass = newChild.assertCast()
ENUM_ENTRY_INITIALIZER_SLOT -> initializerExpression = newChild.assertCast()
else -> throwNoSuchSlot(slot)
}
}
@@ -96,6 +96,7 @@ class IrLocalDelegatedPropertyImpl(
DELEGATE_SLOT -> delegate = newChild.assertCast()
PROPERTY_GETTER_SLOT -> getter = newChild.assertCast()
PROPERTY_SETTER_SLOT -> setter = newChild.assertCast()
else -> throwNoSuchSlot(slot)
}
}
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.ir.declarations
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.throwNoSuchSlot
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
interface IrTypeAlias : IrDeclaration {
@@ -44,6 +45,6 @@ class IrTypeAliasImpl(
override fun getChild(slot: Int): IrElement? = null
override fun replaceChild(slot: Int, newChild: IrElement) {
// no children
throwNoSuchSlot(slot)
}
}
@@ -39,7 +39,7 @@ class IrEmptyBlockImpl(startOffset: Int, endOffset: Int, type: KotlinType, overr
override fun getChild(slot: Int): IrElement? = null
override fun replaceChild(slot: Int, newChild: IrElement) {
// no children
throwNoSuchSlot(slot)
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R {
@@ -79,12 +79,12 @@ class IrBlockImpl(startOffset: Int, endOffset: Int, type: KotlinType, override v
statements.getOrNull(slot)
override fun replaceChild(slot: Int, newChild: IrElement) {
if (slot < 0 || slot >= statements.size) throwNoSuchSlot(slot)
newChild.assertDetached()
if (0 <= slot && slot < statements.size) {
statements[slot].detach()
statements[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
}
statements[slot].detach()
statements[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
@@ -63,6 +63,7 @@ class IrExpressionBodyImpl(startOffset: Int, endOffset: Int) : IrElementBase(sta
override fun replaceChild(slot: Int, newChild: IrElement) {
when (slot) {
CHILD_EXPRESSION_SLOT -> expression = newChild.assertCast()
else -> throwNoSuchSlot(slot)
}
}
@@ -82,6 +82,8 @@ class IrErrorCallExpressionImpl(
arguments.getOrNull(slot)
override fun replaceChild(slot: Int, newChild: IrElement) {
if (slot < 0 || slot >= arguments.size) throwNoSuchSlot(slot)
newChild.assertDetached()
arguments[slot].detach()
arguments[slot] = newChild.assertCast()
@@ -49,6 +49,7 @@ class IrGetClassImpl(startOffset: Int, endOffset: Int, type: KotlinType) : IrExp
override fun replaceChild(slot: Int, newChild: IrElement) {
when (slot) {
CHILD_EXPRESSION_SLOT -> argument = newChild.assertCast()
else -> throwNoSuchSlot(slot)
}
}
@@ -68,6 +68,7 @@ abstract class IrLoopBase(
when (slot) {
LOOP_BODY_SLOT -> body = newChild.assertCast()
LOOP_CONDITION_SLOT -> condition = newChild.assertCast()
else -> throwNoSuchSlot(slot)
}
}
}
@@ -62,7 +62,7 @@ class IrNullaryPrimitiveImpl constructor(
override fun getChild(slot: Int): IrElement? = null
override fun replaceChild(slot: Int, newChild: IrElement) {
// no children
throwNoSuchSlot(slot)
}
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
@@ -43,15 +43,12 @@ class IrStringConcatenationImpl(
arguments.getOrNull(slot)
override fun replaceChild(slot: Int, newChild: IrElement) {
if (slot < 0 || slot >= arguments.size) throwNoSuchSlot(slot)
newChild.assertDetached()
if (0 <= slot && slot < arguments.size) {
arguments[slot].detach()
arguments[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
}
else {
throwNoSuchSlot(slot)
}
arguments[slot].detach()
arguments[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
}
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
@@ -94,10 +94,14 @@ class IrTryCatchImpl(
putCatchClauseElement(catchClauseResults, newChild, slot)
slot == FINALLY_EXPRESSION_SLOT ->
finallyExpression = newChild.assertCast()
else ->
throwNoSuchSlot(slot)
}
}
private inline fun <reified T : IrElement> putCatchClauseElement(list: MutableList<T>, newChild: IrElement, slot: Int) {
if (slot < 0 || slot >= list.size) throwNoSuchSlot(slot)
list[slot].detach()
list[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
@@ -51,6 +51,7 @@ class IrVarargImpl(
override fun replaceChild(slot: Int, newChild: IrElement) {
if (slot < 0 || slot >= elements.size) throwNoSuchSlot(slot)
newChild.assertDetached()
elements[slot].detach()
elements[slot] = newChild.assertCast()
@@ -94,6 +95,7 @@ class IrSpreadElementImpl(
override fun replaceChild(slot: Int, newChild: IrElement) {
when (slot) {
CHILD_EXPRESSION_SLOT -> expression = newChild.assertCast()
else -> throwNoSuchSlot(slot)
}
}
@@ -17,10 +17,8 @@
package org.jetbrains.kotlin.ir.expressions
import org.jetbrains.kotlin.ir.*
import org.jetbrains.kotlin.ir.declarations.IrVariable
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.utils.SmartList
import java.util.*
interface IrWhen : IrExpression {
@@ -74,6 +72,8 @@ class IrWhenImpl(
branchParts[slot] = newChild.assertCast()
newChild.setTreeLocation(this, slot)
}
else ->
throwNoSuchSlot(slot)
}
}