Skip to content

Commit 3082b07

Browse files
authored
Merge pull request #166 from microsphere-projects/dev
Release 0.1.2
2 parents a6bf28d + 3b5a84d commit 3082b07

438 files changed

Lines changed: 24729 additions & 3587 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.

microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/ConfigurationPropertyAnnotationProcessor.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@
4444
/**
4545
* The {@link Processor} for the {@link ConfigurationProperty} annotation
4646
*
47+
* <p>This class processes the {@link ConfigurationProperty} annotations during the compilation phase,
48+
* collects metadata about annotated elements, and generates a JSON metadata file that contains
49+
* configuration property information.
50+
*
51+
* <ul>
52+
* <li>{@link #init(ProcessingEnvironment)} initializes required utilities such as the Messager and ResourceProcessor.</li>
53+
* <li>{@link #process(Set, RoundEnvironment)} handles each processing round:
54+
* <ul>
55+
* <li>During normal rounds, it resolves metadata from annotated elements.</li>
56+
* <li>On the final round, it writes collected metadata into a resource file.</li>
57+
* </ul>
58+
* </li>
59+
* <li>{@link #resolveMetadata(RoundEnvironment)} traverses all root elements to extract configuration property metadata.</li>
60+
* <li>{@link #writeMetadata()} writes the generated metadata into a JSON file under
61+
* {@value #CONFIGURATION_PROPERTY_METADATA_RESOURCE_NAME} using a writer.</li>
62+
* </ul>
63+
*
4764
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
4865
* @see ConfigurationProperty
4966
* @since 1.0.0

microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/FilerProcessor.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,17 @@
2828
import static io.microsphere.reflect.FieldUtils.getFieldValue;
2929

3030
/**
31-
* The {@link Filer} Processor
31+
* A processor class that provides safe and exception-handled operations for interacting with the {@link Filer}
32+
* in an annotation processing environment. This class wraps calls to the underlying {@link Filer} instance
33+
* obtained from the provided {@link ProcessingEnvironment}, ensuring robust resource handling and simplifying
34+
* error management through functional interfaces.
35+
*
36+
* <p>It supports executing operations on the {@link Filer} using a callback model, allowing custom logic to be
37+
* applied while handling exceptions gracefully using provided handlers.</p>
3238
*
3339
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
34-
* @see ProcessingEnvironment
35-
* @see Filer
40+
* @see #processInFiler(ThrowableFunction)
41+
* @see #processInFiler(ThrowableFunction, BiFunction)
3642
* @since 1.0.0
3743
*/
3844
public class FilerProcessor {

microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/ResourceProcessor.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,22 @@
4141
import static java.util.Optional.of;
4242

4343
/**
44-
* The {@link ProcessingEnvironment} Processor
44+
* A processor class that provides a comprehensive and exception-safe mechanism for handling resources during annotation processing.
45+
* It extends the capabilities of the {@link FilerProcessor} to manage both reading from and writing to resources using various I/O operations.
46+
* This class abstracts away boilerplate code required for resource management, including opening/closing streams, handling exceptions,
47+
* and caching accessed file objects to avoid redundant operations.
48+
*
49+
* <p>It supports functional-style interaction with resources through callback interfaces like {@link ThrowableFunction},
50+
* allowing custom logic to be applied on resources such as reading content, writing data, or manipulating streams in a type-safe manner.</p>
51+
*
52+
* <p>The class also maintains an internal cache of accessed file objects to optimize performance by avoiding repeated calls to locate or create them.
53+
* It handles both input (read) and output (write) operations seamlessly, offering convenience methods for common use cases like:
54+
* - Processing resources via InputStream or Reader
55+
* - Manipulating resources via OutputStream or Writer
56+
* - Reading or modifying the content directly as CharSequence</p>
4557
*
4658
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
47-
* @see ProcessingEnvironment
59+
* @see FilerProcessor
4860
* @since 1.0.0
4961
*/
5062
public class ResourceProcessor {

microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/AnnotationUtils.java

Lines changed: 379 additions & 2 deletions
Large diffs are not rendered by default.

microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/ClassUtils.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,41 @@
3636
*/
3737
public interface ClassUtils extends Utils {
3838

39+
/**
40+
* Returns the fully qualified name of the class represented by the given {@link TypeMirror}.
41+
*
42+
* @param type the type mirror to get the class name from
43+
* @return the fully qualified class name
44+
*/
3945
static String getClassName(TypeMirror type) {
4046
return ofTypeElement(type).getQualifiedName().toString();
4147
}
4248

49+
50+
/**
51+
* Loads the class represented by the given {@link TypeMirror}.
52+
*
53+
* <p>This method attempts to resolve the class using the fully qualified name derived from the type mirror.
54+
* If the class cannot be resolved directly, an attempt is made to resolve it as a nested or inner class by
55+
* replacing the last dot ({@code .}) with a dollar sign ({@code $}).
56+
*
57+
* @param type the type mirror representing the class to load
58+
* @return the resolved {@link Class}, or {@code null} if the class cannot be found
59+
*/
4360
static Class loadClass(TypeMirror type) {
4461
return loadClass(getClassName(type));
4562
}
4663

64+
/**
65+
* Loads the class represented by the given fully qualified class name.
66+
*
67+
* <p>This method attempts to resolve the class using the provided class name and the class loader
68+
* obtained from {@link ClassUtils}. If the class is not found, an attempt is made to resolve it
69+
* as a nested or inner class by replacing the last dot ({@code .}) with a dollar sign ({@code $}).
70+
*
71+
* @param className the fully qualified name of the class to load
72+
* @return the resolved {@link Class}, or {@code null} if the class cannot be found
73+
*/
4774
static Class loadClass(String className) {
4875
ClassLoader classLoader = getClassLoader(ClassUtils.class);
4976
Class<?> klass = resolveClass(className, classLoader);

microsphere-annotation-processor/src/main/java/io/microsphere/annotation/processor/util/ElementUtils.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,14 +245,34 @@ static boolean matchesElementType(Element element, ElementType... elementTypes)
245245
}
246246

247247

248+
/**
249+
* Checks whether the specified {@link Element} has the specified {@link ElementKind}.
250+
*
251+
* @param member the {@link Element} to check, may be {@code null}
252+
* @param kind the {@link ElementKind} to match, may be {@code null}
253+
* @return {@code true} if the element is not null and its kind matches the specified kind; otherwise, {@code false}
254+
*/
248255
static boolean matchesElementKind(Element member, ElementKind kind) {
249256
return member == null || kind == null ? false : kind.equals(member.getKind());
250257
}
251258

259+
/**
260+
* Checks whether the specified {@link Element} is public and non-static.
261+
*
262+
* @param member the {@link Element} to check, may be {@code null}
263+
* @return {@code true} if the element is public and not static; otherwise, {@code false}
264+
*/
252265
static boolean isPublicNonStatic(Element member) {
253266
return hasModifiers(member, PUBLIC) && !hasModifiers(member, STATIC);
254267
}
255268

269+
/**
270+
* Checks whether the specified {@link Element} has all of the specified {@link Modifier}s.
271+
*
272+
* @param member the {@link Element} to check, may be {@code null}
273+
* @param modifiers the array of {@link Modifier}s to match, may be {@code null}
274+
* @return {@code true} if the element is not null and contains all specified modifiers; otherwise, {@code false}
275+
*/
256276
static boolean hasModifiers(Element member, Modifier... modifiers) {
257277
if (member == null || modifiers == null) {
258278
return false;
@@ -266,6 +286,17 @@ static boolean hasModifiers(Element member, Modifier... modifiers) {
266286
return true;
267287
}
268288

289+
/**
290+
* Filters the provided list of {@link Element} objects based on the given array of {@link Predicate} conditions.
291+
*
292+
* <p>If the input list of elements is empty or the array of predicates is null, an empty list is returned.</p>
293+
*
294+
* @param elements The list of elements to be filtered, may be {@code null}
295+
* @param elementPredicates An array of predicates used to filter the elements, may be {@code null}
296+
* @param <E> The type of the elements, which must be a subclass of {@link Element}
297+
* @return A filtered list of elements that match all the provided predicates. Returns an empty list if no elements match,
298+
* or if the input list or predicate array is invalid.
299+
*/
269300
static <E extends Element> List<E> filterElements(List<E> elements, Predicate<? super E>... elementPredicates) {
270301
if (isEmpty(elements) || elementPredicates == null) {
271302
return emptyList();
@@ -277,15 +308,52 @@ static <E extends Element> List<E> filterElements(List<E> elements, Predicate<?
277308
return elements.isEmpty() ? emptyList() : elements;
278309
}
279310

311+
/**
312+
* Checks whether the parameter types of the given {@link ExecutableElement} match the specified {@link Type types}.
313+
*
314+
* <p>
315+
* If either the executable element or the parameter types array is {@code null}, this method returns {@code false}.
316+
* Otherwise, it compares the fully qualified type names of the parameters.
317+
* </p>
318+
*
319+
* @param executableElement the executable element whose parameters are to be checked, may be {@code null}
320+
* @param parameterTypes the expected parameter types, may be {@code null}
321+
* @return {@code true} if the parameter types match; {@code false} otherwise
322+
*/
280323
static boolean matchParameterTypes(ExecutableElement executableElement, Type... parameterTypes) {
281324
return executableElement == null || parameterTypes == null ? false :
282325
matchParameterTypeNames(executableElement.getParameters(), getTypeNames(parameterTypes));
283326
}
284327

328+
/**
329+
* Checks whether the parameter types of the given list of {@link VariableElement} parameters match the specified {@link Type types}.
330+
*
331+
* <p>
332+
* If either the parameters list or the parameter types array is {@code null}, this method returns {@code false}.
333+
* Otherwise, it compares the fully qualified type names of the parameters.
334+
* </p>
335+
*
336+
* @param parameters the list of variable elements representing the parameters, may be {@code null}
337+
* @param parameterTypes the expected parameter types, may be {@code null}
338+
* @return {@code true} if the parameter types match; {@code false} otherwise
339+
*/
285340
static boolean matchParameterTypes(List<? extends VariableElement> parameters, Type... parameterTypes) {
286341
return parameters == null || parameterTypes == null ? false : matchParameterTypeNames(parameters, getTypeNames(parameterTypes));
287342
}
288343

344+
/**
345+
* Checks whether the parameter types of the given list of {@link VariableElement} parameters match the specified type names.
346+
*
347+
* <p>
348+
* If either the parameters list or the parameter type names array is {@code null}, this method returns {@code false}.
349+
* It also returns {@code false} if the sizes of the two arrays do not match.
350+
* Otherwise, it compares each parameter's type with the corresponding type name using {@link TypeUtils#isSameType(Element, CharSequence)}.
351+
* </p>
352+
*
353+
* @param parameters the list of variable elements representing the parameters, may be {@code null}
354+
* @param parameterTypeNames the expected fully qualified type names of the parameters, may be {@code null}
355+
* @return {@code true} if all parameter types match their corresponding type names; {@code false} otherwise
356+
*/
289357
static boolean matchParameterTypeNames(List<? extends VariableElement> parameters, CharSequence... parameterTypeNames) {
290358
if (parameters == null || parameterTypeNames == null) {
291359
return false;

0 commit comments

Comments
 (0)