Skip to content

Commit c553c29

Browse files
cweillclaude
andcommitted
refactor: remove unused helper functions from models
Removed five unused functions from internal/models/models.go that were added for generics support but are not currently used: - HasGenericReceiver() - not called anywhere - TypeParamMapping() - only used by SubstituteType (also unused) - TypeParamMappings() - not called anywhere - getAlternativeTypes() - only used by TypeParamMappings (also unused) - SubstituteType() - not called anywhere These functions were implemented for potential future use but are not needed for current generics functionality. Removing them: - Reduces maintenance burden - Improves code coverage (removes 109 uncovered lines) - Keeps codebase focused on actively used code All tests continue to pass. Coverage improved as dead code was removed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 88ad3df commit c553c29

File tree

1 file changed

+0
-109
lines changed

1 file changed

+0
-109
lines changed

internal/models/models.go

Lines changed: 0 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -163,115 +163,6 @@ func (f *Function) IsGeneric() bool {
163163
return len(f.TypeParams) > 0
164164
}
165165

166-
func (f *Function) HasGenericReceiver() bool {
167-
return f.Receiver != nil && strings.Contains(f.Receiver.Type.Value, "[")
168-
}
169-
170-
// TypeParamMapping returns a map from type parameter names to concrete types for testing
171-
func (f *Function) TypeParamMapping() map[string]string {
172-
mapping := make(map[string]string)
173-
for _, tp := range f.TypeParams {
174-
mapping[tp.Name] = mapConstraintToConcreteType(tp.Constraint)
175-
}
176-
return mapping
177-
}
178-
179-
// TypeParamMappings returns multiple mappings for generating tests with different type combinations
180-
// Returns a slice of mappings, each representing a different concrete instantiation
181-
func (f *Function) TypeParamMappings() []map[string]string {
182-
if !f.IsGeneric() {
183-
return nil
184-
}
185-
186-
// For now, generate 2-3 variants per type parameter
187-
var allMappings []map[string]string
188-
189-
// Generate the primary mapping (using defaults)
190-
primaryMapping := make(map[string]string)
191-
for _, tp := range f.TypeParams {
192-
primaryMapping[tp.Name] = mapConstraintToConcreteType(tp.Constraint)
193-
}
194-
allMappings = append(allMappings, primaryMapping)
195-
196-
// Generate alternative mappings
197-
// For single type parameter, add 1-2 more variants
198-
if len(f.TypeParams) == 1 {
199-
tp := f.TypeParams[0]
200-
alternatives := getAlternativeTypes(tp.Constraint)
201-
for _, altType := range alternatives {
202-
altMapping := make(map[string]string)
203-
altMapping[tp.Name] = altType
204-
allMappings = append(allMappings, altMapping)
205-
}
206-
}
207-
208-
return allMappings
209-
}
210-
211-
// getAlternativeTypes returns alternative concrete types for a constraint
212-
func getAlternativeTypes(constraint string) []string {
213-
constraint = strings.TrimSpace(constraint)
214-
215-
switch {
216-
case constraint == "any":
217-
return []string{"string"} // Primary is int, alternative is string
218-
case constraint == "comparable":
219-
return []string{"int"} // Primary is string, alternative is int
220-
case strings.Contains(constraint, "|"):
221-
// For union types, return other options beyond the first
222-
parts := strings.Split(constraint, "|")
223-
var alternatives []string
224-
for i := 1; i < len(parts) && i < 3; i++ { // Max 2 alternatives
225-
alternatives = append(alternatives, strings.TrimSpace(parts[i]))
226-
}
227-
return alternatives
228-
default:
229-
return nil
230-
}
231-
}
232-
233-
// mapConstraintToConcreteType maps a constraint to a concrete type
234-
func mapConstraintToConcreteType(constraint string) string {
235-
constraint = strings.TrimSpace(constraint)
236-
237-
switch {
238-
case constraint == "any":
239-
return "int"
240-
case constraint == "comparable":
241-
return "string"
242-
case strings.Contains(constraint, "|"):
243-
// Union type - pick the first option
244-
parts := strings.Split(constraint, "|")
245-
return strings.TrimSpace(parts[0])
246-
case strings.Contains(constraint, "~"):
247-
// Approximation constraint like ~int
248-
constraint = strings.TrimPrefix(constraint, "~")
249-
return strings.TrimSpace(constraint)
250-
default:
251-
return "string"
252-
}
253-
}
254-
255-
// SubstituteType replaces type parameter names in a type string with concrete types
256-
func (f *Function) SubstituteType(typeStr string) string {
257-
if !f.IsGeneric() {
258-
return typeStr
259-
}
260-
261-
result := typeStr
262-
mapping := f.TypeParamMapping()
263-
264-
// Replace each type parameter with its concrete type
265-
// We need to be careful about word boundaries to avoid replacing parts of type names
266-
for paramName, concreteType := range mapping {
267-
// Simple replacement for now - this handles most cases
268-
// More sophisticated parsing would be needed for complex nested types
269-
result = strings.ReplaceAll(result, paramName, concreteType)
270-
}
271-
272-
return result
273-
}
274-
275166
type Import struct {
276167
Name, Path string
277168
}

0 commit comments

Comments
 (0)