Build ObjC selector: `greet`, `doThing:`, or `doThing:with:`.
(node: SyntaxNode, source: string)
| 22 | |
| 23 | /** Build ObjC selector: `greet`, `doThing:`, or `doThing:with:`. */ |
| 24 | function extractObjcMethodName(node: SyntaxNode, source: string): string | undefined { |
| 25 | if (node.type !== 'method_definition' && node.type !== 'method_declaration') { |
| 26 | return undefined; |
| 27 | } |
| 28 | |
| 29 | const identifiers = node.namedChildren.filter((c) => c.type === 'identifier'); |
| 30 | if (identifiers.length === 0) return undefined; |
| 31 | |
| 32 | const hasParameters = node.namedChildren.some((c) => c.type === 'method_parameter'); |
| 33 | const firstIdentifier = identifiers[0]; |
| 34 | if (!firstIdentifier) return undefined; |
| 35 | if (!hasParameters) { |
| 36 | return getNodeText(firstIdentifier, source); |
| 37 | } |
| 38 | |
| 39 | return identifiers.map((id) => `${getNodeText(id, source)}:`).join(''); |
| 40 | } |
| 41 | |
| 42 | /** Nullability / ARC qualifiers that sit where a return type's first type |
| 43 | * identifier does (`(nonnull instancetype)`, `(nullable Bar *)`) — never the type. */ |
no test coverage detected