[comments formatting] minor, move class

This commit is contained in:
Yaroslav Lepenkin
2017-07-17 16:46:55 +03:00
parent f88142ca55
commit 06ab690fa7
3 changed files with 86 additions and 49 deletions
@@ -15,23 +15,14 @@
*/
package com.intellij.formatting.blocks
import com.intellij.formatting.*
import com.intellij.formatting.Block
import com.intellij.formatting.Indent
import com.intellij.formatting.Spacing
import com.intellij.lang.ASTNode
import com.intellij.openapi.util.TextRange
import com.intellij.psi.TokenType
import com.intellij.psi.formatter.common.AbstractBlock
fun ASTNode.prev(): ASTNode? {
var prev = treePrev
while (prev != null && prev.elementType == TokenType.WHITE_SPACE) {
prev = prev.treePrev
}
if (prev != null) return prev
return if (treeParent != null) treeParent.prev() else null
}
class CStyleCommentBlock(comment: ASTNode, private val indent: Indent?): AbstractBlock(comment, null, null) {
private val lines by lazy { lineBlocks() }
@@ -93,43 +84,6 @@ class CStyleCommentBlock(comment: ASTNode, private val indent: Indent?): Abstrac
private class LineInfo(val text: String, val textRange: TextRange)
class TextLineBlock(
val text: String,
private val textRange: TextRange,
private val alignment: Alignment?,
private val indent: Indent?,
val spacing: Spacing?
) : Block {
override fun getTextRange(): TextRange {
return textRange
}
override fun getSubBlocks(): List<Block> = emptyList()
override fun getWrap() = null
override fun getIndent() = indent
override fun getAlignment() = alignment
override fun getSpacing(child1: Block?, child2: Block) = spacing
override fun getChildAttributes(newChildIndex: Int): ChildAttributes {
throw UnsupportedOperationException("Should not be called")
}
override fun isIncomplete() = false
override fun isLeaf() = true
override fun toString(): String {
return "TextLineBlock(text='$text', textRange=$textRange)"
}
}
fun <T> List<T>.split(predicate: (T) -> Boolean): List<List<T>> {
if (indices.isEmpty()) return listOf()
val result = mutableListOf<List<T>>()
@@ -0,0 +1,28 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.formatting.blocks
import com.intellij.lang.ASTNode
import com.intellij.psi.TokenType
fun ASTNode.prev(): ASTNode? {
var prev = treePrev
while (prev != null && prev.elementType == TokenType.WHITE_SPACE) {
prev = prev.treePrev
}
if (prev != null) return prev
return if (treeParent != null) treeParent.prev() else null
}
@@ -0,0 +1,55 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.formatting.blocks
import com.intellij.formatting.*
import com.intellij.openapi.util.TextRange
class TextLineBlock(
val text: String,
private val textRange: TextRange,
private val alignment: Alignment?,
private val indent: Indent?,
val spacing: Spacing?
) : Block {
override fun getTextRange(): TextRange {
return textRange
}
override fun getSubBlocks(): List<Block> = emptyList()
override fun getWrap() = null
override fun getIndent() = indent
override fun getAlignment() = alignment
override fun getSpacing(child1: Block?, child2: Block) = spacing
override fun getChildAttributes(newChildIndex: Int): ChildAttributes {
throw UnsupportedOperationException("Should not be called")
}
override fun isIncomplete() = false
override fun isLeaf() = true
override fun toString(): String {
return "TextLineBlock(text='$text', textRange=$textRange)"
}
}