generateUtil: cleanup code

This commit is contained in:
Dmitry Gridin
2019-08-16 17:29:02 +07:00
parent cf3b92d80e
commit b570f99aae
@@ -241,16 +241,16 @@ fun <T : KtDeclaration> insertMembersAfter(
otherMembers.mapTo(insertedMembers) { otherMembers.mapTo(insertedMembers) {
if (classOrObject is KtClass && classOrObject.isEnum()) { if (classOrObject is KtClass && classOrObject.isEnum()) {
val enumEntries = classOrObject.declarations.filterIsInstance<KtEnumEntry>() val enumEntries = classOrObject.declarations.filterIsInstance<KtEnumEntry>()
val bound = (enumEntries.lastOrNull() ?: classOrObject.allChildren.firstOrNull { it.node.elementType == KtTokens.SEMICOLON }) val bound = (enumEntries.lastOrNull() ?: classOrObject.allChildren.firstOrNull { element ->
element.node.elementType == KtTokens.SEMICOLON
})
if (it !is KtEnumEntry) { if (it !is KtEnumEntry) {
if (bound != null && afterAnchor.startOffset <= bound.startOffset) { if (bound != null && afterAnchor.startOffset <= bound.startOffset) {
afterAnchor = bound afterAnchor = bound
} }
} } else if (bound == null && body.declarations.isNotEmpty()) {
else if (bound == null && body.declarations.isNotEmpty()) {
afterAnchor = body.lBrace!! afterAnchor = body.lBrace!!
} } else if (bound != null && afterAnchor.startOffset > bound.startOffset) {
else if (bound != null && afterAnchor.startOffset > bound.startOffset) {
afterAnchor = bound.prevSibling!! afterAnchor = bound.prevSibling!!
} }
} }