]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/types/UndefineArgument.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / Cpptasks / net / sf / antcontrib / cpptasks / types / UndefineArgument.java
diff --git a/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/types/UndefineArgument.java b/Tools/Java/Source/Cpptasks/net/sf/antcontrib/cpptasks/types/UndefineArgument.java
new file mode 100644 (file)
index 0000000..2a18fca
--- /dev/null
@@ -0,0 +1,153 @@
+/*\r
+ * \r
+ * Copyright 2001-2004 The Ant-Contrib project\r
+ *\r
+ *  Licensed under the Apache License, Version 2.0 (the "License");\r
+ *  you may not use this file except in compliance with the License.\r
+ *  You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ *  Unless required by applicable law or agreed to in writing, software\r
+ *  distributed under the License is distributed on an "AS IS" BASIS,\r
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ *  See the License for the specific language governing permissions and\r
+ *  limitations under the License.\r
+ */\r
+package net.sf.antcontrib.cpptasks.types;\r
+import java.util.Vector;\r
+\r
+import net.sf.antcontrib.cpptasks.CUtil;\r
+\r
+import org.apache.tools.ant.BuildException;\r
+/**\r
+ * Preprocessor macro undefinition.\r
+ * \r
+ * @author Mark A Russell <a\r
+ *         href="mailto:mark_russell@csgsystems.com">mark_russell@csg_systems.com\r
+ *         </a>\r
+ */\r
+public class UndefineArgument {\r
+    /**\r
+     * This method returns an array of UndefineArgument and DefineArgument's by\r
+     * merging a base list with an override list.\r
+     * \r
+     * Any define in the base list with a name that appears in the override\r
+     * list is suppressed. All entries in the override list are preserved\r
+     *  \r
+     */\r
+    public static UndefineArgument[] merge(UndefineArgument[] base,\r
+            UndefineArgument[] override) {\r
+        if (base.length == 0) {\r
+            UndefineArgument[] overrideClone = (UndefineArgument[]) override\r
+                    .clone();\r
+            return overrideClone;\r
+        }\r
+        if (override.length == 0) {\r
+            UndefineArgument[] baseClone = (UndefineArgument[]) base.clone();\r
+            return baseClone;\r
+        }\r
+        Vector unduplicated = new Vector(base.length);\r
+        for (int i = 0; i < base.length; i++) {\r
+            UndefineArgument current = base[i];\r
+            String currentName = current.getName();\r
+            boolean match = false;\r
+            if (currentName == null) {\r
+                match = true;\r
+            } else {\r
+                for (int j = 0; j < override.length; j++) {\r
+                    UndefineArgument over = override[j];\r
+                    String overName = over.getName();\r
+                    if (overName != null && overName.equals(currentName)) {\r
+                        match = true;\r
+                        break;\r
+                    }\r
+                }\r
+            }\r
+            if (!match) {\r
+                unduplicated.addElement(current);\r
+            }\r
+        }\r
+        UndefineArgument[] combined = new UndefineArgument[unduplicated.size()\r
+                + override.length];\r
+        unduplicated.copyInto(combined);\r
+        int offset = unduplicated.size();\r
+        for (int i = 0; i < override.length; i++) {\r
+            combined[offset + i] = override[i];\r
+        }\r
+        return combined;\r
+    }\r
+    private boolean define = false;\r
+    private String ifCond;\r
+    private String name;\r
+    private String unlessCond;\r
+    public UndefineArgument() {\r
+    }\r
+    protected UndefineArgument(boolean isDefine) {\r
+        this.define = isDefine;\r
+    }\r
+    public void execute() throws org.apache.tools.ant.BuildException {\r
+        throw new org.apache.tools.ant.BuildException(\r
+                "Not an actual task, but looks like one for documentation purposes");\r
+    }\r
+    /** Returns the name of the define */\r
+    public final String getName() {\r
+        return name;\r
+    }\r
+    /** Returns the value of the define */\r
+    public String getValue() {\r
+        return null;\r
+    }\r
+    /**\r
+     * Returns true if the define's if and unless conditions (if any) are\r
+     * satisfied.\r
+     * \r
+     * @exception BuildException\r
+     *                throws build exception if name is not set\r
+     */\r
+    public final boolean isActive(org.apache.tools.ant.Project p)\r
+            throws BuildException {\r
+        if (name == null) {\r
+            throw new BuildException("<define> is missing name attribute");\r
+        }\r
+        return CUtil.isActive(p, ifCond, unlessCond);\r
+    }\r
+    /** Returns true if this is a define, false if an undefine. */\r
+    public final boolean isDefine() {\r
+        return define;\r
+    }\r
+    /**\r
+     * Sets the property name for the 'if' condition.\r
+     * \r
+     * The define will be ignored unless the property is defined.\r
+     * \r
+     * The value of the property is insignificant, but values that would imply\r
+     * misinterpretation ("false", "no") will throw an exception when\r
+     * evaluated.\r
+     * \r
+     * @param propName\r
+     *            property name\r
+     */\r
+    public final void setIf(String propName) {\r
+        ifCond = propName;\r
+    }\r
+    /** Set the name attribute */\r
+    public final void setName(String name) {\r
+        this.name = name;\r
+    }\r
+    /**\r
+     * Set the property name for the 'unless' condition.\r
+     * \r
+     * If named property is set, the define will be ignored.\r
+     * \r
+     * The value of the property is insignificant, but values that would imply\r
+     * misinterpretation ("false", "no") of the behavior will throw an\r
+     * exception when evaluated.\r
+     * \r
+     * @param propName\r
+     *            name of property\r
+     */\r
+    public final void setUnless(String propName) {\r
+        unlessCond = propName;\r
+    }\r
+}\r