It was only a 40 line or so addition to
IntrospectionHelper.createAttributeSetter to add hex support to numeric
types. Definitely it pushes the style guidelines on the size of anon inner
classes, but it seems like a pretty innocuous fix. Octal and binary could
be done by minor extensions, but hex was the most significant to me.
cvs diff -l IntrospectionHelper.java (in directory
C:\apache-xml\jakarta-ant\src\main\org\apache\tools\ant\)
Index: IntrospectionHelper.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
retrieving revision 1.40
diff -r1.40 IntrospectionHelper.java
773a774,813
> //
> // try also to find valueOf(String,int)
> // to use if value looks like hexadecimal numeric literal
> try {
> final Method valueOf = reflectedArg.getMethod("valueOf",
> new Class[] { java.lang.String.class,
> java.lang.Integer.TYPE });
>
> return new AttributeSetter() {
> public void set(Project p, Object parent,
> String value)
> throws InvocationTargetException,
> IllegalAccessException, BuildException {
> try {
> Object attribute = null;
> //
> // if value looks like a hexadecimal literal
> if(value.length() > 2 && value.charAt(0) ==
> '0' &&
> (value.charAt(1) == 'x' || value.charAt(1)
> == 'X')) {
> try {
> attribute = valueOf.invoke(null,
> new Object[] { value.substring(2), new
> Integer(16) });
> }
> catch(Exception ex) {
> }
> }
> if(attribute == null) {
> attribute = c.newInstance(new String[]
> {value});
> }
> if (attribute instanceof ProjectComponent) {
> ((ProjectComponent)
> attribute).setProject(p);
> }
> m.invoke(parent, new Object[] {attribute});
> } catch (InstantiationException ie) {
> throw new BuildException(ie);
> }
> }
> };
> } catch(NoSuchMethodException nme) {
> }
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>