|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.arakhne.vmutil.Caller
public class Caller
This utility class provides a way to determine which class call a function.
It inspirated from the Sun's sun.reflect.Reflection class
| Constructor Summary | |
|---|---|
Caller()
|
|
| Method Summary | |
|---|---|
static Class<?> |
getCallerClass()
Replies the class of the caller that invoked the function from which GetCallerClass() was invoked. |
static Class<?> |
getCallerClass(int level)
Replies the class from the stack according to its level. |
static String |
getCallerMethod()
Replies the method of the caller that invoked the function from which GetCallerClass() was invoked. |
static String |
getCallerMethod(int level)
Replies the method from the stack according to its level. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Caller()
| Method Detail |
|---|
public static String getCallerMethod()
GetCallerClass() was invoked.
The returned value is the name of the method instead of a
Method instance. It is due to JRE that does not
store in the stack trace the complete prototype of the
methods. So the following code failed: the stack contains
the method name "test2", but no function has the prototype
void test2().
class Test {
public void test1(int a) {
test2();
}
public void test2(int a) {
getCallerMethod(); // IllegalArgumentException because test1() not defined.
}
}
Another failure example:
class Test2 {
public void test1(int a) {
test2();
}
public void test1() {
}
public void test2(int a) {
getCallerMethod(); // test1() is replied !!! not test1(int)
}
}
GetCallerClass() was invoked.public static Class<?> getCallerClass()
GetCallerClass() was invoked.
GetCallerClass() was invoked.public static Class<?> getCallerClass(int level)
The given level permits to specify which class to reply:
0: the class where is defined the function (f0)
that has called getCallerClass()1: the class where is defined the function (f1)
that has called f01: the class where is defined the function (f2)
that has called f1
level - is the desired level of the class
public static String getCallerMethod(int level)
The given level permits to specify which method to reply:
0: the method where is defined the function (f0)
that has called getCallerClass()1: the method where is defined the function (f1)
that has called f01: the method where is defined the function (f2)
that has called f1
The returned value is the name of the method instead of a
Method instance. It is due to JRE that does not
store in the stack trace the complete prototype of the
methods. So the following code failed: the stack contains
the method name "test2", but no function has the prototype
void test2().
class Test {
public void test1(int a) {
test2();
}
public void test2(int a) {
getCallerMethod(); // IllegalArgumentException because test1() not defined.
}
}
Another failure example:
class Test2 {
public void test1(int a) {
test2();
}
public void test1() {
}
public void test2(int a) {
getCallerMethod(); // test1() is replied !!! not test1(int)
}
}
level - is the desired level of the class
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||