Hi,
Another quick one. AntTypeDefinition.getTypeClass
if(clazz != null) {
return clazz;
}
try {}catch() etc etc
return clazz;
I've reversed the logic and now there's only one return from this method. ie
if (clazz == null) {
try {
[loads of things]
} catch() {return clazz;
It's not a fix or anything, but IM(very humble)O having one return makes the code easier to understand.
Included test case.
Kev
Index: AntTypeDefinition.java
===================================================================
RCS file:
/home/cvspublic/ant/src/main/org/apache/tools/ant/AntTypeDefinition.java,v
retrieving revision 1.14
diff -u -r1.14 AntTypeDefinition.java
--- AntTypeDefinition.java 14 Sep 2004 12:45:12 -0000 1.14
+++ AntTypeDefinition.java 4 Nov 2004 06:00:16 -0000
@@ -152,27 +152,25 @@
* @return the type of the definition
*/
public Class getTypeClass(Project project) {
- if (clazz != null) {
- return clazz;
- }
-
- try {
- if (classLoader == null) {
- clazz = Class.forName(className);
- } else {
- clazz = classLoader.loadClass(className);
- }
- } catch (NoClassDefFoundError ncdfe) {
- project.log("Could not load a dependent class ("
+ if (clazz == null) {
+ try {
+ if (classLoader == null) {
+ clazz = Class.forName(className);
+ } else {
+ clazz = classLoader.loadClass(className);
+ }
+ } catch (NoClassDefFoundError ncdfe) {
+ project.log("Could not load a dependent class ("
+ ncdfe.getMessage() + ") for type "
+ name, Project.MSG_DEBUG);
- } catch (ClassNotFoundException cnfe) {
- project.log("Could not load class (" + className
+ } catch (ClassNotFoundException cnfe) {
+ project.log("Could not load class (" + className
+ ") for type " + name, Project.MSG_DEBUG);
- }
+ }
+ }
return clazz;
}
-
+
/**
* create an instance of the definition.
* The instance may be wrapped in a proxy class.
Index: AntTypeDefinitionTest.java
===================================================================
RCS file: AntTypeDefinitionTest.java
diff -N AntTypeDefinitionTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ AntTypeDefinitionTest.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,82 @@
+package org.apache.tools.ant;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+
+public class AntTypeDefinitionTest extends TestCase {
+
+ private String name;
+ private Class clazz;
+ private ClassLoader classLoader;
+ private String className;
+ private AntTypeDefinition atd;
+ private Project project;
+
+ /**
+ * Constructor
+ */
+ public AntTypeDefinitionTest(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(new AntTypeDefinitionTest("testGetTypeClass"));
+ return suite;
+ }
+
+ public Class oldGetTypeClass(Project project) {
+ if (clazz != null) {
+ return clazz;
+ }
+
+ try {
+ if (classLoader == null) {
+ clazz = Class.forName(className);
+ } else {
+ clazz = classLoader.loadClass(className);
+ }
+ } catch (NoClassDefFoundError ncdfe) {
+ project.log("Could not load a dependent class ("
+ + ncdfe.getMessage() + ") for type "
+ + name, Project.MSG_DEBUG);
+ } catch (ClassNotFoundException cnfe) {
+ project.log("Could not load class (" + className
+ + ") for type " + name, Project.MSG_DEBUG);
+ }
+ return clazz;
+ }
+
+ /*
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.className = this.getName();
+
+ atd = new AntTypeDefinition();
+ atd.setClass(clazz);
+ atd.setClassName(className);
+ project = new Project();
+
+ }
+
+ /*
+ * @see TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testGetTypeClass() {
+ try {
+ assertEquals(oldGetTypeClass(project), atd.getTypeClass(project));
+ } catch (Exception e) {
+ e.printStackTrace();
+ fail();
+ }
+ }
+
+}--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
