I have attached a proposed patch to IntrospectionHelper.java
Please take a look and send in your comments. It doesn't
modify an awful lot - in fact it has more comments than
code ;-)
If you find this ok, then I will star working on
converting tasks that take in String arguments to setFoo
methods, where taking in some other type of argument will
make sense.
Magesh
From: "Magesh Umasankar" <[EMAIL PROTECTED]>
> Hi,
> I notice that there are a few places where setFoo takes
> in String as parameter, where having a custom class
> would make it better. For example, Tar.java uses
> setLongFile(String mode). If we had setLongFile
> (TarMode)
> IMHO it would be better, as we could encapsulate
> features like validations, etc. inside it. For
> backwards compatibility, setLongFile(String) would
> stay
> but invoke setLongFile(TarMode). But this would mean
> refactoring the logic in IntrospectionHelper a bit. I
> propose the following change:
>
> If a task contains a setFoo(String) *and* setFoo(Bar),
> setFoo(Bar) gets invoked by the introspection
> mechanism.
> In other words, setFoo(String) gets a lower priority
> when compared to setFoo(Bar).
>
> What are your opinions?
>
> Magesh
Index: IntrospectionHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
retrieving revision 1.26
diff -u -w -r1.26 IntrospectionHelper.java
--- IntrospectionHelper.java 2001/11/16 12:05:50 1.26
+++ IntrospectionHelper.java 2001/12/04 16:17:19
@@ -164,6 +164,27 @@
&& !args[0].isArray()) {
String propName = getPropertyName(name, "set");
+ if (attributeSetters.get(propName) != null) {
+ if (java.lang.String.class.equals(args[0])) {
+ /*
+ Ignore method m, as there is an overloaded
+ form of this method that takes in a
+ non-string argument, which gains higher
+ priority.
+ */
+ continue;
+ }
+ /*
+ If the argument is not a String, and if there
+ is an overloaded form of this method already defined,
+ we just override that with the new one.
+ This mechanism does not guarantee any specific order
+ in which the methods will be recognized: so any code
+ that depends on the order in which "set" methods have
+ been defined, is not guaranteed to execute in any
+ particular order.
+ */
+ }
AttributeSetter as = createAttributeSetter(m, args[0]);
if (as != null) {
attributeTypes.put(propName, args[0]);
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>