All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.shyiko.ktlint.test.package.kt Maven / Gradle / Ivy

There is a newer version: 0.31.0
Show newest version
package com.github.shyiko.ktlint.test

import com.github.shyiko.ktlint.core.Rule
import org.jetbrains.kotlin.com.intellij.lang.ASTNode

val debugAST = {
    (System.getProperty("ktlintDebug") ?: System.getenv("KTLINT_DEBUG") ?: "")
        .toLowerCase().split(",").contains("ast")
}

class DumpAST : Rule("dump") {

    override fun visit(node: ASTNode, autoCorrect: Boolean,
        emit: (offset: Int, errorMessage: String, corrected: Boolean) -> Unit) {
        var level = -1
        var parent: ASTNode? = node
        do {
            level++
            parent = parent?.treeParent
        } while (parent != null)
        System.err.println("  ".repeat(level) + node.psi.javaClass.name + " (${node.elementType})" +
            (if (node.getChildren(null).isEmpty()) " | \"" + node.text.escape() + "\"" else ""))
    }

    private fun String.escape() =
        this.replace("\\", "\\\\").replace("\n", "\\n").replace("\t", "\\t").replace("\r", "\\r")
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy