name for macrodef. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@275641 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -20,6 +20,26 @@ | |||||
| <my.echo text="Inner Text"/> | <my.echo text="Inner Text"/> | ||||
| </target> | </target> | ||||
| <target name="duplicate.attribute"> | |||||
| <macrodef name="my.echo"> | |||||
| <attribute name="text"/> | |||||
| <attribute name="text"/> | |||||
| <sequential> | |||||
| <echo>${text}</echo> | |||||
| </sequential> | |||||
| </macrodef> | |||||
| </target> | |||||
| <target name="duplicate.element"> | |||||
| <macrodef name="my.echo"> | |||||
| <element name="text"/> | |||||
| <element name="text"/> | |||||
| <sequential> | |||||
| <text/> | |||||
| </sequential> | |||||
| </macrodef> | |||||
| </target> | |||||
| <target name="uri"> | <target name="uri"> | ||||
| <macrodef name="echo" uri="abc"> | <macrodef name="echo" uri="abc"> | ||||
| <attribute name="text"/> | <attribute name="text"/> | ||||
| @@ -78,7 +78,7 @@ import org.apache.tools.ant.UnknownElement; | |||||
| public class MacroDef extends AntlibDefinition { | public class MacroDef extends AntlibDefinition { | ||||
| private NestedSequential nestedSequential; | private NestedSequential nestedSequential; | ||||
| private String name; | private String name; | ||||
| private List attributes = new ArrayList(); | |||||
| private Map attributes = new HashMap(); | |||||
| private Map elements = new HashMap(); | private Map elements = new HashMap(); | ||||
| /** | /** | ||||
| @@ -170,7 +170,7 @@ public class MacroDef extends AntlibDefinition { | |||||
| /** | /** | ||||
| * @return the nested Attributes | * @return the nested Attributes | ||||
| */ | */ | ||||
| public List getAttributes() { | |||||
| public Map getAttributes() { | |||||
| return attributes; | return attributes; | ||||
| } | } | ||||
| @@ -221,7 +221,12 @@ public class MacroDef extends AntlibDefinition { | |||||
| throw new BuildException( | throw new BuildException( | ||||
| "the attribute nested element needed a \"name\" attribute"); | "the attribute nested element needed a \"name\" attribute"); | ||||
| } | } | ||||
| attributes.add(attribute); | |||||
| if (attributes.get(attribute.getName()) != null) { | |||||
| throw new BuildException( | |||||
| "the attribute " + attribute.getName() | |||||
| + " has already been specified"); | |||||
| } | |||||
| attributes.put(attribute.getName(), attribute); | |||||
| } | } | ||||
| /** | /** | ||||
| @@ -234,6 +239,11 @@ public class MacroDef extends AntlibDefinition { | |||||
| throw new BuildException( | throw new BuildException( | ||||
| "the element nested element needed a \"name\" attribute"); | "the element nested element needed a \"name\" attribute"); | ||||
| } | } | ||||
| if (elements.get(element.getName()) != null) { | |||||
| throw new BuildException( | |||||
| "the element " + element.getName() | |||||
| + " has already been specified"); | |||||
| } | |||||
| elements.put(element.getName(), element); | elements.put(element.getName(), element); | ||||
| } | } | ||||
| @@ -294,9 +294,9 @@ public class MacroInstance extends Task implements DynamicConfigurator { | |||||
| public void execute() { | public void execute() { | ||||
| localProperties = new Hashtable(); | localProperties = new Hashtable(); | ||||
| Set copyKeys = new HashSet(map.keySet()); | Set copyKeys = new HashSet(map.keySet()); | ||||
| for (int i = 0; i < macroDef.getAttributes().size(); ++i) { | |||||
| MacroDef.Attribute attribute = | |||||
| (MacroDef.Attribute) macroDef.getAttributes().get(i); | |||||
| for (Iterator i = macroDef.getAttributes().values().iterator(); | |||||
| i.hasNext();) { | |||||
| MacroDef.Attribute attribute = (MacroDef.Attribute) i.next(); | |||||
| String value = (String) map.get(attribute.getName()); | String value = (String) map.get(attribute.getName()); | ||||
| if (value == null) { | if (value == null) { | ||||
| value = attribute.getDefault(); | value = attribute.getDefault(); | ||||
| @@ -78,6 +78,18 @@ public class MacroDefTest extends BuildFileTest { | |||||
| expectLog("text", "Inner Text"); | expectLog("text", "Inner Text"); | ||||
| } | } | ||||
| public void testDuplicateAttribute() { | |||||
| expectBuildException( | |||||
| "duplicate.attribute", | |||||
| "the attribute text has already been specified"); | |||||
| } | |||||
| public void testDuplicateElement() { | |||||
| expectBuildException( | |||||
| "duplicate.element", | |||||
| "the element text has already been specified"); | |||||
| } | |||||
| public void testUri() { | public void testUri() { | ||||
| expectLog("uri", "Hello World"); | expectLog("uri", "Hello World"); | ||||
| } | } | ||||