public final class Reflections extends Object
Reflections
Modifier and Type | Method and Description |
---|---|
static boolean |
accessedFrom(Class<?> clazz)
Returns whether or not the current context was called from a class
(instance or otherwise) that is passed to this method.
|
static boolean |
accessedFrom(String regex)
Returns whether or not the current context was called from a class
(instance or otherwise) that is passed to this method.
|
static boolean |
accessedFromBukkit()
Façade method for determining if Bukkit is the invoker of the method
|
static <T> T |
defaultPrimitiveValue(Class<T> c)
Returns a "default value" of -1 or
false for a default type's
class or autoboxing class. |
static StackTraceElement |
getCaller()
Returns a
StackTraceElement of the direct caller of the current
method's context. |
static StackTraceElement |
getCaller(int offset)
Returns a
StackTraceElement of the direct caller of the current
method's context. |
static org.bukkit.plugin.java.JavaPlugin |
getCallingPlugin()
Returns the
JavaPlugin that immediately called the method in the
current context. |
static org.bukkit.plugin.java.JavaPlugin |
getCallingPlugin(int offset)
Returns the
JavaPlugin that immediately called the method in the
current context. |
static org.bukkit.plugin.java.JavaPlugin |
getPlugin(Class<?> clazz)
Returns the relevant
JavaPlugin that is specified by a
class-level PluginClass annotation if it is loaded, otherwise
null |
static boolean |
hasAnnotation(AnnotatedElement target,
Class<? extends Annotation> check)
Returns
true if the specified target has the passed
Annotation |
public static org.bukkit.plugin.java.JavaPlugin getPlugin(Class<?> clazz)
JavaPlugin
that is specified by a
class-level PluginClass
annotation if it is loaded, otherwise
null
clazz
- The Class
that holds the Annotation
JavaPlugin
, or null
if not foundpublic static boolean hasAnnotation(AnnotatedElement target, Class<? extends Annotation> check)
true
if the specified target has the passed
Annotation
target
- The relevant element to check for an Annotation
check
- The Annotation
class type to check fortrue
if the Annotation
is presentpublic static boolean accessedFrom(String regex)
regex
- The regex to check against the calling classtrue
if accessed from a class that matches the regexpublic static boolean accessedFrom(Class<?> clazz)
clazz
- The class to checktrue
if accessed from this classpublic static boolean accessedFromBukkit()
true
if Bukkit is the direct invoker of the methodpublic static org.bukkit.plugin.java.JavaPlugin getCallingPlugin(int offset)
JavaPlugin
that immediately called the method in the
current context. Useful for finding out which plugins accessed static API
methodsoffset
- The number of additional methods to look backJavaPlugin
UnsupportedOperationException
- If not called from a
JavaPlugin
class (either through an alternative ClassLoader,
executing code directly, or some voodoo magic)public static org.bukkit.plugin.java.JavaPlugin getCallingPlugin()
JavaPlugin
that immediately called the method in the
current context. Useful for finding out which plugins accessed static API
methods. This method is equivalent to calling
Reflections.getCallingPlugin(0)
JavaPlugin
UnsupportedOperationException
- If not called from a
JavaPlugin
class (either through an alternative ClassLoader,
executing code directly, or some voodoo magic)getCallingPlugin(int)
public static StackTraceElement getCaller(int offset)
StackTraceElement
of the direct caller of the current
method's context.offset
- The number of additional methods to look backStackTraceElement
representing where the current
context was called frompublic static StackTraceElement getCaller()
StackTraceElement
of the direct caller of the current
method's context. This method is equivalent to calling
Reflections.getCaller(0)
StackTraceElement
representing where the current
context was called frompublic static <T> T defaultPrimitiveValue(Class<T> c)
false
for a default type's
class or autoboxing class. Will return null
if not relevant to
primitivesT
- The type of the primitivec
- The primitive classnull
if not a primitiveCopyright © 2015. All rights reserved.