MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / objcSelectorForSwiftMethod

Function objcSelectorForSwiftMethod

src/resolution/swift-objc-bridge.ts:76–100  ·  view source on GitHub ↗
(
  baseName: string,
  externalLabels: (string | null)[],
  explicitObjcName?: string | null
)

Source from the content-addressed store, hash-verified

74 * Initializer rules are handled by `objcSelectorForSwiftInit`.
75 */
76export function objcSelectorForSwiftMethod(
77 baseName: string,
78 externalLabels: (string | null)[],
79 explicitObjcName?: string | null
80): string | null {
81 if (!baseName) return null;
82 if (explicitObjcName) return explicitObjcName;
83
84 if (externalLabels.length === 0) {
85 return baseName;
86 }
87
88 const [first, ...rest] = externalLabels;
89 // Single param: "_" → "base:" ; "label" → "baseWithLabel:"
90 // Multi-param mirrors the same first-keyword formation, then appends each
91 // subsequent label as its own keyword. A `null` later label is invalid
92 // ObjC (no way to express unlabeled middle params) — keep as `:` to be safe.
93 const firstKeyword =
94 first === null || first === undefined || first === '_' || first === ''
95 ? `${baseName}:`
96 : `${baseName}With${capFirst(first)}:`;
97
98 const restKeywords = rest.map((l) => `${l ?? ''}:`).join('');
99 return firstKeyword + restKeywords;
100}
101
102/**
103 * Compute the bridged ObjC selector for a Swift `init(...)` declaration.

Callers 1

Calls 2

capFirstFunction · 0.85
joinMethod · 0.45

Tested by

no test coverage detected