일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 전자정부프레임워크
- appspresso
- PHP
- Google Map
- WebLogic
- sencha touch
- JDOM
- 가우스
- MySQL
- Struts
- swingx
- MFC
- ibsheet
- jQuery
- JSON
- 선택적조인
- PLSQL
- Android
- iBATIS
- jsr 296
- rowspan
- phonegap
- oracle
- Ajax
- tomcat
- GPS
- Spring
- dock
- node.js
- Eclipse
Archives
- Today
- Total
Where The Streets Have No Name
호출한 메소드명 알아내기 본문
/**
* Get method name within the current call stack. The top most has offset 0 (that is this method), the next has offset 1
* (that is the caller of this method), and so on.
* Usage: <code>getMethodName(new Throwable())</code>.
*
* @param full If true, not only the method name but the complete package and class string as prefix
* (e.g. "org.happy.tools.Utils.getLucky")
* @param offset Index offset from top most stack trace element. If the caller wants to get the name of the
* method of its caller, the offset has to be 2.
* @return Method name of the top StackTraceElement.
*/
static public String getMethodName(final boolean full, final int offset) {
String result = null;
final Throwable t = new Throwable();
if (t != null) {
final StackTraceElement[] stes = t.getStackTrace();
if (stes != null && stes.length > 0) {
if (full) {
result = stes[offset].getClassName().concat(".").concat(stes[offset].getMethodName());
} else {
result = stes[offset].getMethodName();
}
}//else: StackTraceElement unavailable
}//else: input unavailable
return result;
}//getMethodName()
사용법) System.out.println(HelloWorld.getMethodName(true,1)); //이부분이 코딩된 메소드명이 출력됨
public String getMethodName() {
String result = null;
final Throwable t = new Throwable();
if (t != null) {
final StackTraceElement[] stes = t.getStackTrace();
if (stes != null && stes.length > 0) {
result = stes[1].getClassName().concat(".").concat(stes[1].getMethodName());
}//else: StackTraceElement unavailable
}//else: input unavailable
return result;
}//getMethodName()
* Get method name within the current call stack. The top most has offset 0 (that is this method), the next has offset 1
* (that is the caller of this method), and so on.
* Usage: <code>getMethodName(new Throwable())</code>.
*
* @param full If true, not only the method name but the complete package and class string as prefix
* (e.g. "org.happy.tools.Utils.getLucky")
* @param offset Index offset from top most stack trace element. If the caller wants to get the name of the
* method of its caller, the offset has to be 2.
* @return Method name of the top StackTraceElement.
*/
static public String getMethodName(final boolean full, final int offset) {
String result = null;
final Throwable t = new Throwable();
if (t != null) {
final StackTraceElement[] stes = t.getStackTrace();
if (stes != null && stes.length > 0) {
if (full) {
result = stes[offset].getClassName().concat(".").concat(stes[offset].getMethodName());
} else {
result = stes[offset].getMethodName();
}
}//else: StackTraceElement unavailable
}//else: input unavailable
return result;
}//getMethodName()
사용법) System.out.println(HelloWorld.getMethodName(true,1)); //이부분이 코딩된 메소드명이 출력됨
public String getMethodName() {
String result = null;
final Throwable t = new Throwable();
if (t != null) {
final StackTraceElement[] stes = t.getStackTrace();
if (stes != null && stes.length > 0) {
result = stes[1].getClassName().concat(".").concat(stes[1].getMethodName());
}//else: StackTraceElement unavailable
}//else: input unavailable
return result;
}//getMethodName()