]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/types/UndefineArgument.java
Initial import.
[mirror_edk2.git] / Tools / Source / Cpptasks / net / sf / antcontrib / cpptasks / types / UndefineArgument.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 /**
24 * Preprocessor macro undefinition.
25 *
26 * @author Mark A Russell <a
27 * href="mailto:mark_russell@csgsystems.com">mark_russell@csg_systems.com
28 * </a>
29 */
30 public class UndefineArgument {
31 /**
32 * This method returns an array of UndefineArgument and DefineArgument's by
33 * merging a base list with an override list.
34 *
35 * Any define in the base list with a name that appears in the override
36 * list is suppressed. All entries in the override list are preserved
37 *
38 */
39 public static UndefineArgument[] merge(UndefineArgument[] base,
40 UndefineArgument[] override) {
41 if (base.length == 0) {
42 UndefineArgument[] overrideClone = (UndefineArgument[]) override
43 .clone();
44 return overrideClone;
45 }
46 if (override.length == 0) {
47 UndefineArgument[] baseClone = (UndefineArgument[]) base.clone();
48 return baseClone;
49 }
50 Vector unduplicated = new Vector(base.length);
51 for (int i = 0; i < base.length; i++) {
52 UndefineArgument current = base[i];
53 String currentName = current.getName();
54 boolean match = false;
55 if (currentName == null) {
56 match = true;
57 } else {
58 for (int j = 0; j < override.length; j++) {
59 UndefineArgument over = override[j];
60 String overName = over.getName();
61 if (overName != null && overName.equals(currentName)) {
62 match = true;
63 break;
64 }
65 }
66 }
67 if (!match) {
68 unduplicated.addElement(current);
69 }
70 }
71 UndefineArgument[] combined = new UndefineArgument[unduplicated.size()
72 + override.length];
73 unduplicated.copyInto(combined);
74 int offset = unduplicated.size();
75 for (int i = 0; i < override.length; i++) {
76 combined[offset + i] = override[i];
77 }
78 return combined;
79 }
80 private boolean define = false;
81 private String ifCond;
82 private String name;
83 private String unlessCond;
84 public UndefineArgument() {
85 }
86 protected UndefineArgument(boolean isDefine) {
87 this.define = isDefine;
88 }
89 public void execute() throws org.apache.tools.ant.BuildException {
90 throw new org.apache.tools.ant.BuildException(
91 "Not an actual task, but looks like one for documentation purposes");
92 }
93 /** Returns the name of the define */
94 public final String getName() {
95 return name;
96 }
97 /** Returns the value of the define */
98 public String getValue() {
99 return null;
100 }
101 /**
102 * Returns true if the define's if and unless conditions (if any) are
103 * satisfied.
104 *
105 * @exception BuildException
106 * throws build exception if name is not set
107 */
108 public final boolean isActive(org.apache.tools.ant.Project p)
109 throws BuildException {
110 if (name == null) {
111 throw new BuildException("<define> is missing name attribute");
112 }
113 return CUtil.isActive(p, ifCond, unlessCond);
114 }
115 /** Returns true if this is a define, false if an undefine. */
116 public final boolean isDefine() {
117 return define;
118 }
119 /**
120 * Sets the property name for the 'if' condition.
121 *
122 * The define will be ignored unless the property is defined.
123 *
124 * The value of the property is insignificant, but values that would imply
125 * misinterpretation ("false", "no") will throw an exception when
126 * evaluated.
127 *
128 * @param propName
129 * property name
130 */
131 public final void setIf(String propName) {
132 ifCond = propName;
133 }
134 /** Set the name attribute */
135 public final void setName(String name) {
136 this.name = name;
137 }
138 /**
139 * Set the property name for the 'unless' condition.
140 *
141 * If named property is set, the define will be ignored.
142 *
143 * The value of the property is insignificant, but values that would imply
144 * misinterpretation ("false", "no") of the behavior will throw an
145 * exception when evaluated.
146 *
147 * @param propName
148 * name of property
149 */
150 public final void setUnless(String propName) {
151 unlessCond = propName;
152 }
153 }