Skip to content

Commit 8de66ea

Browse files
committed
docs: improve documentation
Signed-off-by: Marcos Tischer Vallim <tischer@gmail.com>
1 parent 9c58530 commit 8de66ea

44 files changed

Lines changed: 2907 additions & 1314 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
name: java-docs
3+
description: 'Ensure that Java types are documented with Javadoc comments and follow best practices for documentation.'
4+
---
5+
6+
# Javadoc Skill
7+
8+
## 🎯 **Skill Overview**
9+
This skill enables the creation and maintenance of comprehensive Javadoc documentation for Java codebases, ensuring professional code documentation standards.
10+
11+
## 📋 **Skill Details**
12+
13+
### 🔧 **Core Competencies**
14+
- **Javadoc Generation**: Create comprehensive documentation using Javadoc comments
15+
- **Code Documentation**: Document methods, and interfaces with proper tags
16+
- **Standard Compliance**: Follow Javadoc conventions and best practices
17+
- **Tool Integration**: Generate documentation using javadoc tool and IDE integration
18+
19+
### 📝 **Technical Requirements**
20+
21+
#### **Basic Javadoc Structure**
22+
```java
23+
public class MyClass {
24+
/**
25+
* Method description
26+
* @param parameter Description of parameter
27+
* @return Description of return value
28+
* @throws Exception Description of exception
29+
*/
30+
public void myMethod(String parameter) throws Exception {
31+
// implementation
32+
}
33+
}
34+
```
35+
36+
#### **Required Javadoc Tags**
37+
- `@param` - Parameter descriptions
38+
- `@return` - Return value description
39+
- `@throws` - Exception descriptions
40+
- `@see` - Related documentation
41+
- `@deprecated` - Deprecation notice
42+
43+
### 🎯 **Performance Indicators**
44+
45+
#### **Mastery Levels**
46+
- **Beginner**: Basic Javadoc comments for public methods
47+
- **Intermediate**: Complete method documentation with all required tags
48+
- **Advanced**: Professional documentation with cross-references and examples
49+
50+
#### **Quality Metrics**
51+
- 100% of public methods documented
52+
- Proper use of all required Javadoc tags
53+
- Consistent documentation style
54+
- No missing or incomplete documentation
55+
56+
### 🛠️ **Implementation Process**
57+
58+
#### **Step 1: Method Documentation**
59+
```java
60+
/**
61+
* Creates a new user account
62+
* @param username the user's username
63+
* @param email the user's email address
64+
* @return the created user object
65+
* @throws IllegalArgumentException when username or email is null
66+
* @throws UserCreationException when user creation fails
67+
*/
68+
public User createUser(String username, String email)
69+
throws IllegalArgumentException, UserCreationException {
70+
// implementation
71+
}
72+
```
73+
74+
### 📊 **Skill Validation**
75+
76+
#### **Checklist**
77+
- [ ] All public methods have Javadoc
78+
- [ ] Required tags are present
79+
- [ ] Documentation is clear and concise
80+
- [ ] Examples are provided when needed
81+
- [ ] Cross-references are included appropriately
82+
83+
#### **Quality Standards**
84+
- Documentation must be written in English
85+
- Use proper grammar and spelling
86+
- Maintain consistent formatting
87+
- Include relevant examples
88+
- Update documentation with code changes
89+
90+
### 📈 **Skill Progression**
91+
92+
#### **Level 1: Complete Documentation**
93+
- Document all public API
94+
- Include parameter and return descriptions
95+
- Add exception documentation
96+
97+
#### **Level 2: Professional Documentation**
98+
- Advanced cross-references
99+
- Code examples
100+
- Comprehensive coverage
101+
- Integration with documentation tools
102+
103+
### 🎯 **Best Practices**
104+
105+
#### **Documentation Standards**
106+
1. **Clarity**: Write clear, concise descriptions
107+
2. **Consistency**: Maintain uniform style throughout
108+
3. **Completeness**: Include all required information
109+
4. **Accuracy**: Keep documentation updated with code changes
110+
5. **Readability**: Use proper formatting and structure
111+
112+
#### **Tools Integration**
113+
- IDE auto-completion support
114+
- Documentation generation tools
115+
- Continuous integration integration
116+
- Version control integration
117+
118+
### 📚 **Resources**
119+
120+
#### **Reference Materials**
121+
- Oracle Javadoc Documentation
122+
- Java Language Specification
123+
- Code style guidelines
124+
- Project documentation standards
125+
126+
#### **Training Resources**
127+
- Javadoc tutorial examples
128+
- Documentation style guides
129+
- Code review checklists
130+
- Best practice workshops
131+
132+
### 🎯 **Expected Outcomes**
133+
- Professional quality code documentation
134+
- Maintainable and readable documentation
135+
- Consistent documentation standards
136+
- Improved code understanding and maintenance
137+
- Better collaboration among development teams
138+
139+
## 🎯 **Skill Assessment**
140+
141+
### **Evaluation Criteria**
142+
- Documentation completeness
143+
- Tag usage accuracy
144+
- Code clarity and quality
145+
- Tool integration effectiveness
146+
- Consistency across codebase
147+
148+
### **Success Metrics**
149+
- 95%+ documentation coverage
150+
- Zero missing required tags
151+
- Positive code review feedback
152+
- Successful tool integration
153+
- Team adoption rate

