Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

DeclarationCollector

Mattt edited this page Aug 2, 2020 · 6 revisions

DeclarationCollector

A Swift syntax visitor that collects declarations.

open class DeclarationCollector:​ SyntaxVisitor

Create an instance of DeclarationCollector and pass it by reference when walking an AST created by SyntaxParser to collect any visited declarations:​

import SwiftSyntax
import SwiftSemantics

let source = #"enum E {}"#

var collector = DeclarationCollector()
let tree = try SyntaxParser.parse(source:​ source)
tree.walk(&collector)

collector.enumerations.first?.name // "E"

Inheritance

SyntaxVisitor

Initializers

init()

Creates a new declaration collector.

public override init()

Properties

associatedTypes

The collected associated type declarations.

var associatedTypes:[AssociatedType] = []

classes

The collected class declarations.

var classes:[Class] = []

conditionalCompilationBlocks

The collected conditional compilation block declarations.

var conditionalCompilationBlocks:[ConditionalCompilationBlock] = []

deinitializers

The collected deinitializer declarations.

var deinitializers:[Deinitializer] = []

enumerations

The collected enumeration declarations.

var enumerations:[Enumeration] = []

enumerationCases

The collected enumeration case declarations.

var enumerationCases:[Enumeration.Case] = []

extensions

The collected extension declarations.

var extensions:[Extension] = []

functions

The collected function declarations.

var functions:[Function] = []

imports

The collected import declarations.

var imports:[Import] = []

initializers

The collected initializer declarations.

var initializers:[Initializer] = []

operators

The collected operator declarations.

var operators:[Operator] = []

precedenceGroups

The collected precedence group declarations.

var precedenceGroups:[PrecedenceGroup] = []

protocols

The collected protocol declarations.

var protocols:[Protocol] = []

structures

The collected structure declarations.

var structures:[Structure] = []

subscripts

The collected subscript declarations.

var subscripts:[Subscript] = []

typealiases

The collected type alias declarations.

var typealiases:[Typealias] = []

variables

The collected variable declarations.

var variables:[Variable] = []

Methods

visit(_:​)

Called when visiting an AssociatedtypeDeclSyntax node

public override func visit(_ node:​ AssociatedtypeDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting a ClassDeclSyntax node

public override func visit(_ node:​ ClassDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting a DeinitializerDeclSyntax node

public override func visit(_ node:​ DeinitializerDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting an EnumDeclSyntax node

public override func visit(_ node:​ EnumDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting an EnumCaseDeclSyntax node

public override func visit(_ node:​ EnumCaseDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting an ExtensionDeclSyntax node

public override func visit(_ node:​ ExtensionDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting a FunctionDeclSyntax node

public override func visit(_ node:​ FunctionDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting an IfConfigDeclSyntax node

public override func visit(_ node:​ IfConfigDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting an ImportDeclSyntax node

public override func visit(_ node:​ ImportDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting an InitializerDeclSyntax node

public override func visit(_ node:​ InitializerDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting an OperatorDeclSyntax node

public override func visit(_ node:​ OperatorDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting a PrecedenceGroupDeclSyntax node

public override func visit(_ node:​ PrecedenceGroupDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting a ProtocolDeclSyntax node

public override func visit(_ node:​ ProtocolDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting a SubscriptDeclSyntax node

public override func visit(_ node:​ SubscriptDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting a StructDeclSyntax node

public override func visit(_ node:​ StructDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting a TypealiasDeclSyntax node

public override func visit(_ node:​ TypealiasDeclSyntax) -> SyntaxVisitorContinueKind

visit(_:​)

Called when visiting a VariableDeclSyntax node

public override func visit(_ node:​ VariableDeclSyntax) -> SyntaxVisitorContinueKind
Clone this wiki locally