Browse Source

#41058: permit Java 5 enumerations to work like EnumeratedAttribute.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@481322 13f79535-47bb-0310-9956-ffa450edef68
master
Jesse N. Glick 18 years ago
parent
commit
f40249fb49
3 changed files with 40 additions and 0 deletions
  1. +3
    -0
      WHATSNEW
  2. +19
    -0
      src/main/org/apache/tools/ant/IntrospectionHelper.java
  3. +18
    -0
      src/main/org/apache/tools/ant/taskdefs/AntStructure.java

+ 3
- 0
WHATSNEW View File

@@ -51,6 +51,9 @@ Other changes:

* Do not uppercase the drive letters systematically in FileUtils#normalize.

* Java 5 enumerations may now be used as values in XML attributes in place of
EnumeratedAttribute. Bugzilla 41058.

Changes from Ant 1.7.0Beta3 to Ant 1.7.0RC1
===========================================



+ 19
- 0
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

@@ -1008,6 +1008,25 @@ public final class IntrospectionHelper {
}
}
};
} else if (reflectedArg.getSuperclass() != null && reflectedArg.getSuperclass().getName().equals("java.lang.Enum")) {
return new AttributeSetter(m) {
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) {
if (x.getTargetException() instanceof IllegalArgumentException) {
throw new BuildException("'" + value + "' is not a permitted value for " + reflectedArg.getName());
} else {
throw new BuildException(x.getTargetException());
}
} catch (Exception x) {
throw new BuildException(x);
}
}
};
// worst case. look for a public String constructor and use it
// also supports new Whatever(Project, String) as for Path or Reference
// This is used (deliberately) for all primitives/wrappers other than


+ 18
- 0
src/main/org/apache/tools/ant/taskdefs/AntStructure.java View File

@@ -370,6 +370,24 @@ public class AntStructure extends Task {
} catch (IllegalAccessException ie) {
sb.append("CDATA ");
}
} else if (type.getSuperclass() != null && type.getSuperclass().getName().equals("java.lang.Enum")) {
try {
Object[] values = (Object[]) type.getMethod("values", null).invoke(null, null);
if (values.length == 0) {
sb.append("CDATA ");
} else {
sb.append('(');
for (int i = 0; i < values.length; i++) {
if (i != 0) {
sb.append(" | ");
}
sb.append(type.getMethod("name", null).invoke(values[i], null));
}
sb.append(") ");
}
} catch (Exception x) {
sb.append("CDATA ");
}
} else {
sb.append("CDATA ");
}


Loading…
Cancel
Save