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