Code refactoring

This commit is contained in:
Valentin Kipyatkov
2014-11-14 14:46:00 +03:00
parent 58a67a2bf3
commit d421e7ac72
@@ -35,9 +35,13 @@ public object KotlinKeywordInsertHandler : InsertHandler<LookupElement> {
JetTokens.CONTINUE_KEYWORD.toString()) JetTokens.CONTINUE_KEYWORD.toString())
override fun handleInsert(context: InsertionContext, item: LookupElement) { 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()) { if (keyword == JetTokens.RETURN_KEYWORD.toString()) {
val element = context.getFile().findElementAt(context.getStartOffset()) val element = context.getFile().findElementAt(context.getStartOffset())
@@ -45,12 +49,11 @@ public object KotlinKeywordInsertHandler : InsertHandler<LookupElement> {
val jetFunction = PsiTreeUtil.getParentOfType(element, javaClass<JetFunction>()) val jetFunction = PsiTreeUtil.getParentOfType(element, javaClass<JetFunction>())
if (jetFunction != null && (!jetFunction.hasDeclaredReturnType() || JetPsiUtil.isVoidType(jetFunction.getTypeReference()))) { if (jetFunction != null && (!jetFunction.hasDeclaredReturnType() || JetPsiUtil.isVoidType(jetFunction.getTypeReference()))) {
// No space for void function // No space for void function
return return false
} }
} }
} }
// Add space after keyword return true
WithTailInsertHandler.spaceTail().postHandleInsert(context, item)
} }
} }