Class ReflectionMap<V>
- Type Parameters:
V- The type of values stored in this map.
- Direct Known Subclasses:
DebugEnablementMap
This utility allows you to create flexible mappings between reflection elements and custom values. It supports various pattern formats for identifying classes and their members, with intelligent matching that handles inner classes, method signatures, and field names.
Example:
Supported Pattern Formats:
The following pattern formats are supported for mapping keys:
- Classes:
- Fully qualified:
"com.foo.MyClass"
- Fully qualified inner class:
"com.foo.MyClass$Inner1$Inner2"
- Simple class name:
"MyClass"
- Simple inner class:
"MyClass$Inner1$Inner2" "Inner1$Inner2" "Inner2"
- All classes wildcard:
"*"
- Fully qualified:
- Methods:
- Fully qualified with args:
"com.foo.MyClass.myMethod(String,int)" "com.foo.MyClass.myMethod(java.lang.String,int)" "com.foo.MyClass.myMethod()"
- Fully qualified without args (matches any args):
"com.foo.MyClass.myMethod"
- Simple with args:
"MyClass.myMethod(String,int)" "MyClass.myMethod(java.lang.String,int)" "MyClass.myMethod()"
- Simple without args (matches any args):
"MyClass.myMethod"
- Simple inner class:
"MyClass$Inner1$Inner2.myMethod" "Inner1$Inner2.myMethod" "Inner2.myMethod"
- Fully qualified with args:
- Fields:
- Fully qualified:
"com.foo.MyClass.myField"
- Simple:
"MyClass.myField"
- Simple inner class:
"MyClass$Inner1$Inner2.myField" "Inner1$Inner2.myField" "Inner2.myField"
- Fully qualified:
- Constructors:
- Fully qualified with args:
"com.foo.MyClass(String,int)" "com.foo.MyClass(java.lang.String,int)" "com.foo.MyClass()"
- Simple with args:
"MyClass(String,int)" "MyClass(java.lang.String,int)" "MyClass()"
- Simple inner class:
"MyClass$Inner1$Inner2()" "Inner1$Inner2()" "Inner2()"
- Fully qualified with args:
- Multiple patterns:
- A comma-delimited list of any patterns above:
"com.foo.MyClass, com.bar.OtherClass" "MyClass.method1, MyClass.method2, MyClass.field1"
- A comma-delimited list of any patterns above:
Notes:
- Method and constructor patterns without parentheses match any method signature.
- Method and constructor argument types can be specified with simple or fully qualified names.
- Array types in signatures use either
"Type[]" or JVM notation like"[LType;" . - Generic type parameters are stripped from method signatures during matching.
- Patterns are case-sensitive.
See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <V> ReflectionMap.Builder<V>Creates a new builder for constructing aReflectionMap.Finds all values associated with the specified class.find(Constructor<?> c) Finds all values associated with the specified constructor.Finds all values associated with the specified field.Finds all values associated with the specified method.toString()
-
Constructor Details
-
ReflectionMap
Constructor.- Parameters:
b- The builder containing the mappings to initialize this map with.
-
-
Method Details
-
create
Creates a new builder for constructing aReflectionMap.Example:
ReflectionMap<String>
map = ReflectionMap .create (String.class ) .append("com.foo.MyClass" ,"value1" ) .append("com.foo.MyClass.myMethod" ,"value2" ) .build();- Type Parameters:
V- The type of values stored in the map.- Parameters:
c- The class type of values (used for type safety, not stored).- Returns:
- A new builder instance.
-
find
Finds all values associated with the specified class.This method searches for mappings that match the given class, including patterns for the fully qualified name, simple name, inner class names, and wildcard patterns.
Example:
ReflectionMap<String>
map = ReflectionMap .create (String.class ) .append("com.foo.MyClass" ,"value1" ) .append("MyClass" ,"value2" ) .build();// Find all values for MyClass Stream<String>values =map .find(MyClass.class );// Returns stream containing ["value1", "value2"] - Parameters:
c- The class to find mappings for. Can benull .- Returns:
- A stream of all values associated with the class. Empty stream if no matches found.
-
find
Finds all values associated with the specified constructor.This method searches for mappings that match the given constructor, considering both the declaring class and parameter types.
Example:
ReflectionMap<String>
map = ReflectionMap .create (String.class ) .append("MyClass(String,int)" ,"value1" ) .build();// Find value for specific constructor Constructor<?>ctor = MyClass.class .getConstructor(String.class ,int .class ); Stream<String>values =map .find(ctor );- Parameters:
c- The constructor to find mappings for. Can benull .- Returns:
- A stream of all values associated with the constructor. Empty stream if no matches found.
-
find
Finds all values associated with the specified field.This method searches for mappings that match the given field, considering both the declaring class and field name.
Example:
ReflectionMap<String>
map = ReflectionMap .create (String.class ) .append("MyClass.myField" ,"value1" ) .build();// Find value for specific field Fieldfield = MyClass.class .getField("myField" ); Stream<String>values =map .find(field );- Parameters:
f- The field to find mappings for. Can benull .- Returns:
- A stream of all values associated with the field. Empty stream if no matches found.
-
find
Finds all values associated with the specified method.This method searches for mappings that match the given method, considering the declaring class, method name, and parameter types.
Example:
ReflectionMap<String>
map = ReflectionMap .create (String.class ) .append("MyClass.myMethod" ,"value1" ) .append("MyClass.myMethod(String)" ,"value2" ) .build();// Find values for specific method Methodmethod = MyClass.class .getMethod("myMethod" , String.class ); Stream<String>values =map .find(method );// Returns stream containing ["value1", "value2"] - first matches any signature - Parameters:
m- The method to find mappings for. Can benull .- Returns:
- A stream of all values associated with the method. Empty stream if no matches found.
-
properties
-
toString
-