ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r549681 - /ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java
Date Fri, 22 Jun 2007 03:08:50 GMT
Author: mbenson
Date: Thu Jun 21 20:08:49 2007
New Revision: 549681

URL: http://svn.apache.org/viewvc?view=rev&rev=549681
Log:
fmting/max line length, remove unnecessary Java 1.2 compatibility, some unnecessary elses

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java?view=diff&rev=549681&r1=549680&r2=549681
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/IntrospectionHelper.java Thu Jun 21 20:08:49 2007
@@ -15,7 +15,6 @@
  *  limitations under the License.
  *
  */
-
 package org.apache.tools.ant;
 
 import java.lang.reflect.Constructor;
@@ -53,18 +52,10 @@
  * ...do not make any assumptions about its uniqueness, or its validity after the Project
  * instance has finished its build.
  *
- *
  */
 public final class IntrospectionHelper  {
 
     /**
-     * EMPTY_MAP was added in java 1.3 (EMPTY_SET and EMPTY_LIST
-     * is in java 1.2!)
-     */
-    private static final Map EMPTY_MAP
-        = Collections.unmodifiableMap(new HashMap(0));
-
-    /**
      * Helper instances we've already created (Class.getName() to IntrospectionHelper).
      */
     private static final Map HELPERS = new Hashtable();
@@ -79,12 +70,10 @@
 
     // Set up PRIMITIVE_TYPE_MAP
     static {
-        Class[] primitives = {Boolean.TYPE, Byte.TYPE, Character.TYPE,
-                              Short.TYPE, Integer.TYPE, Long.TYPE,
-                              Float.TYPE, Double.TYPE};
-        Class[] wrappers = {Boolean.class, Byte.class, Character.class,
-                            Short.class, Integer.class, Long.class,
-                            Float.class, Double.class};
+        Class[] primitives = { Boolean.TYPE, Byte.TYPE, Character.TYPE, Short.TYPE,
+                               Integer.TYPE, Long.TYPE, Float.TYPE, Double.TYPE };
+        Class[] wrappers = { Boolean.class, Byte.class, Character.class, Short.class,
+                             Integer.class, Long.class, Float.class, Double.class };
         for (int i = 0; i < primitives.length; i++) {
             PRIMITIVE_TYPE_MAP.put (primitives[i], wrappers[i]);
         }
@@ -188,28 +177,25 @@
 
             // check of add[Configured](Class) pattern
             if (args.length == 1 && java.lang.Void.TYPE.equals(returnType)
-                && ("add".equals(name) || "addConfigured".equals(name))) {
+                    && ("add".equals(name) || "addConfigured".equals(name))) {
                 insertAddTypeMethod(m);
                 continue;
             }
             // not really user settable properties on tasks/project components
-            if (org.apache.tools.ant.ProjectComponent.class.isAssignableFrom(
-                    bean)
-                 && args.length == 1 && isHiddenSetMethod(name, args[0])) {
+            if (org.apache.tools.ant.ProjectComponent.class.isAssignableFrom(bean)
+                    && args.length == 1 && isHiddenSetMethod(name, args[0])) {
                 continue;
             }
             // hide addTask for TaskContainers
             if (isContainer() && args.length == 1 && "addTask".equals(name)
-                && org.apache.tools.ant.Task.class.equals(args[0])) {
+                    && org.apache.tools.ant.Task.class.equals(args[0])) {
                 continue;
             }
             if ("addText".equals(name) && java.lang.Void.TYPE.equals(returnType)
-                && args.length == 1 && java.lang.String.class.equals(args[0])) {
-
+                    && args.length == 1 && java.lang.String.class.equals(args[0])) {
                 addText = methods[i];
-            } else if (name.startsWith("set")
-                       && java.lang.Void.TYPE.equals(returnType)
-                       && args.length == 1 && !args[0].isArray()) {
+            } else if (name.startsWith("set") && java.lang.Void.TYPE.equals(returnType)
+                    && args.length == 1 && !args[0].isArray()) {
                 String propName = getPropertyName(name, "set");
                 if (attributeSetters.get(propName) != null) {
                     if (java.lang.String.class.equals(args[0])) {
@@ -238,7 +224,7 @@
                     attributeSetters.put(propName, as);
                 }
             } else if (name.startsWith("create") && !returnType.isArray()
-                       && !returnType.isPrimitive() && args.length == 0) {
+                    && !returnType.isPrimitive() && args.length == 0) {
 
                 String propName = getPropertyName(name, "create");
                 // Check if a create of this property is already present
@@ -248,16 +234,15 @@
                     nestedCreators.put(propName, new CreateNestedCreator(m));
                 }
             } else if (name.startsWith("addConfigured")
-                && java.lang.Void.TYPE.equals(returnType) && args.length == 1
-                && !java.lang.String.class.equals(args[0])
-                && !args[0].isArray() && !args[0].isPrimitive()) {
+                    && java.lang.Void.TYPE.equals(returnType) && args.length == 1
+                    && !java.lang.String.class.equals(args[0])
+                    && !args[0].isArray() && !args[0].isPrimitive()) {
                 try {
                     Constructor constructor = null;
                     try {
                         constructor = args[0].getConstructor(new Class[] {});
                     } catch (NoSuchMethodException ex) {
-                        constructor =
-                            args[0].getConstructor(new Class[] {Project.class});
+                        constructor = args[0].getConstructor(new Class[] {Project.class});
                     }
                     String propName = getPropertyName(name, "addConfigured");
                     nestedTypes.put(propName, args[0]);
@@ -267,18 +252,16 @@
                     // ignore
                 }
             } else if (name.startsWith("add")
-                && java.lang.Void.TYPE.equals(returnType) && args.length == 1
-                && !java.lang.String.class.equals(args[0])
-                && !args[0].isArray() && !args[0].isPrimitive()) {
+                    && java.lang.Void.TYPE.equals(returnType) && args.length == 1
+                    && !java.lang.String.class.equals(args[0])
+                    && !args[0].isArray() && !args[0].isPrimitive()) {
                 try {
                     Constructor constructor = null;
                     try {
                         constructor = args[0].getConstructor(new Class[] {});
                     } catch (NoSuchMethodException ex) {
-                        constructor =
-                            args[0].getConstructor(new Class[] {Project.class});
+                        constructor = args[0].getConstructor(new Class[] {Project.class});
                     }
-
                     String propName = getPropertyName(name, "add");
                     if (nestedTypes.get(propName) != null) {
                         /*
@@ -290,7 +273,7 @@
                     }
                     nestedTypes.put(propName, args[0]);
                     nestedCreators.put(propName, new AddNestedCreator(m,
-                        constructor, AddNestedCreator.ADD));
+                            constructor, AddNestedCreator.ADD));
                 } catch (NoSuchMethodException nse) {
                     // ignore
                 }
@@ -307,16 +290,12 @@
      * @return true if the given set method is to be hidden.
      */
     private boolean isHiddenSetMethod(String name, Class type) {
-        if ("setLocation".equals(name)
-             && org.apache.tools.ant.Location.class.equals(type)) {
+        if ("setLocation".equals(name) && org.apache.tools.ant.Location.class.equals(type)) {
             return true;
         }
-
-        if ("setTaskType".equals(name)
-             && java.lang.String.class.equals(type)) {
+        if ("setTaskType".equals(name) && java.lang.String.class.equals(type)) {
             return true;
         }
-
         return false;
     }
 
@@ -381,36 +360,29 @@
      */
     public void setAttribute(Project p, Object element, String attributeName,
                              String value) throws BuildException {
-        AttributeSetter as
-            = (AttributeSetter) attributeSetters.get(
+        AttributeSetter as = (AttributeSetter) attributeSetters.get(
                 attributeName.toLowerCase(Locale.US));
         if (as == null) {
             if (element instanceof DynamicAttributeNS) {
                 DynamicAttributeNS dc = (DynamicAttributeNS) element;
-                String uriPlusPrefix =
-                    ProjectHelper.extractUriFromComponentName(attributeName);
-                String uri =
-                    ProjectHelper.extractUriFromComponentName(uriPlusPrefix);
-                String localName =
-                    ProjectHelper.extractNameFromComponentName(attributeName);
-                String qName = ("".equals(uri)
-                                ? localName : (uri + ":" + localName));
-
+                String uriPlusPrefix = ProjectHelper.extractUriFromComponentName(attributeName);
+                String uri = ProjectHelper.extractUriFromComponentName(uriPlusPrefix);
+                String localName = ProjectHelper.extractNameFromComponentName(attributeName);
+                String qName = "".equals(uri) ? localName : uri + ":" + localName;
                 dc.setDynamicAttribute(uri, localName, qName, value);
                 return;
-            } else if (element instanceof DynamicAttribute) {
+            }
+            if (element instanceof DynamicAttribute) {
                 DynamicAttribute dc = (DynamicAttribute) element;
                 dc.setDynamicAttribute(attributeName.toLowerCase(Locale.US), value);
                 return;
-            } else {
-                if (attributeName.indexOf(':') != -1) {
-                    return; // Ignore attribute from unknown uri's
-                }
-                String msg = getElementName(p, element)
-                    + " doesn't support the \"" + attributeName
-                    + "\" attribute.";
-                throw new UnsupportedAttributeException(msg, attributeName);
             }
+            if (attributeName.indexOf(':') != -1) {
+                return; // Ignore attribute from unknown uri's
+            }
+            String msg = getElementName(p, element)
+                    + " doesn't support the \"" + attributeName + "\" attribute.";
+            throw new UnsupportedAttributeException(msg, attributeName);
         }
         try {
             as.set(p, element, value);
@@ -422,7 +394,6 @@
         }
     }
 
-
     /**
      * Adds PCDATA to an element, using the element's
      * <code>void addText(String)</code> method, if it has one. If no
@@ -448,13 +419,10 @@
             if (text.length() == 0) {
                 // Only whitespace - ignore
                 return;
-            } else {
-                // Not whitespace - fail
-                String msg = project.getElementName(element)
-                    + " doesn't support nested text data (\""
-                    + condenseText(text) + "\").";
-                throw new BuildException(msg);
             }
+            // Not whitespace - fail
+            throw new BuildException(project.getElementName(element)
+                    + " doesn't support nested text data (\"" + condenseText(text) + "\").");
         }
         try {
             addText.invoke(element, new Object[] {text});
@@ -473,10 +441,9 @@
      * @param parent the object which doesn't support a requested element
      * @param elementName the name of the Element which is trying to be created.
      */
-    public void throwNotSupported(Project project, Object parent,
-        String elementName) {
+    public void throwNotSupported(Project project, Object parent, String elementName) {
         String msg = project.getElementName(parent)
-            + " doesn't support the nested \"" + elementName + "\" element.";
+                + " doesn't support the nested \"" + elementName + "\" element.";
         throw new UnsupportedElementException(msg, elementName);
     }
 
@@ -505,24 +472,20 @@
             parentUri = "";
         }
         NestedCreator nc = null;
-        if (uri.equals(parentUri) || uri.length()==0) {
-            nc = (NestedCreator) nestedCreators.get(
-                name.toLowerCase(Locale.US));
+        if (uri.equals(parentUri) || uri.length() == 0) {
+            nc = (NestedCreator) nestedCreators.get(name.toLowerCase(Locale.US));
         }
         if (nc == null) {
             nc = createAddTypeCreator(project, parent, elementName);
         }
         if (nc == null && parent instanceof DynamicElementNS) {
             DynamicElementNS dc = (DynamicElementNS) parent;
-            String qName = (child == null ? name : child.getQName());
-            final Object nestedElement =
-                dc.createDynamicElement(
-                    (child == null ? "" : child.getNamespace()),
-                    name, qName);
+            String qName = child == null ? name : child.getQName();
+            final Object nestedElement = dc.createDynamicElement(
+                    child == null ? "" : child.getNamespace(), name, qName);
             if (nestedElement != null) {
                 nc = new NestedCreator(null) {
-                    Object create(
-                        Project project, Object parent, Object ignore) {
+                    Object create(Project project, Object parent, Object ignore) {
                         return nestedElement;
                     }
                 };
@@ -530,12 +493,10 @@
         }
         if (nc == null && parent instanceof DynamicElement) {
             DynamicElement dc = (DynamicElement) parent;
-            final Object nestedElement =
-                dc.createDynamicElement(name.toLowerCase(Locale.US));
+            final Object nestedElement = dc.createDynamicElement(name.toLowerCase(Locale.US));
             if (nestedElement != null) {
                 nc = new NestedCreator(null) {
-                    Object create(
-                        Project project, Object parent, Object ignore) {
+                    Object create(Project project, Object parent, Object ignore) {
                         return nestedElement;
                     }
                 };
@@ -567,11 +528,10 @@
      *             This is not a namespace aware method.
      *
      * @exception BuildException if no method is available to create the
-     *                           element instance, or if the creating method
-     *                           fails.
+     *                           element instance, or if the creating method fails.
      */
-    public Object createElement(Project project, Object parent,
-        String elementName) throws BuildException {
+    public Object createElement(Project project, Object parent, String elementName)
+            throws BuildException {
         NestedCreator nc = getNestedCreator(project, "", parent, elementName, null);
         try {
             Object nestedElement = nc.create(project, parent, null);
@@ -603,10 +563,8 @@
      * @return a creator object to create and store the element instance.
      */
     public Creator getElementCreator(
-        Project project, String parentUri, Object parent, String elementName,
-        UnknownElement ue) {
-        NestedCreator nc = getNestedCreator(
-            project, parentUri, parent, elementName, ue);
+        Project project, String parentUri, Object parent, String elementName, UnknownElement ue) {
+        NestedCreator nc = getNestedCreator(project, parentUri, parent, elementName, ue);
         return new Creator(project, parent, nc);
     }
 
@@ -616,14 +574,14 @@
      *
      * @return <code>true<code> if the introspected class is dynamic;
      *         <code>false<code> otherwise.
-     * @since  Ant 1.6.3
+     * @since Ant 1.6.3
      *
      * @see DynamicElement
      * @see DynamicElementNS
      */
     public boolean isDynamic() {
         return DynamicElement.class.isAssignableFrom(bean)
-            || DynamicElementNS.class.isAssignableFrom(bean);
+                || DynamicElementNS.class.isAssignableFrom(bean);
     }
 
     /**
@@ -632,7 +590,7 @@
      *
      * @return <code>true<code> if the introspected class is a container;
      *         <code>false<code> otherwise.
-     * @since  Ant 1.6.3
+     * @since Ant 1.6.3
      *
      * @see TaskContainer
      */
@@ -649,9 +607,7 @@
      * @return true if the given nested element is supported
      */
     public boolean supportsNestedElement(String elementName) {
-        return nestedCreators.containsKey(elementName.toLowerCase(Locale.US))
-            || isDynamic()
-            || addTypeMethods.size() != 0;
+        return supportsNestedElement("", elementName);
     }
 
     /**
@@ -664,19 +620,24 @@
      * @return true if the given nested element is supported
      */
     public boolean supportsNestedElement(String parentUri, String elementName) {
-        if (parentUri.equals(ProjectHelper.ANT_CORE_URI)) {
-            parentUri = "";
+        if (isDynamic() || addTypeMethods.size() > 0) {
+            return true;
+        }
+        String name = ProjectHelper.extractNameFromComponentName(elementName);
+        if (!nestedCreators.containsKey(name.toLowerCase(Locale.US))) {
+            return false;
         }
         String uri = ProjectHelper.extractUriFromComponentName(elementName);
         if (uri.equals(ProjectHelper.ANT_CORE_URI)) {
             uri = "";
         }
-        String name = ProjectHelper.extractNameFromComponentName(elementName);
-
-        return (
-            nestedCreators.containsKey(name.toLowerCase(Locale.US))
-            && (uri.equals(parentUri) || "".equals(uri)))
-            || isDynamic() || addTypeMethods.size() != 0;
+        if ("".equals(uri)) {
+            return true;
+        }
+        if (parentUri.equals(ProjectHelper.ANT_CORE_URI)) {
+            parentUri = "";
+        }
+        return uri.equals(parentUri);
     }
 
     /**
@@ -704,8 +665,7 @@
         if (elementName == null) {
             return;
         }
-        NestedCreator ns = (NestedCreator) nestedCreators.get(
-            elementName.toLowerCase(Locale.US));
+        NestedCreator ns = (NestedCreator) nestedCreators.get(elementName.toLowerCase(Locale.US));
         if (ns == null) {
             return;
         }
@@ -749,13 +709,12 @@
      * @exception BuildException if the introspected class does not
      *                           support the named nested element.
      */
-    public Class getElementType(String elementName)
-        throws BuildException {
+    public Class getElementType(String elementName) throws BuildException {
         Class nt = (Class) nestedTypes.get(elementName);
         if (nt == null) {
             throw new UnsupportedElementException("Class "
-                + bean.getName() + " doesn't support the nested \""
-                + elementName + "\" element.", elementName);
+                    + bean.getName() + " doesn't support the nested \""
+                    + elementName + "\" element.", elementName);
         }
         return nt;
     }
@@ -772,13 +731,12 @@
      * @exception BuildException if the introspected class does not
      *                           support the named attribute.
      */
-    public Class getAttributeType(String attributeName)
-        throws BuildException {
+    public Class getAttributeType(String attributeName) throws BuildException {
         Class at = (Class) attributeTypes.get(attributeName);
         if (at == null) {
             throw new UnsupportedAttributeException("Class "
-                + bean.getName() + " doesn't support the \""
-                + attributeName + "\" attribute.", attributeName);
+                    + bean.getName() + " doesn't support the \""
+                    + attributeName + "\" attribute.", attributeName);
         }
         return at;
     }
@@ -791,13 +749,12 @@
      *         Cannot be <code>null</code>.
      * @throws BuildException if the introspected class does not
      *         support the nested text.
-     * @since  Ant 1.6.3
+     * @since Ant 1.6.3
      */
-    public Method getAddTextMethod()
-                  throws BuildException {
+    public Method getAddTextMethod() throws BuildException {
         if (!supportsCharacters()) {
             throw new BuildException("Class " + bean.getName()
-                + " doesn't support nested text data.");
+                    + " doesn't support nested text data.");
         }
         return addText;
     }
@@ -812,15 +769,14 @@
      *         class is a dynamic configurator!
      * @throws BuildException if the introspected class does not
      *         support the named nested element.
-     * @since  Ant 1.6.3
+     * @since Ant 1.6.3
      */
-    public Method getElementMethod(String elementName)
-                  throws BuildException {
+    public Method getElementMethod(String elementName) throws BuildException {
         Object creator = nestedCreators.get(elementName);
         if (creator == null) {
             throw new UnsupportedElementException("Class "
-                + bean.getName() + " doesn't support the nested \""
-                + elementName + "\" element.", elementName);
+                    + bean.getName() + " doesn't support the nested \""
+                    + elementName + "\" element.", elementName);
         }
         return ((NestedCreator) creator).method;
     }
@@ -834,15 +790,14 @@
      *         This will never be <code>null</code>.
      * @throws BuildException if the introspected class does not
      *         support the named attribute.
-     * @since  Ant 1.6.3
+     * @since Ant 1.6.3
      */
-    public Method getAttributeMethod(String attributeName)
-                  throws BuildException {
+    public Method getAttributeMethod(String attributeName) throws BuildException {
         Object setter = attributeSetters.get(attributeName);
         if (setter == null) {
             throw new UnsupportedAttributeException("Class "
-                + bean.getName() + " doesn't support the \""
-                + attributeName + "\" attribute.", attributeName);
+                    + bean.getName() + " doesn't support the \""
+                    + attributeName + "\" attribute.", attributeName);
         }
         return ((AttributeSetter) setter).method;
     }
@@ -857,11 +812,9 @@
     }
 
     /**
-     * Returns an enumeration of the names of the attributes supported
-     * by the introspected class.
+     * Returns an enumeration of the names of the attributes supported by the introspected class.
      *
-     * @return an enumeration of the names of the attributes supported
-     *         by the introspected class.
+     * @return an enumeration of the names of the attributes supported by the introspected class.
      * @see #getAttributeMap
      */
     public Enumeration getAttributes() {
@@ -869,16 +822,15 @@
     }
 
     /**
-     * Returns a read-only map of attributes supported
-     * by the introspected class.
+     * Returns a read-only map of attributes supported by the introspected class.
      *
      * @return an attribute name to attribute <code>Class</code>
      *         unmodifiable map. Can be empty, but never <code>null</code>.
-     * @since  Ant 1.6.3
+     * @since Ant 1.6.3
      */
     public Map getAttributeMap() {
-        return (attributeTypes.size() < 1)
-            ? EMPTY_MAP : Collections.unmodifiableMap(attributeTypes);
+        return attributeTypes.isEmpty()
+            ? Collections.EMPTY_MAP : Collections.unmodifiableMap(attributeTypes);
     }
 
     /**
@@ -899,11 +851,11 @@
      *
      * @return a nested-element name to nested-element <code>Class</code>
      *         unmodifiable map. Can be empty, but never <code>null</code>.
-     * @since  Ant 1.6.3
+     * @since Ant 1.6.3
      */
     public Map getNestedElementMap() {
-        return (nestedTypes.size() < 1)
-            ? EMPTY_MAP : Collections.unmodifiableMap(nestedTypes);
+        return nestedTypes.isEmpty()
+            ? Collections.EMPTY_MAP : Collections.unmodifiableMap(nestedTypes);
     }
 
     /**
@@ -921,11 +873,11 @@
      *         method derives from another type also an argument of a method
      *         of this list, the method with the most derived argument will
      *         always appear first. Can be empty, but never <code>null</code>.
-     * @since  Ant 1.6.3
+     * @since Ant 1.6.3
      */
     public List getExtensionPoints() {
-        return (addTypeMethods.size() < 1) ? Collections.EMPTY_LIST
-            : Collections.unmodifiableList(addTypeMethods);
+        return addTypeMethods.isEmpty()
+                ? Collections.EMPTY_LIST : Collections.unmodifiableList(addTypeMethods);
     }
 
     /**
@@ -972,70 +924,77 @@
             return new AttributeSetter(m) {
                 public void set(Project p, Object parent, String value)
                         throws InvocationTargetException, IllegalAccessException {
-                    m.invoke(parent, (Object[]) (new String[] {value}));
+                    m.invoke(parent, (Object[]) new String[] { value });
                 }
             };
+        }
         // char and Character get special treatment - take the first character
-        } else if (java.lang.Character.class.equals(reflectedArg)) {
+        if (java.lang.Character.class.equals(reflectedArg)) {
             return new AttributeSetter(m) {
                 public void set(Project p, Object parent, String value)
                         throws InvocationTargetException, IllegalAccessException {
                     if (value.length() == 0) {
                         throw new BuildException("The value \"\" is not a "
-                            + "legal value for attribute \"" + attrName + "\"");
+                                + "legal value for attribute \"" + attrName + "\"");
                     }
-                    m.invoke(parent, (Object[])
-                        (new Character[] {new Character(value.charAt(0))}));
+                    m.invoke(parent, (Object[]) new Character[] { new Character(value.charAt(0)) });
                 }
             };
-        // boolean and Boolean get special treatment because we
-        // have a nice method in Project
-        } else if (java.lang.Boolean.class.equals(reflectedArg)) {
+        }
+        // boolean and Boolean get special treatment because we have a nice method in Project
+        if (java.lang.Boolean.class.equals(reflectedArg)) {
             return new AttributeSetter(m) {
                 public void set(Project p, Object parent, String value)
                         throws InvocationTargetException, IllegalAccessException {
-                    m.invoke(parent, (Object[]) (
-                         new Boolean[] {Project.toBoolean(value)
-                                        ? Boolean.TRUE : Boolean.FALSE}));
+                    m.invoke(parent, (Object[]) new Boolean[] {
+                            Project.toBoolean(value) ? Boolean.TRUE : Boolean.FALSE });
                 }
             };
+        }
         // Class doesn't have a String constructor but a decent factory method
-        } else if (java.lang.Class.class.equals(reflectedArg)) {
+        if (java.lang.Class.class.equals(reflectedArg)) {
             return new AttributeSetter(m) {
                 public void set(Project p, Object parent, String value)
                         throws InvocationTargetException, IllegalAccessException, BuildException {
                     try {
-                        m.invoke(parent, new Object[] {Class.forName(value)});
+                        m.invoke(parent, new Object[] { Class.forName(value) });
                     } catch (ClassNotFoundException ce) {
                         throw new BuildException(ce);
                     }
                 }
             };
+        }
         // resolve relative paths through Project
-        } else if (java.io.File.class.equals(reflectedArg)) {
+        if (java.io.File.class.equals(reflectedArg)) {
             return new AttributeSetter(m) {
                 public void set(Project p, Object parent, String value)
                         throws InvocationTargetException, IllegalAccessException {
-                    m.invoke(parent, new Object[] {p.resolveFile(value)});
+                    m.invoke(parent, new Object[] { p.resolveFile(value) });
                 }
             };
+        }
         // EnumeratedAttributes have their own helper class
-        } else if (EnumeratedAttribute.class.isAssignableFrom(reflectedArg)) {
+        if (EnumeratedAttribute.class.isAssignableFrom(reflectedArg)) {
             return new AttributeSetter(m) {
                 public void set(Project p, Object parent, String value)
                         throws InvocationTargetException, IllegalAccessException, BuildException {
                     try {
-                        EnumeratedAttribute ea =
-                            (EnumeratedAttribute) reflectedArg.newInstance();
+                        EnumeratedAttribute ea = (EnumeratedAttribute) reflectedArg.newInstance();
                         ea.setValue(value);
-                        m.invoke(parent, new Object[] {ea});
+                        m.invoke(parent, new Object[] { ea });
                     } catch (InstantiationException ie) {
                         throw new BuildException(ie);
                     }
                 }
             };
-        } else if (reflectedArg.getSuperclass() != null
-                   && reflectedArg.getSuperclass().getName().equals("java.lang.Enum")) {
+        }
+        Class enumClass = null;
+        try {
+            enumClass = Class.forName("java.lang.Enum");
+        } catch (ClassNotFoundException e) {
+            //ignore
+        }
+        if (enumClass != null && enumClass.isAssignableFrom(reflectedArg)) {
             return new AttributeSetter(m) {
                 public void set(Project p, Object parent, String value)
                         throws InvocationTargetException, IllegalAccessException, BuildException {
@@ -1047,88 +1006,86 @@
                         //there is specific logic here for the value being out of the allowed
                         //set of enumerations.
                         if (x.getTargetException() instanceof IllegalArgumentException) {
-                            throw new BuildException(
-                                "'" + value + "' is not a permitted value for "
-                                + reflectedArg.getName());
-                        } else {
-                            //only if the exception is not an IllegalArgument, do we hand off
-                            //to extractBuildException() to get the buildexception from the InvocationTarget
-                            throw extractBuildException(x);
+                            throw new BuildException("'" + value + "' is not a permitted value for "
+                                    + reflectedArg.getName());
                         }
+                        //only if the exception is not an IllegalArgument do we request the
+                        //BuildException via extractBuildException():
+                        throw extractBuildException(x);
                     } catch (Exception x) {
                         //any other failure of invoke() to work.
                         throw new BuildException(x);
                     }
                 }
             };
-        } else if (java.lang.Long.class.equals(reflectedArg)) {
+        }
+        if (java.lang.Long.class.equals(reflectedArg)) {
             return new AttributeSetter(m) {
                 public void set(Project p, Object parent, String value)
                         throws InvocationTargetException, IllegalAccessException, BuildException {
-                    long ell;
                     try {
-                        ell = StringUtils.parseHumanSizes(value);
+                        m.invoke(parent, new Object[] {
+                                new Long(StringUtils.parseHumanSizes(value)) });
+                    } catch (InvocationTargetException e) {
+                        throw e;
+                    } catch (IllegalAccessException e) {
+                        throw e;
                     } catch (Exception e) {
                         throw new BuildException(e);
                     }
-                    m.invoke(parent, new Object[] { new Long(ell) });
                 }
             };
-        } else {
+        }
         // worst case. look for a public String constructor and use it
         // also supports new Whatever(Project, String) as for Path or Reference
         // This is used (deliberately) for all primitives/wrappers other than
         // char, boolean, and long.
-            boolean includeProject;
-            Constructor c;
+        boolean includeProject;
+        Constructor c;
+        try {
+            // First try with Project.
+            c = reflectedArg.getConstructor(new Class[] {Project.class, String.class});
+            includeProject = true;
+        } catch (NoSuchMethodException nme) {
+            // OK, try without.
             try {
-                // First try with Project.
-                c = reflectedArg.getConstructor(new Class[] {Project.class, String.class});
-                includeProject = true;
-            } catch (NoSuchMethodException nme) {
-                // OK, try without.
-                try {
-                    c = reflectedArg.getConstructor(new Class[] {String.class});
-                    includeProject = false;
-                } catch (NoSuchMethodException nme2) {
-                    // Well, no matching constructor.
-                    return null;
-                }
+                c = reflectedArg.getConstructor(new Class[] {String.class});
+                includeProject = false;
+            } catch (NoSuchMethodException nme2) {
+                // Well, no matching constructor.
+                return null;
             }
-            final boolean finalIncludeProject = includeProject;
-            final Constructor finalConstructor = c;
-
-            return new AttributeSetter(m) {
-                public void set(Project p, Object parent, String value)
-                        throws InvocationTargetException, IllegalAccessException, BuildException {
-                    try {
-                        Object[] args = (finalIncludeProject)
+        }
+        final boolean finalIncludeProject = includeProject;
+        final Constructor finalConstructor = c;
+
+        return new AttributeSetter(m) {
+            public void set(Project p, Object parent, String value)
+                    throws InvocationTargetException, IllegalAccessException, BuildException {
+                try {
+                    Object[] args = finalIncludeProject
                             ? new Object[] {p, value} : new Object[] {value};
 
-                        Object attribute = finalConstructor.newInstance(args);
-                        if (p != null) {
-                            p.setProjectReference(attribute);
-                        }
-                        m.invoke(parent, new Object[] {attribute});
-                    } catch (InstantiationException ie) {
-                        throw new BuildException(ie);
+                    Object attribute = finalConstructor.newInstance(args);
+                    if (p != null) {
+                        p.setProjectReference(attribute);
                     }
+                    m.invoke(parent, new Object[] {attribute});
+                } catch (InstantiationException ie) {
+                    throw new BuildException(ie);
                 }
-            };
-        }
+            }
+        };
     }
 
     /**
      * Returns a description of the type of the given element in
      * relation to a given project. This is used for logging purposes
-     * when the element is asked to cope with some data it has no
-     * way of handling.
+     * when the element is asked to cope with some data it has no way of handling.
      *
-     * @param project The project the element is defined in.
-     *                Must not be <code>null</code>.
+     * @param project The project the element is defined in. Must not be <code>null</code>.
      *
-     * @param element The element to describe.
-     *                Must not be <code>null</code>.
+     * @param element The element to describe. Must not be <code>null</code>.
      *
      * @return a description of the element type
      */
@@ -1142,10 +1099,8 @@
      * code to make sure the method name does actually begin with the
      * specified prefix - no checking is done in this method.
      *
-     * @param methodName The name of the method in question.
-     *                   Must not be <code>null</code>.
-     * @param prefix     The prefix to remove.
-     *                   Must not be <code>null</code>.
+     * @param methodName The name of the method in question. Must not be <code>null</code>.
+     * @param prefix     The prefix to remove. Must not be <code>null</code>.
      *
      * @return the lower-cased method name with the prefix removed.
      */
@@ -1172,15 +1127,13 @@
          * create to create an object, the object then gets
          * configured and then UnknownElement calls store.
          * SetPolyType may be used to override the type used
-         * to create the object with. SetPolyType gets called
-         * before create.
+         * to create the object with. SetPolyType gets called before create.
          *
          * @param project the current project
          * @param parent  the parent object to create the object in
          * @param nestedCreator the nested creator object to use
          */
-        private Creator(
-            Project project, Object parent, NestedCreator nestedCreator) {
+        private Creator(Project project, Object parent, NestedCreator nestedCreator) {
             this.project = project;
             this.parent = parent;
             this.nestedCreator = nestedCreator;
@@ -1196,8 +1149,7 @@
         }
 
         /**
-         * Create an object using this creator, which is determined
-         * by introspection.
+         * Create an object using this creator, which is determined by introspection.
          *
          * @return the created object
          */
@@ -1205,20 +1157,16 @@
             if (polyType != null) {
                 if (!nestedCreator.isPolyMorphic()) {
                     throw new BuildException(
-                        "Not allowed to use the polymorphic form"
-                        + " for this element");
+                            "Not allowed to use the polymorphic form for this element");
                 }
-                ComponentHelper helper =
-                    ComponentHelper.getComponentHelper(project);
+                ComponentHelper helper = ComponentHelper.getComponentHelper(project);
                 nestedObject = helper.createComponent(polyType);
                 if (nestedObject == null) {
-                    throw new BuildException(
-                        "Unable to create object of type " + polyType);
+                    throw new BuildException("Unable to create object of type " + polyType);
                 }
             }
             try {
-                nestedObject = nestedCreator.create(
-                    project, parent, nestedObject);
+                nestedObject = nestedCreator.create(project, parent, nestedObject);
                 if (project != null) {
                     project.setProjectReference(nestedObject);
                 }
@@ -1228,27 +1176,24 @@
             } catch (InstantiationException ex) {
                 throw new BuildException(ex);
             } catch (IllegalArgumentException ex) {
-                if (polyType != null) {
-                    throw new BuildException(
-                        "Invalid type used " + polyType);
+                if (polyType == null) {
+                    throw ex;
                 }
-                throw ex;
+                throw new BuildException("Invalid type used " + polyType);
             } catch (InvocationTargetException ex) {
                 throw extractBuildException(ex);
             }
         }
 
         /**
-         * @return the real object (used currently only
-         *         for preset def).
+         * @return the real object (used currently only for presetdef).
          */
         public Object getRealObject() {
             return nestedCreator.getRealObject();
         }
 
         /**
-         * Stores the nested element object using a storage method
-         * determined by introspection.
+         * Stores the nested element object using a storage method determined by introspection.
          *
          */
         public void store() {
@@ -1259,11 +1204,10 @@
             } catch (InstantiationException ex) {
                 throw new BuildException(ex);
             } catch (IllegalArgumentException ex) {
-                if (polyType != null) {
-                    throw new BuildException(
-                        "Invalid type used " + polyType);
+                if (polyType == null) {
+                    throw ex;
                 }
-                throw ex;
+                throw new BuildException("Invalid type used " + polyType);
             } catch (InvocationTargetException ex) {
                 throw extractBuildException(ex);
             }
@@ -1290,13 +1234,10 @@
             return null;
         }
         abstract Object create(Project project, Object parent, Object child)
-                        throws InvocationTargetException,
-                               IllegalAccessException,
-                               InstantiationException;
+                throws InvocationTargetException, IllegalAccessException, InstantiationException;
+
         void store(Object parent, Object child)
-             throws InvocationTargetException,
-                    IllegalAccessException,
-                    InstantiationException {
+                 throws InvocationTargetException, IllegalAccessException, InstantiationException {
             // DO NOTHING
         }
     }
@@ -1307,7 +1248,7 @@
         }
 
         Object create(Project project, Object parent, Object ignore)
-            throws InvocationTargetException, IllegalAccessException {
+                throws InvocationTargetException, IllegalAccessException {
             return getMethod().invoke(parent, new Object[] {});
         }
     }
@@ -1332,16 +1273,14 @@
         }
 
         Object create(Project project, Object parent, Object child)
-                throws InvocationTargetException,
-                IllegalAccessException, InstantiationException {
+                throws InvocationTargetException, IllegalAccessException, InstantiationException {
             if (child == null) {
                 child = constructor.newInstance(
-                    (constructor.getParameterTypes().length == 0)
-                    ? new Object[] {} : new Object[] {project});
+                        constructor.getParameterTypes().length == 0
+                                ? new Object[] {} : new Object[] {project});
             }
             if (child instanceof PreSetDef.PreSetDefinition) {
-                child = ((PreSetDef.PreSetDefinition) child)
-                    .createObject(project);
+                child = ((PreSetDef.PreSetDefinition) child).createObject(project);
             }
             if (behavior == ADD) {
                 istore(parent, child);
@@ -1350,16 +1289,14 @@
         }
 
         void store(Object parent, Object child)
-                throws InvocationTargetException,
-                IllegalAccessException, InstantiationException {
+                throws InvocationTargetException, IllegalAccessException, InstantiationException {
             if (behavior == ADD_CONFIGURED) {
                 istore(parent, child);
             }
         }
 
         private void istore(Object parent, Object child)
-                throws InvocationTargetException,
-                IllegalAccessException, InstantiationException {
+                throws InvocationTargetException, IllegalAccessException, InstantiationException {
             getMethod().invoke(parent, new Object[] {child});
         }
     }
@@ -1375,9 +1312,7 @@
             method = m;
         }
         abstract void set(Project p, Object parent, String value)
-                      throws InvocationTargetException,
-                             IllegalAccessException,
-                             BuildException;
+                throws InvocationTargetException, IllegalAccessException, BuildException;
     }
 
     /**
@@ -1397,8 +1332,7 @@
      * @throws BuildException
      */
     private NestedCreator createAddTypeCreator(
-            Project project, Object parent, String elementName)
-            throws BuildException {
+            Project project, Object parent, String elementName) throws BuildException {
         if (addTypeMethods.size() == 0) {
             return null;
         }
@@ -1420,8 +1354,7 @@
         }
         Object rObject = addedObject;
         if (addedObject instanceof PreSetDef.PreSetDefinition) {
-            rObject = ((PreSetDef.PreSetDefinition) addedObject).createObject(
-                project);
+            rObject = ((PreSetDef.PreSetDefinition) addedObject).createObject(project);
         }
         final Object nestedObject = addedObject;
         final Object realObject = rObject;
@@ -1439,9 +1372,8 @@
                 return realObject;
             }
 
-            void store(Object parent, Object child)
-                    throws InvocationTargetException, IllegalAccessException,
-                    InstantiationException {
+            void store(Object parent, Object child) throws InvocationTargetException,
+                    IllegalAccessException, InstantiationException {
                 if (getMethod().getName().endsWith("Configured")) {
                     getMethod().invoke(parent, new Object[] {realObject});
                 }
@@ -1452,10 +1384,8 @@
     /**
      * Inserts an add or addConfigured method into
      * the addTypeMethods array. The array is
-     * ordered so that the more derived classes
-     * are first.
-     * If both add and addConfigured are present, the addConfigured
-     * will take priority.
+     * ordered so that the more derived classes are first.
+     * If both add and addConfigured are present, the addConfigured will take priority.
      * @param method the <code>Method</code> to insert.
      */
     private void insertAddTypeMethod(Method method) {
@@ -1469,8 +1399,7 @@
                 }
                 return; // Already present
             }
-            if (current.getParameterTypes()[0].isAssignableFrom(
-                            argClass)) {
+            if (current.getParameterTypes()[0].isAssignableFrom(argClass)) {
                 addTypeMethods.add(c, method);
                 return; // higher derived
             }
@@ -1496,13 +1425,9 @@
                 if (matchedClass == null) {
                     matchedClass = methodClass;
                     matchedMethod = method;
-                } else {
-                    if (!methodClass.isAssignableFrom(matchedClass)) {
-                        throw new BuildException("ambiguous: types "
-                            + matchedClass.getName() + " and "
-                            + methodClass.getName() + " match "
-                            + paramClass.getName());
-                    }
+                } else if (!methodClass.isAssignableFrom(matchedClass)) {
+                    throw new BuildException("ambiguous: types " + matchedClass.getName() + " and "
+                            + methodClass.getName() + " match " + paramClass.getName());
                 }
             }
         }
@@ -1514,7 +1439,6 @@
             return text;
         }
         int ends = (MAX_REPORT_NESTED_TEXT - ELLIPSIS.length()) / 2;
-        return new StringBuffer(text).replace(ends, text.length() - ends,
-            ELLIPSIS).toString();
+        return new StringBuffer(text).replace(ends, text.length() - ends, ELLIPSIS).toString();
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message