]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/Cpptasks/net/sf/antcontrib/cpptasks/types/UndefineArgument.java
3 * Copyright 2001-2004 The Ant-Contrib project
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package net
.sf
.antcontrib
.cpptasks
.types
;
18 import java
.util
.Vector
;
20 import net
.sf
.antcontrib
.cpptasks
.CUtil
;
22 import org
.apache
.tools
.ant
.BuildException
;
24 * Preprocessor macro undefinition.
26 * @author Mark A Russell <a
27 * href="mailto:mark_russell@csgsystems.com">mark_russell@csg_systems.com
30 public class UndefineArgument
{
32 * This method returns an array of UndefineArgument and DefineArgument's by
33 * merging a base list with an override list.
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
39 public static UndefineArgument
[] merge(UndefineArgument
[] base
,
40 UndefineArgument
[] override
) {
41 if (base
.length
== 0) {
42 UndefineArgument
[] overrideClone
= (UndefineArgument
[]) override
46 if (override
.length
== 0) {
47 UndefineArgument
[] baseClone
= (UndefineArgument
[]) base
.clone();
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) {
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
)) {
68 unduplicated
.addElement(current
);
71 UndefineArgument
[] combined
= new UndefineArgument
[unduplicated
.size()
73 unduplicated
.copyInto(combined
);
74 int offset
= unduplicated
.size();
75 for (int i
= 0; i
< override
.length
; i
++) {
76 combined
[offset
+ i
] = override
[i
];
80 private boolean define
= false;
81 private String ifCond
;
83 private String unlessCond
;
84 public UndefineArgument() {
86 protected UndefineArgument(boolean isDefine
) {
87 this.define
= isDefine
;
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");
93 /** Returns the name of the define */
94 public final String
getName() {
97 /** Returns the value of the define */
98 public String
getValue() {
102 * Returns true if the define's if and unless conditions (if any) are
105 * @exception BuildException
106 * throws build exception if name is not set
108 public final boolean isActive(org
.apache
.tools
.ant
.Project p
)
109 throws BuildException
{
111 throw new BuildException("<define> is missing name attribute");
113 return CUtil
.isActive(p
, ifCond
, unlessCond
);
115 /** Returns true if this is a define, false if an undefine. */
116 public final boolean isDefine() {
120 * Sets the property name for the 'if' condition.
122 * The define will be ignored unless the property is defined.
124 * The value of the property is insignificant, but values that would imply
125 * misinterpretation ("false", "no") will throw an exception when
131 public final void setIf(String propName
) {
134 /** Set the name attribute */
135 public final void setName(String name
) {
139 * Set the property name for the 'unless' condition.
141 * If named property is set, the define will be ignored.
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.
150 public final void setUnless(String propName
) {
151 unlessCond
= propName
;