[Jiemamy-notify:2820] commit [3742] refactor

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2009年 10月 25日 (日) 23:20:22 JST


Revision: 3742
          http://sourceforge.jp/projects/jiemamy/svn/view?view=rev&revision=3742
Author:   daisuke_m
Date:     2009-10-25 23:20:22 +0900 (Sun, 25 Oct 2009)

Log Message:
-----------
refactor

Modified Paths:
--------------
    leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/LogMarker.java
    leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/MethodUtil.java

Added Paths:
-----------
    leto/jiemamy-commons/trunk/src/test/java/org/jiemamy/utils/MethodUtilTest.java

Modified: leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/LogMarker.java
===================================================================
--- leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/LogMarker.java	2009-10-20 10:50:23 UTC (rev 3741)
+++ leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/LogMarker.java	2009-10-25 14:20:22 UTC (rev 3742)
@@ -18,11 +18,11 @@
  */
 package org.jiemamy.utils;
 
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
 
+import org.apache.commons.collections15.iterators.EmptyIterator;
 import org.slf4j.Marker;
 import org.slf4j.helpers.BasicMarker;
 
@@ -158,9 +158,7 @@
 		if (refereceList != null) {
 			return refereceList.iterator();
 		} else {
-			@SuppressWarnings("unchecked")
-			Iterator<Marker> result = Collections.EMPTY_LIST.iterator();
-			return result;
+			return EmptyIterator.getInstance();
 		}
 	}
 	

Modified: leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/MethodUtil.java
===================================================================
--- leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/MethodUtil.java	2009-10-20 10:50:23 UTC (rev 3741)
+++ leto/jiemamy-commons/trunk/src/main/java/org/jiemamy/utils/MethodUtil.java	2009-10-25 14:20:22 UTC (rev 3742)
@@ -21,8 +21,6 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
-import org.jiemamy.exception.JiemamyError;
-
 /**
  * {@link Method}用のユーティリティクラス。
  * 
@@ -62,44 +60,6 @@
 	
 
 	/**
-	 * <code>ReflectionUtil#getElementTypeOf<var>Xxx</var>FromParameter</code>の{@link Method}を取得する。
-	 * 
-	 * @param type 取得するメソッドが対象とする型名
-	 * 
-	 * @return {@link Method}
-	 */
-	protected static Method getElementTypeFromParameterMethod(final String type) {
-		try {
-			final Class<?> reflectionUtilClass = ReflectionUtil.class;
-			return reflectionUtilClass.getMethod("getElementTypeOf" + type + "FromParameterType", new Class[] {
-				Method.class,
-				int.class
-			});
-		} catch (final Throwable ignore) {
-			// ignore
-		}
-		return null;
-	}
-	
-	/**
-	 * <code>ReflectionUtil#getElementTypeOf<var>Xxx</var>FromReturn</code>の{@link Method}を取得する。
-	 * 
-	 * @param type 取得するメソッドが対象とする型名
-	 * @return {@link Method}
-	 */
-	protected static Method getElementTypeFromReturnMethod(final String type) {
-		try {
-			final Class<?> reflectionUtilClass = ReflectionUtil.class;
-			return reflectionUtilClass.getMethod("getElementTypeOf" + type + "FromReturnType", new Class[] {
-				Method.class
-			});
-		} catch (final Throwable ignore) {
-			// ignore
-		}
-		return null;
-	}
-	
-	/**
 	 * メソッドの引数型 (パラメタ化されたコレクション)の要素型を取得する。
 	 * 
 	 * @param method メソッド
@@ -110,8 +70,8 @@
 	 * @throws IllegalArgumentException 引数が正しくない場合
 	 */
 	public static Class<?> getElementTypeOfCollectionFromParameterType(final Method method, final int position)
