Class
DeclarationCollector
open class DeclarationCollector: SyntaxVisitor
A Swift syntax visitor that collects declarations.
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"
Relationships
Conforms To
SyntaxVisitor
Initializers
init()
public override init()
Creates a new declaration collector.
Properties
associatedTypes
var associatedTypes: [AssociatedType] = []
The collected associated type declarations.
conditionalCompilationBlocks
var conditionalCompilationBlocks: [ConditionalCompilationBlock] = []
The collected conditional compilation block declarations.
enumerationCases
var enumerationCases: [Enumeration.Case] = []
The collected enumeration case declarations.
precedenceGroups
var precedenceGroups: [PrecedenceGroup] = []
The collected precedence group declarations.
Methods
visit(_:)
public override func visit(_ node: AssociatedtypeDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting an AssociatedtypeDeclSyntax
node
visit(_:)
public override func visit(_ node: ClassDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting a ClassDeclSyntax
node
visit(_:)
public override func visit(_ node: DeinitializerDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting a DeinitializerDeclSyntax
node
visit(_:)
public override func visit(_ node: EnumDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting an EnumDeclSyntax
node
visit(_:)
public override func visit(_ node: EnumCaseDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting an EnumCaseDeclSyntax
node
visit(_:)
public override func visit(_ node: ExtensionDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting an ExtensionDeclSyntax
node
visit(_:)
public override func visit(_ node: FunctionDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting a FunctionDeclSyntax
node
visit(_:)
public override func visit(_ node: IfConfigDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting an IfConfigDeclSyntax
node
visit(_:)
public override func visit(_ node: ImportDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting an ImportDeclSyntax
node
visit(_:)
public override func visit(_ node: InitializerDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting an InitializerDeclSyntax
node
visit(_:)
public override func visit(_ node: OperatorDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting an OperatorDeclSyntax
node
visit(_:)
public override func visit(_ node: PrecedenceGroupDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting a PrecedenceGroupDeclSyntax
node
visit(_:)
public override func visit(_ node: ProtocolDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting a ProtocolDeclSyntax
node
visit(_:)
public override func visit(_ node: SubscriptDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting a SubscriptDeclSyntax
node
visit(_:)
public override func visit(_ node: StructDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting a StructDeclSyntax
node
visit(_:)
public override func visit(_ node: TypealiasDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting a TypealiasDeclSyntax
node
visit(_:)
public override func visit(_ node: VariableDeclSyntax) -> SyntaxVisitorContinueKind
Called when visiting a VariableDeclSyntax
node