Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove usages of getPsi() #2901

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7f8984c
implement ASTNode.isPartOfComment without psi
mgroth0 Dec 8, 2024
2562354
remove psi from existingSuppressionsFromNamedArgumentOrNull
mgroth0 Dec 10, 2024
a05595f
remove psi from visitKtlintSuppressionInAnnotation
mgroth0 Dec 10, 2024
1b76046
remove psi from getAnnotationUseSiteTarget
mgroth0 Dec 10, 2024
546dfca
remove psi from isOnSameLineAsControlFlowKeyword
mgroth0 Dec 10, 2024
5f0f4a8
reduce psi in NoUnusedImportsRule
mgroth0 Dec 10, 2024
7e2f282
remove psi from SpacingAroundColonRule
mgroth0 Dec 10, 2024
bd1596b
remove psi from SpacingAroundDoubleColonRule
mgroth0 Dec 10, 2024
d0c798e
remove psi from StatementWrappingRule
mgroth0 Dec 10, 2024
0058330
reduce psi in TrailingCommaOnDeclarationSiteRule
mgroth0 Dec 10, 2024
a10fd38
deprecate and replace usages of "isPartOf(klass: KClass<out PsiElemen…
mgroth0 Dec 10, 2024
94624ba
remove psi from SuppressionLocator
mgroth0 Dec 10, 2024
e962b64
simple psi removals
mgroth0 Dec 10, 2024
c8d1a54
refactor token sets
mgroth0 Dec 10, 2024
efd32be
remove psi from BlankLineBeforeDeclarationRule
mgroth0 Dec 10, 2024
6094819
remove psi from EnumEntryNameCaseRule
mgroth0 Dec 10, 2024
e2846c1
changs from review
mgroth0 Dec 20, 2024
fe71a48
add kdoc for findChildByTypeRecursively and endOffset
mgroth0 Dec 29, 2024
d92140d
remove a getPsi() from TrailingCommaOnDeclarationSiteRule
mgroth0 Dec 29, 2024
ffda19b
add contract to isWhiteSpace
mgroth0 Dec 29, 2024
3efbf7a
make token sets more maintainable
mgroth0 Dec 29, 2024
cb757a9
alternative solution to token set
mgroth0 Dec 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.pinterest.ktlint.rule.engine.core.api.ElementType.VARARG_KEYWORD
import com.pinterest.ktlint.rule.engine.core.api.ElementType.VAR_KEYWORD
import com.pinterest.ktlint.rule.engine.core.api.ElementType.WHITE_SPACE
import org.jetbrains.kotlin.com.intellij.lang.ASTNode
import org.jetbrains.kotlin.com.intellij.psi.PsiComment
import org.jetbrains.kotlin.com.intellij.psi.PsiElement
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.CompositeElement
import org.jetbrains.kotlin.com.intellij.psi.impl.source.tree.LeafElement
Expand Down Expand Up @@ -223,7 +222,11 @@ public fun ASTNode.isLeaf(): Boolean = firstChildNode == null
*/
public fun ASTNode.isCodeLeaf(): Boolean = isLeaf() && !isWhiteSpace() && !isPartOfComment()

public fun ASTNode.isPartOfComment(): Boolean = parent(strict = false) { it.psi is PsiComment } != null
public fun ASTNode.isPartOfComment(): Boolean =
parent(strict = false) {
val eType = it.elementType
eType == ElementType.BLOCK_COMMENT || eType == ElementType.EOL_COMMENT || eType == ElementType.KDOC
} != null

public fun ASTNode.children(): Sequence<ASTNode> = generateSequence(firstChildNode) { node -> node.treeNext }

Expand Down