Skip to content

Hack23/RefactorAIOperationsIDE

πŸ”§ RefactorAIOperationsIDE: Bridging AI Intelligence with IDE Refactoring Power

πŸš€ Open-source solution that transforms AI-generated code suggestions into safe, semantic-aware IDE refactoring operations

πŸ“‹ Table of Contents

The Fundamental Flaw: Generative vs Transformative

Approach Method Result Risk Level
πŸ”΄ AI Generative Creates new code from scratch Loses all context, breaks dependencies ⚠️ HIGH
🟑 Text Replacement Find & replace strings Misses semantic meaning ⚠️ MEDIUM
🟒 IDE Refactoring AST transformations Preserves all relationships βœ… ZERO

Key Insight: Current AI assistants GENERATE code instead of TRANSFORMING it, making them fundamentally destructive rather than constructive.

πŸ’‘ The Solution

RefactorAIOperationsIDE: Non-Destructive, Guaranteed-Safe Transformations

graph LR
    subgraph "✨ NON-DESTRUCTIVE Refactoring Flow"
        A[πŸ‘€ Developer Intent] -->|"Natural Language"| B[πŸ€– AI Understanding]
        B -->|"Maps to Operations"| C[πŸ”§ RefactorAI Engine]
        C -->|"IDE Commands"| D[πŸ’» AST Transformations]
        D -->|"Atomic & Safe"| E[βœ… Perfect Result]
        
        style A fill:#74c0fc,stroke:#339af0,color:#fff
        style B fill:#8ce99a,stroke:#51cf66,color:#fff
        style C fill:#ffd43b,stroke:#fab005,color:#000
        style D fill:#a5d8ff,stroke:#4dabf7,color:#000
        style E fill:#8ce99a,stroke:#51cf66,color:#fff
    end
    
    subgraph "πŸ›‘οΈ Safety Guarantees"
        G1[Compilation Success βœ“]
        G2[All Tests Pass βœ“]
        G3[References Updated βœ“]
        G4[Rollback Available βœ“]
        
        style G1 fill:#d3f9d8,stroke:#51cf66
        style G2 fill:#d3f9d8,stroke:#51cf66
        style G3 fill:#d3f9d8,stroke:#51cf66
        style G4 fill:#d3f9d8,stroke:#51cf66
    end
Loading

🎯 Core Principles

1. Always Working Code 🟒

Every refactoring operation MUST result in compilable, working code. No exceptions.

2. Non-Destructive Transformations πŸ›‘οΈ

We TRANSFORM existing code using IDE operations, never GENERATE replacements.

3. Semantic Awareness 🧠

Every operation understands the code's meaning, not just its text.

4. Atomic & Reversible ↩️

All operations can be undone with a single command.

5. Cross-File Consistency πŸ”—

Updates ALL references across the entire codebase automatically.

πŸ”§ Supported Refactoring Operations

Complete Eclipse JDT Refactoring Mapping

mindmap
  root((πŸ”§ IDE Operations))
    πŸ“ Naming & References
      Rename Element
        Methods
        Fields
        Variables
        Types
        Packages
      Update References
        Same File
        Cross File
        JavaDoc
        Comments
    πŸ“¦ Code Organization
      Extract Operations
        Extract Method
        Extract Variable
        Extract Constant
        Extract Class
        Extract Interface
        Extract Superclass
      Introduce Operations
        Parameter Object
        Factory Method
        Indirection
        Parameter
    πŸš€ Code Movement
      Move Operations
        Move Method
        Move Type
        Move Package
        Move Static Members
      Hierarchy Changes
        Pull Up
        Push Down
        Extract Interface
        Use Supertype
    πŸ”„ Structural Changes
      Method Signature
        Add Parameter
        Remove Parameter
        Change Return Type
        Reorder Parameters
      Inline Operations
        Inline Method
        Inline Variable
        Inline Constant
      Encapsulation
        Encapsulate Field
        Generate Getters/Setters
    🎯 Advanced Patterns
      Dependency Breaking
        Extract Interface
        Dependency Inversion
        Introduce Facade
      Design Patterns
        Factory Pattern
        Builder Pattern
        Strategy Pattern
      Cycle Resolution
        Package Restructuring
        Layer Separation
        Module Extraction
Loading

Refactoring Safety Matrix

