java-code-comments
npx skills add https://github.com/teachingai/full-stack-skills --skill java-code-comments
Agent 安装分布
Skill 文档
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:
- Scan and Understand – Scan the entire codebase and related documentation to gain comprehensive understanding
- Confirm Component Types – Ask user to confirm which component types need comments
- Create Todo List – Generate a detailed todo list with class names and method names
- 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:
-
Scan all Java files in the project:
- Read all
.javafiles in the current directory and subdirectories - Understand the project structure and architecture
- Identify relationships between classes (dependencies, inheritance, composition)
- Read all
-
Read related documentation:
- README.md files
- API documentation
- Architecture documentation
- Business requirements documents (if available)
-
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?
-
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:
-
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
- Use file search to find classes matching the pattern (e.g.,
-
For each class, identify:
- Class name
- Methods that need comments
- Fields that need comments
-
Generate a structured todo list in the following format:
## 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:
- Class-level comments (类注é) – First
- Method-level comments (æ¹æ³æ³¨é) – Second
- Field-level comments (屿§æ³¨é) – Third
For each item in the todo list:
-
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
-
Class-level comment format (Standard JavaDoc):
/** * [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):
/** * <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:
/** * {æå¡åç§°}åºç¨æå¡ * * <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:
/** * {æå¡åç§°}é¢åæå¡ * * <p>{è¯¦ç»æè¿°æå¡çé¢åèè´£åä¸å¡é»è¾}</p> * <p>主è¦åè½å æ¬:</p> * <ul> * <li>{åè½ç¹1}</li> * <li>{åè½ç¹2}</li> * </ul> * * @author system * @since 2025-01-21 */ public class UserDomainService {Feign Service Interface:
/** * {æå¡åç§°}Feignè¿ç¨æå¡æ¥å£ * * <p>éè¿Feignè°ç¨{ç®æ æå¡}çè¿ç¨æ¥å£</p> * <p>主è¦åè½:</p> * <ul> * <li>{æ¥å£åè½1}</li> * <li>{æ¥å£åè½2}</li> * </ul> * * @author system * @since 2025-01-21 */ public interface UserFeignService { -
Method-level comment format (Standard JavaDoc):
/** * [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):
/** * <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) { -
Field-level comment format (Standard JavaDoc):
/** * [Field description] */ private Long userId;Field-level comment format (Java Coding Standards – strict):
/** * <p>[Field description]</p> * * <p>[Detailed description if needed]</p> */ private Long userId; -
After completing each class:
- Update the todo list: mark completed items with
[x] - Show progress to the user
- Continue to the next class
- Update the todo list: mark completed items with
Example progress update:
## 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:
- Standard JavaDoc (default): See javadoc-standards.md (within this skill)
- Java Coding Standards (strict): See 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
- Be concise but complete: Comments should be clear and informative without being verbose
- Use JavaDoc format: Follow standard JavaDoc conventions
- Maintain consistency: Use consistent style across all comments
- Update todo list: Always update the todo list after completing each item
- One class at a time: Process one complete class before moving to the next
- Respect existing code: Don’t modify code logic, only add comments
- 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 commentstemplates/service-comment-template.md– Service interface commentstemplates/serviceimpl-comment-template.md– Service implementation commentstemplates/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 commentstemplates/mapper-comment-template.md– Mapper commentstemplates/entity-comment-template.md– Entity class commentstemplates/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 (local reference)
- Java Coding Standards (strict format): See 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 exampleexamples/service-example.md– Service commenting exampleexamples/entity-example.md– Entity commenting exampleexamples/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 注é, ä»£ç æ³¨è§£