Functions to properties

This commit is contained in:
Valentin Kipyatkov
2015-10-21 17:40:26 +03:00
parent 6cfb30bb81
commit b7809ed94a
6 changed files with 17 additions and 17 deletions
@@ -264,7 +264,7 @@ private fun createKeywordElementWithSpace(
return if (addSpaceAfter) { return if (addSpaceAfter) {
object: LookupElementDecorator<LookupElement>(element) { object: LookupElementDecorator<LookupElement>(element) {
override fun handleInsert(context: InsertionContext) { override fun handleInsert(context: InsertionContext) {
WithTailInsertHandler.spaceTail().handleInsert(context, getDelegate()) WithTailInsertHandler.SPACE.handleInsert(context, getDelegate())
} }
} }
} }
@@ -99,9 +99,9 @@ class LookupElementsCollector(
if (context.shouldAddCompletionChar() && !isJustTyping(context, this)) { if (context.shouldAddCompletionChar() && !isJustTyping(context, this)) {
when (context.getCompletionChar()) { when (context.getCompletionChar()) {
',' -> WithTailInsertHandler.commaTail().postHandleInsert(context, getDelegate()) ',' -> WithTailInsertHandler.COMMA.postHandleInsert(context, getDelegate())
'=' -> WithTailInsertHandler.eqTail().postHandleInsert(context, getDelegate()) '=' -> WithTailInsertHandler.EQ.postHandleInsert(context, getDelegate())
'!' -> { '!' -> {
WithExpressionPrefixInsertHandler("!").postHandleInsert(context) WithExpressionPrefixInsertHandler("!").postHandleInsert(context)
@@ -73,7 +73,7 @@ object NamedArgumentCompletion {
editor.getDocument().replaceString(context.getStartOffset(), context.getTailOffset(), text) editor.getDocument().replaceString(context.getStartOffset(), context.getTailOffset(), text)
editor.getCaretModel().moveToOffset(context.getStartOffset() + text.length()) editor.getCaretModel().moveToOffset(context.getStartOffset() + text.length())
WithTailInsertHandler.eqTail().postHandleInsert(context, item) WithTailInsertHandler.EQ.postHandleInsert(context, item)
} }
} }
} }
@@ -44,7 +44,7 @@ object KotlinKeywordInsertHandler : InsertHandler<LookupElement> {
override fun handleInsert(context: InsertionContext, item: LookupElement) { override fun handleInsert(context: InsertionContext, item: LookupElement) {
val keyword = item.lookupString val keyword = item.lookupString
if (keyword !in NO_SPACE_AFTER) { if (keyword !in NO_SPACE_AFTER) {
WithTailInsertHandler.spaceTail().postHandleInsert(context, item) WithTailInsertHandler.SPACE.postHandleInsert(context, item)
} }
} }
} }
@@ -86,12 +86,12 @@ class WithTailInsertHandler(val tailText: String,
} }
companion object { companion object {
fun commaTail() = WithTailInsertHandler(",", spaceBefore = false, spaceAfter = true /*TODO: use code style option*/) val COMMA = WithTailInsertHandler(",", spaceBefore = false, spaceAfter = true /*TODO: use code style option*/)
fun rparenthTail() = WithTailInsertHandler(")", spaceBefore = false, spaceAfter = false) val RPARENTH = WithTailInsertHandler(")", spaceBefore = false, spaceAfter = false)
fun rbracketTail() = WithTailInsertHandler("]", spaceBefore = false, spaceAfter = false) val RBRACKET = WithTailInsertHandler("]", spaceBefore = false, spaceAfter = false)
fun rbraceTail() = WithTailInsertHandler("}", spaceBefore = true, spaceAfter = false) val RBRACE = WithTailInsertHandler("}", spaceBefore = true, spaceAfter = false)
fun elseTail() = WithTailInsertHandler("else", spaceBefore = true, spaceAfter = true) val ELSE = WithTailInsertHandler("else", spaceBefore = true, spaceAfter = true)
fun eqTail() = WithTailInsertHandler("=", spaceBefore = true, spaceAfter = true) /*TODO: use code style options*/ val EQ = WithTailInsertHandler("=", spaceBefore = true, spaceAfter = true) /*TODO: use code style options*/
fun spaceTail() = WithTailInsertHandler(" ", spaceBefore = false, spaceAfter = false, overwriteText = false) val SPACE = WithTailInsertHandler(" ", spaceBefore = false, spaceAfter = false, overwriteText = false)
} }
} }
@@ -65,31 +65,31 @@ fun LookupElement.addTail(tail: Tail?): LookupElement {
Tail.COMMA -> object: LookupElementDecorator<LookupElement>(this) { Tail.COMMA -> object: LookupElementDecorator<LookupElement>(this) {
override fun handleInsert(context: InsertionContext) { override fun handleInsert(context: InsertionContext) {
WithTailInsertHandler.commaTail().handleInsert(context, getDelegate()) WithTailInsertHandler.COMMA.handleInsert(context, getDelegate())
} }
} }
Tail.RPARENTH -> object: LookupElementDecorator<LookupElement>(this) { Tail.RPARENTH -> object: LookupElementDecorator<LookupElement>(this) {
override fun handleInsert(context: InsertionContext) { override fun handleInsert(context: InsertionContext) {
WithTailInsertHandler.rparenthTail().handleInsert(context, getDelegate()) WithTailInsertHandler.RPARENTH.handleInsert(context, getDelegate())
} }
} }
Tail.RBRACKET -> object: LookupElementDecorator<LookupElement>(this) { Tail.RBRACKET -> object: LookupElementDecorator<LookupElement>(this) {
override fun handleInsert(context: InsertionContext) { override fun handleInsert(context: InsertionContext) {
WithTailInsertHandler.rbracketTail().handleInsert(context, getDelegate()) WithTailInsertHandler.RBRACKET.handleInsert(context, getDelegate())
} }
} }
Tail.ELSE -> object: LookupElementDecorator<LookupElement>(this) { Tail.ELSE -> object: LookupElementDecorator<LookupElement>(this) {
override fun handleInsert(context: InsertionContext) { override fun handleInsert(context: InsertionContext) {
WithTailInsertHandler.elseTail().handleInsert(context, getDelegate()) WithTailInsertHandler.ELSE.handleInsert(context, getDelegate())
} }
} }
Tail.RBRACE -> object: LookupElementDecorator<LookupElement>(this) { Tail.RBRACE -> object: LookupElementDecorator<LookupElement>(this) {
override fun handleInsert(context: InsertionContext) { override fun handleInsert(context: InsertionContext) {
WithTailInsertHandler.rbraceTail().handleInsert(context, getDelegate()) WithTailInsertHandler.RBRACE.handleInsert(context, getDelegate())
} }
} }
} }