graph TB
    subgraph "🟒 SAFE Operations - Always Non-Destructive"
        S1[βœ… Rename with References]
        S2[βœ… Extract Method]
        S3[βœ… Move with Updates]
        S4[βœ… Change Signature]
        S5[βœ… Extract Interface]
        
        style S1 fill:#8ce99a,stroke:#51cf66
        style S2 fill:#8ce99a,stroke:#51cf66
        style S3 fill:#8ce99a,stroke:#51cf66
        style S4 fill:#8ce99a,stroke:#51cf66
        style S5 fill:#8ce99a,stroke:#51cf66
    end
    
    subgraph "🟑 VALIDATED Operations - Checked Before Execution"
        V1[⚠️ Inline Method]
        V2[⚠️ Pull Up Method]
        V3[⚠️ Push Down Field]
        
        style V1 fill:#fff3bf,stroke:#fab005
        style V2 fill:#fff3bf,stroke:#fab005
        style V3 fill:#fff3bf,stroke:#fab005
    end
    
    subgraph "πŸ”΄ NEVER - Destructive Anti-Patterns"
        D1[❌ Delete & Recreate]
        D2[❌ String Replace]
        D3[❌ Manual Edit]
        
        style D1 fill:#ffe3e3,stroke:#ff6b6b
        style D2 fill:#ffe3e3,stroke:#ff6b6b
        style D3 fill:#ffe3e3,stroke:#ff6b6b
    end
Loading

πŸ—οΈ Architecture

System Components

graph TB
    subgraph "🎨 User Interface Layer"
        UI[IDE Plugin UI]
        CLI[CLI Interface]
        API[REST API]
    end
    
    subgraph "🧠 Intelligence Layer"
        INT[Intent Analyzer]
        MAP[Operation Mapper]
        VAL[Validation Engine]
    end
    
    subgraph "πŸ”§ Execution Layer"
        MCP[MCP Server]
        ADAPT[IDE Adapters]
        EXEC[Refactoring Executor]
        ROLL[Rollback Manager]
    end
    
    subgraph "πŸ›‘οΈ Safety Layer"
        PRE[Pre-conditions Check]
        POST[Post-conditions Verify]
        TEST[Test Runner]
        COMP[Compiler Check]
    end
    
    UI --> INT
    INT --> MAP
    MAP --> VAL
    VAL --> PRE
    PRE --> MCP
    MCP --> ADAPT
    ADAPT --> EXEC
    EXEC --> POST
    POST --> TEST
    TEST --> COMP
    
    style UI fill:#ffd43b,stroke:#fab005
    style INT fill:#74c0fc,stroke:#339af0
    style PRE fill:#ff8cc3,stroke:#f06595
    style EXEC fill:#8ce99a,stroke:#51cf66
Loading

RefactorAI: Intelligence Meets Precision

graph LR
    subgraph "✨ RefactorAI Solution"
        A[πŸ‘€ Developer Intent] -->|"Natural Language"| B[πŸ€– AI Analysis]
        B -->|"MCP Protocol"| C[πŸ”§ RefactorAI Engine]
        C -->|"IDE Commands"| D[πŸ’» Native IDE Operations]
        D -->|"Safe Refactoring"| E[βœ… Clean Code]
        
        style A fill:#74c0fc,stroke:#339af0,color:#fff
        style B fill:#8ce99a,stroke:#51cf66,color:#fff
        style C fill:#ffd43b,stroke:#fab005,color:#000
        style D fill:#a5d8ff,stroke:#4dabf7,color:#000
        style E fill:#8ce99a,stroke:#51cf66,color:#fff
    end
Loading

Core Innovation

RefactorAI acts as an intelligent bridge between AI language models and IDE refactoring engines:

  1. 🧠 Understands Intent: AI interprets what you want to achieve
  2. 🎯 Maps to Operations: Translates intent to specific IDE refactoring commands
  3. ⚑ Executes Safely: Uses native IDE operations with full semantic awareness
  4. βœ… Guarantees Consistency: All references updated, no broken code

🎯 Key Features

Intelligent Refactoring Operations

