public class JavaClassNames
extends java.lang.Object
Constructor and Description |
---|
JavaClassNames() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
callerNiceClassAndMethod(int depth)
returns nice class name and method for the caller, going up the stack (filtered to remove invocation etc),
with 0 typically being the context where this method is called, 1 being its caller, etc
|
static java.lang.StackTraceElement |
callerStackElement(int depth)
returns element in cleaned stack trace; usually the caller's location is at the top,
and caller of that is up one, etc
|
static java.lang.String |
cleanSimpleClassName(java.lang.Class<?> x)
as
simpleClassName(Object) but making the result clean for use on filesystems and as java identifiers |
static java.lang.String |
cleanSimpleClassName(java.lang.Object x)
as
simpleClassName(Object) but making the result clean for use on filesystems and as java identifiers |
static java.lang.Class<?> |
componentType(java.lang.Object x)
like type, but removes any array modifiers
|
static java.lang.StackTraceElement |
currentStackElement()
returns top of cleaned stack trace; usually the caller's location
|
static java.lang.StackTraceElement[] |
currentStackTraceCleaned()
returns a cleaned stack trace; caller is usually at the top
|
static java.lang.String |
niceClassAndMethod()
convenience for
callerNiceClassAndMethod(int) with depth 0 |
static java.lang.String |
niceClassAndMethod(java.lang.StackTraceElement st)
returns nice class name and method for the given element
|
static java.lang.String |
packageName(java.lang.Object x) |
static java.lang.String |
packagePath(java.lang.Object x)
returns e.g.
|
static java.lang.String |
resolveClasspathUrl(java.lang.Object context,
java.lang.String path)
returns a "classpath:" URL given a context object and a file to be found in that directory or a sub-directory
(ignoring the context object if the given path is absolute, i.e.
|
static java.lang.String |
resolveName(java.lang.Object context,
java.lang.String path)
returns path relative to the package of x, unless path is absolute.
|
static java.lang.String |
simpleClassName(java.lang.Class<?> t)
returns a simplified name of the class, just the simple name if it seems useful, else the full name
|
static java.lang.String |
simpleClassName(java.lang.Object x)
as
simpleClassName(Class) but taking the type of the object if it is not already a class
or a type-token; callers should usually do the getClass themselves, unless they aren't sure whether
it is already a Class-type object |
static java.lang.String |
simplifyClassName(java.lang.String className)
as
simpleClassName(Class) but taking a string rep'n of the class name,
and doing best effort to simplify it (without instantiating) |
static java.lang.Class<?> |
type(java.lang.Object x)
returns the Class of anything which isn't a class; if input is class it is pass-through
|
public static java.lang.Class<?> type(java.lang.Object x)
public static java.lang.Class<?> componentType(java.lang.Object x)
public static java.lang.String simpleClassName(java.lang.Class<?> t)
public static java.lang.String simpleClassName(java.lang.Object x)
simpleClassName(Class)
but taking the type of the object if it is not already a class
or a type-token; callers should usually do the getClass themselves, unless they aren't sure whether
it is already a Class-type objectpublic static java.lang.String simplifyClassName(java.lang.String className)
simpleClassName(Class)
but taking a string rep'n of the class name,
and doing best effort to simplify it (without instantiating)public static java.lang.String cleanSimpleClassName(java.lang.Object x)
simpleClassName(Object)
but making the result clean for use on filesystems and as java identifierspublic static java.lang.String cleanSimpleClassName(java.lang.Class<?> x)
simpleClassName(Object)
but making the result clean for use on filesystems and as java identifierspublic static java.lang.String packageName(java.lang.Object x)
public static java.lang.String packagePath(java.lang.Object x)
public static java.lang.String resolveName(java.lang.Object context, java.lang.String path)
public static java.lang.String resolveClasspathUrl(java.lang.Object context, java.lang.String path)
public static java.lang.StackTraceElement[] currentStackTraceCleaned()
public static java.lang.StackTraceElement currentStackElement()
public static java.lang.StackTraceElement callerStackElement(int depth)
public static java.lang.String niceClassAndMethod(java.lang.StackTraceElement st)
public static java.lang.String callerNiceClassAndMethod(int depth)
public static java.lang.String niceClassAndMethod()
callerNiceClassAndMethod(int)
with depth 0
useful for tests and other debug-facing log messages!