---
name: wildcard-import-fixer
description: Converts wildcard imports (e.g., import java.util.*) to specific imports in Kotlin/Java files. Use when fixing wildcard imports, cleaning up imports, or improving code quality.
allowed-tools: Bash, Read, Glob, Grep
---

# Wildcard Import Fixer

Automatically converts wildcard imports to specific imports in Kotlin and Java files by analyzing actual class usage in the code.

## Instructions

### Step 1: Analyze the Request
When a user asks to fix wildcard imports:
1. Determine the scope (entire project, specific directory, or single file)
2. Decide if a dry-run preview is appropriate first
3. Check if backups should be created

### Step 2: Run the Fixer Script
Execute the appropriate command based on the scope:

```bash
# Fix all wildcard imports in the project
kotlinc -script .claude/skills/wildcard-import-fixer/scripts/fix-wildcards.kts

# Fix a specific file
kotlinc -script .claude/skills/wildcard-import-fixer/scripts/fix-wildcards.kts -- --file <path>

# Fix all files in a directory
kotlinc -script .claude/skills/wildcard-import-fixer/scripts/fix-wildcards.kts -- --dir <path>

# Preview changes without modifying files
kotlinc -script .claude/skills/wildcard-import-fixer/scripts/fix-wildcards.kts -- --dry-run

# Fix without creating backups
kotlinc -script .claude/skills/wildcard-import-fixer/scripts/fix-wildcards.kts -- --no-backup
```

### Step 3: Review Results
After running:
1. Check the console output for success/failure status
2. Review the generated HTML report in `.claude/skills/wildcard-import-fixer/reports/`
3. If any wildcards couldn't be resolved, explain why to the user

### Step 4: Handle Edge Cases
- If no usage is detected for a wildcard package, suggest removing the unused import
- For packages not in the built-in mappings, inform the user about limitations
- If the script fails, check that `kotlinc` is installed and accessible

## Examples

### Example 1: Fix All Wildcards in Project
**User:** "Fix all wildcard imports in my project"

**Action:**
```bash
kotlinc -script .claude/skills/wildcard-import-fixer/scripts/fix-wildcards.kts
```

### Example 2: Preview Changes First
**User:** "Can you check what wildcard imports exist?"

**Action:**
```bash
kotlinc -script .claude/skills/wildcard-import-fixer/scripts/fix-wildcards.kts -- --dry-run
```

### Example 3: Fix Specific File
**User:** "Fix wildcards in MainActivity.kt"

**Action:**
```bash
kotlinc -script .claude/skills/wildcard-import-fixer/scripts/fix-wildcards.kts -- --file app/src/main/java/com/example/jsclaude/MainActivity.kt
```

### Example 4: Before and After
**Before:**
```kotlin
import java.util.*
import java.io.*

class Example {
    fun process() {
        val locale = Locale.getDefault()
        val file = File("test.txt")
    }
}
```

**After:**
```kotlin
import java.io.File
import java.util.Locale

class Example {
    fun process() {
        val locale = Locale.getDefault()
        val file = File("test.txt")
    }
}
```

## Supported Packages

The fixer has built-in mappings for:
- `java.util.*` - Collections, Date/Time, Locale, UUID, etc.
- `java.io.*` - File, streams, readers, writers
- `javax.xml.namespace.*` - QName, NamespaceContext
- `org.junit.*` - Test annotations and Assert methods
- `androidx.compose.foundation.layout.*` - Compose layout components
- `androidx.compose.material3.*` - Material 3 components
- `androidx.compose.ui.*` - Compose UI components

## Output Files

- **Backups:** `.claude/skills/wildcard-import-fixer/backups/<timestamp>/`
- **Reports:** `.claude/skills/wildcard-import-fixer/reports/wildcard_fix_<timestamp>.html`

The script automatically keeps only the 5 most recent backups and reports.

## Troubleshooting

| Issue | Solution |
|-------|----------|
| "kotlinc not found" | Install Kotlin compiler via `brew install kotlin` or download from kotlinlang.org |
| No classes detected | The wildcard package may not be in built-in mappings, or classes are used indirectly |
| Script fails to run | Ensure project has `settings.gradle.kts` or `settings.gradle` at root |
