incremental-java-programmer
Incrementally implement new features in Java repositories from natural language descriptions. Use when adding functionality to existing Java codebases (Maven or Gradle projects). Takes a feature description as input and outputs modified repository with implementation code, corresponding JUnit tests, and verification that all tests pass. Supports method additions, new class creation, and method modifications with proper Java conventions.
git clone --depth 1 https://github.com/ArabelaTso/Skills-4-SE /tmp/incremental-java-programmer && cp -r /tmp/incremental-java-programmer/skills/incremental-java-programmer ~/.claude/skills/incremental-java-programmerSKILL.md
# Incremental Java Programmer
## Overview
Implement new features in Java repositories by analyzing the codebase, generating implementation code, creating comprehensive tests, and ensuring all tests pass before completion.
## Workflow
### 1. Analyze Repository Structure
Understand the Java project structure and build system:
**Identify build system**:
- Maven: Look for `pom.xml` in root directory
- Gradle: Look for `build.gradle` or `build.gradle.kts`
**Examine project structure**:
```
src/
├── main/
│ └── java/
│ └── com/example/project/
│ ├── model/
│ ├── service/
│ ├── controller/
│ └── util/
└── test/
└── java/
└── com/example/project/
├── model/
├── service/
└── controller/
```
**Extract key information**:
- Package structure and naming conventions
- Existing class hierarchy and relationships
- Dependencies from `pom.xml` or `build.gradle`
- Testing framework (JUnit 4, JUnit 5, TestNG)
- Code style and patterns used in the project
### 2. Parse Feature Description
Break down the natural language feature description into actionable components:
**Identify feature type**:
- **New functionality**: Adding entirely new capabilities
- **Enhancement**: Extending existing functionality
- **Modification**: Changing existing behavior
**Extract requirements**:
- What classes/methods need to be created or modified
- Input parameters and return types
- Business logic and validation rules
- Error handling requirements
- Integration points with existing code
**Example feature description**:
```
"Add a method to calculate the total price of items in a shopping cart,
including tax. The tax rate should be configurable. If the cart is empty,
return 0. The method should throw an exception if the tax rate is negative."
```
**Parsed components**:
- Target class: `ShoppingCart`
- New method: `calculateTotalWithTax(double taxRate)`
- Return type: `double`
- Validation: Check for negative tax rate, handle empty cart
- Exception: `IllegalArgumentException` for negative tax rate
### 3. Locate Target Files
Find where the implementation should be added:
**For new classes**:
- Determine appropriate package based on functionality
- Follow existing package structure conventions
- Place in `src/main/java/[package-path]/`
**For existing classes**:
- Use Grep to find the target class
- Read the class to understand current structure
- Identify where new methods should be added
**For modifications**:
- Locate the specific method to modify
- Understand current implementation
- Plan minimal changes to achieve feature
### 4. Implement Feature Code
Write Java code following project conventions:
**Code structure**:
```java
/**
* [Javadoc description of what the method does]
*
* @param paramName description of parameter
* @return description of return value
* @throws ExceptionType description of when exception is thrown
*/
public ReturnType methodName(ParamType paramName) {
// Input validation
if (invalidCondition) {
throw new IllegalArgumentException("Error message");
}
// Business logic
ReturnType result = performCalculation();
// Return result
return result;
}
```
**Best practices**:
- Follow existing code style (indentation, naming, formatting)
- Add comprehensive Javadoc comments
- Include input validation
- Handle edge cases
- Use appropriate access modifiers
- Follow SOLID principles
- Avoid code duplication
**For new classes**:
```java
package com.example.project.service;
import java.util.List;
/**
* Service class for managing shopping cart operations.
*/
public class ShoppingCartService {
private final TaxCalculator taxCalculator;
public ShoppingCartService(TaxCalculator taxCalculator) {
this.taxCalculator = taxCalculator;
}
// Methods here
}
```
### 5. Generate Unit Tests
Create comprehensive JUnit tests for the new functionality:
**Test class structure**:
```java
package com.example.project.service;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;
import static org.junit.jupiter.api.Assertions.*;
class ShoppingCartServiceTest {
private ShoppingCartService service;
@BeforeEach
void setUp() {
service = new ShoppingCartService(new TaxCalculator());
}
@Test
@DisplayName("Should calculate total with tax correctly")
void testCalculateTotalWithTax() {
// Arrange
double subtotal = 100.0;
double taxRate = 0.08;
// Act
double result = service.calculateTotalWithTax(subtotal, taxRate);
// Assert
assertEquals(108.0, result, 0.01);
}
@Test
@DisplayName("Should throw exception for negative tax rate")
void testNegativeTaxRate() {
assertThrows(IllegalArgumentException.class, () -> {
service.calculateTotalWithTax(100.0, -0.05);
});
}
@Test
@DisplayName("Should return zero for empty cart")
void testEmptyCart() {
double result = service.calculateTotalWithTax(0.0, 0.08);
assertEquals(0.0, result, 0.01);
}
}
```
**Test coverage requirements**:
- Happy path (normal operation)
- Edge cases (empty inputs, boundary values)
- Error cases (invalid inputs, exceptions)
- Integration with existing code
**Test naming conventions**:
- Use descriptive test method names
- Follow project's existing test naming pattern
- Use `@DisplayName` for readable test descriptions
### 6. Update Existing Tests
Modify existing tests if the feature changes existing behavior:
**Identify affected tests**:
- Search for tests that call modified methods
- Find tests that assert on changed behavior
- Locate integration tests that may be affected
**Update test assertions**:
```java
// Before
assertEquals(100.0, cart.getTotal());
// After (if feature adds tax calculation)
assertEquals(108.0, cart.getTotalWithTax(0.08));
```
**Applies abstract interpretation using different abstract domains (intervals, octagons, polyhedra, sign, congruence) to statically analyze program variables and infer invariants, value ranges, and relationships. Use when analyzing program properties, inferring loop invariants, detecting potential errors, or understanding variable relationships through static analysis.
Uses abstract interpretation to automatically infer loop invariants, function preconditions, and postconditions for formal verification. Generates invariants that capture program behavior and support correctness proofs in Dafny, Isabelle, Coq, and other verification systems. Use when adding formal specifications to code, generating verification conditions, inferring contracts for functions, or discovering loop invariants for proofs.
Performs abstract interpretation over source code to infer possible program states, variable ranges, and data properties without executing the program. Reports potential runtime errors including out-of-bounds accesses, null dereferences, type inconsistencies, division by zero, and integer overflows. Use when analyzing code for potential runtime errors, performing static analysis, checking safety properties, or verifying program behavior without execution.
Performs abstract interpretation to produce summarized execution traces and high-level program behavior representations. Highlights key control flow paths, variable relationships, loop invariants, function summaries, and potential runtime states using abstract domains (intervals, signs, nullness, etc.). Use when analyzing program behavior, understanding execution paths, computing loop invariants, tracking variable ranges, detecting potential runtime errors, or generating program summaries without concrete execution.
Create ACSL (ANSI/ISO C Specification Language) formal annotations for C/C++ programs. Use this skill when working with formal verification, adding function contracts (requires/ensures), loop invariants, assertions, memory safety annotations, or any ACSL specifications. Supports Frama-C verification and generates comprehensive formal specifications for C/C++ code.
CLI-based browser automation with persistent page state using ref-based element interaction. Use when users ask to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.
Detects and analyzes ambiguous language in software requirements and user stories. Use when reviewing requirements documents, user stories, specifications, or any software requirement text to identify vague quantifiers, unclear scope, undefined terms, missing edge cases, subjective language, and incomplete specifications. Provides detailed analysis with clarifying questions and suggested improvements.
Design and review APIs with suggestions for endpoints, parameters, return types, and best practices. Use when designing new APIs from requirements, reviewing existing API designs, generating API documentation, or getting implementation guidance. Supports REST APIs with focus on endpoint structure, request/response schemas, authentication, pagination, filtering, versioning, and OpenAPI specifications. Triggers when users ask to design, review, document, or improve APIs.