Pick a base name from the naming context (before deduplication).
(ctx: &NamingContext)
| 408 | |
| 409 | /// Pick a base name from the naming context (before deduplication). |
| 410 | fn derive_base_name(ctx: &NamingContext) -> String { |
| 411 | let enc = ctx.enclosing_name; |
| 412 | |
| 413 | // 1. Guard strategies → {enclosing}Guard |
| 414 | match ctx.return_strategy { |
| 415 | ReturnStrategy::VoidGuards |
| 416 | | ReturnStrategy::UniformGuards(_) |
| 417 | | ReturnStrategy::NullGuardWithValue(_) => { |
| 418 | if !enc.is_empty() { |
| 419 | return format!("{}Guard", enc); |
| 420 | } |
| 421 | return "guard".to_string(); |
| 422 | } |
| 423 | |
| 424 | // 2. SentinelNull → try{Enclosing} |
| 425 | ReturnStrategy::SentinelNull => { |
| 426 | if !enc.is_empty() { |
| 427 | return format!("try{}", capitalise(enc)); |
| 428 | } |
| 429 | return "tryExtract".to_string(); |
| 430 | } |
| 431 | |
| 432 | // 3–4. TrailingReturn |
| 433 | ReturnStrategy::TrailingReturn => { |
| 434 | // 3. Factory: body contains `new ClassName` → create{ClassName} |
| 435 | if let Some(class_name) = detect_factory_pattern(ctx.body_text) { |
| 436 | return format!("create{}", class_name); |
| 437 | } |
| 438 | // 4. Generic trailing return |
| 439 | if !enc.is_empty() { |
| 440 | // If there's a return type, use it for a more descriptive name |
| 441 | if !ctx.trailing_return_type.is_empty() { |
| 442 | // Only use the return type if it's a class name (starts uppercase) |
| 443 | if let Some(name) = ctx.trailing_return_type.base_name() { |
| 444 | return format!("get{}", name); |
| 445 | } |
| 446 | } |
| 447 | return format!("get{}Result", capitalise(enc)); |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | ReturnStrategy::None | ReturnStrategy::Unsafe => {} |
| 452 | } |
| 453 | |
| 454 | // 5. Pure output → render{Enclosing} |
| 455 | if is_pure_output(ctx.body_text) && !enc.is_empty() { |
| 456 | return format!("render{}", capitalise(enc)); |
| 457 | } |
| 458 | |
| 459 | // 6. Single return variable → compute{VarName} |
| 460 | if ctx.return_var_names.len() == 1 { |
| 461 | let var = ctx.return_var_names[0].trim_start_matches('$'); |
| 462 | if !var.is_empty() { |
| 463 | return format!("compute{}", capitalise(var)); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | // 7. Ends with output (setup + echo/print) → render{Enclosing} |
no test coverage detected