-			throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
-		return (Class<?>) MethodUtil.invoke(GET_ELEMENT_TYPE_OF_COLLECTION_FROM_PARAMETER_METHOD, null, new Object[] {
+			throws IllegalAccessException, InvocationTargetException {
+		return (Class<?>) invoke(GET_ELEMENT_TYPE_OF_COLLECTION_FROM_PARAMETER_METHOD, null, new Object[] {
 			method,
 			Integer.valueOf(position)
 		});
@@ -126,9 +86,9 @@
 	 * @throws IllegalAccessException メソッドにアクセスできない場合
 	 * @throws IllegalArgumentException 引数が正しくない場合
 	 */
-	public static Class<?> getElementTypeOfCollectionFromReturnType(final Method method)
-			throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
-		return (Class<?>) MethodUtil.invoke(GET_ELEMENT_TYPE_OF_COLLECTION_FROM_RETURN_METHOD, null, new Object[] {
+	public static Class<?> getElementTypeOfCollectionFromReturnType(final Method method) throws IllegalAccessException,
+			InvocationTargetException {
+		return (Class<?>) invoke(GET_ELEMENT_TYPE_OF_COLLECTION_FROM_RETURN_METHOD, null, new Object[] {
 			method
 		});
 	}
@@ -144,8 +104,8 @@
 	 * @throws IllegalArgumentException 引数が正しくない場合
 	 */
 	public static Class<?> getElementTypeOfListFromParameterType(final Method method, final int position)
-			throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
-		return (Class<?>) MethodUtil.invoke(GET_ELEMENT_TYPE_OF_LIST_FROM_PARAMETER_METHOD, null, new Object[] {
+			throws IllegalAccessException, InvocationTargetException {
+		return (Class<?>) invoke(GET_ELEMENT_TYPE_OF_LIST_FROM_PARAMETER_METHOD, null, new Object[] {
 			method,
 			Integer.valueOf(position)
 		});
@@ -160,9 +120,9 @@
 	 * @throws IllegalAccessException メソッドにアクセスできない場合
 	 * @throws IllegalArgumentException 引数が正しくない場合
 	 */
-	public static Class<?> getElementTypeOfListFromReturnType(final Method method) throws IllegalArgumentException,
-			IllegalAccessException, InvocationTargetException {
-		return (Class<?>) MethodUtil.invoke(GET_ELEMENT_TYPE_OF_LIST_FROM_RETURN_METHOD, null, new Object[] {
+	public static Class<?> getElementTypeOfListFromReturnType(final Method method) throws IllegalAccessException,
+			InvocationTargetException {
+		return (Class<?>) invoke(GET_ELEMENT_TYPE_OF_LIST_FROM_RETURN_METHOD, null, new Object[] {
 			method
 		});
 	}
@@ -178,8 +138,8 @@
 	 * @throws IllegalArgumentException 引数が正しくない場合
 	 */
 	public static Class<?> getElementTypeOfSetFromParameterType(final Method method, final int position)
-			throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
-		return (Class<?>) MethodUtil.invoke(GET_ELEMENT_TYPE_OF_SET_FROM_PARAMETER_METHOD, null, new Object[] {
+			throws IllegalAccessException, InvocationTargetException {
+		return (Class<?>) invoke(GET_ELEMENT_TYPE_OF_SET_FROM_PARAMETER_METHOD, null, new Object[] {
 			method,
 			Integer.valueOf(position)
 		});
@@ -194,39 +154,21 @@
 	 * @throws IllegalAccessException メソッドにアクセスできない場合
 	 * @throws IllegalArgumentException 引数が正しくない場合
 	 */
-	public static Class<?> getElementTypeOfSetFromReturnType(final Method method) throws IllegalArgumentException,
-			IllegalAccessException, InvocationTargetException {
+	public static Class<?> getElementTypeOfSetFromReturnType(final Method method) throws IllegalAccessException,
+			InvocationTargetException {
 		if (GET_ELEMENT_TYPE_OF_SET_FROM_RETURN_METHOD == null) {
 			return null;
 		}
-		return (Class<?>) MethodUtil.invoke(GET_ELEMENT_TYPE_OF_SET_FROM_RETURN_METHOD, null, new Object[] {
+		return (Class<?>) invoke(GET_ELEMENT_TYPE_OF_SET_FROM_RETURN_METHOD, null, new Object[] {
 			method
 		});
 	}
 	
-	private static Method getIsBridgeMethod() {
-		try {
-			return Method.class.getMethod("isBridge", new Class<?>[] {
-				null
-			});
-		} catch (final NoSuchMethodException e) {
-			return null;
-		}
-	}
-	
-	private static Method getIsSyntheticMethod() {
-		try {
-			return Method.class.getMethod("isSynthetic", new Class<?>[] {
-				null
-			});
-		} catch (final NoSuchMethodException e) {
-			return null;
-		}
-	}
-	
 	/**
 	 * シグニチャを取得する。
 	 * 
+	 * <p>例: {@code getSignature(java.lang.String, java.lang.Class[])}
+	 * 
 	 * @param methodName メソッド名
 	 * @param argTypes 引数
 	 * @return シグニチャ
@@ -286,8 +228,8 @@
 	 * @throws InvocationTargetException メソッドが例外をスローする場合
 	 * @see Method#invoke(Object, Object[])
 	 */
-	public static Object invoke(Method method, Object target, Object[] args) throws IllegalArgumentException,
-			IllegalAccessException, InvocationTargetException {
+	public static Object invoke(Method method, Object target, Object[] args) throws IllegalAccessException,
+			InvocationTargetException {
 		try {
 			return method.invoke(target, args);
 		} catch (InvocationTargetException ex) {
@@ -303,10 +245,10 @@
 	}
 	
 	/**
-	 * <code>abstract</code>かどうかを取得する。
+	 * {@code abstract}メソッドかどうかを取得する。
 	 * 
 	 * @param method メソッド
-	 * @return <code>abstract</code>かどうか
+	 * @return {@code abstract}の場合は{@code true}、そうでない場合は{@code false}
 	 */
 	public static boolean isAbstract(Method method) {
 		int mod = method.getModifiers();
@@ -322,16 +264,15 @@
 	 * @throws IllegalAccessException メソッドにアクセス場合
 	 * @throws IllegalArgumentException 引数が正しくない場合
 	 */
-	public static boolean isBridgeMethod(final Method method) throws IllegalArgumentException, IllegalAccessException,
-			InvocationTargetException {
+	public static boolean isBridgeMethod(final Method method) throws IllegalAccessException, InvocationTargetException {
 		if (IS_BRIDGE_METHOD == null) {
 			return false;
 		}
-		return ((Boolean) MethodUtil.invoke(IS_BRIDGE_METHOD, method, null)).booleanValue();
+		return ((Boolean) invoke(IS_BRIDGE_METHOD, method, null)).booleanValue();
 	}
 	
 	/**
-	 * equalsメソッドかどうかを取得する。
+	 * {@link #equals(Object)}メソッドかどうかを取得する。
 	 * 
 	 * @param method {@link Method}
 	 * @return equalsメソッドかどうか
@@ -342,7 +283,7 @@
 	}
 	
 	/**
-	 * hashCodeメソッドかどうか取得する。
+	 * {@link #hashCode()}メソッドかどうか取得する。
 	 * 
 	 * @param method {@link Method}
 	 * @return hashCodeメソッドかどうか
@@ -361,16 +302,16 @@
 	 * @throws IllegalAccessException メソッドにアクセス場合
 	 * @throws IllegalArgumentException 引数が正しくない場合
 	 */
-	public static boolean isSyntheticMethod(final Method method) throws IllegalArgumentException,
-			IllegalAccessException, InvocationTargetException {
+	public static boolean isSyntheticMethod(final Method method) throws IllegalAccessException,
+			InvocationTargetException {
 		if (IS_SYNTHETIC_METHOD == null) {
 			return false;
 		}
-		return ((Boolean) MethodUtil.invoke(IS_SYNTHETIC_METHOD, method, null)).booleanValue();
+		return ((Boolean) invoke(IS_SYNTHETIC_METHOD, method, null)).booleanValue();
 	}
 	
 	/**
-	 * toStringメソッドかどうか取得する。
+	 * {@link #toString()}メソッドかどうか取得する。
 	 * 
 	 * @param method {@link Method}
 	 * @return toStringメソッドかどうか
@@ -380,8 +321,64 @@
 				&& method.getParameterTypes().length == 0;
 	}
 	
+	/**
+	 * <code>ReflectionUtil#getElementTypeOf<var>Xxx</var>FromParameter</code>の{@link Method}を取得する。
+	 * 
+	 * @param type 取得するメソッドが対象とする型名
+	 * @return {@link Method}
+	 */
+	protected static Method getElementTypeFromParameterMethod(final String type) {
+		try {
+			final Class<?> reflectionUtilClass = ReflectionUtil.class;
+			return reflectionUtilClass.getMethod("getElementTypeOf" + type + "FromParameterType", new Class[] {
+				Method.class,
+				int.class
+			});
+		} catch (final Throwable ignore) {
+			// ignore
+		}
+		return null;
+	}
+	
+	/**
+	 * <code>ReflectionUtil#getElementTypeOf<var>Xxx</var>FromReturn</code>の{@link Method}を取得する。
+	 * 
+	 * @param type 取得するメソッドが対象とする型名
+	 * @return {@link Method}
+	 */
+	protected static Method getElementTypeFromReturnMethod(final String type) {
+		try {
+			final Class<?> reflectionUtilClass = ReflectionUtil.class;
+			return reflectionUtilClass.getMethod("getElementTypeOf" + type + "FromReturnType", new Class[] {
+				Method.class
+			});
+		} catch (final Throwable ignore) {
+			// ignore
+		}
+		return null;
+	}
+	
+	private static Method getIsBridgeMethod() {
+		try {
+			return Method.class.getMethod("isBridge", new Class<?>[] {
+				null
+			});
+		} catch (final NoSuchMethodException e) {
+			return null;
+		}
+	}
+	
+	private static Method getIsSyntheticMethod() {
+		try {
+			return Method.class.getMethod("isSynthetic", new Class<?>[] {
+				null
+			});
+		} catch (final NoSuchMethodException e) {
+			return null;
+		}
+	}
+	
 	private MethodUtil() {
-		throw new JiemamyError("不到達ポイント");
 	}
 	
 }

Added: leto/jiemamy-commons/trunk/src/test/java/org/jiemamy/utils/MethodUtilTest.java
===================================================================
--- leto/jiemamy-commons/trunk/src/test/java/org/jiemamy/utils/MethodUtilTest.java	                        (rev 0)
+++ leto/jiemamy-commons/trunk/src/test/java/org/jiemamy/utils/MethodUtilTest.java	2009-10-25 14:20:22 UTC (rev 3742)
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2007-2009 Jiemamy Project and the Others.
+ * Created on 2009/10/25
+ *
+ * This file is part of Jiemamy.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific language
+ * governing permissions and limitations under the License.
+ */
+package org.jiemamy.utils;
+
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+
+/**
+ * {@link MethodUtil}のテストクラス。
+ * 
+ * @version $Id$
+ * @author daisuke
+ */
+public class MethodUtilTest {
+	
+	/**
+	 * {@link MethodUtil#getSignature(String, Class[])}のテスト。
+	 * 
+	 * @throws Exception 例外が発生した場合
+	 */
+	@Test
+	public void test01_getSignature() throws Exception {
+		assertThat(MethodUtil.getSignature("getSignature", new Class[0]), is("getSignature()"));
+		
+		assertThat(MethodUtil.getSignature("getSignature", new Class[] {
+			String.class,
+			Class.class
+		}), is("getSignature(java.lang.String, java.lang.Class)"));
+		
+		assertThat(MethodUtil.getSignature("getSignature", new Class[] {
+			String.class,
+			Class[].class
+		}), is("getSignature(java.lang.String, [Ljava.lang.Class;)"));
+	}
+}


Property changes on: leto/jiemamy-commons/trunk/src/test/java/org/jiemamy/utils/MethodUtilTest.java
___________________________________________________________________
Added: svn:eol-style
   + native




Jiemamy-notify メーリングリストの案内
Back to archive index