public class ReflectedUniverse extends Object
Note: use of this class is discouraged in favor of compile-time (i.e.,
type-safe) dependency linkages. However, there are times when it proves very
useful for writing blocks of reflected code in a more succinct way than you
can do with the vanilla java.lang.reflect
API. Of course, debugging
such reflected code becomes much more difficult—caveat emptor!
Constructor and Description |
---|
ReflectedUniverse()
Constructs a new reflected universe.
|
ReflectedUniverse(ClassLoader loader)
Constructs a new reflected universe that uses the given class loader.
|
ReflectedUniverse(URL[] urls)
Constructs a new reflected universe, with the given URLs representing
additional search paths for imported classes (in addition to the
CLASSPATH).
|
Modifier and Type | Method and Description |
---|---|
Object |
exec(String command)
Executes a command in the universe.
|
Object |
getVar(String varName)
Returns the value of a variable or field in the universe.
|
boolean |
isAccessibilityIgnored()
Gets whether access modifiers (protected, private, etc.) are ignored.
|
static boolean |
isInstance(Class<?> c,
Object o)
Returns whether the given object is compatible with the specified class for
the purposes of reflection.
|
static void |
main(String[] args)
Allows exploration of a reflected universe in an interactive environment.
|
void |
setAccessibilityIgnored(boolean ignore)
Sets whether access modifiers (protected, private, etc.) are ignored.
|
void |
setVar(String varName,
boolean b)
Registers a variable of primitive type boolean in the universe.
|
void |
setVar(String varName,
byte b)
Registers a variable of primitive type byte in the universe.
|
void |
setVar(String varName,
char c)
Registers a variable of primitive type char in the universe.
|
void |
setVar(String varName,
double d)
Registers a variable of primitive type double in the universe.
|
void |
setVar(String varName,
float f)
Registers a variable of primitive type float in the universe.
|
void |
setVar(String varName,
int i)
Registers a variable of primitive type int in the universe.
|
void |
setVar(String varName,
long l)
Registers a variable of primitive type long in the universe.
|
void |
setVar(String varName,
Object obj)
Registers a variable in the universe.
|
void |
setVar(String varName,
short s)
Registers a variable of primitive type short in the universe.
|
public ReflectedUniverse()
public ReflectedUniverse(URL[] urls)
public ReflectedUniverse(ClassLoader loader)
public static boolean isInstance(Class<?> c, Object o)
public Object exec(String command) throws ReflectException
ReflectException
public void setVar(String varName, boolean b)
public void setVar(String varName, byte b)
public void setVar(String varName, char c)
public void setVar(String varName, double d)
public void setVar(String varName, float f)
public void setVar(String varName, int i)
public void setVar(String varName, long l)
public void setVar(String varName, short s)
public Object getVar(String varName) throws ReflectException
ReflectException
public void setAccessibilityIgnored(boolean ignore)
public boolean isAccessibilityIgnored()
public static void main(String[] args) throws IOException
IOException
Copyright © 2015–2022 SciJava. All rights reserved.