mindmap
  root((πŸ”§ RefactorAI))
    🎯 Core Refactorings
      πŸ“ Rename
        Types
        Methods
        Variables
        Packages
      πŸ“¦ Extract
        Method
        Interface
        Superclass
        Variable
      πŸš€ Move
        Class
        Method
        Package
      πŸ”„ Transform
        Inline
        Pull Up
        Push Down
    🧠 Advanced Features
      πŸ” Cycle Detection
        Package cycles
        Class dependencies
        Import analysis
      πŸ—οΈ Architecture
        Layer violations
        Pattern detection
        SOLID compliance
      πŸ“Š Analytics
        Tech debt scoring
        Complexity metrics
        Impact analysis
    πŸ”Œ Integrations
      πŸ’» IDEs
        Eclipse
        IntelliJ
        VS Code
        Visual Studio
      πŸ€– AI Models
        GitHub Copilot
        Claude
        GPT-4
        Local LLMs
      πŸ”§ Tools
        Git
        Maven/Gradle
        CI/CD
Loading

Supported Refactoring Operations

graph TB
    subgraph "πŸ”§ Basic Refactorings"
        R1[🏷️ Rename]
        R2[πŸ“€ Extract Method]
        R3[πŸ“₯ Inline]
        R4[🚚 Move]
        
        style R1 fill:#e3f2fd,stroke:#2196f3,color:#0d47a1
        style R2 fill:#e3f2fd,stroke:#2196f3,color:#0d47a1
        style R3 fill:#e3f2fd,stroke:#2196f3,color:#0d47a1
        style R4 fill:#e3f2fd,stroke:#2196f3,color:#0d47a1
    end
    
    subgraph "πŸ—οΈ Structural Refactorings"
        S1[πŸ”Ί Extract Superclass]
        S2[πŸ”» Extract Interface]
        S3[⬆️ Pull Up]
        S4[⬇️ Push Down]
        
        style S1 fill:#f3e5f5,stroke:#9c27b0,color:#4a148c
        style S2 fill:#f3e5f5,stroke:#9c27b0,color:#4a148c
        style S3 fill:#f3e5f5,stroke:#9c27b0,color:#4a148c
        style S4 fill:#f3e5f5,stroke:#9c27b0,color:#4a148c
    end
    
    subgraph "🎯 Advanced Refactorings"
        A1[πŸ”„ Break Cycles]
        A2[πŸ“¦ Parameter Object]
        A3[🏭 Introduce Factory]
        A4[🎭 Introduce Facade]
        
        style A1 fill:#e8f5e9,stroke:#4caf50,color:#1b5e20
        style A2 fill:#e8f5e9,stroke:#4caf50,color:#1b5e20
        style A3 fill:#e8f5e9,stroke:#4caf50,color:#1b5e20
        style A4 fill:#e8f5e9,stroke:#4caf50,color:#1b5e20
    end
Loading

πŸ—οΈ Architecture

System Components

graph TB
    subgraph "🎨 Frontend Layer"
        UI[IDE Plugin UI]
        CLI[CLI Interface]
        API[REST API]
    end
    
    subgraph "🧠 Intelligence Layer"
        INT[Intent Analyzer]
        SMELL[Code Smell Detector]
        PLAN[Refactoring Planner]
    end
    
    subgraph "πŸ”§ Execution Layer"
        MCP[MCP Server]
        ADAPT[IDE Adapters]
        EXEC[Refactoring Executor]
    end
    
    subgraph "πŸ’Ύ Data Layer"
        HIST[History Store]
        METR[Metrics DB]
        CONF[Configuration]
    end
    
    UI --> INT
    CLI --> INT
    API --> INT
    INT --> SMELL
    SMELL --> PLAN
    PLAN --> MCP
    MCP --> ADAPT
    ADAPT --> EXEC
    EXEC --> HIST
    EXEC --> METR
    
    style UI fill:#ffd43b,stroke:#fab005
    style INT fill:#74c0fc,stroke:#339af0
    style MCP fill:#8ce99a,stroke:#51cf66
    style EXEC fill:#ff8cc3,stroke:#f06595
Loading

πŸ“Š Refactoring Operations

Operation Categories & Capabilities

