Skip to content

Commit

Permalink
Merge pull request #6 from mkowalski87/main
Browse files Browse the repository at this point in the history
small code refactoring
  • Loading branch information
mkowalski87 authored Nov 8, 2023
2 parents 6136060 + 0ebc626 commit 1a48bb4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions Sources/XCTestParametrizedMacroMacros/MacroDeclarationHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ struct MacroDeclarationHelper {
self.declaration = declaration
}


/// Returns 'TokenSyntax' representing name of the input parameter.
var inputParamName: TokenSyntax? {
declaration.signature.input.parameterList.first?.secondName
}

/// Returns 'TypeSyntax' representing type of the input object.
var inputParamType: TypeSyntax? {
declaration.signature.input.parameterList.first?.type
}

var firstAttribute: AttributeSyntax? {
return declaration.attributes.first?.as(AttributeSyntax.self)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public struct ParametrizeMacro: PeerMacro {
let macroDeclarationHelper = MacroDeclarationHelper(declaration)

let funcName = declaration.identifier
guard let inputParamName = declaration.signature.input.parameterList.first?.secondName?.text else {
guard let inputParamName = macroDeclarationHelper.inputParamName?.text else {
throw ParametrizeMacroError.functionInputParamSecondNameMissing
}

guard let inputParamType = declaration.signature.input.parameterList.first?.type else {
guard let inputParamType = macroDeclarationHelper.inputParamType else {
throw ParametrizeMacroError.functionInputParamTypeMissing
}

Expand Down

0 comments on commit 1a48bb4

Please sign in to comment.