java-code-comments

Adds JavaDoc comments to Java code following industry standards. Covers class-level, method-level, and field-level comments for Controller, Service, ServiceImpl, Mapper, Entity, BO, DTO, VO, and other component types. Use when the user wants to add comments to Java code, generate JavaDoc documentation, or systematically document a Java codebase.

261 stars

Best use case

java-code-comments is best used when you need a repeatable AI agent workflow instead of a one-off prompt. It is especially useful for teams working in multi. Adds JavaDoc comments to Java code following industry standards. Covers class-level, method-level, and field-level comments for Controller, Service, ServiceImpl, Mapper, Entity, BO, DTO, VO, and other component types. Use when the user wants to add comments to Java code, generate JavaDoc documentation, or systematically document a Java codebase.

Adds JavaDoc comments to Java code following industry standards. Covers class-level, method-level, and field-level comments for Controller, Service, ServiceImpl, Mapper, Entity, BO, DTO, VO, and other component types. Use when the user wants to add comments to Java code, generate JavaDoc documentation, or systematically document a Java codebase.

Users should expect a more consistent workflow output, faster repeated execution, and less time spent rewriting prompts from scratch.

Practical example

Example input

Use the "java-code-comments" skill to help with this workflow task. Context: Adds JavaDoc comments to Java code following industry standards. Covers class-level, method-level, and field-level comments for Controller, Service, ServiceImpl, Mapper, Entity, BO, DTO, VO, and other component types. Use when the user wants to add comments to Java code, generate JavaDoc documentation, or systematically document a Java codebase.

Example output

A structured workflow result with clearer steps, more consistent formatting, and an output that is easier to reuse in the next run.

When to use this skill

  • Use this skill when you want a reusable workflow rather than writing the same prompt again and again.

When not to use this skill

  • Do not use this when you only need a one-off answer and do not need a reusable workflow.
  • Do not use it if you cannot install or maintain the related files, repository context, or supporting tools.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/java-code-comments/SKILL.md --create-dirs "https://raw.githubusercontent.com/partme-ai/full-stack-skills/main/skills/dev-utils-skills/java-code-comments/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/java-code-comments/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How java-code-comments Compares

Feature / Agentjava-code-commentsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Adds JavaDoc comments to Java code following industry standards. Covers class-level, method-level, and field-level comments for Controller, Service, ServiceImpl, Mapper, Entity, BO, DTO, VO, and other component types. Use when the user wants to add comments to Java code, generate JavaDoc documentation, or systematically document a Java codebase.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

## When to use this skill

**ALWAYS use this skill when the user mentions:**
- Adding comments to Java code
- Documenting Java classes, methods, or fields
- Generating JavaDoc comments
- Improving code documentation
- Code annotation or code commenting
- 给 Java 代码添加注释
- 生成 Java 文档注释
- 代码注释
- 添加注释

**Trigger phrases include:**
- "给这段代码添加注释" (add comments to this code)
- "生成 JavaDoc" (generate JavaDoc)
- "添加类注释" (add class comments)
- "添加方法注释" (add method comments)
- "添加属性注释" (add field comments)
- "代码注释" (code comments)
- "文档注释" (documentation comments)
- "一句话给 Java 代码添加注释" (add comments to Java code with one sentence)

**Component types this skill handles:**
- Controller (REST controllers, Spring MVC controllers)
- Service (business service interfaces)
- ServiceImpl (service implementations)
- Application Service (DDD application services, orchestrating domain logic)
- Domain Service (DDD domain services, domain business logic)
- Feign Service Interface (Feign remote service interfaces)
- Mapper (MyBatis mappers, data access layer)
- Model (data models, domain models)
- Entity (JPA entities, database entities)
- BO (Business Object, business logic objects)
- DTO (Data Transfer Object)
- VO (Value Object, View Object)
- DAO (Data Access Object)
- Repository (Spring Data repositories)
- Configuration (Spring configuration classes)
- Component (Spring components)
- Utility (utility classes)
- Exception (custom exception classes)

## How to use this skill

**CRITICAL: This skill should be triggered when the user wants to add comments to Java code, regardless of the component type or complexity.**

### Workflow Overview

This skill follows a systematic 4-step workflow:

1. **Scan and Understand** - Scan the entire codebase and related documentation to gain comprehensive understanding
2. **Confirm Component Types** - Ask user to confirm which component types need comments
3. **Create Todo List** - Generate a detailed todo list with class names and method names
4. **Execute Commenting** - Add comments in order: class comments → method comments → field comments, updating todo list after each completion

### Step-by-Step Process

#### Step 1: Scan and Understand the Codebase

**CRITICAL: Before adding any comments, you MUST:**

1. **Scan all Java files** in the project:
   - Read all `.java` files in the current directory and subdirectories
   - Understand the project structure and architecture
   - Identify relationships between classes (dependencies, inheritance, composition)

