Class CallSource

java.lang.Object
valorless.rarespawns.utils.CallSource

public class CallSource extends Object
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 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

      public Boolean 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

      public String getClassName()
      Gets the fully qualified class name of the immediate caller, if available.
      Returns:
      the caller's class name, or null if unavailable
    • getLineNumber

      public Integer getLineNumber()
      Gets the source line number of the immediate caller, if available.
      Returns:
      the caller's source line number, or null if unavailable
    • getClazz

      public Class<?> 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