graph LR
    subgraph "🎯 Scope & Naming"
        REN[Rename]
        REN --> REN1[Variables]
        REN --> REN2[Methods]
        REN --> REN3[Classes]
        REN --> REN4[Packages]
        
        style REN fill:#e1f5fe,stroke:#03a9f4
        style REN1 fill:#b3e5fc,stroke:#03a9f4
        style REN2 fill:#b3e5fc,stroke:#03a9f4
        style REN3 fill:#b3e5fc,stroke:#03a9f4
        style REN4 fill:#b3e5fc,stroke:#03a9f4
    end
    
    subgraph "πŸ“¦ Code Organization"
        EXT[Extract]
        EXT --> EXT1[Method]
        EXT --> EXT2[Variable]
        EXT --> EXT3[Interface]
        EXT --> EXT4[Superclass]
        
        style EXT fill:#f3e5f5,stroke:#9c27b0
        style EXT1 fill:#e1bee7,stroke:#9c27b0
        style EXT2 fill:#e1bee7,stroke:#9c27b0
        style EXT3 fill:#e1bee7,stroke:#9c27b0
        style EXT4 fill:#e1bee7,stroke:#9c27b0
    end
    
    subgraph "πŸ”„ Dependency Management"
        CYC[Break Cycles]
        CYC --> CYC1[Package Level]
        CYC --> CYC2[Class Level]
        CYC --> CYC3[Method Level]
        
        style CYC fill:#e8f5e9,stroke:#4caf50
        style CYC1 fill:#c8e6c9,stroke:#4caf50
        style CYC2 fill:#c8e6c9,stroke:#4caf50
        style CYC3 fill:#c8e6c9,stroke:#4caf50
    end
Loading

Complexity Reduction Strategies

Refactoring Before Complexity After Complexity Impact
πŸ“€ Extract Method CC: 15 CC: 3 Γ— 5 -67% complexity
πŸ—οΈ Extract Class LOC: 500 LOC: 200 + 150 + 150 Better cohesion
πŸ“¦ Parameter Object Params: 8 Params: 2 -75% parameters
πŸ”„ Break Cycle Circular: Yes Circular: No 100% improvement
🎯 Move Method Feature Envy: High Feature Envy: None Proper encapsulation

πŸ”Œ IDE Support

Feature Matrix

Feature Eclipse IntelliJ VS Code Visual Studio
Basic Refactorings βœ… βœ… βœ… βœ…
AI Integration βœ… βœ… βœ… βœ…

βœ… Full Support | 🚧 In Development | ❌ Not Planned

πŸ’Ό Use Cases

1. Breaking Circular Dependencies

graph TB
    subgraph "❌ Before: Circular Dependency"
        A1[Service A] --> B1[Service B]
        B1 --> C1[Service C]
        C1 --> A1
        
        style A1 fill:#ff6b6b,stroke:#c92a2a
        style B1 fill:#ff6b6b,stroke:#c92a2a
        style C1 fill:#ff6b6b,stroke:#c92a2a
    end
    
    subgraph "βœ… After: Clean Architecture"
        A2[Service A] --> I[Interface]
        B2[Service B] --> I
        C2[Service C] --> I
        
        style A2 fill:#8ce99a,stroke:#51cf66
        style B2 fill:#8ce99a,stroke:#51cf66
        style C2 fill:#8ce99a,stroke:#51cf66
        style I fill:#74c0fc,stroke:#339af0
    end
Loading

Command: "Break the circular dependency between these services"

RefactorAI Actions:

  1. Detects cycle using graph analysis
  2. Suggests Extract Interface refactoring
  3. Creates common interface
  4. Updates all implementations
  5. Verifies no cycles remain

2. Legacy Code Modernization

// Before: 500-line method with 15 parameters
public void processOrder(String id, String customer, String product, 
                        int quantity, double price, String address, 
                        String city, String zip, String country, 
                        boolean express, double discount, String coupon,
                        String payment, String card, Date delivery) {
    // 500 lines of spaghetti code...
}

// After: Clean, testable code
public void processOrder(OrderRequest request) {
    Order order = createOrder(request);
    validateOrder(order);
    applyDiscounts(order);
    processPayment(order);
    scheduleDelivery(order);
}

3. Microservice Extraction

graph LR
    subgraph "πŸ“¦ Monolith"
        M[Monolithic App]
    end
    
    subgraph "🎯 Microservices"
        MS1[User Service]
        MS2[Order Service]
        MS3[Payment Service]
        MS4[Notification Service]
    end
    
    M -->|"RefactorAI"| MS1
    M -->|"Extraction"| MS2
    M -->|"Process"| MS3
    M -->|"✨"| MS4
    
    style M fill:#ffd43b,stroke:#fab005
    style MS1 fill:#74c0fc,stroke:#339af0
    style MS2 fill:#8ce99a,stroke:#51cf66
    style MS3 fill:#ff8cc3,stroke:#f06595
    style MS4 fill:#c5f6fa,stroke:#22b8cf
Loading

πŸ“„ License

MIT License - see LICENSE file for details.


🌟 Star us on GitHub to support the project!

About

Bridging AI Intelligence with IDE Refactoring Power

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published