2. **Read related documentation**:
   - README.md files
   - API documentation
   - Architecture documentation
   - Business requirements documents (if available)

3. **Understand the context**:
   - What does each class do?
   - What is the purpose of each method?
   - What do fields represent?
   - How do components interact with each other?

4. **Identify patterns**:
   - Naming conventions used in the project
   - Existing comment styles (if any)
   - Architecture patterns (MVC, DDD, etc.)
   - Framework usage (Spring, MyBatis, etc.)

**Output**: A summary of your understanding of the codebase, including:
- Project structure overview
- Key components identified
- Architecture patterns detected
- Existing documentation status

#### Step 2: Confirm Component Types

**CRITICAL: You MUST ask the user to confirm which component types need comments.**

Present a checklist of common Java component types and ask the user to select:

```
请确认需要进行代码注释的分类(可多选):
- [ ] Controller(控制器)
- [ ] Service(服务接口)
- [ ] ServiceImpl(服务实现)
- [ ] Application Service(应用服务,DDD架构)
- [ ] Domain Service(领域服务,DDD架构)
- [ ] Feign Service Interface(Feign远程服务接口)
- [ ] Mapper(数据访问层)
- [ ] Model(数据模型)
- [ ] Entity(实体类)
- [ ] BO(业务对象)
- [ ] DTO(数据传输对象)
- [ ] VO(视图对象)
- [ ] DAO(数据访问对象)
- [ ] Repository(仓储)
- [ ] Configuration(配置类)
- [ ] Component(组件类)
- [ ] Utility(工具类)
- [ ] Exception(异常类)
- [ ] 其他(请 specify)
```

**Also ask about comment types:**
- [ ] 类注释(Class-level comments)
- [ ] 方法注释(Method-level comments)
- [ ] 属性注释(Field-level comments)

**Wait for user confirmation** before proceeding to the next step.

#### Step 3: Create Todo List

**CRITICAL: After user confirms component types, create a detailed todo list.**

For each component type selected by the user:

1. **Scan the codebase** to find all matching classes:
   - Use file search to find classes matching the pattern (e.g., `*Controller.java`, `*Service.java`)
   - List all classes that need comments

2. **For each class, identify**:
   - Class name
   - Methods that need comments
   - Fields that need comments

3. **Generate a structured todo list** in the following format:

```markdown
## Todo List: Java Code Comments

### Controller 层
- [ ] UserController
  - [ ] 类注释
  - [ ] createUser() - 方法注释
  - [ ] updateUser() - 方法注释
  - [ ] deleteUser() - 方法注释
  - [ ] userId - 属性注释

### Service 层
- [ ] UserService
  - [ ] 类注释
  - [ ] findUserById() - 方法注释
  - [ ] saveUser() - 方法注释

### ServiceImpl 层
- [ ] UserServiceImpl
  - [ ] 类注释
  - [ ] findUserById() - 方法注释
  - [ ] saveUser() - 方法注释

### Mapper 层
- [ ] UserMapper
  - [ ] 类注释
  - [ ] selectById() - 方法注释

### Model/Entity 层
- [ ] User
  - [ ] 类注释
  - [ ] id - 属性注释
  - [ ] username - 属性注释
  - [ ] email - 属性注释
```

**Important**: 
- Organize by component type
- List all classes that match the selected types
- Include all methods and fields that need comments
- Use checkboxes for tracking progress

#### Step 4: Execute Commenting Work

**CRITICAL: Add comments in the specified order and update todo list after each completion.**

**Order of execution:**
1. **Class-level comments** (类注释) - First
2. **Method-level comments** (方法注释) - Second
3. **Field-level comments** (属性注释) - Third

**For each item in the todo list:**

1. **Process one class at a time**:
   - Start with class-level comment
   - Then process all methods in that class
   - Finally process all fields in that class
   - Update the todo list after completing each class

