-
Notifications
You must be signed in to change notification settings - Fork 518
Deprecate functions in ASTNodeExtensions, and where applicable provide property accessors #3026
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…n "isPartOfString" in Ktlint 2.0
…"isWhiteSpace" in KtLint 2.0
…e function "isWhiteSpaceWithNewline" in KtLint 2.0
…lace function "isWhiteSpaceWithoutNewline" in Ktlint 2.0
…f20" in Ktlint 2.0
…on "isPartOfComment" in Ktlint 2.0
…ldren" in Ktlint 2.0
…perty accessor "indent20", to replace function "children" in Ktlint 2.0
…ors "leavesForwardsIncludingSelf", and "leavesBackwardsIncludingSelf"
…y property accessor "leavesOnLine20" to replace function "leavesOnLine(Boolean)" in Ktlint 2.0
…cessor "firstLeafOnLineOrSelf"
…essor "lastLeafOnLineOrSelf"
…thoutNewlinePrefix" in Ktlint 2.0
…tlint 2.0 Add property accessor "isCode"
… "isKtAnnotated" in Ktlint 2.0
… "isDeclaration" in Ktlint 2.0
…f" in Ktlint 2.0. Note that the property accessor replaces the default usage of the function with parameter values includeEmpty equals false, and skipSubtree equals false.
…lint 2.0. Note that the property accessor replaces the default usage of the function with parameter values includeEmpty equals false, and skipSubtree equals false.
…unction "firstChildLeafOrSelf" in Ktlint 2.0
…on "nextCodeSibling" in Ktlint 2.0
…erty accessor "nextSibling20" to replace function "ASTNode.nextSibling()" in Ktlint 2.0.
…Node.parent(IElementType,Boolean): ASTNode?"
…ASTNode?", and add "public fun ASTNode.parent((ASTNode) -> Boolean): ASTNode?" Refactor use case where parameter "strict" was used by replacing it with a call to "isPartOf(TokenSet)"
… ASTNode?", and add "ASTNode.findChildByTypeRecursively(IElementType): ASTNode?" Refactor calls to deprecated method
… ASTNode?", and add "ASTNode.findChildByTypeRecursively(IElementType): ASTNode?" Refactor calls to deprecated method
…ElementType" are not the adjacent sibling of the current ASTNode
…erty accessor "prevSibling20" to replace function "ASTNode.prevSibling()" in Ktlint 2.0.
…and property accessors to avoid migration to psi
…casting is required
…possible so no casting is required
# Conflicts: # ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/FunctionSignatureRule.kt # ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/UnnecessaryParenthesesBeforeTrailingLambdaRule.kt
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Replace functions below with property accessors. Most of the new property accessors have a temporary name using sufix
20
to avoid binary compatability issues. In KtLint 2.0 the functions will be removed, and the property accessors will be renamed.ASTNode.nextLeaf(includeEmpty: Boolean = false, skipSubtree: Boolean = false): ASTNode?
astNode.nextLeaf()
withastNode.nextLeaf
includeEmpty=true
orskipSubtree=true
ASTNode.prevLeaf(includeEmpty: Boolean = false): ASTNode?
astNode.prevLeaf()
withastNode.prevLeaf
includeEmpty=true
ASTNode.nextCodeLeaf(includeEmpty: Boolean = false): ASTNode?
astNode.nextCodeLeaf()
withastNode.nextCodeLeaf
includeEmpty=true
orskipSubtree=true
ASTNode.prevCodeLeaf(includeEmpty: Boolean = false): ASTNode?
astNode.prevCodeLeaf()
withastNode.prevCodeLeaf
includeEmpty=true
ASTNode.nextSibling(): ASTNode?
astNode.nextSibling()
withastNode.nextSibling20
ASTNode.prevSibling(): ASTNode?
astNode.prevSibling()
withastNode.prevSibling20
ASTNode.nextCodeSibling(): ASTNode?
astNode.nextCodeSibling()
withastNode.nextCodeSibling20
ASTNode.prevCodeSibling(): ASTNode?
astNode.prevCodeSibling()
withastNode.prevCodeSibling20
ASTNode.firstChildLeafOrSelf(): ASTNode
astNode.firstChildLeafOrSelf()
withastNode.firstChildLeafOrSelf20
ASTNode.lastChildLeafOrSelf(): ASTNode
astNode.lastChildLeafOrSelf()
withastNode.lastChildLeafOrSelf20
ASTNode.parent(elementType: IElementType, strict: Boolean = true): ASTNode?
astNode.parent(elementType)
withastNode.findParentByType(elementType)
strict=false
ASTNode.parent(strict: Boolean = true, predicate: (ASTNode) -> Boolean): ASTNode?
astNode.parent(strict = true) { ... }
withastNode.parent { ... }
strict=false
ASTNode.isPartOfString(): Boolean
astNode.isPartOfString()
withastNode.isPartOfString20
ASTNode?.isWhiteSpace(): Boolean
astNode.isWhiteSpace()
withastNode.isWhiteSpace20
ASTNode?.isWhiteSpaceWithNewline(): Boolean
astNode.isWhiteSpaceWithNewline()
withastNode.isWhiteSpaceWithNewline20
ASTNode?.isWhiteSpaceWithoutNewline(): Boolean
astNode.isWhiteSpaceWithoutNewline()
withastNode.isWhiteSpaceWithoutNewline20
ASTNode.isRoot(): Boolean
astNode.isRoot()
withastNode.isRoot20
ASTNode.isLeaf(): Boolean
astNode.isLeaf()
withastNode.isLeaf20
ASTNode.isPartOfComment(): Boolean
astNode.isPartOfComment()
withastNode.isPartOfComment20
ASTNode.children(): Sequence<ASTNode>
astNode.children()
withastNode.children20
ASTNode.recursiveChildren(includeSelf: Boolean = false): Sequence<ASTNode>
astNode.recursiveChildren(includeSelf = false)
withastNode.recursiveChildren20
includeSelf=true
ASTNode.indent(includeNewline: Boolean = true): String
astNode.indent()
andastNode.indent(includeNewline = true)
withastNode.indent20
astNode.indent(includeNewline = false)
withastNode.indentWithoutNewlinePrefix
ASTNode.leavesIncludingSelf(forward: Boolean = true): Sequence<ASTNode>
astNode.leavesIncludingSelf()
andastNode.leavesIncludingSelf(forward = true)
withastNode.leavesForwardsIncludingSelf
astNode.leavesIncludingSelf(forward = false)
withastNode.leavesBackwardsIncludingSelf
ASTNode.leavesOnLine(): Sequence<ASTNode>
astNode.leavesOnLine
withastNode.leavesOnLine20
ASTNode.leavesOnLine(excludeEolComment: Boolean): Sequence<ASTNode>
astNode.leavesOnLine(excludeEolComment = true)
withastNode.leavesOnLine20.dropTrailingEolComment()
ASTNode.lineLengthWithoutNewlinePrefix(): Int
astNode.lineLengthWithoutNewlinePrefix()
withastNode.leavesOnLine20.lineLength
ASTNode.lineLength(excludeEolComment: Boolean = false): Int
astNode.lineLength()
andastNode.lineLength(excludeEolComment = false)
withastNode.leavesOnLine20.lineLength
with
astNode.leavesOnLine20.dropTrailingEolComment().lineLength`Sequence<ASTNode>.lineLengthWithoutNewlinePrefix(): Int
with
astNode.lineLength`ASTNode.findChildByTypeRecursively(elementType: IElementType, includeSelf: Boolean): ASTNode?
with
astNode.findChildByTypeRecursively(elementType)`includeSelf=true
ASTNode.endOffset(): Int
with
astNode.endOffset20`fun ASTNode.isKtAnnotated(): Boolean
with
astNode.isKtAnnotated20`ASTNode?.isDeclaration(): Boolean
with
astNode.isDeclaration20`Functions below are deprecated without replacement:
ASTNode.isPartOfCompositeElementOfType(iElementType: IElementType): Boolean
ASTNode.findCompositeParentElementOfType(iElementType: IElementType): ASTNode?
ASTNode.isCodeLeaf(): Boolean
ASTNode.logStructure(): ASTNode
ASTNode.isValOrVarKeyword(): Boolean
ASTNode.isKtExpression(): Boolean
ASTNode.isKtLoopExpression(): Boolean
Newly added property accessors:
ASTNode.isCode get(): Boolean
:true
when [ASTNode] is not a whitespace element, and is not part of a commentASTNode.parent get(): ASTNode?
: The parent of the [ASTNode]. This counterpart of the PSItreeParent
function is nullable as the root node does not have a parent.ASTNode?.isWhiteSpaceWithoutNewlineOrNull get(): Boolean
:true
when [ASTNode] is null, or when [ASTNode] is a whitespace element containing a newlineNewly added functions:
ASTNode.replaceTextWith(text: String)
: Replace text [ASTNode] with [text]. [ASTNode] must be a [LeafElement].Closes #2919
Checklist
Before submitting the PR, please check following (checks which are not relevant may be ignored):
Closes #<xxx>
orFixes #<xxx>
(replace<xxx>
with issue number)Documentation is updated. See difference between snapshot and release documentation