Bug 14831 - EnumeratedAttributes are not developer friendly
EnumeratedAttributes are not developer friendly
Status: RESOLVED FIXED
Product: Ant
Classification: Unclassified
Component: Core
1.5.1
All other
: P3 enhancement with 1 vote (vote)
: ---
Assigned To: Ant Notifications List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2002-11-25 18:15 UTC by Dominique Devienne
Modified: 2008-02-22 12:18 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dominique Devienne 2002-11-25 18:15:59 UTC
The code below illustrates the 3 lines of code necessary to set an enum attrib 
programmatically. I find it heavy...

PresentSelector present = new PresentSelector();
present.setTargetdir(file);
// 1) Instantiate enum attrib
PresentSelector.FilePresence both = new PresentSelector.FilePresence();
// 2) Set value of enum attrib
both.setValue("both");
// 3) Set enum attrib
present.setPresent(both);
none.appendSelector(present);

I propose 3 different things:

1) Adding a protected EnumeratedAttribute(String value) Ctor
2) Adding EnumClass(String value) { super(value); } Ctor to the various enums.
2') Prebuilt declare the various enum values, like in

public class PresentSelector extends BaseSelector {
    public static class FilePresence extends EnumeratedAttribute {
        public static final FilePresence BOTH = new FilePresence("both");
        public static final FilePresence SRCONLY = new FilePresence("srconly");
        private FilePresence(String value) { super(value); }
        public String[] getValues() {
            return new String[] {SRCONLY.getValue(), BOTH.getValue()};
        }
    }
}

My example then becomes:

PresentSelector present = new PresentSelector();
present.setTargetdir(file);
present.setPresent(PresentSelector.FilePresence.BOTH);
none.appendSelector(present);

As an aside, I personnally think that although the Bean pattern is generic and 
fine, I'd rather be able to write programmatically:

none.appendSelector(new PresentSelector(file,
                                        PresentSelector.FilePresence.BOTH));

Thanks, --DD
Comment 1 Jan Mat 2006-10-13 02:04:34 UTC
I think with the committed change your example would result in

   PresentSelector present = new PresentSelector();
   present.setTargetdir(file);
   present.setPresent(
EnumeratedAttribute.getInstance(PresentSelector.FilePresence.class, "both") );
   none.appendSelector(present);


Jan