Class ReflectiveNamespace
java.lang.Object
com.cryptomorin.xseries.reflection.ReflectiveNamespace
This class is mostly only useful if you're planning to use string-based API (see
Also, all the types that are passed to or parsed from this namespace (e.g. from
ReflectionParser),
other than that most of the work is done behind the scenes, and it's not needed to use it directly.
You can initiate this class using XReflection.namespaced(). Like other reflection classes, this should
be used as a temporary class and you should cache the results of ReflectiveHandle classes.
This class is used just like XReflection except that it
allows enhanced performance and security checks. Performance because a single reflection lookup
object is used for all reflections that use this namespace, security because of the same lookup
object, the MethodHandles.lookup() which is caller sensitive.
This class also provides an import statement feature. For example look at the following code:
XReflection.of(Test.class).method("public List<String> getNames();").unreflect();
Assuming that the class and the method exist, this works, it knows about the "List" type from List
because it's predefined and hardcoded. But if we look at another code:
XReflection.of(Test.class).method("public MyCustomClass getCustomData();").unreflect();
This will fail, because it doesn't know where MyCustomClass is, you could give it the fully qualified name:
XReflection.of(Test.class).method("public my.package.MyCustomClass getCustomData();").unreflect();
But what if you want to keep using this type a lot? It makes the code look very ugly. That is what this class is for:
ReflectiveNamespace ns = XReflection.namespaced().imports(MyCustomClass.class);
ns.of(Test.class).method("public MyCustomClass getCustomData();").unreflect();
Also, all the types that are passed to or parsed from this namespace (e.g. from
of(Class), ofMinecraft(String), classHandle(String))
are imported automatically. Making this a powerful mini-IDE!-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclassHandle(String declaration) Imports the specified classes into this namespace so the names can be used directly.Imports a class with a custom name.voidlink(ClassHandle handle) ofMinecraft(String declaration)
-
Constructor Details
-
ReflectiveNamespace
protected ReflectiveNamespace()
-
-
Method Details
-
imports
Imports the specified classes into this namespace so the names can be used directly. (For more info readReflectiveNamespace.This can also override predefined Java standard types if the names are the same.
-
imports
Imports a class with a custom name.- Parameters:
name- the custom name of the class.clazz- the actual definition of the class.- See Also:
-
getImports
-
getLookup
-
of
- Since:
- v11.0.0
-
link
-
classHandle
-
ofMinecraft
-