Skip to content

Commit 254fe77

Browse files
authored
Extend/Update API part 11 (#61)
1 parent 043d6ab commit 254fe77

161 files changed

Lines changed: 4777 additions & 1745 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/copilot-instructions.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,39 @@ Common pitfalls and fixes
5151
Linting & style
5252
- The root does not expose an obvious global formatting tool (no Spotless or root Checkstyle detected). Use the existing code style. Run `./gradlew check` to execute configured verification tasks.
5353

54+
Testing conventions
55+
- Use AssertJ for assertions (import `org.assertj.core.api.Assertions`), not JUnit's `Assertions`.
56+
- Test class naming: `<ClassName>Test.java` in the same package under `src/test/java`.
57+
- Test class visibility: use package-private (no `public` modifier) for test classes.
58+
- Test method naming: `should<ExpectedBehavior>` pattern (e.g., `shouldReturnEmptyArrayForNullInput`).
59+
- Use given/when/then comments with trailing colons to structure test methods (e.g., `// given:`, `// when:`, `// then:`, `// when/then:`).
60+
- For cleanup steps, use `// cleanup:` comment section at the end of the test method.
61+
- Prefer project collections (e.g., `MutableArray`) over JDK collections (e.g., `ArrayList`) in tests when appropriate.
62+
- Use proper imports instead of fully qualified class names in test code.
63+
- When adding new public methods, ensure corresponding unit tests are added.
64+
- Use JUnit's `@TempDir Path tempDir` parameter injection for tests that need temporary directories instead of manually creating temp directories with `Files.createTempDirectory()`.
65+
- For resources created outside `@TempDir` (e.g., `Files.createTempFile()`), add explicit cleanup in the `// cleanup:` section.
66+
- For `assertThat()` calls: break method chains onto new lines with indentation when the assertion has arguments or multiple chained methods (e.g., `assertThat(result)\n .isEqualTo("expected")`). Short simple assertions can stay on one line.
67+
- For fluent builder/method chains: break onto new lines with indentation (e.g., `tempDir\n .resolve("level1")\n .resolve("level2")`).
68+
69+
Javadoc conventions
70+
- All public classes, interfaces, and methods should have javadoc.
71+
- Javadoc must include `@since` tag with version (e.g., `@since 10.0.0`).
72+
- Use short, active-voice descriptions (e.g., "Returns an array" not "Return an array").
73+
- Do not use trailing periods in `@param` and `@return` descriptions (e.g., `@param value the value` not `@param value the value.`).
74+
- Include `@param` and `@return` tags for non-trivial methods.
75+
- Omit javadoc for simple getters/setters (e.g., `getArch()`, `setArch(String)`); they are self-explanatory.
76+
- Omit obvious field comments that just repeat the field name (e.g., `/** The name. */ private String name;`).
77+
- Omit obvious constant comments (e.g., `/** The constant FOO. */ public static final String FOO = "foo";`).
78+
- Type parameter descriptions should use consistent format: "the type of..." (e.g., `@param <T> the type of elements` not `@param <T> the element type`).
79+
- Do not generate javadoc for implementation classes (only interfaces and public API classes).
80+
- For `@see` tags, avoid duplicate references (e.g., use `@see Math#sin(double)` not `@see Math#sin(double) Math#sin(double)`).
81+
- For functional interfaces:
82+
- Consumer descriptions must include "and returns no result" (e.g., "Represents an operation that accepts an int and an object argument, and returns no result.").
83+
- Use type-specific @param descriptions (e.g., "the int argument", "the object argument") instead of generic "the first argument".
84+
- Function @return should use "the function result" for consistency.
85+
- Predicate @return should use "true if the arguments match the predicate".
86+
5487
Project layout & where to change things
5588
- Root-level important files:
5689
- `build.gradle` — root build settings, wrapper config.

.github/skills/generate-javadoc.md

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ When the user asks to:
88
- Generate javadocs for a module
99
- Add documentation to public APIs
1010
- Document interfaces/classes with `@since` tags
11+
- Review and fix existing javadocs
12+
- Clean up javadoc formatting
1113

1214
## Requirements
1315

@@ -16,23 +18,42 @@ When the user asks to:
1618
2. **Skip implementation classes** - files in `impl/` packages are NOT documented
1719
3. **Skip test classes** - files in `src/test/` are NOT documented
1820

21+
### What to Omit
22+
1. **Simple getters/setters** - methods like `getArch()`, `setArch(String)` are self-explanatory
23+
2. **Obvious field comments** - avoid comments that just repeat the field name (e.g., `/** The name. */ private String name;`)
24+
3. **Obvious constructor javadocs** - avoid comments like "Instantiates a new Foo"
25+
4. **Obvious constant comments** - avoid comments like "The constant FOO" for `public static final String FOO`
26+
27+
### Formatting Rules
28+
1. **Active voice** - use "Returns" not "Return", "Creates" not "Create"
29+
2. **No trailing periods** - in `@param` and `@return` descriptions (e.g., `@param value the value` not `@param value the value.`)
30+
3. **No duplicate @see references** - use `@see Math#sin(double)` not `@see Math#sin(double) Math#sin(double)`
31+
4. **Lowercase @param/@return descriptions** - start with lowercase (e.g., `@param value the value` not `@param value The value`)
32+
5. **Consistent type parameter format** - use "the type of..." pattern (e.g., `@param <T> the type of elements` not `@param <T> the element type`)
33+
6. **Descriptive @param names** - for functional interfaces, use type-specific descriptions (e.g., "the int argument", "the object argument") instead of generic "the first argument"
34+
35+
### Functional Interface Conventions
36+
1. **Consumer descriptions** - always include "and returns no result" (e.g., "Represents an operation that accepts an int and an object argument, and returns no result.")
37+
2. **Function @return** - use "the function result" for consistency
38+
3. **Predicate @return** - use "true if the arguments match the predicate" or "true if the arguments match the predicate, false otherwise"
39+
4. **Supplier @return** - describe what is supplied (e.g., "the char value" not just "a result")
40+
1941
### Javadoc Standards
2042
Each documented element must include:
2143

2244
1. **Class/Interface level:**
23-
- Short description of purpose
24-
- `@param` for type parameters (if generic)
25-
- `@author JavaSaBr`
45+
- Short description of purpose (active voice)
46+
- `@param` for type parameters with meaningful descriptions (if generic)
2647
- `@since 10.0.0`
2748

2849
2. **Method level:**
29-
- Short description for ALL methods
50+
- Short description for non-trivial methods
3051
- `@param` and `@return` only for **non-trivial** methods
3152
- `@since 10.0.0`
3253
- `@throws` only when explicitly thrown
3354

3455
3. **Constants/Fields:**
35-
- Short description
56+
- Short description (only if not obvious from the name)
3657
- `@since 10.0.0`
3758

3859
### Example Format
@@ -42,7 +63,6 @@ Each documented element must include:
4263
* An immutable array interface that provides type-safe, indexed access to elements.
4364
*
4465
* @param <E> the type of elements in this array
45-
* @author JavaSaBr
4666
* @since 10.0.0
4767
*/
4868
public interface Array<E> extends Iterable<E> {
@@ -79,6 +99,37 @@ public interface Array<E> extends Iterable<E> {
7999
}
80100
```
81101

102+
### Functional Interface Example
103+
104+
```java
105+
/**
106+
* Represents an operation that accepts an int and an object argument, and returns no result.
107+
*
108+
* @param <B> the type of the object argument
109+
* @since 10.0.0
110+
*/
111+
@FunctionalInterface
112+
public interface IntObjConsumer<B> {
113+
114+
/**
115+
* Performs this operation on the given arguments.
116+
*
117+
* @param arg1 the int argument
118+
* @param arg2 the object argument
119+
* @since 10.0.0
120+
*/
121+
void accept(int arg1, B arg2);
122+
}
123+
```
124+
125+
### Common Fixes When Reviewing Existing Javadocs
126+
- Change "Return the" to "Returns the"
127+
- Change "Compare the" to "Compares the"
128+
- Remove trailing periods from `@param` and `@return` lines
129+
- Remove obvious/redundant javadocs (getters, setters, constants)
130+
- Remove duplicate `@see` references
131+
- Add missing `@since` tags
132+
82133
## Execution Steps
83134

84135
1. **Analyze module structure:**
@@ -94,7 +145,7 @@ public interface Array<E> extends Iterable<E> {
94145
3. **Read each file** to understand existing documentation state
95146

96147
4. **Add Javadocs** using `replace_string_in_file` tool:
97-
- Add class-level Javadoc with description, `@author`, `@since`
148+
- Add class-level Javadoc with description and `@since`
98149
- Add method-level Javadocs with description and `@since`
99150
- Add `@param`/`@return` only for non-trivial methods
100151

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ repositories {
4545
}
4646
4747
ext {
48-
rlibVersion = "10.0.alpha12"
48+
rlibVersion = "10.0.alpha13"
4949
}
5050
5151
dependencies {

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
rootProject.version = "10.0.alpha12"
1+
rootProject.version = "10.0.alpha13"
22
group = 'javasabr.rlib'
33

44
allprojects {

rlib-classpath/src/main/java/javasabr/rlib/classpath/ClassPathScanner.java

Lines changed: 137 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,35 @@
1010
import org.jspecify.annotations.Nullable;
1111

1212
/**
13-
* @author JavaSaBr
13+
* Scanner for discovering classes and resources on the classpath.
14+
*
15+
* @since 10.0.0
1416
*/
1517
public interface ClassPathScanner {
1618

19+
/**
20+
* The JAR file extension.
21+
*/
1722
String JAR_EXTENSION = ".jar";
23+
24+
/**
25+
* The Java source file extension.
26+
*/
1827
String SOURCE_EXTENSION = ".java";
28+
29+
/**
30+
* The compiled class file extension.
31+
*/
1932
String CLASS_EXTENSION = ".class";
2033

34+
/**
35+
* A null scanner constant.
36+
*/
2137
@Nullable ClassPathScanner NULL_SCANNER = null;
2238

39+
/**
40+
* An empty scanner that performs no operations.
41+
*/
2342
ClassPathScanner EMPTY_SCANNER = new ClassPathScannerImpl(ClassPathScanner.class.getClassLoader()) {
2443

2544
@Override
@@ -38,55 +57,172 @@ public void addResources(Array<String> resources) {}
3857
public void scan(Predicate<String> filter) {}
3958
};
4059

60+
/**
61+
* An empty class loader with no URLs.
62+
*/
4163
URLClassLoader EMPTY_CLASS_LOADER = new URLClassLoader(new URL[0], ClassPathScanner.class.getClassLoader());
4264

65+
/**
66+
* A null class loader constant.
67+
*/
4368
@Nullable URLClassLoader NULL_CLASS_LOADER = null;
4469

70+
/**
71+
* Adds discovered classes to the specified collection.
72+
*
73+
* @param classes the collection to add classes to
74+
* @since 10.0.0
75+
*/
4576
void addClasses(Array<Class<?>> classes);
4677

78+
/**
79+
* Adds discovered resources to the specified collection.
80+
*
81+
* @param resources the collection to add resources to
82+
* @since 10.0.0
83+
*/
4784
void addResources(Array<String> resources);
4885

86+
/**
87+
* Sets whether to include the system classpath in scanning.
88+
*
89+
* @param useSystemClasspath true to include system classpath
90+
* @since 10.0.0
91+
*/
4992
void useSystemClassPath(boolean useSystemClasspath);
5093

94+
/**
95+
* Finds all implementations of the specified interface.
96+
*
97+
* @param <T> the type of the interface
98+
* @param interfaceClass the interface class to find implementations for
99+
* @return an array of implementing classes
100+
* @since 10.0.0
101+
*/
51102
default <T> Array<Class<T>> findImplementations(Class<T> interfaceClass) {
52103
MutableArray<Class<T>> result = MutableArray.ofType(Class.class);
53104
findImplementationsTo(result, interfaceClass);
54105
return result;
55106
}
56107

108+
/**
109+
* Finds all implementations of the specified interface and adds them to the container.
110+
*
111+
* @param <T> the type of the interface
112+
* @param container the container to add implementations to
113+
* @param interfaceClass the interface class to find implementations for
114+
* @since 10.0.0
115+
*/
57116
<T> void findImplementationsTo(MutableArray<Class<T>> container, Class<T> interfaceClass);
58117

118+
/**
119+
* Finds all classes that inherit from the specified parent class.
120+
*
121+
* @param <T> the type of the parent class
122+
* @param parentClass the parent class to find subclasses for
123+
* @return an array of subclasses
124+
* @since 10.0.0
125+
*/
59126
default <T> Array<Class<T>> findInherited(Class<T> parentClass) {
60127
MutableArray<Class<T>> result = MutableArray.ofType(Class.class);
61128
findInheritedTo(result, parentClass);
62129
return result;
63130
}
64131

132+
/**
133+
* Finds all classes that inherit from the specified parent class and adds them to the container.
134+
*
135+
* @param <T> the type of the parent class
136+
* @param container the container to add subclasses to
137+
* @param parentClass the parent class to find subclasses for
138+
* @since 10.0.0
139+
*/
65140
<T> void findInheritedTo(MutableArray<Class<T>> container, Class<T> parentClass);
66141

142+
/**
143+
* Finds all classes annotated with the specified annotation.
144+
*
145+
* @param annotationClass the annotation class to search for
146+
* @return an array of annotated classes
147+
* @since 10.0.0
148+
*/
67149
default Array<Class<?>> findAnnotated(Class<? extends Annotation> annotationClass) {
68150
MutableArray<Class<?>> result = MutableArray.ofType(Class.class);
69151
findAnnotatedTo(result, annotationClass);
70152
return result;
71153
}
72154

155+
/**
156+
* Finds all classes annotated with the specified annotation and adds them to the container.
157+
*
158+
* @param container the container to add annotated classes to
159+
* @param annotationClass the annotation class to search for
160+
* @since 10.0.0
161+
*/
73162
void findAnnotatedTo(MutableArray<Class<?>> container, Class<? extends Annotation> annotationClass);
74163

164+
/**
165+
* Adds all found classes to the specified container.
166+
*
167+
* @param container the container to add classes to
168+
* @since 10.0.0
169+
*/
75170
void foundClassesTo(MutableArray<Class<?>> container);
76171

172+
/**
173+
* Adds all found resources to the specified container.
174+
*
175+
* @param container the container to add resources to
176+
* @since 10.0.0
177+
*/
77178
void foundResourcesTo(MutableArray<String> container);
78179

180+
/**
181+
* Returns all classes found during scanning.
182+
*
183+
* @return an array of found classes
184+
* @since 10.0.0
185+
*/
79186
Array<Class<?>> foundClasses();
80187

188+
/**
189+
* Returns all resources found during scanning.
190+
*
191+
* @return an array of found resource paths
192+
* @since 10.0.0
193+
*/
81194
Array<String> foundResources();
82195

196+
/**
197+
* Scans the classpath without any filter.
198+
*
199+
* @since 10.0.0
200+
*/
83201
default void scan() {
84202
scan(null);
85203
}
86204

205+
/**
206+
* Scans the classpath with the specified filter.
207+
*
208+
* @param filter the filter to apply during scanning, or null for no filter
209+
* @since 10.0.0
210+
*/
87211
void scan(@Nullable Predicate<String> filter);
88212

213+
/**
214+
* Adds an additional path to scan.
215+
*
216+
* @param path the path to add
217+
* @since 10.0.0
218+
*/
89219
void addAdditionalPath(String path);
90220

221+
/**
222+
* Adds additional paths to scan.
223+
*
224+
* @param paths the paths to add
225+
* @since 10.0.0
226+
*/
91227
void addAdditionalPaths(String[] paths);
92228
}

0 commit comments

Comments
 (0)