From eefee2f267c1f2fe0c2a1f2aa1c0af625ca3daed Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Mon, 20 Aug 2007 08:36:17 +0000 Subject: [PATCH] make a big method a little smaller git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@567600 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/IntrospectionHelper.java | 76 +++++++++++-------- 1 file changed, 46 insertions(+), 30 deletions(-) diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java index fd648b98c..b2ed38f7e 100644 --- a/src/main/org/apache/tools/ant/IntrospectionHelper.java +++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java @@ -1012,37 +1012,12 @@ public final class IntrospectionHelper { } }; } - Class enumClass = null; - try { - enumClass = Class.forName("java.lang.Enum"); - } catch (ClassNotFoundException e) { - //ignore - } - if (enumClass != null && enumClass.isAssignableFrom(reflectedArg)) { - return new AttributeSetter(m, arg) { - public void set(Project p, Object parent, String value) - throws InvocationTargetException, IllegalAccessException, BuildException { - try { - m.invoke(parent, new Object[] { - reflectedArg.getMethod("valueOf", new Class[] {String.class}). - invoke(null, new Object[] {value})}); - } catch (InvocationTargetException x) { - //there is specific logic here for the value being out of the allowed - //set of enumerations. - if (x.getTargetException() instanceof IllegalArgumentException) { - throw new BuildException("'" + value + "' is not a permitted value for " - + reflectedArg.getName()); - } - //only if the exception is not an IllegalArgument do we request the - //BuildException via extractBuildException(): - throw extractBuildException(x); - } catch (Exception x) { - //any other failure of invoke() to work. - throw new BuildException(x); - } - } - }; + + AttributeSetter setter = getEnumSetter(reflectedArg, m, arg); + if (setter != null) { + return setter; } + if (java.lang.Long.class.equals(reflectedArg)) { return new AttributeSetter(m, arg) { public void set(Project p, Object parent, String value) @@ -1102,6 +1077,47 @@ public final class IntrospectionHelper { }; } + private AttributeSetter getEnumSetter( + final Class reflectedArg, final Method m, Class arg) { + Class enumClass = null; + try { + enumClass = Class.forName("java.lang.Enum"); + } catch (ClassNotFoundException e) { + //ignore + } + if (enumClass != null && enumClass.isAssignableFrom(reflectedArg)) { + return new AttributeSetter(m, arg) { + public void set(Project p, Object parent, String value) + throws InvocationTargetException, IllegalAccessException, + BuildException { + try { + m.invoke( + parent, new Object[] { + reflectedArg.getMethod( + "valueOf", new Class[] {String.class}). + invoke(null, new Object[] {value})}); + } catch (InvocationTargetException x) { + //there is specific logic here for the value + // being out of the allowed set of enumerations. + if (x.getTargetException() instanceof IllegalArgumentException) { + throw new BuildException( + "'" + value + "' is not a permitted value for " + + reflectedArg.getName()); + } + //only if the exception is not an IllegalArgument do we + // request the + //BuildException via extractBuildException(): + throw extractBuildException(x); + } catch (Exception x) { + //any other failure of invoke() to work. + throw new BuildException(x); + } + } + }; + } + return null; + } + /** * Returns a description of the type of the given element in * relation to a given project. This is used for logging purposes