Skip to content

Commit 1a48bb4

Browse files
authored
Merge pull request #6 from mkowalski87/main
small code refactoring
2 parents 6136060 + 0ebc626 commit 1a48bb4

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Sources/XCTestParametrizedMacroMacros/MacroDeclarationHelper.swift

+11
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ struct MacroDeclarationHelper {
88
self.declaration = declaration
99
}
1010

11+
12+
/// Returns 'TokenSyntax' representing name of the input parameter.
13+
var inputParamName: TokenSyntax? {
14+
declaration.signature.input.parameterList.first?.secondName
15+
}
16+
17+
/// Returns 'TypeSyntax' representing type of the input object.
18+
var inputParamType: TypeSyntax? {
19+
declaration.signature.input.parameterList.first?.type
20+
}
21+
1122
var firstAttribute: AttributeSyntax? {
1223
return declaration.attributes.first?.as(AttributeSyntax.self)
1324
}

Sources/XCTestParametrizedMacroMacros/XCTestParametrizedMacroMacro.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public struct ParametrizeMacro: PeerMacro {
1818
let macroDeclarationHelper = MacroDeclarationHelper(declaration)
1919

2020
let funcName = declaration.identifier
21-
guard let inputParamName = declaration.signature.input.parameterList.first?.secondName?.text else {
21+
guard let inputParamName = macroDeclarationHelper.inputParamName?.text else {
2222
throw ParametrizeMacroError.functionInputParamSecondNameMissing
2323
}
2424

25-
guard let inputParamType = declaration.signature.input.parameterList.first?.type else {
25+
guard let inputParamType = macroDeclarationHelper.inputParamType else {
2626
throw ParametrizeMacroError.functionInputParamTypeMissing
2727
}
2828

0 commit comments

Comments
 (0)