- /*
- * Minecraft Development for IntelliJ
- *
- * https://mcdev.io/
- *
- * Copyright (C) 2024 minecraft-dev
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation, version 3.0 only.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- package com.demonwav.mcdev.translations.lang.formatting
- import com.demonwav.mcdev.translations.lang.gen.psi.LangTypes
- import com.intellij.formatting.Alignment
- import com.intellij.formatting.Block
- import com.intellij.formatting.Indent
- import com.intellij.formatting.SpacingBuilder
- import com.intellij.formatting.Wrap
- import com.intellij.formatting.WrapType
- import com.intellij.lang.ASTNode
- import com.intellij.psi.TokenType
- import com.intellij.psi.formatter.common.AbstractBlock
- class LangBlock(node: ASTNode, wrap: Wrap?, alignment: Alignment?, private val spacingBuilder: SpacingBuilder) :
- AbstractBlock(node, wrap, alignment) {
- override fun buildChildren(): List<Block> {
- val blocks = ArrayList<Block>()
- var child: ASTNode? = myNode.firstChildNode
- var previousChild: ASTNode? = null
- while (child != null) {
- if (
- child.elementType !== TokenType.WHITE_SPACE &&
- (
- previousChild == null ||
- previousChild.elementType !== LangTypes.LINE_ENDING ||
- child.elementType !== LangTypes.LINE_ENDING
- )
- ) {
- val block = LangBlock(
- child,
- Wrap.createWrap(WrapType.NONE, false),
- Alignment.createAlignment(),
- spacingBuilder,
- )
- blocks.add(block)
- }
- previousChild = child
- child = child.treeNext
- }
- return blocks
- }
- override fun getIndent(): Indent = Indent.getNoneIndent()
- override fun getSpacing(child1: Block?, child2: Block) = spacingBuilder.getSpacing(this, child1, child2)
- override fun isLeaf() = myNode.firstChildNode == null
- }
- /*
- * Minecraft Development for IntelliJ
- *
- * https://mcdev.io/
- *
- * Copyright (C) 2025 minecraft-dev
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation, version 3.0 only.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- package com.demonwav.mcdev.translations.lang.formatting
- import com.demonwav.mcdev.translations.lang.gen.psi.LangTypes
- import com.intellij.formatting.Alignment
- import com.intellij.formatting.Block
- import com.intellij.formatting.Indent
- import com.intellij.formatting.SpacingBuilder
- import com.intellij.formatting.Wrap
- import com.intellij.formatting.WrapType
- import com.intellij.lang.ASTNode
- import com.intellij.psi.TokenType
- import com.intellij.psi.formatter.common.AbstractBlock
- class LangBlock(node: ASTNode, wrap: Wrap?, alignment: Alignment?, private val spacingBuilder: SpacingBuilder) :
- AbstractBlock(node, wrap, alignment) {
- override fun buildChildren(): List<Block> {
- val blocks = ArrayList<Block>()
- var child: ASTNode? = myNode.firstChildNode
- var previousChild: ASTNode? = null
- while (child != null) {
- if (
- child.elementType !== TokenType.WHITE_SPACE &&
- (
- previousChild == null ||
- previousChild.elementType !== LangTypes.LINE_ENDING ||
- child.elementType !== LangTypes.LINE_ENDING
- )
- ) {
- val block = LangBlock(
- child,
- Wrap.createWrap(WrapType.NONE, false),
- Alignment.createAlignment(),
- spacingBuilder,
- )
- blocks.add(block)
- }
- previousChild = child
- child = child.treeNext
- }
- return blocks
- }
- override fun getIndent(): Indent = Indent.getNoneIndent()
- override fun getSpacing(child1: Block?, child2: Block) = spacingBuilder.getSpacing(this, child1, child2)
- override fun isLeaf() = myNode.firstChildNode == null
- }