[Arakhnę-Dev] [328] * Adapt Caller utility class to Android. |
[ Thread Index |
Date Index
| More arakhne.org/dev Archives
]
Revision: 328
Author: galland
Date: 2012-02-07 00:22:36 +0100 (Tue, 07 Feb 2012)
Log Message:
-----------
* Adapt Caller utility class to Android.
Modified Paths:
--------------
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Caller.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/caller/Caller.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/caller/StackTraceCaller.java
trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/caller/SunCaller.java
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Caller.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Caller.java 2012-02-06 21:21:36 UTC (rev 327)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/Caller.java 2012-02-06 23:22:36 UTC (rev 328)
@@ -45,10 +45,10 @@
synchronized(Caller.class) {
if (caller==null) {
if (OperatingSystem.getCurrentOS()==OperatingSystem.ANDROID) {
- caller = new StackTraceCaller(1);
+ caller = new StackTraceCaller();
}
else {
- caller = new SunCaller(1);
+ caller = new SunCaller();
}
}
return caller;
@@ -92,7 +92,7 @@
* from which <code>GetCallerClass()</code> was invoked.
*/
public static String getCallerMethod() {
- return getCaller().getCallerMethod();
+ return getCaller().getCallerMethod(1);
}
/** Replies the class of the caller that invoked the function
@@ -102,7 +102,7 @@
* from which <code>GetCallerClass()</code> was invoked.
*/
public static Class<?> getCallerClass() {
- return getCaller().getCallerClass();
+ return getCaller().getCallerClass(1);
}
/** Replies the class from the stack according to its level.
@@ -113,7 +113,7 @@
* that has called <code>getCallerClass()</code></li>
* <li><code>1</code>: the class where is defined the function (<code>f<sub>1</sub></code>)
* that has called <code>f<sub>0</sub></code></li>
- * <li><code>1</code>: the class where is defined the function (<code>f<sub>2</sub></code>)
+ * <li><code>2</code>: the class where is defined the function (<code>f<sub>2</sub></code>)
* that has called <code>f<sub>1</sub></code></li>
* <li>etc.</li>
* </ul>
@@ -122,7 +122,7 @@
* @return the class from the call stack according to the given level.
*/
public static Class<?> getCallerClass(int level) {
- return getCaller().getCallerClass(level);
+ return getCaller().getCallerClass(level+1);
}
/** Replies the method from the stack according to its level.
@@ -133,7 +133,7 @@
* that has called <code>getCallerClass()</code></li>
* <li><code>1</code>: the method where is defined the function (<code>f<sub>1</sub></code>)
* that has called <code>f<sub>0</sub></code></li>
- * <li><code>1</code>: the method where is defined the function (<code>f<sub>2</sub></code>)
+ * <li><code>2</code>: the method where is defined the function (<code>f<sub>2</sub></code>)
* that has called <code>f<sub>1</sub></code></li>
* <li>etc.</li>
* </ul>
@@ -172,7 +172,7 @@
* @return the method from the call stack according to the given level.
*/
public static String getCallerMethod(int level) {
- return getCaller().getCallerMethod(level);
+ return getCaller().getCallerMethod(level+1);
}
}
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/caller/Caller.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/caller/Caller.java 2012-02-06 21:21:36 UTC (rev 327)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/caller/Caller.java 2012-02-06 23:22:36 UTC (rev 328)
@@ -33,52 +33,6 @@
* @mavenartifactid $ArtifactId$
*/
public interface Caller {
-
- /** Replies the method of the caller that invoked the function
- * from which <code>GetCallerClass()</code> was invoked.
- * <p>
- * The returned value is the name of the method instead of a
- * {@link 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
- * {@code void test2()}.
- * <pre>
- * class Test {
- * public void test1(int a) {
- * test2();
- * }
- * public void test2(int a) {
- * getCallerMethod(); // IllegalArgumentException because test1() not defined.
- * }
- * }
- * </pre>
- * Another failure example:
- * <pre>
- * class Test2 {
- * public void test1(int a) {
- * test2();
- * }
- * public void test1() {
- * }
- * public void test2(int a) {
- * getCallerMethod(); // test1() is replied !!! not test1(int)
- * }
- * }
- * </pre>
- *
- * @return the method of the caller that invoked the function
- * from which <code>GetCallerClass()</code> was invoked.
- */
- public String getCallerMethod();
-
- /** Replies the class of the caller that invoked the function
- * from which <code>GetCallerClass()</code> was invoked.
- *
- * @return the class of the caller that invoked the function
- * from which <code>GetCallerClass()</code> was invoked.
- */
- public Class<?> getCallerClass();
/** Replies the class from the stack according to its level.
* <p>
@@ -88,7 +42,7 @@
* that has called <code>getCallerClass()</code></li>
* <li><code>1</code>: the class where is defined the function (<code>f<sub>1</sub></code>)
* that has called <code>f<sub>0</sub></code></li>
- * <li><code>1</code>: the class where is defined the function (<code>f<sub>2</sub></code>)
+ * <li><code>2</code>: the class where is defined the function (<code>f<sub>2</sub></code>)
* that has called <code>f<sub>1</sub></code></li>
* <li>etc.</li>
* </ul>
@@ -106,7 +60,7 @@
* that has called <code>getCallerClass()</code></li>
* <li><code>1</code>: the method where is defined the function (<code>f<sub>1</sub></code>)
* that has called <code>f<sub>0</sub></code></li>
- * <li><code>1</code>: the method where is defined the function (<code>f<sub>2</sub></code>)
+ * <li><code>2</code>: the method where is defined the function (<code>f<sub>2</sub></code>)
* that has called <code>f<sub>1</sub></code></li>
* <li>etc.</li>
* </ul>
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/caller/StackTraceCaller.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/caller/StackTraceCaller.java 2012-02-06 21:21:36 UTC (rev 327)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/caller/StackTraceCaller.java 2012-02-06 23:22:36 UTC (rev 328)
@@ -36,40 +36,15 @@
*/
public class StackTraceCaller implements Caller {
- private final int delta;
-
/**
- * @param delta is the number of entries to ignore
- * at the top of the stack.
*/
- public StackTraceCaller(int delta) {
- this.delta = delta + 3;
+ public StackTraceCaller() {
+ //
}
- /**
- * {@inheritDoc}
- */
- @Override
- public String getCallerMethod() {
- // Parameter value:
- // 0: is the top from the trace stack, ie this function (Caller.class)
- // 1: is the third top of the trace stack ie, the caller of this function
- return getCallerMethod(1);
- }
-
/** {@inheritDoc}
*/
@Override
- public Class<?> getCallerClass() {
- // Parameter value:
- // 0: is the top from the trace stack, ie this function (Caller.class)
- // 1: is the third top of the trace stack ie, the caller of this function
- return getCallerClass(1);
- }
-
- /** {@inheritDoc}
- */
- @Override
public Class<?> getCallerClass(int level) {
// Parameter value of Reflection.getClassClass:
//
@@ -79,7 +54,7 @@
// 3: ??? | Caller of the caller of this function - START INTEREST HERE
try {
- int reflectionIndex = level + this.delta;
+ int reflectionIndex = level + 3;
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
StackTraceElement element = stackTrace[reflectionIndex];
@@ -114,7 +89,7 @@
if (level<0) throw new IllegalArgumentException();
try {
- int reflectionIndex = level + this.delta;
+ int reflectionIndex = level + 3;
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
StackTraceElement element = stackTrace[reflectionIndex];
Modified: trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/caller/SunCaller.java
===================================================================
--- trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/caller/SunCaller.java 2012-02-06 21:21:36 UTC (rev 327)
+++ trunk/arakhneVmutils/java/src/main/java/org/arakhne/vmutil/caller/SunCaller.java 2012-02-06 23:22:36 UTC (rev 328)
@@ -37,40 +37,15 @@
@SuppressWarnings("restriction")
public class SunCaller implements Caller {
- private final int delta;
-
/**
- * @param delta is the number of entries to ignore
- * at the top of the stack.
*/
- public SunCaller(int delta) {
- this.delta = delta + 3;
+ public SunCaller() {
+ //
}
- /**
- * {@inheritDoc}
- */
- @Override
- public String getCallerMethod() {
- // Parameter value:
- // 0: is the top from the trace stack, ie this function (Caller.class)
- // 1: is the third top of the trace stack ie, the caller of this function
- return getCallerMethod(1);
- }
-
/** {@inheritDoc}
*/
@Override
- public Class<?> getCallerClass() {
- // Parameter value:
- // 0: is the top from the trace stack, ie this function (Caller.class)
- // 1: is the third top of the trace stack ie, the caller of this function
- return getCallerClass(1);
- }
-
- /** {@inheritDoc}
- */
- @Override
public Class<?> getCallerClass(int level) {
// Parameter value of Reflection.getClassClass:
//
@@ -79,7 +54,7 @@
// 2: ??? | Caller of this function - not interesting because known
// 3: ??? | Caller of the caller of this function - START INTEREST HERE
if (level<0) throw new IllegalArgumentException();
- return Reflection.getCallerClass(level+this.delta);
+ return Reflection.getCallerClass(level+3);
}
/** {@inheritDoc}
@@ -95,7 +70,7 @@
if (level<0) throw new IllegalArgumentException();
try {
- int reflectionIndex = level + this.delta;
+ int reflectionIndex = level + 3;
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
StackTraceElement element = stackTrace[reflectionIndex];