diff --git a/README.prompts.md b/README.prompts.md index ad5ba7b1..5560affc 100644 --- a/README.prompts.md +++ b/README.prompts.md @@ -80,6 +80,7 @@ Ready-to-use prompt templates for specific development scenarios and tasks, defi | [Project Folder Structure Blueprint Generator](prompts/folder-structure-blueprint-generator.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Ffolder-structure-blueprint-generator.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Ffolder-structure-blueprint-generator.prompt.md) | Comprehensive technology-agnostic prompt for analyzing and documenting project folder structures. Auto-detects project types (.NET, Java, React, Angular, Python, Node.js, Flutter), generates detailed blueprints with visualization options, naming conventions, file placement patterns, and extension templates for maintaining consistent code organization across diverse technology stacks. | | [Project Workflow Documentation Generator](prompts/project-workflow-analysis-blueprint-generator.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fproject-workflow-analysis-blueprint-generator.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fproject-workflow-analysis-blueprint-generator.prompt.md) | Comprehensive technology-agnostic prompt generator for documenting end-to-end application workflows. Automatically detects project architecture patterns, technology stacks, and data flow patterns to generate detailed implementation blueprints covering entry points, service layers, data access, error handling, and testing approaches across multiple technologies including .NET, Java/Spring, React, and microservices architectures. | | [README Generator Prompt](prompts/readme-blueprint-generator.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Freadme-blueprint-generator.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Freadme-blueprint-generator.prompt.md) | Intelligent README.md generation prompt that analyzes project documentation structure and creates comprehensive repository documentation. Scans .github/copilot directory files and copilot-instructions.md to extract project information, technology stack, architecture, development workflow, coding standards, and testing approaches while generating well-structured markdown documentation with proper formatting, cross-references, and developer-focused content. | +| [Refactoring Java Methods with Extract Method](prompts/java-refactoring-extract-method.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-refactoring-extract-method.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-refactoring-extract-method.prompt.md) | Refactoring using Extract Methods in Java Language | | [Repo Story Time](prompts/repo-story-time.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Frepo-story-time.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Frepo-story-time.prompt.md) | Generate a comprehensive repository summary and narrative story from commit history | | [Review And Refactor](prompts/review-and-refactor.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Freview-and-refactor.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Freview-and-refactor.prompt.md) | Review and refactor code in your project according to defined instructions | | [Spring Boot Best Practices](prompts/java-springboot.prompt.md)
[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install-0098FF?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-springboot.prompt.md)
[![Install in VS Code Insiders](https://img.shields.io/badge/VS_Code_Insiders-Install-24bfa5?style=flat-square&logo=visualstudiocode&logoColor=white)](https://aka.ms/awesome-copilot/install/prompt?url=vscode-insiders%3Achat-prompt%2Finstall%3Furl%3Dhttps%3A%2F%2Fraw.githubusercontent.com%2Fgithub%2Fawesome-copilot%2Fmain%2Fprompts%2Fjava-springboot.prompt.md) | Get best practices for developing applications with Spring Boot. | diff --git a/prompts/java-refactoring-extract-method.prompt.md b/prompts/java-refactoring-extract-method.prompt.md new file mode 100644 index 00000000..b3bab657 --- /dev/null +++ b/prompts/java-refactoring-extract-method.prompt.md @@ -0,0 +1,105 @@ +--- +title: 'Refactoring Java Methods with Extract Method' +mode: 'agent' +description: 'Refactoring using Extract Methods in Java Language' +--- + +# Refactoring Java Methods with Extract Method + +## Role + +You are an expert in refactoring Java methods. + +Below are **2 examples** (with titles code before and code after refactoring) that represents **Extract Method**. + +## Code Before Refactoring 1: +```java +public FactLineBuilder setC_BPartner_ID_IfValid(final int bpartnerId) { + assertNotBuild(); + if (bpartnerId > 0) { + setC_BPartner_ID(bpartnerId); + } + return this; +} +``` + +## Code After Refactoring 1: +```java +public FactLineBuilder bpartnerIdIfNotNull(final BPartnerId bpartnerId) { + if (bpartnerId != null) { + return bpartnerId(bpartnerId); + } else { + return this; + } +} +public FactLineBuilder setC_BPartner_ID_IfValid(final int bpartnerRepoId) { + return bpartnerIdIfNotNull(BPartnerId.ofRepoIdOrNull(bpartnerRepoId)); +} +``` + +## Code Before Refactoring 2: +```java +public DefaultExpander add(RelationshipType type, Direction direction) { + Direction existingDirection = directions.get(type.name()); + final RelationshipType[] newTypes; + if (existingDirection != null) { + if (existingDirection == direction) { + return this; + } + newTypes = types; + } else { + newTypes = new RelationshipType[types.length + 1]; + System.arraycopy(types, 0, newTypes, 0, types.length); + newTypes[types.length] = type; + } + Map newDirections = new HashMap(directions); + newDirections.put(type.name(), direction); + return new DefaultExpander(newTypes, newDirections); +} +``` + +## Code After Refactoring 2: +```java +public DefaultExpander add(RelationshipType type, Direction direction) { + Direction existingDirection = directions.get(type.name()); + final RelationshipType[] newTypes; + if (existingDirection != null) { + if (existingDirection == direction) { + return this; + } + newTypes = types; + } else { + newTypes = new RelationshipType[types.length + 1]; + System.arraycopy(types, 0, newTypes, 0, types.length); + newTypes[types.length] = type; + } + Map newDirections = new HashMap(directions); + newDirections.put(type.name(), direction); + return (DefaultExpander) newExpander(newTypes, newDirections); +} +protected RelationshipExpander newExpander(RelationshipType[] types, + Map directions) { + return new DefaultExpander(types, directions); +} +``` + +## Task + +Apply **Extract Method** to improve readability, testability, maintainability, reusability, modularity, cohesion, low coupling, and consistency. + +Always return a complete and compilable method (Java 17). + +Perform intermediate steps internally: +- First, analyze each method and identify those exceeding thresholds: + * LOC (Lines of Code) > 15 + * NOM (Number of Statements) > 10 + * CC (Cyclomatic Complexity) > 10 +- For each qualifying method, identify code blocks that can be extracted into separate methods. +- Extract at least one new method with a descriptive name. +- Output only the refactored code inside a single ```java``` block. +- Do not remove any functionality from the original method. +- Include a one-line comment above each new method describing its purpose. + +## Code to be Refactored: + +Now, assess all methods with high complexity and refactor them using **Extract Method** \ No newline at end of file