SwiftSemantics Documentation Beta

Class Declaration​Collector

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"
%3 DeclarationCollector DeclarationCollector SyntaxVisitor SyntaxVisitor DeclarationCollector->SyntaxVisitor

Conforms To

SyntaxVisitor

Initializers

init()

public override init()

Creates a new declaration collector.

Properties

associated​Types

var associatedTypes: [AssociatedType] = []

The collected associated type declarations.

classes

var classes: [Class] = []

The collected class declarations.

conditional​Compilation​Blocks

var conditionalCompilationBlocks: [ConditionalCompilationBlock] = []

The collected conditional compilation block declarations.

deinitializers

var deinitializers: [Deinitializer] = []

The collected deinitializer declarations.

enumerations

var enumerations: [Enumeration] = []

The collected enumeration declarations.

enumeration​Cases

var enumerationCases: [Enumeration.Case] = []

The collected enumeration case declarations.

extensions

var extensions: [Extension] = []

The collected extension declarations.

functions

var functions: [Function] = []

The collected function declarations.

imports

var imports: [Import] = []

The collected import declarations.

initializers

var initializers: [Initializer] = []

The collected initializer declarations.

operators

var operators: [Operator] = []

The collected operator declarations.

precedence​Groups

var precedenceGroups: [PrecedenceGroup] = []

The collected precedence group declarations.

protocols

var protocols: [Protocol] = []

The collected protocol declarations.

structures

var structures: [Structure] = []

The collected structure declarations.

subscripts

var subscripts: [Subscript] = []

The collected subscript declarations.

typealiases

var typealiases: [Typealias] = []

The collected type alias declarations.

variables

var variables: [Variable] = []

The collected variable 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