Skip to content

Commit b93cc82

Browse files
committed
update javadoc
1 parent f77d64d commit b93cc82

22 files changed

Lines changed: 470 additions & 66 deletions

File tree

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
}

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,41 @@
44
import javasabr.rlib.classpath.impl.ManifestClassPathScannerImpl;
55

66
/**
7-
* @author JavaSaBr
7+
* Factory for creating {@link ClassPathScanner} instances.
8+
*
9+
* @since 10.0.0
810
*/
911
public final class ClassPathScannerFactory {
1012

13+
/**
14+
* Creates a new default scanner using the factory's class loader.
15+
*
16+
* @return a new classpath scanner
17+
* @since 10.0.0
18+
*/
1119
public static ClassPathScanner newDefaultScanner() {
1220
return new ClassPathScannerImpl(ClassPathScannerFactory.class.getClassLoader());
1321
}
1422

23+
/**
24+
* Creates a new default scanner using the specified class loader.
25+
*
26+
* @param classLoader the class loader to use
27+
* @return a new classpath scanner
28+
* @since 10.0.0
29+
*/
1530
public static ClassPathScanner newDefaultScanner(ClassLoader classLoader) {
1631
return new ClassPathScannerImpl(classLoader);
1732
}
1833

34+
/**
35+
* Creates a new default scanner using the specified class loader and additional paths.
36+
*
37+
* @param classLoader the class loader to use
38+
* @param additionalPaths additional paths to scan
39+
* @return a new classpath scanner
40+
* @since 10.0.0
41+
*/
1942
public static ClassPathScanner newDefaultScanner(
2043
ClassLoader classLoader,
2144
String[] additionalPaths) {
@@ -24,13 +47,28 @@ public static ClassPathScanner newDefaultScanner(
2447
return scanner;
2548
}
2649

50+
/**
51+
* Creates a new manifest-based scanner that reads classpath entries from the JAR manifest.
52+
*
53+
* @param rootClass the class whose JAR manifest should be read
54+
* @return a new manifest-based scanner
55+
* @since 10.0.0
56+
*/
2757
public static ClassPathScanner newManifestScanner(Class<?> rootClass) {
2858
return new ManifestClassPathScannerImpl(
2959
ClassPathScannerFactory.class.getClassLoader(),
3060
rootClass,
3161
"Class-Path");
3262
}
3363

64+
/**
65+
* Creates a new manifest-based scanner with a custom classpath key.
66+
*
67+
* @param rootClass the class whose JAR manifest should be read
68+
* @param classPathKey the manifest attribute key for classpath entries
69+
* @return a new manifest-based scanner
70+
* @since 10.0.0
71+
*/
3472
public static ClassPathScanner newManifestScanner(Class<?> rootClass, String classPathKey) {
3573
return new ManifestClassPathScannerImpl(
3674
ClassPathScannerFactory.class.getClassLoader(),
Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
package javasabr.rlib.compiler;
22

33
/**
4-
* @author JavaSaBr
4+
* Represents compiled class bytecode data.
5+
*
6+
* @since 10.0.0
57
*/
68
public interface CompiledClassData {
79

10+
/**
11+
* Returns the compiled bytecode of the class.
12+
*
13+
* @return the bytecode array
14+
* @since 10.0.0
15+
*/
816
byte[] byteCode();
917

18+
/**
19+
* Returns the size of the bytecode in bytes.
20+
*
21+
* @return the bytecode size
22+
* @since 10.0.0
23+
*/
1024
int size();
1125

26+
/**
27+
* Returns the fully qualified name of the compiled class.
28+
*
29+
* @return the class name
30+
* @since 10.0.0
31+
*/
1232
String name();
1333
}

rlib-compiler/src/main/java/javasabr/rlib/compiler/Compiler.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,46 @@
55
import javasabr.rlib.collections.array.Array;
66

77
/**
8-
* @author JavaSaBr
8+
* Runtime Java compiler interface for compiling Java source files.
9+
*
10+
* @since 10.0.0
911
*/
1012
public interface Compiler {
1113

14+
/**
15+
* The Java source file extension.
16+
*/
1217
String SOURCE_EXTENSION = ".java";
18+
19+
/**
20+
* The compiled class file extension.
21+
*/
1322
String CLASS_EXTENSION = ".class";
1423

24+
/**
25+
* Compiles Java source files from the specified URIs.
26+
*
27+
* @param urls the URIs of the source files to compile
28+
* @return an array of compiled classes
29+
* @since 10.0.0
30+
*/
1531
Array<Class<?>> compileByUrls(Array<URI> urls);
1632

33+
/**
34+
* Compiles Java source files from the specified paths.
35+
*
36+
* @param files the paths to the source files to compile
37+
* @return an array of compiled classes
38+
* @since 10.0.0
39+
*/
1740
Array<Class<?>> compileFiles(Array<Path> files);
1841

42+
/**
43+
* Compiles all Java source files in the specified directories.
44+
*
45+
* @param directories the directories containing source files to compile
46+
* @return an array of compiled classes
47+
* @since 10.0.0
48+
*/
1949
Array<Class<?>> compileDirectories(Array<Path> directories);
2050
}

rlib-compiler/src/main/java/javasabr/rlib/compiler/CompilerFactory.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,29 @@
66
import lombok.NoArgsConstructor;
77

88
/**
9-
* @author JavaSaBr
9+
* Factory for creating {@link Compiler} instances.
10+
*
11+
* @since 10.0.0
1012
*/
1113
@NoArgsConstructor(access = AccessLevel.PRIVATE)
1214
public class CompilerFactory {
1315

1416
/**
15-
* Check availability compiler API in current runtime.
17+
* Checks if the compiler API is available in the current runtime.
18+
*
19+
* @return true if the compiler is available
20+
* @since 10.0.0
1621
*/
1722
public static boolean isAvailableCompiler() {
1823
return ToolProvider.getSystemJavaCompiler() != null;
1924
}
2025

26+
/**
27+
* Creates a new default compiler instance.
28+
*
29+
* @return a new compiler
30+
* @since 10.0.0
31+
*/
2132
public static Compiler newDefaultCompiler() {
2233
return new JdkCompiler(true);
2334
}

0 commit comments

Comments
 (0)