Code refactoring
This commit is contained in:
@@ -35,9 +35,13 @@ public object KotlinKeywordInsertHandler : InsertHandler<LookupElement> {
|
||||
JetTokens.CONTINUE_KEYWORD.toString())
|
||||
|
||||
override fun handleInsert(context: InsertionContext, item: LookupElement) {
|
||||
val keyword = item.getLookupString()
|
||||
if (shouldInsertSpaceAfter(item.getLookupString(), context)) {
|
||||
WithTailInsertHandler.spaceTail().postHandleInsert(context, item)
|
||||
}
|
||||
}
|
||||
|
||||
if (keyword in NO_SPACE_AFTER) return
|
||||
private fun shouldInsertSpaceAfter(keyword: String, context: InsertionContext): Boolean {
|
||||
if (keyword in NO_SPACE_AFTER) return false
|
||||
|
||||
if (keyword == JetTokens.RETURN_KEYWORD.toString()) {
|
||||
val element = context.getFile().findElementAt(context.getStartOffset())
|
||||
@@ -45,12 +49,11 @@ public object KotlinKeywordInsertHandler : InsertHandler<LookupElement> {
|
||||
val jetFunction = PsiTreeUtil.getParentOfType(element, javaClass<JetFunction>())
|
||||
if (jetFunction != null && (!jetFunction.hasDeclaredReturnType() || JetPsiUtil.isVoidType(jetFunction.getTypeReference()))) {
|
||||
// No space for void function
|
||||
return
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add space after keyword
|
||||
WithTailInsertHandler.spaceTail().postHandleInsert(context, item)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user