Package valorless.rarespawns.utils
Class CallSource
java.lang.Object
valorless.rarespawns.utils.CallSource
Utility to capture the current thread's stack trace at construction time and
provide information about the immediate caller of this utility.
Notes:
- Uses Thread.currentThread().getStackTrace(); stack[0] is getStackTrace,
stack[1] is this constructor, and stack[2] is the direct caller.
- Stack inspection has a performance cost; avoid frequent use on hot paths.
-
Constructor Summary
ConstructorsConstructorDescriptionCaptures the current thread's stack trace for later inspection. -
Method Summary
Modifier and TypeMethodDescriptionGets the fully qualified class name of the immediate caller, if available.Class<?> getClazz()Attempts to resolve the Class object for the immediate caller.Gets the source line number of the immediate caller, if available.isLocal()Indicates whether the immediate caller belongs to the "valorless.rarespawns" package namespace.
-
Constructor Details
-
CallSource
public CallSource()Captures the current thread's stack trace for later inspection. The element at index 2 is considered the immediate caller of this utility.
-
-
Method Details
-
isLocal
Indicates whether the immediate caller belongs to the "valorless.rarespawns" package namespace.- Returns:
- true if the caller's class name starts with "valorless.rarespawns", false if it does not, or null if the stack trace is shorter than expected.
-
getClassName
Gets the fully qualified class name of the immediate caller, if available.- Returns:
- the caller's class name, or null if unavailable
-
getLineNumber
Gets the source line number of the immediate caller, if available.- Returns:
- the caller's source line number, or null if unavailable
-
getClazz
Attempts to resolve the Class object for the immediate caller.- Returns:
- the Classinvalid input: '<'?> of the caller, or null if it cannot be resolved
-