1 /* 2 * Copyright (c) Meta Platforms, Inc. and affiliates. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.facebook.ktfmt.format 18 19 import com.google.common.base.MoreObjects 20 import com.google.googlejavaformat.Input 21 import com.google.googlejavaformat.Newlines 22 import org.jetbrains.kotlin.lexer.KtToken 23 24 class KotlinTok( 25 private val index: Int, 26 private val originalText: String, 27 private val text: String, 28 private val position: Int, 29 private val column: Int, 30 val isToken: Boolean, 31 private val kind: KtToken 32 ) : Input.Tok { 33 getIndexnull34 override fun getIndex(): Int = index 35 36 override fun getText(): String = text 37 38 override fun getOriginalText(): String = originalText 39 40 override fun length(): Int = originalText.length 41 42 override fun getPosition(): Int = position 43 44 override fun getColumn(): Int = column 45 46 override fun isNewline(): Boolean = Newlines.isNewline(text) 47 48 override fun isSlashSlashComment(): Boolean = text.startsWith("//") 49 50 override fun isSlashStarComment(): Boolean = text.startsWith("/*") 51 52 override fun isJavadocComment(): Boolean = text.startsWith("/**") && text.length > 4 53 54 override fun isComment(): Boolean = isSlashSlashComment || isSlashStarComment 55 56 fun kind(): KtToken = kind 57 58 override fun toString(): String { 59 return MoreObjects.toStringHelper(this) 60 .add("index", index) 61 .add("text", text) 62 .add("position", position) 63 .add("column", column) 64 .add("isToken", isToken) 65 .toString() 66 } 67 } 68