Browse Source

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
master
Peter Reilly 18 years ago
parent
commit
eefee2f267
1 changed files with 46 additions and 30 deletions
  1. +46
    -30
      src/main/org/apache/tools/ant/IntrospectionHelper.java

+ 46
- 30
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

@@ -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


Loading…
Cancel
Save