2. **Class-level comment format** (Standard JavaDoc):
   ```java
   /**
    * [Class description]
    * 
    * <p>This class [purpose and responsibility]
    * 
    * @author [Author name if available]
    * @since [Version or date if available]
    */
   public class UserController {
   ```

   **Class-level comment format** (Java Coding Standards - strict):
   ```java
   /**
    * <p>[Class description]</p>
    * 
    * <p>This class [purpose and responsibility]</p>
    * 
    * @author [Author name if available]
    * @since [Version or date if available]
    */
   public class UserController {
   ```

   **Specialized class comment formats** (Java Coding Standards - strict):

   **Application Service:**
   ```java
   /**
    * {服务名称}应用服务
    *
    * <p>{详细描述服务的业务功能、职责和应用场景}</p>
    * <p>主要功能包括:</p>
    * <ul>
    *   <li>{功能点1}</li>
    *   <li>{功能点2}</li>
    *   <li>{功能点3}</li>
    * </ul>
    *
    * @author system
    * @since 2025-01-21
    */
   public class UserApplicationService {
   ```

   **Domain Service:**
   ```java
   /**
    * {服务名称}领域服务
    *
    * <p>{详细描述服务的领域职责和业务逻辑}</p>
    * <p>主要功能包括:</p>
    * <ul>
    *   <li>{功能点1}</li>
    *   <li>{功能点2}</li>
    * </ul>
    *
    * @author system
    * @since 2025-01-21
    */
   public class UserDomainService {
   ```

   **Feign Service Interface:**
   ```java
   /**
    * {服务名称}Feign远程服务接口
    *
    * <p>通过Feign调用{目标服务}的远程接口</p>
    * <p>主要功能:</p>
    * <ul>
    *   <li>{接口功能1}</li>
    *   <li>{接口功能2}</li>
    * </ul>
    *
    * @author system
    * @since 2025-01-21
    */
   public interface UserFeignService {
   ```

3. **Method-level comment format** (Standard JavaDoc):
   ```java
   /**
    * [Method description]
    * 
    * @param [paramName] [parameter description]
    * @return [return value description]
    * @throws [ExceptionType] [exception description]
    */
   public UserDTO createUser(@RequestBody UserCreateRequest request) {
   ```

   **Method-level comment format** (Java Coding Standards - strict):
   ```java
   /**
    * <p>[Method description]</p>
    * 
    * <p>[Detailed description]</p>
    * 
    * @param [paramName] [paramType] [parameter description]
    * @return [returnType] [return value description]
    * @exception [full.package.ExceptionType] [exception description]
    */
   public UserDTO createUser(@RequestBody UserCreateRequest request) {
   ```

4. **Field-level comment format** (Standard JavaDoc):
   ```java
   /**
    * [Field description]
    */
   private Long userId;
   ```

   **Field-level comment format** (Java Coding Standards - strict):
   ```java
   /**
    * <p>[Field description]</p>
    * 
    * <p>[Detailed description if needed]</p>
    */
   private Long userId;
   ```

5. **After completing each class**:
   - Update the todo list: mark completed items with `[x]`
   - Show progress to the user
   - Continue to the next class

**Example progress update:**
```markdown
## Progress Update

✅ Completed: UserController
  - [x] 类注释
  - [x] createUser() - 方法注释
  - [x] updateUser() - 方法注释
  - [x] deleteUser() - 方法注释
  - [x] userId - 属性注释

🔄 In Progress: UserService
  - [x] 类注释
  - [ ] findUserById() - 方法注释
  - [ ] saveUser() - 方法注释
```

### Comment Quality Guidelines

**IMPORTANT: Comment Format Standards**

This skill follows two standards:
1. **Standard JavaDoc** (default): See [javadoc-standards.md](reference/javadoc-standards.md) (within this skill)
2. **Java Coding Standards** (strict): See [java-coding-standards.md](reference/java-coding-standards.md) (within this skill)

The Java Coding Standards require:
- **Description must be wrapped in `<p>` tags**: `<p>description</p>`
- **Parameter types must be declared**: `@param paramName paramType description`
- **Return types must be declared**: `@return returnType description`
- **Exception types must be declared with full package name**: `@exception java.lang.Exception description`

**Class Comments Should Include:**
- Clear description of the class purpose (wrapped in `<p>` tags if following Java Coding Standards)
- Main responsibilities
- Usage examples (if complex)
- Related classes or components
- Author and version (if available)

**Method Comments Should Include:**
- Clear description of what the method does (wrapped in `<p>` tags if following Java Coding Standards)
- All parameters with descriptions and types
- Return value description with type
- Exceptions that may be thrown (with full package names)
- Usage examples (for complex methods)
- Side effects (if any)

**Field Comments Should Include:**
- Clear description of what the field represents (wrapped in `<p>` tags if following Java Coding Standards)
- Data type and constraints (if applicable)
- Default values (if applicable)
- Relationships to other fields (if applicable)

### Best Practices

1. **Be concise but complete**: Comments should be clear and informative without being verbose
2. **Use JavaDoc format**: Follow standard JavaDoc conventions
3. **Maintain consistency**: Use consistent style across all comments
4. **Update todo list**: Always update the todo list after completing each item
5. **One class at a time**: Process one complete class before moving to the next
6. **Respect existing code**: Don't modify code logic, only add comments
7. **Context-aware**: Comments should reflect the actual code behavior and business context

### Comment Templates

