### Query API Basics Source: https://github.com/ronmamo/reflections/blob/master/README.md Explains the fundamental operations of the Query API, including retrieving direct values with `get()` and transitive values with `with()` or `of()`. ```APIDOC Query API: Each Scanner and ReflectionUtils function supports: - `get()`: Returns direct values. - `with()` or `of()`: Returns all transitive values. Example: `Scanners.SubTypes.get(T)` returns direct subtypes. `Scanners.SubTypes.of(T)` returns transitive subtypes hierarchy. This applies similarly to `Scanners.TypesAnnotated` and `ReflectionUtils.SuperTypes`, etc. ``` -------------------------------- ### Getting Merged Annotations of Rest Controllers Source: https://github.com/ronmamo/reflections/blob/master/README.md An advanced example demonstrating how to retrieve merged annotations for REST controller endpoints, including method and declaring class annotations. ```java // get all annotations of RequestMapping hierarchy (GetMapping, PostMapping, ...) Set> metaAnnotations = reflections.get(TypesAnnotated.getAllIncluding(RequestMapping.class.getName()).asClass()); QueryFunction> queryAnnotations = // get all controller endpoint methods MethodsAnnotated.with(metaAnnotations).as(Method.class) .map(method -> // get both method's + declaring class's RequestMapping annotations get(Annotations.of(method.getDeclaringClass()) .add(Annotations.of(method)) .filter(a -> metaAnnotations.contains(a.annotationType()))) .stream() // merge annotations' member values into a single hash map .collect(new AnnotationMergeCollector(method))); // apply query and map merged hashmap into java annotation proxy Set mergedAnnotations = reflections.get(mergedAnnotation .map(map -> ReflectionUtils.toAnnotation(map, metaAnnotation))); ``` -------------------------------- ### Reflections Configuration with Packages Source: https://github.com/ronmamo/reflections/blob/master/README.md Illustrates how to configure the Reflections library to scan a specific package using ConfigurationBuilder and default scanners. ```java Reflections reflections = new Reflections( new ConfigurationBuilder() .forPackage("com.my.project") .filterInputsBy(new FilterBuilder().includePackage("com.my.project"))); ``` -------------------------------- ### Apache License 2.0 Boilerplate Source: https://github.com/ronmamo/reflections/blob/master/LICENSE-2.0.txt The standard boilerplate notice required for projects licensed under the Apache License 2.0. This includes copyright and licensing information. ```text Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ``` -------------------------------- ### Reflections Configuration with Specific Scanners Source: https://github.com/ronmamo/reflections/blob/master/README.md Demonstrates configuring Reflections to scan a package with specific scanners (TypesAnnotated, MethodsAnnotated, MethodsReturn) and input filters. ```java import static org.reflections.scanners.Scanners.*; Reflections reflections = new Reflections( new ConfigurationBuilder() .forPackage("com.my.project") .filterInputsBy(new FilterBuilder().includePackage("com.my.project").excludePackage("com.my.project.exclude")) .setScanners(TypesAnnotated, MethodsAnnotated, MethodsReturn)); ``` -------------------------------- ### Comparing Reflections Scanners with Previous API Source: https://github.com/ronmamo/reflections/blob/master/README.md Provides a comparison table between the current Reflections scanners and the previous 0.9.x API, highlighting the equivalent methods and scanners. It also notes obsolete scanners and provides clarifications on specific scanner usages. ```APIDOC Scanners vs. Previous 0.9.x API: | Scanners | previous 0.9.x API | previous Scanner | | ---------------------------------------------------- | ------------------------------------------------------------------------------- | ------------------------ | | `get(SubType.of(T))` | `getSubTypesOf(T)` | `~~SubTypesScanner~~` | | `get(SubTypes.of(TypesAnnotated.with(A)))` | `getTypesAnnotatedWith(A) *(1)*` | `~~TypeAnnotationsScanner~~` | | `get(MethodsAnnotated.with(A))` | `getMethodsAnnotatedWith(A)` | `~~MethodAnnotationsScanner~~` | | `get(ConstructorsAnnotated.with(A))` | `getConstructorsAnnotatedWith(A) *(2)*` | `~~MethodAnnotationsScanner~~` | | `get(FieldsAnnotated.with(A))` | `getFieldsAnnotatedWith(A)` | `~~FieldAnnotationsScanner~~` | | `get(Resources.with(regex))` | `getResources(regex)` | `~~ResourcesScanner~~` | | `get(MethodsParameter.with(P))` | `getMethodsWithParameter(P) *(3)*`
`~~getMethodsWithAnyParamAnnotated(P)~~ | `~~MethodParameterScanner~~`
*obsolete* | | `get(MethodsSignature.of(P, ...))` | `getMethodsWithSignature(P, ...) *(3)`
`~~getMethodsMatchParams(P, ...)~~` | `~~MethodParameterScanner~~` | | `get(MethodsReturn.of(T))` | `getMethodsReturn(T) *(3)*` | `~~MethodParameterScanner~~` | | `get(ConstructorsParameter.with(P))` | `getConstructorsWithParameter(P) *(3)`
`~~getConstructorsWithAnyParamAnnotated(P)~~` | `~~MethodParameterScanner~~` | | `get(ConstructorsSignature.of(P, ...))` | `getConstructorsWithSignature(P, ...) *(3)`
`~~getConstructorsMatchParams(P, ...)~~` | `~~MethodParameterScanner~~` | *Note: `asClass()` and `as()` mappings were omitted* *(1): The equivalent of `getTypesAnnotatedWith(A)` is `get(SubTypes.of(TypesAnnotated.with(A)))`, including SubTypes* *(2): MethodsAnnotatedScanner does not include constructor annotation scanning, use instead Scanners.ConstructorsAnnotated* *(3): MethodParameterScanner is obsolete, use instead as required: Scanners.MethodsParameter, Scanners.MethodsSignature, Scanners.MethodsReturn, Scanners.ConstructorsParameter, Scanners.ConstructorsSignature* ``` -------------------------------- ### Composing Scanners and ReflectionUtils Functions Source: https://github.com/ronmamo/reflections/blob/master/README.md Shows how to compose functions from Scanners and ReflectionUtils to obtain methods from a given type's classpath metadata. ```java QueryFunction methods = SubTypes.of(type).asClass() // <-- classpath scanned metadata .flatMap(Methods::of); // <-- java reflection api ``` -------------------------------- ### Query API Usage with Filter and Map Source: https://github.com/ronmamo/reflections/blob/master/README.md Demonstrates using the Query API with filter and map operations to retrieve public methods with no parameters, returning them as Method objects. ```java QueryFunction getters = Methods.of(C1.class) .filter(withModifier(Modifier.PUBLIC)) .filter(withPrefix("get").and(withParametersCount(0))) .as(Method.class); ``` -------------------------------- ### Querying Indexed Metadata with Reflections Scanners Source: https://github.com/ronmamo/reflections/blob/master/README.md Demonstrates how to use various Reflections scanners to query indexed metadata, including subtypes, annotated types, annotated methods, annotated fields, and resources. It shows how to specify the return type using '.asClass()' or '.as(Type.class)'. ```java import static org.reflections.scanners.Scanners.*; // SubTypes Set> modules = reflections.get(SubTypes.of(Module.class).asClass()); // TypesAnnotated (*1) Set> singletons = reflections.get(TypesAnnotated.with(Singleton.class).asClass()); // MethodsAnnotated Set resources = reflections.get(MethodsAnnotated.with(GetMapping.class).as(Method.class)); // FieldsAnnotated Set ids = reflections.get(FieldsAnnotated.with(Id.class).as(Field.class)); // Resources Set properties = reflections.get(Resources.with(".*\\.properties")); ``` ```java // MethodsReturn Set voidMethods = reflections.get(MethodsReturn.with(void.class).as(Method.class)); // MethodsSignature Set someMethods = reflections.get(MethodsSignature.of(long.class, int.class).as(Method.class)); // MethodsParameter Set pathParam = reflections.get(MethodsParameter.of(PathParam.class).as(Method.class)); // ConstructorsAnnotated Set injectables = reflections.get(ConstructorsAnnotated.with(Inject.class).as(Constructor.class)); // ConstructorsSignature Set someConstructors = reflections.get(ConstructorsSignature.of(String.class).as(Constructor.class)); // MethodParameterNamesScanner List parameterNames = reflections.getMemberParameterNames(member); // MemberUsageScanner Set usages = reflections.getMemberUsages(member) ``` -------------------------------- ### MemberUsageScanner Source: https://github.com/ronmamo/reflections/blob/master/README.md Introduces the experimental MemberUsageScanner for querying member usages across packages, types, and elements, useful for dependency analysis. ```APIDOC MemberUsageScanner: Experimental scanner for querying member usages (e.g., `getMemberUsages()`). Allows finding usages between packages, layers, modules, types, etc. ``` -------------------------------- ### Reflections Serialization and Collection Source: https://github.com/ronmamo/reflections/blob/master/README.md Describes how to save scanned metadata using `Reflections.save()` and collect it on bootstrap with `Reflections.collect()`, useful for build lifecycle integration. ```APIDOC Build Lifecycle Integration: - `Reflections.save()`: Saves scanned metadata (e.g., to XML/JSON) as part of the build lifecycle. - `Reflections.collect()`: Collects previously saved metadata on bootstrap, avoiding runtime scanning. See [reflections-maven](https://github.com/ronmamo/reflections-maven/) for an example. ``` -------------------------------- ### Using ReflectionUtils for Classpath Metadata Access Source: https://github.com/ronmamo/reflections/blob/master/README.md Illustrates how to use utility methods from ReflectionUtils to access various aspects of Java classes, including supertypes, fields, constructors, methods, resources, annotations, and annotation types. It mentions support for previous 0.9.x APIs. ```java import static org.reflections.ReflectionUtils.*; Set> superTypes = get(SuperTypes.of(T)); Set fields = get(Fields.of(T)); Set constructors = get(Constructors.of(T)); Set methods = get(Methods.of(T)); Set resources = get(Resources.with(T)); Set annotations = get(Annotations.of(T)); Set> annotationTypes = get(AnnotationTypes.of(T)); ``` -------------------------------- ### Basic Reflections Usage (0.10.x API) Source: https://github.com/ronmamo/reflections/blob/master/README.md Demonstrates the basic usage of the Reflections library with its newer functional API to find subtypes of a class and types annotated with a specific annotation. ```java Reflections reflections = new Reflections("com.my.project"); Set> subTypes = reflections.get(SubTypes.of(SomeType.class).asClass()); Set> annotated = reflections.get(SubTypes.of(TypesAnnotated.with(SomeAnnotation.class)).asClass()); ``` -------------------------------- ### Add Reflections Dependency (Maven/Gradle) Source: https://github.com/ronmamo/reflections/blob/master/README.md This snippet shows how to add the Reflections library as a dependency to your Java project using either Maven or Gradle build tools. ```xml org.reflections reflections 0.10.2 ``` ```gradle implementation 'org.reflections:reflections:0.10.2' ``` -------------------------------- ### Basic Reflections Usage (0.9.x API) Source: https://github.com/ronmamo/reflections/blob/master/README.md Shows the older API usage for finding subtypes of a class and types annotated with a specific annotation using the Reflections library. ```java Set> subTypes = reflections.getSubTypesOf(SomeType.class); Set> annotated = reflections.getTypesAnnotatedWith(SomeAnnotation.class); ``` -------------------------------- ### JavaCodeSerializer Source: https://github.com/ronmamo/reflections/blob/master/README.md Explains the JavaCodeSerializer for persisting scanned metadata into generated Java source code, enabling strongly typed access. ```APIDOC JavaCodeSerializer: Persists scanned metadata into generated Java source code. Useful for accessing types and members in a strongly typed manner. See example: [MyTestModelStore.java](https://github.com/ronmamo/reflections/blob/master/src/test/java/org/reflections/MyTestModelStore.java) ``` -------------------------------- ### QueryFunction Fluent Interface Source: https://github.com/ronmamo/reflections/blob/master/README.md Details the fluent functional interface provided by QueryFunction for composing operations like filter, map, flatMap, and as. ```APIDOC QueryFunction Interface: Provides a fluent functional interface for composing operations such as: - `filter()` - `map()` - `flatMap()` - `as()` This allows for chaining operations to refine query results. ``` -------------------------------- ### AnnotationMergeCollector Source: https://github.com/ronmamo/reflections/blob/master/README.md Details the AnnotationMergeCollector utility for merging similar annotations, with a reference to its usage in tests. ```APIDOC AnnotationMergeCollector: Utility for merging similar annotations. See test usage: [ReflectionUtilsQueryTest.java#L216](https://github.com/ronmamo/reflections/blob/master/src/test/java/org/reflections/ReflectionUtilsQueryTest.java#L216) ``` -------------------------------- ### Function of Function for Annotation Querying Source: https://github.com/ronmamo/reflections/blob/master/README.md Illustrates a 'function of function' pattern to query annotations of methods within a specific class. ```java QueryFunction> queryAnnotations = Annotations.of(Methods.of(C4.class)) .map(Annotation::annotationType); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.