ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kuiper, Arnout" <>
Subject RE: Ant Principles
Date Fri, 21 Apr 2000 14:53:50 GMT
> From: Ludovic Claude []
> I wrote some time ago in my experimental version of ant 
> something similar. Here
> goes the code.
> If you like it, tell me, i will integrate it in the current 
> version of ant
> (unless we do further developments
> in the utah branch). Little benefit of this aditional class: 
> you can cache it
> and save time because you don't
> have to run reflexion more than one time on a class.

>                 // make sure that there's only 1 param and that it
>                 // takes a supported parameter (String, 
> boolean, int, float),
>                 // all other setMethods need to get screened out

The original proposal goes further. Besides the String and
primitive types, any class that has a String-constructor
is acceptable (Like File and StringReader to name a few), so
the following setters are acceptable:

setFoo(String value);
setFoo(long value);
setFoo(int value);
setFoo(short value);
setFoo(byte value);
setFoo(char value);
setFoo(double value);
setFoo(float value);
setFoo(boolean value);
setFoo(File value);
setFoo(StringReader value);
setFoo(URL value);

Now I think of it, we can go even further by also allowing
classes that have a primitive-type-constructor (Foo(int)).
The String value of the attribute should be cast to the
primitive type, with which the desired object can be
instantiated, which can in his turn be passed to the
attribute setter. Some generic classes like File and
URL could also be allowed as argument for the constructor,
when the nature of Ant is taken into account

In case a class has multiple candidate single-argument
constructors, we have to fail because we cannot make
an educated guess what is the constructor to use.

So in short:

1. setFoo(String) -> use String value
2. setFoo(primitive) -> cast String value to primitive and 
                        use it
3. setFoo(SomeObject) -> See below

SomeObject is allowed under the following conditions:
1. it has a single-argument String-constructor or,
2. it has a single-argument primitive-constructor or,
3. it has a single-argument constructor with the type
   File or URL (Which is constructed using the String

Your idea about caching is good. But it should be enhanced a
bit to support overloading of types of attribute setters in
subclasses of a task (Only use the latest method declaration
in the inheritance hierarchy (or lowest method declaration
when the root of the tree is on top)).


View raw message