File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -145,6 +145,46 @@ struct Extractor {
145145 func extractAccessLevel( from protocolDeclSyntax: ProtocolDeclSyntax ) -> DeclModifierSyntax ? {
146146 protocolDeclSyntax. modifiers. first ( where: \. name. isAccessLevelSupportedInProtocol)
147147 }
148+
149+ func extractInheritedTypes(
150+ from attribute: AttributeSyntax ,
151+ in context: some MacroExpansionContext
152+ ) -> String ? {
153+ guard case let . argumentList( argumentList) = attribute. arguments else {
154+ // No arguments are present in the attribute.
155+ return nil
156+ }
157+
158+ let inheritedTypesArgument = argumentList. first { argument in
159+ argument. label? . text == " inheritedTypes "
160+ }
161+
162+ guard let inheritedTypesArgument else {
163+ // The `inheritedTypes` argument is missing.
164+ return nil
165+ }
166+
167+ let segments = inheritedTypesArgument. expression
168+ . as ( StringLiteralExprSyntax . self) ?
169+ . segments
170+
171+ guard let segments,
172+ segments. count == 1 ,
173+ case let . stringSegment( literalSegment) ? = segments. first
174+ else {
175+ // The `inheritedTypes` argument's value is not a static string literal.
176+ context. diagnose (
177+ Diagnostic (
178+ node: attribute,
179+ message: SpyableDiagnostic . behindPreprocessorFlagArgumentRequiresStaticStringLiteral,
180+ highlights: [ Syntax ( inheritedTypesArgument. expression) ]
181+ )
182+ )
183+ return nil
184+ }
185+
186+ return literalSegment. content. text
187+ }
148188}
149189
150190extension TokenSyntax {
You can’t perform that action at this time.
0 commit comments