KtVisitor¶
The base visitor over the Kotlin PSI, implementing the visitor pattern for KtElements.
Each concrete element type has a dedicated visit* method. Dispatch is triggered by accept, which invokes the method matching the element's runtime type. To handle a specific element type, subclass KtVisitor and override the corresponding method.
The visit* methods form a hierarchy that mirrors the PSI type hierarchy: an unoverridden method delegates to the method for its supertype (for example, visitClass falls back to visitClassOrObject, then to visitNamedDeclaration, and ultimately to visitKtElement). Overriding a method higher up the hierarchy therefore provides a default for all of its subtypes.
This visitor does not recurse into children on its own; a visit* method visits only the element it is given. Use KtTreeVisitor for automatic recursive traversal.
Parameters¶
-
: the type of value returned by each visit*method -
: the type of the extra data threaded through the traversal (use Voidwhen none is needed)
See also¶
Inheritors¶
Constructors¶
KtVisitor¶
constructor()
Companion properties¶
EMPTY_VISITOR¶
val EMPTY_VISITOR: PsiElementVisitor
Functions¶
visitAnnotatedExpression¶
open fun visitAnnotatedExpression(@NotNull expression: KtAnnotatedExpression, data: D): R
visitAnnotation¶
open fun visitAnnotation(@NotNull annotation: KtAnnotation, data: D): R
visitAnnotationEntry¶
open fun visitAnnotationEntry(@NotNull annotationEntry: KtAnnotationEntry, data: D): R
visitAnnotationUseSiteTarget¶
open fun visitAnnotationUseSiteTarget(@NotNull annotationTarget: KtAnnotationUseSiteTarget, data: D): R
visitAnonymousInitializer¶
open fun visitAnonymousInitializer(@NotNull initializer: KtAnonymousInitializer, data: D): R
visitArgument¶
open fun visitArgument(@NotNull argument: KtValueArgument, data: D): R
visitArrayAccessExpression¶
open fun visitArrayAccessExpression(@NotNull expression: KtArrayAccessExpression, data: D): R
visitBackingField¶
open fun visitBackingField(@NotNull accessor: KtBackingField, data: D): R
visitBinaryExpression¶
open fun visitBinaryExpression(@NotNull expression: KtBinaryExpression, data: D): R
Visits the input expression using a stack if it's a string literals concatenation expression (to prevent potential stack overflow exception), otherwise visits the expression using regular recursive calls. If you need to handle nested binary expressions inside string literals concatenation, you have to override this method and write the necessary logic there.
visitBinaryFile¶
open fun visitBinaryFile(file: @NotNull PsiBinaryFile)
visitBinaryWithTypeRHSExpression¶
open fun visitBinaryWithTypeRHSExpression(@NotNull expression: KtBinaryExpressionWithTypeRHS, data: D): R
visitBlockExpression¶
open fun visitBlockExpression(@NotNull expression: KtBlockExpression, data: D): R
visitBlockStringTemplateEntry¶
open fun visitBlockStringTemplateEntry(@NotNull entry: KtBlockStringTemplateEntry, data: D): R
visitBreakExpression¶
open fun visitBreakExpression(@NotNull expression: KtBreakExpression, data: D): R
visitCallableReferenceExpression¶
open fun visitCallableReferenceExpression(@NotNull expression: KtCallableReferenceExpression, data: D): R
visitCallExpression¶
open fun visitCallExpression(@NotNull expression: KtCallExpression, data: D): R
visitCatchSection¶
open fun visitCatchSection(@NotNull catchClause: KtCatchClause, data: D): R
visitClass¶
open fun visitClass(@NotNull klass: KtClass, data: D): R
visitClassBody¶
open fun visitClassBody(@NotNull classBody: KtClassBody, data: D): R
visitClassInitializer¶
open fun visitClassInitializer(@NotNull initializer: KtClassInitializer, data: D): R
visitClassLiteralExpression¶
open fun visitClassLiteralExpression(@NotNull expression: KtClassLiteralExpression, data: D): R
visitClassOrObject¶
open fun visitClassOrObject(@NotNull classOrObject: KtClassOrObject, data: D): R
visitCollectionLiteralExpression¶
open fun visitCollectionLiteralExpression(@NotNull expression: KtCollectionLiteralExpression, data: D): R
visitComment¶
open fun visitComment(comment: @NotNull PsiComment)
visitCompanionBlock¶
open fun visitCompanionBlock(@NotNull companionBlock: KtCompanionBlock, data: D): R
visitConstantExpression¶
open fun visitConstantExpression(@NotNull expression: KtConstantExpression, data: D): R
visitConstructor¶
open fun visitConstructor(@NotNull constructor: KtConstructor<*>, data: D): R
visitConstructorCalleeExpression¶
open fun visitConstructorCalleeExpression(@NotNull constructorCalleeExpression: KtConstructorCalleeExpression, data: D): R
visitConstructorDelegationCall¶
open fun visitConstructorDelegationCall(@NotNull call: KtConstructorDelegationCall, data: D): R
visitContextParameterList¶
open fun visitContextParameterList(@NotNull contextParameterList: KtContextParameterList, data: D): R
visitContextReceiver¶
open fun visitContextReceiver(@NotNull contextReceiver: KtContextReceiver, data: D): R
visitContextReceiverList¶
open fun visitContextReceiverList(@NotNull contextReceiverList: KtContextReceiverList, data: D): R
The visitor returns null since KtContextReceiverList invoke both visitContextParameterList and visitContextReceiverList. Because of this, the visitor implementation must not implement both methods at the same time.
visitContinueExpression¶
open fun visitContinueExpression(@NotNull expression: KtContinueExpression, data: D): R
visitDeclaration¶
open fun visitDeclaration(@NotNull dcl: KtDeclaration, data: D): R
visitDelegatedSuperTypeEntry¶
open fun visitDelegatedSuperTypeEntry(@NotNull specifier: KtDelegatedSuperTypeEntry, data: D): R
visitDestructuringDeclaration¶
open fun visitDestructuringDeclaration(@NotNull multiDeclaration: KtDestructuringDeclaration, data: D): R
visitDestructuringDeclarationEntry¶
open fun visitDestructuringDeclarationEntry(@NotNull multiDeclarationEntry: KtDestructuringDeclarationEntry, data: D): R
visitDirectory¶
open fun visitDirectory(dir: @NotNull PsiDirectory)
visitDotQualifiedExpression¶
open fun visitDotQualifiedExpression(@NotNull expression: KtDotQualifiedExpression, data: D): R
visitDoubleColonExpression¶
open fun visitDoubleColonExpression(@NotNull expression: KtDoubleColonExpression, data: D): R
visitDoWhileExpression¶
open fun visitDoWhileExpression(@NotNull expression: KtDoWhileExpression, data: D): R
visitDynamicType¶
open fun visitDynamicType(@NotNull type: KtDynamicType, data: D): R
visitElement¶
open fun visitElement(element: @NotNull PsiElement)
visitEnumEntry¶
open fun visitEnumEntry(@NotNull enumEntry: KtEnumEntry, data: D): R
visitErrorElement¶
open fun visitErrorElement(element: @NotNull PsiErrorElement)
visitErrorSafeQualifiedExpression¶
open fun visitErrorSafeQualifiedExpression(@NotNull expression: KtErrorSafeQualifiedExpression, data: D): R
visitEscapeStringTemplateEntry¶
open fun visitEscapeStringTemplateEntry(@NotNull entry: KtEscapeStringTemplateEntry, data: D): R
visitExpression¶
open fun visitExpression(@NotNull expression: KtExpression, data: D): R
visitExpressionWithLabel¶
open fun visitExpressionWithLabel(@NotNull expression: KtExpressionWithLabel, data: D): R
visitFile¶
open fun visitFile(psiFile: @NotNull PsiFile)
visitFileAnnotationList¶
open fun visitFileAnnotationList(@NotNull fileAnnotationList: KtFileAnnotationList, data: D): R
visitFinallySection¶
open fun visitFinallySection(@NotNull finallySection: KtFinallySection, data: D): R
visitForExpression¶
open fun visitForExpression(@NotNull expression: KtForExpression, data: D): R
visitFunctionType¶
open fun visitFunctionType(@NotNull type: KtFunctionType, data: D): R
visitIfExpression¶
open fun visitIfExpression(@NotNull expression: KtIfExpression, data: D): R
visitImportAlias¶
open fun visitImportAlias(@NotNull importAlias: KtImportAlias, data: D): R
visitImportDirective¶
open fun visitImportDirective(@NotNull importDirective: KtImportDirective, data: D): R
visitImportList¶
open fun visitImportList(@NotNull importList: KtImportList, data: D): R
visitInitializerList¶
open fun visitInitializerList(@NotNull list: KtInitializerList, data: D): R
visitIntersectionType¶
open fun visitIntersectionType(@NotNull definitelyNotNullType: KtIntersectionType, data: D): R
visitIsExpression¶
open fun visitIsExpression(@NotNull expression: KtIsExpression, data: D): R
visitKtCommonFile¶
fun visitKtCommonFile(@NotNull file: KtCommonFile): R
Required for KtCommonFile implementation. It is not expected to be used, because KtCommonFile should not be used directly.
visitKtElement¶
open fun visitKtElement(@NotNull element: KtElement, data: D): R
visitKtFile¶
open fun visitKtFile(@NotNull file: KtFile, data: D): R
visitLabeledExpression¶
open fun visitLabeledExpression(@NotNull expression: KtLabeledExpression, data: D): R
visitLambdaExpression¶
open fun visitLambdaExpression(@NotNull expression: KtLambdaExpression, data: D): R
visitLiteralStringTemplateEntry¶
open fun visitLiteralStringTemplateEntry(@NotNull entry: KtLiteralStringTemplateEntry, data: D): R
visitLoopExpression¶
open fun visitLoopExpression(@NotNull loopExpression: KtLoopExpression, data: D): R
visitModifierList¶
open fun visitModifierList(@NotNull list: KtModifierList, data: D): R
visitNamedDeclaration¶
open fun visitNamedDeclaration(@NotNull declaration: KtNamedDeclaration, data: D): R
visitNamedFunction¶
open fun visitNamedFunction(@NotNull function: KtNamedFunction, data: D): R
visitNullableType¶
open fun visitNullableType(@NotNull nullableType: KtNullableType, data: D): R
visitObjectDeclaration¶
open fun visitObjectDeclaration(@NotNull declaration: KtObjectDeclaration, data: D): R
visitObjectLiteralExpression¶
open fun visitObjectLiteralExpression(@NotNull expression: KtObjectLiteralExpression, data: D): R
visitOuterLanguageElement¶
open fun visitOuterLanguageElement(element: @NotNull OuterLanguageElement)
visitPackageDirective¶
open fun visitPackageDirective(@NotNull directive: KtPackageDirective, data: D): R
visitParameter¶
open fun visitParameter(@NotNull parameter: KtParameter, data: D): R
visitParameterList¶
open fun visitParameterList(@NotNull list: KtParameterList, data: D): R
visitParenthesizedExpression¶
open fun visitParenthesizedExpression(@NotNull expression: KtParenthesizedExpression, data: D): R
visitPlainText¶
open fun visitPlainText(content: @NotNull PsiPlainText)
visitPlainTextFile¶
open fun visitPlainTextFile(file: @NotNull PsiPlainTextFile)
visitPostfixExpression¶
open fun visitPostfixExpression(@NotNull expression: KtPostfixExpression, data: D): R
visitPrefixExpression¶
open fun visitPrefixExpression(@NotNull expression: KtPrefixExpression, data: D): R
visitPrimaryConstructor¶
open fun visitPrimaryConstructor(@NotNull constructor: KtPrimaryConstructor, data: D): R
visitProperty¶
open fun visitProperty(@NotNull property: KtProperty, data: D): R
visitPropertyAccessor¶
open fun visitPropertyAccessor(@NotNull accessor: KtPropertyAccessor, data: D): R
visitPropertyDelegate¶
open fun visitPropertyDelegate(@NotNull delegate: KtPropertyDelegate, data: D): R
visitQualifiedExpression¶
open fun visitQualifiedExpression(@NotNull expression: KtQualifiedExpression, data: D): R
visitReferenceExpression¶
open fun visitReferenceExpression(@NotNull expression: KtReferenceExpression, data: D): R
visitReturnExpression¶
open fun visitReturnExpression(@NotNull expression: KtReturnExpression, data: D): R
visitSafeQualifiedExpression¶
open fun visitSafeQualifiedExpression(@NotNull expression: KtSafeQualifiedExpression, data: D): R
visitScript¶
open fun visitScript(@NotNull script: KtScript, data: D): R
visitScriptInitializer¶
open fun visitScriptInitializer(@NotNull initializer: KtScriptInitializer, data: D): R
visitSecondaryConstructor¶
open fun visitSecondaryConstructor(@NotNull constructor: KtSecondaryConstructor, data: D): R
visitSimpleNameExpression¶
open fun visitSimpleNameExpression(@NotNull expression: KtSimpleNameExpression, data: D): R
visitSimpleNameStringTemplateEntry¶
open fun visitSimpleNameStringTemplateEntry(@NotNull entry: KtSimpleNameStringTemplateEntry, data: D): R
visitStringInterpolationPrefix¶
open fun visitStringInterpolationPrefix(@NotNull prefix: KtStringInterpolationPrefix, data: D): R
See also
visitStringTemplateEntry¶
open fun visitStringTemplateEntry(@NotNull entry: KtStringTemplateEntry, data: D): R
visitStringTemplateEntryWithExpression¶
open fun visitStringTemplateEntryWithExpression(@NotNull entry: KtStringTemplateEntryWithExpression, data: D): R
visitStringTemplateExpression¶
open fun visitStringTemplateExpression(@NotNull expression: KtStringTemplateExpression, data: D): R
visitSuperExpression¶
open fun visitSuperExpression(@NotNull expression: KtSuperExpression, data: D): R
visitSuperTypeCallEntry¶
open fun visitSuperTypeCallEntry(@NotNull call: KtSuperTypeCallEntry, data: D): R
visitSuperTypeEntry¶
open fun visitSuperTypeEntry(@NotNull specifier: KtSuperTypeEntry, data: D): R
visitSuperTypeList¶
open fun visitSuperTypeList(@NotNull list: KtSuperTypeList, data: D): R
visitSuperTypeListEntry¶
open fun visitSuperTypeListEntry(@NotNull specifier: KtSuperTypeListEntry, data: D): R
visitThisExpression¶
open fun visitThisExpression(@NotNull expression: KtThisExpression, data: D): R
visitThrowExpression¶
open fun visitThrowExpression(@NotNull expression: KtThrowExpression, data: D): R
visitTryExpression¶
open fun visitTryExpression(@NotNull expression: KtTryExpression, data: D): R
visitTypeAlias¶
open fun visitTypeAlias(@NotNull typeAlias: KtTypeAlias, data: D): R
visitTypeArgumentList¶
open fun visitTypeArgumentList(@NotNull typeArgumentList: KtTypeArgumentList, data: D): R
visitTypeConstraint¶
open fun visitTypeConstraint(@NotNull constraint: KtTypeConstraint, data: D): R
visitTypeConstraintList¶
open fun visitTypeConstraintList(@NotNull list: KtTypeConstraintList, data: D): R
visitTypeParameter¶
open fun visitTypeParameter(@NotNull parameter: KtTypeParameter, data: D): R
visitTypeParameterList¶
open fun visitTypeParameterList(@NotNull list: KtTypeParameterList, data: D): R
visitTypeProjection¶
open fun visitTypeProjection(@NotNull typeProjection: KtTypeProjection, data: D): R
visitTypeReference¶
open fun visitTypeReference(@NotNull typeReference: KtTypeReference, data: D): R
visitUnaryExpression¶
open fun visitUnaryExpression(@NotNull expression: KtUnaryExpression, data: D): R
visitUnionType¶
open fun visitUnionType(@NotNull unionType: KtUnionType, data: D): R
visitUserType¶
open fun visitUserType(@NotNull type: KtUserType, data: D): R
visitValueArgumentList¶
open fun visitValueArgumentList(@NotNull list: KtValueArgumentList, data: D): R
visitWhenConditionInRange¶
open fun visitWhenConditionInRange(@NotNull condition: KtWhenConditionInRange, data: D): R
visitWhenConditionIsPattern¶
open fun visitWhenConditionIsPattern(@NotNull condition: KtWhenConditionIsPattern, data: D): R
visitWhenConditionWithExpression¶
open fun visitWhenConditionWithExpression(@NotNull condition: KtWhenConditionWithExpression, data: D): R
visitWhenEntry¶
open fun visitWhenEntry(@NotNull ktWhenEntry: KtWhenEntry, data: D): R
visitWhenExpression¶
open fun visitWhenExpression(@NotNull expression: KtWhenExpression, data: D): R
visitWhileExpression¶
open fun visitWhileExpression(@NotNull expression: KtWhileExpression, data: D): R
visitWhiteSpace¶
open fun visitWhiteSpace(space: @NotNull PsiWhiteSpace)