For different component types, use appropriate templates from the `templates/` directory:
- `templates/controller-comment-template.md` - Controller class comments
- `templates/service-comment-template.md` - Service interface comments
- `templates/serviceimpl-comment-template.md` - Service implementation comments
- `templates/application-service-comment-template.md` - Application Service comments (DDD)
- `templates/domain-service-comment-template.md` - Domain Service comments (DDD)
- `templates/feign-service-comment-template.md` - Feign Service Interface comments
- `templates/mapper-comment-template.md` - Mapper comments
- `templates/entity-comment-template.md` - Entity class comments
- `templates/dto-comment-template.md` - DTO class comments

### Comment Standards Reference

**Note**: All reference documents are located within this skill's directory structure.

- **Standard JavaDoc**: See [reference/javadoc-standards.md](reference/javadoc-standards.md) (local reference)
- **Java Coding Standards** (strict format): See [reference/java-coding-standards.md](reference/java-coding-standards.md) (local reference)

**When to use Java Coding Standards format:**
- When the project explicitly follows 《JAVA 编程规范》
- When the project requires strict format with `<p>` tags for descriptions
- When parameter and return types must be explicitly declared in comments

### Examples

See the `examples/` directory for complete examples:
- `examples/controller-example.md` - Controller commenting example
- `examples/service-example.md` - Service commenting example
- `examples/entity-example.md` - Entity commenting example
- `examples/full-workflow-example.md` - Complete workflow example

## Keywords

**English keywords:**
java, code comments, javadoc, documentation, class comments, method comments, field comments, code annotation, code documentation, java documentation, add comments, generate comments, document code, code comments java, java code comments, controller comments, service comments, mapper comments, entity comments, dto comments

**Chinese keywords (中文关键词):**
Java 代码注释, 添加注释, 生成注释, 代码注释, 文档注释, JavaDoc, 类注释, 方法注释, 属性注释, 字段注释, 给代码添加注释, 代码文档, Java 文档, 注释生成, 一句话添加注释, Controller 注释, Service 注释, Mapper 注释, Entity 注释, DTO 注释, 代码注解

Related Skills

vant-vue3

261
from partme-ai/full-stack-skills

Provides structured guidance for Vant of Vue 3.0. Use when the user needs Vant with Vue 3, asks about mobile UI components such as Button, Cell, Form, Dialog, Toast, Popup, ConfigProvider, theme customization, project setup, or wants to implement mobile-first interfaces with vant or van- components.

layui-vue3

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Layui Vue component library including components, layer dialogs, and utilities. Use when the user asks about Layui Vue, needs to use Layui components in Vue 3, or implement UI components.

element-plus-vue3

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Element Plus Vue 3 component library including installation, components, themes, internationalization, and API reference. Use when the user asks about Element Plus for Vue 3, needs to build Vue 3 applications with Element Plus, or customize component styles.

bootstrap-vue3

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Bootstrap Vue 3 component library including Bootstrap components, grid system, utilities, and Vue 3 integration. Use when the user asks about Bootstrap Vue 3, needs to use Bootstrap components in Vue 3, or implement responsive layouts.

vuex-vue2

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Vuex 2.x state management in Vue 2 applications including state, mutations, actions, getters, modules, and plugins. Use when the user asks about Vuex for Vue 2, needs to manage state in Vue 2 applications, or implement Vuex patterns.

vue3

261
from partme-ai/full-stack-skills

Guidance for Vue 3 using the official guide and API reference. Use when the user needs Vue 3 concepts, patterns, or API details to build components, apps, and tooling.

vue2

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Vue 2.x development including Options API, components, directives, lifecycle hooks, computed properties, watchers, Vuex state management, and Vue Router. Use when the user asks about Vue 2, needs to create Vue 2 components, implement reactive data binding, handle component communication, or work with Vue 2 ecosystem tools.

vue-router

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Vue Router including route configuration, navigation, dynamic routes, nested routes, route guards, programmatic navigation, and route meta. Use when the user asks about Vue Router, needs to set up routing, implement navigation guards, handle route parameters, or manage route transitions.

vue-router-v4

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Vue Router v4 including route configuration, navigation, nested routes, route guards, and Vue 3 integration. Use when the user asks about Vue Router v4, needs to set up routing for Vue 3 applications, implement navigation guards, or work with Vue Router v4 features.

vue-router-v3

261
from partme-ai/full-stack-skills

Guidance for Vue Router v3 using the official Installation, Guide, and API docs. Use when users need routing setup, navigation patterns, or API details for Vue 2 projects.

pinia

261
from partme-ai/full-stack-skills

Provides comprehensive guidance for Pinia state management including stores, state, getters, actions, plugins, and TypeScript support. Use when the user asks about Pinia, needs to manage application state, create stores, implement state persistence, or migrate from Vuex.

vscode-project-init

261
from partme-ai/full-stack-skills

Scaffold a new VS Code extension project using TypeScript via Yeoman generator (yo code), creating src/extension.ts entry point and package.json manifest. Use when the user wants to start a new VS Code extension project from scratch.