mbenson 2004/12/15 15:44:06 Modified: src/main/org/apache/tools/ant AntTypeDefinition.java ComponentHelper.java RuntimeConfigurable.java Log: More javadoc work and LOC bumming. Revision Changes Path 1.15 +75 -128 ant/src/main/org/apache/tools/ant/AntTypeDefinition.java Index: AntTypeDefinition.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/AntTypeDefinition.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- AntTypeDefinition.java 14 Sep 2004 12:45:12 -0000 1.14 +++ AntTypeDefinition.java 15 Dec 2004 23:44:05 -0000 1.15 @@ -36,68 +36,65 @@ private ClassLoader classLoader; /** - * set the definition's name - * @param name the name of the definition + * Set the definition's name. + * @param name the name of the definition. */ public void setName(String name) { this.name = name; } /** - * return the definition's name - * @return the name of the definition + * Return the definition's name. + * @return the name of the definition. */ public String getName() { return name; } /** - * set the class of the definition. - * as a side-effect may set the classloader and classname - * @param clazz the class of this definition + * Set the class of the definition. + * As a side-effect may set the classloader and classname. + * @param clazz the class of this definition. */ public void setClass(Class clazz) { this.clazz = clazz; if (clazz == null) { return; } - if (classLoader == null) { - this.classLoader = clazz.getClassLoader(); - } - if (className == null) { - this.className = clazz.getName(); - } + this.classLoader = (classLoader == null) + ? clazz.getClassLoader() : classLoader; + this.className = (className == null) ? clazz.getName() : className; } /** - * set the classname of the definition - * @param className the classname of this definition + * Set the classname of the definition. + * @param className the classname of this definition. */ public void setClassName(String className) { this.className = className; } /** - * get the classname of the definition - * @return the name of the class of this definition + * Get the classname of the definition. + * @return the name of the class of this definition. */ public String getClassName() { return className; } /** - * set the adapter class for this definition. - * this class is used to adapt the definitions class if + * Set the adapter class for this definition. + * This class is used to adapt the definitions class if * required. - * @param adapterClass the adapterClass + * @param adapterClass the adapterClass. */ public void setAdapterClass(Class adapterClass) { this.adapterClass = adapterClass; } /** - * set the assignable class for this definition. - * @param adaptToClass the assignable class + * Set the assignable class for this definition. + * @param adaptToClass the assignable class. */ public void setAdaptToClass(Class adaptToClass) { @@ -105,57 +102,50 @@ } /** - * set the classloader to use to create an instance - * of the definition - * @param classLoader the classLoader + * Set the classloader to use to create an instance + * of the definition. + * @param classLoader the ClassLoader. */ public void setClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } /** - * get the classloader for this definition - * @return the classloader for this definition + * Get the classloader for this definition. + * @return the classloader for this definition. */ public ClassLoader getClassLoader() { return classLoader; } /** - * get the exposed class for this + * Get the exposed class for this * definition. This will be a proxy class * (adapted class) if there is an adapter * class and the definition class is not * assignable from the assignable class. - * @param project the current project - * @return the exposed class + * @param project the current project. + * @return the exposed class. */ public Class getExposedClass(Project project) { if (adaptToClass != null) { Class z = getTypeClass(project); - if (z == null) { - return null; - } - if (adaptToClass.isAssignableFrom(z)) { + if (z == null || adaptToClass.isAssignableFrom(z)) { return z; } } - if (adapterClass != null) { - return adapterClass; - } - return getTypeClass(project); + return (adapterClass == null) ? getTypeClass(project) : adapterClass; } /** - * get the definition class - * @param project the current project - * @return the type of the definition + * Get the definition class. + * @param project the current project. + * @return the type of the definition. */ public Class getTypeClass(Project project) { if (clazz != null) { return clazz; } - try { if (classLoader == null) { clazz = Class.forName(className); @@ -174,10 +164,10 @@ } /** - * create an instance of the definition. + * Create an instance of the definition. * The instance may be wrapped in a proxy class. - * @param project the current project - * @return the created object + * @param project the current project. + * @return the created object. */ public Object create(Project project) { return icreate(project); @@ -185,31 +175,28 @@ /** * Create a component object based on - * its definition + * its definition. + * @return the component as an <code>Object</code>. */ private Object icreate(Project project) { Class c = getTypeClass(project); if (c == null) { return null; } - Object o = createAndSet(project, c); if (o == null || adapterClass == null) { return o; } - if (adaptToClass != null) { if (adaptToClass.isAssignableFrom(o.getClass())) { return o; } } - TypeAdapter adapterObject = (TypeAdapter) createAndSet( project, adapterClass); if (adapterObject == null) { return null; } - adapterObject.setProxy(o); return adapterObject; } @@ -222,7 +209,7 @@ * <li>if the type is assignable from adapto</li> * <li>if the type can be used with the adapter class</li> * </dl> - * @param project the current project + * @param project the current project. */ public void checkClass(Project project) { if (clazz == null) { @@ -233,26 +220,21 @@ } } // check adapter - if (adapterClass != null) { - boolean needToCheck = true; - if (adaptToClass != null - && adaptToClass.isAssignableFrom(clazz)) { - needToCheck = false; - } - if (needToCheck) { - TypeAdapter adapter = (TypeAdapter) createAndSet( - project, adapterClass); - if (adapter == null) { - throw new BuildException("Unable to create adapter object"); - } - adapter.checkProxyClass(clazz); + if (adapterClass != null && (adaptToClass == null + || !adaptToClass.isAssignableFrom(clazz))) { + TypeAdapter adapter = (TypeAdapter) createAndSet( + project, adapterClass); + if (adapter == null) { + throw new BuildException("Unable to create adapter object"); } + adapter.checkProxyClass(clazz); } } /** - * get the constructor of the definition + * Get the constructor of the definition * and invoke it. + * @return the instantiated <code>Object</code>. */ private Object createAndSet(Project project, Class c) { try { @@ -267,13 +249,9 @@ ctor = c.getConstructor(new Class[] {Project.class}); noArg = false; } + Object o = ctor.newInstance( + ((noArg) ? new Object[0] : new Object[] {project})); - Object o = null; - if (noArg) { - o = ctor.newInstance(new Object[0]); - } else { - o = ctor.newInstance(new Object[] {project}); - } project.setProjectReference(o); return o; } catch (java.lang.reflect.InvocationTargetException ex) { @@ -291,84 +269,53 @@ } /** - * Equality method for this definition (assumes the names are the same) + * Equality method for this definition (assumes the names are the same). * - * @param other another definition - * @param project the project the definition - * @return true if the definitions are the same + * @param other another definition. + * @param project the project the definition. + * @return true if the definitions are the same. */ public boolean sameDefinition(AntTypeDefinition other, Project project) { - if (other == null) { - return false; - } - if (other.getClass() != this.getClass()) { - return false; - } - if (!(other.getTypeClass(project).equals(getTypeClass(project)))) { - return false; - } - if (!other.getExposedClass(project).equals(getExposedClass(project))) { - return false; - } - if (other.adapterClass != adapterClass) { - return false; - } - if (other.adaptToClass != adaptToClass) { - return false; - } - return true; + return (other != null && other.getClass() == getClass() + && other.getTypeClass(project).equals(getTypeClass(project)) + && other.getExposedClass(project).equals(getExposedClass(project)) + && other.adapterClass == adapterClass + && other.adaptToClass == adaptToClass); } /** - * Similar definition + * Similar definition; * used to compare two definitions defined twice with the same * name and the same types. - * the classloader may be different but have the same + * The classloader may be different but have the same * path so #sameDefinition cannot * be used. - * @param other the definition to compare to - * @param project the current project - * @return true if the definitions are the same + * @param other the definition to compare to. + * @param project the current project. + * @return true if the definitions are the same. */ public boolean similarDefinition(AntTypeDefinition other, Project project) { - if (other == null) { - return false; - } - if (getClass() != other.getClass()) { - return false; - } - if (!getClassName().equals(other.getClassName())) { - return false; - } - if (!extractClassname(adapterClass).equals( - extractClassname(other.adapterClass))) { - return false; - } - if (!extractClassname(adaptToClass).equals( - extractClassname(other.adaptToClass))) { + if (other == null + || getClass() != other.getClass() + || !getClassName().equals(other.getClassName()) + || !extractClassname(adapterClass).equals( + extractClassname(other.adapterClass)) + || !extractClassname(adaptToClass).equals( + extractClassname(other.adaptToClass))) { return false; } // all the names are the same: check if the class path of the loader // is the same ClassLoader oldLoader = other.getClassLoader(); - ClassLoader newLoader = this.getClassLoader(); - if (oldLoader == newLoader) { - return true; - } - return - newLoader != null - && oldLoader != null - && oldLoader instanceof AntClassLoader + ClassLoader newLoader = getClassLoader(); + return oldLoader == newLoader + || (oldLoader instanceof AntClassLoader && newLoader instanceof AntClassLoader && ((AntClassLoader) oldLoader).getClasspath() - .equals(((AntClassLoader) newLoader).getClasspath()); + .equals(((AntClassLoader) newLoader).getClasspath())); } private String extractClassname(Class c) { - if (c == null) { - return "<null>"; - } else { - return c.getClass().getName(); - } + return (c == null) ? "<null>" : c.getClass().getName(); } } 1.40 +33 -53 ant/src/main/org/apache/tools/ant/ComponentHelper.java Index: ComponentHelper.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/ComponentHelper.java,v retrieving revision 1.39 retrieving revision 1.40 diff -u -r1.39 -r1.40 --- ComponentHelper.java 22 Nov 2004 09:23:26 -0000 1.39 +++ ComponentHelper.java 15 Dec 2004 23:44:05 -0000 1.40 @@ -157,7 +157,8 @@ } } - /** Factory method to create the components. + /** + * Factory method to create the components. * * This should be called by UnknownElement. * @@ -173,10 +174,6 @@ String componentType) throws BuildException { Object component = createComponent(componentType); - if (component == null) { - return null; - } - if (component instanceof Task) { Task task = (Task) component; task.setLocation(ue.getLocation()); @@ -186,7 +183,6 @@ task.init(); addCreatedTask(componentType, task); } - return component; } @@ -213,10 +209,7 @@ */ public Class getComponentClass(String componentName) { AntTypeDefinition def = getDefinition(componentName); - if (def == null) { - return null; - } - return def.getExposedClass(project); + return (def == null) ? null : def.getExposedClass(project); } /** @@ -392,9 +385,8 @@ def.setName(typeName); def.setClass(typeClass); updateDataTypeDefinition(def); - String msg = " +User datatype: " + typeName + " " - + typeClass.getName(); - project.log(msg, Project.MSG_DEBUG); + project.log(" +User datatype: " + typeName + " " + + typeClass.getName(), Project.MSG_DEBUG); } /** @@ -443,7 +435,6 @@ org.apache.tools.ant.taskdefs.Property.class); task = createNewTask(taskType); } - if (task != null) { addCreatedTask(taskType, task); } @@ -468,7 +459,6 @@ if (c == null) { return null; } - if (!(Task.class.isAssignableFrom(c))) { return null; } @@ -481,8 +471,7 @@ // set default value, can be changed by the user task.setTaskName(taskType); - String msg = " +Task: " + taskType; - project.log (msg, Project.MSG_DEBUG); + project.log(" +Task: " + taskType, Project.MSG_DEBUG); return task; } @@ -520,8 +509,7 @@ if (v != null) { Enumeration taskEnum = v.elements(); while (taskEnum.hasMoreElements()) { - WeakReference ref = - (WeakReference) taskEnum.nextElement(); + WeakReference ref = (WeakReference) taskEnum.nextElement(); Task t = (Task) ref.get(); //being a weak ref, it may be null by this point if (t != null) { @@ -558,7 +546,7 @@ * @param element The element to describe. * Must not be <code>null</code>. * - * @return a description of the element type + * @return a description of the element type. * * @since Ant 1.6 */ @@ -578,39 +566,34 @@ /** - * check if definition is a valid definition - it + * Check if definition is a valid definition - it * may be a definition of an optional task that - * does not exist - * @param def the definition to test - * @return true if exposed type of definition is present + * does not exist. + * @param def the definition to test. + * @return true if exposed type of definition is present. */ private boolean validDefinition(AntTypeDefinition def) { - if (def.getTypeClass(project) == null - || def.getExposedClass(project) == null) { - return false; - } - return true; + return !(def.getTypeClass(project) == null + || def.getExposedClass(project) == null); } /** - * check if two definitions are the same - * @param def the new definition - * @param old the old definition - * @return true if the two definitions are the same + * Check if two definitions are the same. + * @param def the new definition. + * @param old the old definition. + * @return true if the two definitions are the same. */ private boolean sameDefinition( AntTypeDefinition def, AntTypeDefinition old) { - if (!validDefinition(def) || !validDefinition(old)) { - return validDefinition(def) == validDefinition(old); - } - return def.sameDefinition(old, project); + return ((validDefinition(def) && validDefinition(old) + && def.sameDefinition(old, project)) + || !(validDefinition(def) | validDefinition(old))); } - /** - * update the component definition table with a new or + * Update the component definition table with a new or * modified definition. - * @param def the definition to update or insert + * @param def the definition to update or insert. */ private void updateDataTypeDefinition(AntTypeDefinition def) { String name = def.getName(); @@ -644,8 +627,8 @@ } /** - * Called at the start of processing an antlib - * @param uri the uri that is associated with this antlib + * Called at the start of processing an antlib. + * @param uri the uri that is associated with this antlib. */ public void enterAntLib(String uri) { antLibCurrentUri = uri; @@ -653,26 +636,23 @@ } /** - * @return the current antlib uri + * @return the current antlib uri. */ public String getCurrentAntlibUri() { return antLibCurrentUri; } /** - * Called at the end of processing an antlib + * Called at the end of processing an antlib. */ public void exitAntLib() { antLibStack.pop(); - if (antLibStack.size() != 0) { - antLibCurrentUri = (String) antLibStack.peek(); - } else { - antLibCurrentUri = null; - } + antLibCurrentUri = (antLibStack.size() == 0) + ? null : (String)antLibStack.peek(); } /** - * load ant's tasks + * Load ant's tasks. */ private void initTasks() { ClassLoader classLoader = null; @@ -717,7 +697,7 @@ } /** - * load ant's datatypes + * Load ant's datatypes. */ private void initTypes() { ClassLoader classLoader = null; @@ -760,7 +740,7 @@ } /** - * called for each component name, check if the + * Called for each component name, check if the * associated URI has been examined for antlibs. */ private synchronized void checkNamespace(String componentName) { @@ -788,7 +768,7 @@ } /** - * map that contains the component definitions + * Map that contains the component definitions. */ private static class AntTypeTable extends Hashtable { private Project project; 1.56 +13 -11 ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java Index: RuntimeConfigurable.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/RuntimeConfigurable.java,v retrieving revision 1.55 retrieving revision 1.56 diff -u -r1.55 -r1.56 --- RuntimeConfigurable.java 13 Dec 2004 19:12:36 -0000 1.55 +++ RuntimeConfigurable.java 15 Dec 2004 23:44:06 -0000 1.56 @@ -113,9 +113,9 @@ /** * Sets the creator of the element to be configured - * used to store the element in the parent; + * used to store the element in the parent. * - * @param creator the creator object + * @param creator the creator object. */ void setCreator(IntrospectionHelper.Creator creator) { this.creator = creator; @@ -123,7 +123,7 @@ /** * Get the object for which this RuntimeConfigurable holds the configuration - * information + * information. * * @return the object whose configure is held by this instance. */ @@ -132,16 +132,16 @@ } /** - * get the polymorphic type for this element - * @return the ant component type name, null if not set + * Get the polymorphic type for this element. + * @return the ant component type name, null if not set. */ public String getPolyType() { return polyType; } /** - * set the polymorphic type for this element - * @param polyType the ant component type name, null if not set + * Set the polymorphic type for this element. + * @param polyType the ant component type name, null if not set. */ public void setPolyType(String polyType) { this.polyType = polyType; @@ -162,7 +162,7 @@ } /** - * Set an attribute to a given value + * Set an attribute to a given value. * * @param name the name of the attribute. * @param value the attribute's value. @@ -180,9 +180,10 @@ } } - /** Return the attribute map. + /** + * Return the attribute map. * - * @return Attribute name to attribute value map + * @return Attribute name to attribute value map. * @since Ant 1.6 */ public Hashtable getAttributeMap() { @@ -264,7 +265,8 @@ characters.append(buf, start, count); } - /** Get the text content of this element. Various text chunks are + /** + * Get the text content of this element. Various text chunks are * concatenated, there is no way ( currently ) of keeping track of * multiple fragments. *
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]