src/main/java/br/com/fluentvalidator/Validator.java

Lines changed: 130 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,99 +26,198 @@
2626
import br.com.fluentvalidator.rule.Rule;
2727
import br.com.fluentvalidator.transform.ValidationResultTransform;
2828

29+
/**
30+
* Interface that defines the contract for fluent validators.
31+
* <p>
32+
* This interface extends {@link Rule} and provides methods for building and executing
33+
* validation rules in a fluent, chainable manner. It supports validation of single objects,
34+
* collections of objects, and provides flexible result transformation capabilities.
35+
* </p>
36+
* <p>
37+
* Implementations should define validation rules by implementing the {@link #rules()} method
38+
* and using the fluent API provided by {@link #ruleFor(Function)} and {@link #ruleForEach(Function)}
39+
* to build validation constraints.
40+
* </p>
41+
* <p>
42+
* This interface supports:
43+
* <ul>
44+
* <li>Single object validation with {@link #validate(Object)}</li>
45+
* <li>Collection validation with {@link #validate(Collection)}</li>
46+
* <li>Result transformation for custom output formats</li>
47+
* <li>Fail-fast validation mode</li>
48+
* <li>Contextual property storage and retrieval</li>
49+
* </ul>
50+
* </p>
51+
*
52+
* @param <T> the type of object being validated
53+
*/
2954
public interface Validator<T> extends Rule<T> {
3055

3156
/**
32-
*
57+
* Defines the validation rules for this validator.
58+
* <p>
59+
* Subclasses should implement this method to define validation rules using
60+
* the fluent API provided by {@link #ruleFor(Function)} and {@link #ruleForEach(Function)}.
61+
* This method is called once during initialization in a thread-safe manner.
62+
* </p>
3363
*/
3464
void rules();
3565

3666
/**
37-
*
67+
* Configures this validator to use fail-fast rule processing.
68+
* <p>
69+
* When fail-fast mode is enabled, validation will stop at the first rule failure
70+
* instead of continuing to evaluate all rules. This can improve performance when
71+
* early validation failure is acceptable.
72+
* </p>
3873
*/
3974
void failFastRule();
4075

4176
/**
77+
* Returns the current validation counter.
78+
* <p>
79+
* The counter tracks the number of validation operations or rules that have been
80+
* processed. This can be useful for debugging, monitoring, or performance analysis.
81+
* </p>
4282
*
43-
* @return Current count element on collection
83+
* @return the current counter value, or null if no counter is available
4484
*/
4585
Integer getCounter();
4686

4787
/**
88+
* Sets a property name to be used in the validation context.
89+
* <p>
90+
* This property name will be associated with the validated object in the validation
91+
* context, allowing rules to access contextual information during validation.
92+
* </p>
4893
*
49-
* @param property
94+
* @param property the property name to set in the validation context
5095
*/
5196
void setPropertyOnContext(final String property);
5297

5398
/**
99+
* Retrieves a property value from the validation context.
100+
* <p>
101+
* This method allows access to contextual information that was previously stored
102+
* in the validation context, enabling rules to make decisions based on broader
103+
* validation state.
104+
* </p>
54105
*
55-
* @param property
56-
* @param clazz
57-
* @return
106+
* @param <P> the type of the property value
107+
* @param property the name of the property to retrieve
108+
* @param clazz the class type of the property value
109+
* @return the property value cast to the specified type, or null if not found
58110
*/
59111
<P> P getPropertyOnContext(final String property, final Class<P> clazz);
60112

61113
/**
114+
* Validates a single instance and returns the validation result.
115+
* <p>
116+
* This method processes the given instance through all configured validation rules
117+
* and returns a comprehensive result containing any validation errors or success indicators.
118+
* </p>
62119
*
63-
* @param instance
64-
* @return
120+
* @param instance the object instance to validate
121+
* @return a ValidationResult containing the outcome of validation
65122
*/
66123
ValidationResult validate(final T instance);
67124

68125
/**
126+
* Validates a single instance and transforms the result using the provided transformer.
127+
* <p>
128+
* This method combines validation with result transformation in a single operation,
129+
* allowing for custom result formats or processing without intermediate objects.
130+
* </p>
69131
*
70-
* @param instance
71-
* @param transform
72-
* @return
132+
* @param <E> the type of the transformed result
133+
* @param instance the object instance to validate
134+
* @param transform the transformer to apply to the validation result
135+
* @return the transformed validation result
73136
*/
74137
<E> E validate(final T instance, final ValidationResultTransform<E> transform);
75138

76139
/**
140+
* Validates a collection of instances and returns a list of validation results.
141+
* <p>
142+
* Each instance in the collection is validated independently, and the results are
143+
* collected into a list. The order of results corresponds to the order of instances
144+
* in the input collection.
145+
* </p>
77146
*
78-
* @param instances
79-
* @return
147+
* @param instances the collection of instances to validate
148+
* @return a list of ValidationResult objects, one for each input instance
80149
*/
81150
List<ValidationResult> validate(final Collection<T> instances);
82151

83152
/**
153+
* Validates a collection of instances and transforms each result using the provided transformer.
154+
* <p>
155+
* This method combines collection validation with result transformation, applying
156+
* the transformer to each individual validation result.
157+
* </p>
84158
*
85-
* @param instances
86-
* @param transform
87-
* @return
159+
* @param <E> the type of the transformed results
160+
* @param instances the collection of instances to validate
161+
* @param transform the transformer to apply to each validation result
162+
* @return a list of transformed validation results
88163
*/
89164
<E> List<E> validate(final Collection<T> instances, final ValidationResultTransform<E> transform);
90165

91166
/**
167+
* Creates a validation rule for a specific property of the validated object.
168+
* <p>
169+
* This method starts a fluent chain for defining validation rules that apply to a
170+
* property extracted from the validated object using the provided function. The property
171+
* name will be automatically derived from the function if possible.
172+
* </p>
92173
*
93-
* @param <P>
94-
* @param function
95-
* @return
174+
* @param <P> the type of the property being validated
175+
* @param function a function that extracts the property value from the validated object
176+
* @return a RuleBuilderProperty for chaining additional validation constraints
96177
*/
97178
<P> RuleBuilderProperty<T, P> ruleFor(final Function<T, P> function);
98179

99180
/**
181+
* Creates a validation rule for a named property of the validated object.
182+
* <p>
183+
* This method starts a fluent chain for defining validation rules that apply to a
184+
* property extracted from the validated object. The field name is explicitly provided
185+
* and will be used in error messages and validation context.
186+
* </p>
100187
*
101-
* @param <P>
102-
* @param fieldName
103-
* @param function
104-
* @return
188+
* @param <P> the type of the property being validated
189+
* @param fieldName the name of the field being validated (used in error messages)
190+
* @param function a function that extracts the property value from the validated object
191+
* @return a RuleBuilderProperty for chaining additional validation constraints
105192
*/
106193
<P> RuleBuilderProperty<T, P> ruleFor(final String fieldName, final Function<T, P> function);
107194

108195
/**
196+
* Creates validation rules for each element in a collection property.
197+
* <p>
198+
* This method starts a fluent chain for defining validation rules that apply to each
199+
* element of a collection extracted from the validated object. The field name will be
200+
* automatically derived from the function if possible.
201+
* </p>
109202
*
110-
* @param <P>
111-
* @param function
112-
* @return
203+
* @param <P> the type of elements in the collection being validated
204+
* @param function a function that extracts the collection from the validated object
205+
* @return a RuleBuilderCollection for chaining additional validation constraints
113206
*/
114207
<P> RuleBuilderCollection<T, P> ruleForEach(final Function<T, Collection<P>> function);
115208

116209
/**
210+
* Creates validation rules for each element in a collection property.
211+
* <p>
212+
* This method starts a fluent chain for defining validation rules that apply to each
213+
* element of a collection extracted from the validated object. The field name is
214+
* explicitly provided for error reporting.
215+
* </p>
117216
*
118-
* @param <P>
119-
* @param fieldName
120-
* @param function
121-
* @return
217+
* @param <P> the type of elements in the collection being validated
218+
* @param fieldName the name of the collection field being validated
219+
* @param function a function that extracts the collection from the validated object
220+
* @return a RuleBuilderCollection for chaining additional validation constraints
122221
*/
123222
<P> RuleBuilderCollection<T, P> ruleForEach(final String fieldName, final Function<T, Collection<P>> function);
124223
}

0 commit comments

Comments
 (0)