Brooklyn

brooklyn.util.javalang
[Java] Class JavaClassNames

java.lang.Object
  brooklyn.util.javalang.JavaClassNames

public class JavaClassNames

Method Summary
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.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(java.lang.StackTraceElement st)

returns nice class name and method for the given element

static java.lang.String niceClassAndMethod()

convenience for callerNiceClassAndMethod(int) with depth 0

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. starting with "/" or "protocol:") e.g.

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

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Method Detail

callerNiceClassAndMethod

public 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


callerStackElement

public 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


componentType

public static java.lang.Class componentType(java.lang.Object x)
like type, but removes any array modifiers


currentStackElement

public static java.lang.StackTraceElement currentStackElement()
returns top of cleaned stack trace; usually the caller's location


currentStackTraceCleaned

public static java.lang.StackTraceElement[] currentStackTraceCleaned()
returns a cleaned stack trace; caller is usually at the top


niceClassAndMethod

public static java.lang.String niceClassAndMethod(java.lang.StackTraceElement st)
returns nice class name and method for the given element


niceClassAndMethod

public static java.lang.String niceClassAndMethod()
convenience for callerNiceClassAndMethod(int) with depth 0

useful for tests and other debug-facing log messages!


packageName

public static java.lang.String packageName(java.lang.Object x)


packagePath

public static java.lang.String packagePath(java.lang.Object x)
returns e.g. "/com/acme/" for an object in package com.acme


resolveClasspathUrl

public 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. starting with "/" or "protocol:") e.g. "classpath://com/acme/foo.txt" given a context object com.acme.SomeClass and "foo.txt"


resolveName

public 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. useful to mimic Class.getResource(path) behaviour, cf Class.resolveName where the first argument below is the class.


simpleClassName

public 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


simpleClassName

public 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


simplifyClassName

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


type

public 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


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.