| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| tsukuba_bunko.util.ReflectionUtil |
|
|
| 1 | /* |
|
| 2 | * Common Library for TBAS Softwares |
|
| 3 | * Language: Java |
|
| 4 | * |
|
| 5 | * All Rights Reserved. |
|
| 6 | * Copyright (c) 1999-2003 Tsukuba Bunko. |
|
| 7 | * |
|
| 8 | * $Id: ReflectionUtil.java,v 1.1 2005/07/11 12:49:19 ppoi Exp $ |
|
| 9 | */ |
|
| 10 | package tsukuba_bunko.util; |
|
| 11 | ||
| 12 | import java.lang.reflect.Method; |
|
| 13 | ||
| 14 | ||
| 15 | /** |
|
| 16 | * リフレクション操作をサポートするためのユーティリティクラスです。 |
|
| 17 | * @author $Author: ppoi $ |
|
| 18 | * @version $Revision: 1.1 $ |
|
| 19 | */ |
|
| 20 | public final class ReflectionUtil { |
|
| 21 | ||
| 22 | /** |
|
| 23 | * <code>ReflectionUtil</code> はインスタンスを生成できません。 |
|
| 24 | */ |
|
| 25 | 0 | private ReflectionUtil(){;} |
| 26 | ||
| 27 | ||
| 28 | /** |
|
| 29 | * メソッドを検索します。 |
|
| 30 | * @param clazz 検索対象のクラス |
|
| 31 | * @param methodName 検索するメソッド名 |
|
| 32 | * @param parameterTypes 検索するメソッドの仮引数クラスリスト(配列) |
|
| 33 | * @param searchSuperclasses スーパークラスを検索対象にする場合 <code>true</code>、それ以外の場合 <code>false</code> |
|
| 34 | * @return 検索結果。メソッドが検出されなかった場合は <code>null</code> |
|
| 35 | */ |
|
| 36 | public static Method findMethod( Class clazz, String methodName, Class[] parameterTypes, boolean searchSuperclasses ) |
|
| 37 | { |
|
| 38 | 0 | Method method = null; |
| 39 | do { |
|
| 40 | try { |
|
| 41 | 0 | method = clazz.getDeclaredMethod( methodName, parameterTypes ); |
| 42 | } |
|
| 43 | 0 | catch( NoSuchMethodException nsme ) { |
| 44 | //ignore. |
|
| 45 | 0 | } |
| 46 | 0 | clazz = clazz.getSuperclass(); |
| 47 | 0 | } while( (method == null) && (clazz != class="keyword">null) && searchSuperclasses ); |
| 48 | ||
| 49 | 0 | return method; |
| 50 | } |
|
| 51 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |