OneLineReflection
Simple reflection utility for string->value (Java)
Install / Use
/learn @aramperes/OneLineReflectionREADME
OneLineReflection
Simple reflection utility for string->value.
Example
See the code example for a ready-to-run sample.
Usage
In this scenario, you have an initialized object, we'll call it the context.
In the context's class, Human, you have a method, public String getName(), which returns the value of the field you initialized with the object.
Getting the value from getName() using the utility would be:
Human human = new Human("Bob");
String name = (String) new ReflectionProcessor("$.getName()", human).process(); // Returns "Bob"
Note that $ represents the context. You can also use this to access it.
In another scenario, you want to execute a static method. No context is needed here.
In our com.example.foo.MyClass class, we have a static method, public static void doSomething().
Invoking the method using the utility would be:
new ReflectionProcessor("com.example.foo.MyClass.doSomething()").process();
If you want to use multiple variables in your string, this utility supports multi-contextuality.
For example, if you have two Strings:
String a = "Hello";
String b = "World";
And you have a static method in MyClass, public static void hello(String a, String b);
You can pass the parameters as such:
new ReflectionProcessor("com.example.foo.MyClass.hello($1, $2)", a, b).process();
Note that $1 references the first context, and $2 the second. Using $ alone will reference the first context.
Features
- Object-oriented calls
- Static calls
- Fields, methods (with parameters), classes (with package), literals (String, Boolean, Integer, Long)
- Multi-contextual
Disclaimer
This is for demonstration purposes, some features you could expect might or might not be present.
Features not included:
- Decimal literals (Double, Float)
- Short, Byte literals
- Constructors
Hello.
Related Skills
node-connect
342.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.7kCommit, push, and open a PR
