diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/CommentBinders.kt b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/CommentBinders.kt index 258eda49405..ddf1e9eb14f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/CommentBinders.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/CommentBinders.kt @@ -24,29 +24,27 @@ import com.intellij.openapi.util.text.StringUtil object PrecedingWhitespacesAndCommentsBinder : WhitespacesAndCommentsBinder { override fun getEdgePosition(tokens: List, atStreamEdge: Boolean, getter: WhitespacesAndCommentsBinder.TokenTextGetter): Int { - if (tokens.size() == 0) return 0 + if (tokens.isEmpty()) return 0 // 1. bind doc comment for (idx in tokens.indices.reversed()) { - if (tokens.get(idx) == JetTokens.DOC_COMMENT) return idx + if (tokens[idx] == JetTokens.DOC_COMMENT) return idx } // 2. bind plain comments var result = tokens.size() for (idx in tokens.indices.reversed()) { val tokenType = tokens[idx] - if (tokenType == JetTokens.WHITE_SPACE) { - if (StringUtil.getLineBreakCount(getter[idx]) > 1) break - } - else if (tokenType in JetTokens.COMMENTS && tokenType != JetTokens.DOC_COMMENT) { - if (atStreamEdge || - idx == 0 || - idx > 0 && tokens[idx - 1] == JetTokens.WHITE_SPACE && StringUtil.containsLineBreak(getter[idx - 1])) { - result = idx + when (tokenType) { + JetTokens.WHITE_SPACE -> if (StringUtil.getLineBreakCount(getter[idx]) > 1) break + + in JetTokens.COMMENTS -> { + if (idx == 0 || tokens[idx - 1] == JetTokens.WHITE_SPACE && StringUtil.containsLineBreak(getter[idx - 1])) { + result = idx + } } - } - else { - break + + else -> break } } @@ -62,15 +60,13 @@ object TrailingWhitespacesAndCommentsBinder : WhitespacesAndCommentsBinder { var result = 0 for (idx in tokens.indices) { - val tokenType = tokens.get(idx) - if (tokenType == JetTokens.WHITE_SPACE) { - if (StringUtil.containsLineBreak(getter.get(idx))) break - } - else if (tokenType in JetTokens.COMMENTS) { - result = idx + 1 - } - else { - break + val tokenType = tokens[idx] + when (tokenType) { + JetTokens.WHITE_SPACE -> if (StringUtil.containsLineBreak(getter[idx])) break + + JetTokens.EOL_COMMENT, JetTokens.BLOCK_COMMENT -> result = idx + 1 + + else -> break } }