]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/types/DefineSet.java
Initial import.
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / types / DefineSet.java
CommitLineData
878ddf1f 1/*\r
2 * \r
3 * Copyright 2001-2004 The Ant-Contrib project\r
4 *\r
5 * Licensed under the Apache License, Version 2.0 (the "License");\r
6 * you may not use this file except in compliance with the License.\r
7 * You may obtain a copy of the License at\r
8 *\r
9 * http://www.apache.org/licenses/LICENSE-2.0\r
10 *\r
11 * Unless required by applicable law or agreed to in writing, software\r
12 * distributed under the License is distributed on an "AS IS" BASIS,\r
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 * See the License for the specific language governing permissions and\r
15 * limitations under the License.\r
16 */\r
17package net.sf.antcontrib.cpptasks.types;\r
18import java.util.Vector;\r
19\r
20import net.sf.antcontrib.cpptasks.CUtil;\r
21\r
22import org.apache.tools.ant.BuildException;\r
23import org.apache.tools.ant.types.DataType;\r
24import org.apache.tools.ant.types.Reference;\r
25/**\r
26 * Set of preprocessor macro defines and undefines.\r
27 * \r
28 * @author Mark A Russell <a\r
29 * href="mailto:mark_russell@csgsystems.com">mark_russell@csg_systems.com\r
30 * </a>\r
31 * @author Adam Murdoch\r
32 */\r
33public class DefineSet extends DataType {\r
34 private Vector defineList = new Vector();\r
35 private String ifCond = null;\r
36 private String unlessCond = null;\r
37 /**\r
38 * \r
39 * Adds a define element.\r
40 * \r
41 * @throws BuildException\r
42 * if reference\r
43 */\r
44 public void addDefine(DefineArgument arg) throws BuildException {\r
45 if (isReference()) {\r
46 throw noChildrenAllowed();\r
47 }\r
48 defineList.addElement(arg);\r
49 }\r
50 /** Adds defines/undefines. */\r
51 private void addDefines(String[] defs, boolean isDefine) {\r
52 for (int i = 0; i < defs.length; i++) {\r
53 UndefineArgument def;\r
54 if (isDefine) {\r
55 def = new DefineArgument();\r
56 } else {\r
57 def = new UndefineArgument();\r
58 }\r
59 def.setName(defs[i]);\r
60 defineList.addElement(def);\r
61 }\r
62 }\r
63 /**\r
64 * \r
65 * Adds an undefine element.\r
66 * \r
67 * @throws BuildException\r
68 * if reference\r
69 */\r
70 public void addUndefine(UndefineArgument arg) throws BuildException {\r
71 if (isReference()) {\r
72 throw noChildrenAllowed();\r
73 }\r
74 defineList.addElement(arg);\r
75 }\r
76 public void execute() throws org.apache.tools.ant.BuildException {\r
77 throw new org.apache.tools.ant.BuildException(\r
78 "Not an actual task, but looks like one for documentation purposes");\r
79 }\r
80 /** Returns the defines and undefines in this set. */\r
81 public UndefineArgument[] getDefines() throws BuildException {\r
82 if (isReference()) {\r
83 DefineSet defset = (DefineSet) getCheckedRef(DefineSet.class,\r
84 "DefineSet");\r
85 return defset.getDefines();\r
86 } else {\r
87 if (isActive()) {\r
88 UndefineArgument[] defs = new UndefineArgument[defineList\r
89 .size()];\r
90 defineList.copyInto(defs);\r
91 return defs;\r
92 } else {\r
93 return new UndefineArgument[0];\r
94 }\r
95 }\r
96 }\r
97 /**\r
98 * Returns true if the define's if and unless conditions (if any) are\r
99 * satisfied.\r
100 * \r
101 * @exception BuildException\r
102 * throws build exception if name is not set\r
103 */\r
104 public final boolean isActive() throws BuildException {\r
105 return CUtil.isActive(getProject(), ifCond, unlessCond);\r
106 }\r
107 /**\r
108 * A comma-separated list of preprocessor macros to define. Use nested\r
109 * define elements to define macro values.\r
110 * \r
111 * @param defList\r
112 * comma-separated list of preprocessor macros\r
113 * @throws BuildException\r
114 * throw if defineset is a reference\r
115 */\r
116 public void setDefine(CUtil.StringArrayBuilder defList)\r
117 throws BuildException {\r
118 if (isReference()) {\r
119 throw tooManyAttributes();\r
120 }\r
121 addDefines(defList.getValue(), true);\r
122 }\r
123 /**\r
124 * Sets a description of the current data type.\r
125 */\r
126 public void setDescription(String desc) {\r
127 super.setDescription(desc);\r
128 }\r
129 /**\r
130 * Sets an id that can be used to reference this element.\r
131 * \r
132 * @param id\r
133 * id\r
134 */\r
135 public void setId(String id) {\r
136 //\r
137 // this is actually accomplished by a different\r
138 // mechanism, but we can document it\r
139 //\r
140 }\r
141 /**\r
142 * Sets the property name for the 'if' condition.\r
143 * \r
144 * The define will be ignored unless the property is defined.\r
145 * \r
146 * The value of the property is insignificant, but values that would imply\r
147 * misinterpretation ("false", "no") will throw an exception when\r
148 * evaluated.\r
149 * \r
150 * @param propName\r
151 * property name\r
152 */\r
153 public final void setIf(String propName) {\r
154 ifCond = propName;\r
155 }\r
156 /**\r
157 * Specifies that this element should behave as if the content of the\r
158 * element with the matching id attribute was inserted at this location. If\r
159 * specified, no other attributes or child content should be specified,\r
160 * other than "description".\r
161 * \r
162 */\r
163 public void setRefid(Reference r) throws BuildException {\r
164 if (!defineList.isEmpty()) {\r
165 throw tooManyAttributes();\r
166 }\r
167 super.setRefid(r);\r
168 }\r
169 /**\r
170 * A comma-separated list of preprocessor macros to undefine.\r
171 * \r
172 * @param undefList\r
173 * comma-separated list of preprocessor macros\r
174 * @throws BuildException\r
175 * throw if defineset is a reference\r
176 */\r
177 public void setUndefine(CUtil.StringArrayBuilder undefList)\r
178 throws BuildException {\r
179 if (isReference()) {\r
180 throw tooManyAttributes();\r
181 }\r
182 addDefines(undefList.getValue(), false);\r
183 }\r
184 /**\r
185 * Set the property name for the 'unless' condition.\r
186 * \r
187 * If named property is set, the define will be ignored.\r
188 * \r
189 * The value of the property is insignificant, but values that would imply\r
190 * misinterpretation ("false", "no") of the behavior will throw an\r
191 * exception when evaluated.\r
192 * \r
193 * @param propName\r
194 * name of property\r
195 */\r
196 public final void setUnless(String propName) {\r
197 unlessCond = propName;\r
198 }\r
199}\r