bodewig 02/02/20 04:22:38
Modified: src/main/org/apache/tools/ant IntrospectionHelper.java
Project.java
Log:
move method refactoring - applied in a way that keeps
IntrospectionHelper's API backwards compatible.
Inspired by: Jon Skeet <[EMAIL PROTECTED]>
Revision Changes Path
1.35 +27 -50
jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java
Index: IntrospectionHelper.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v
retrieving revision 1.34
retrieving revision 1.35
diff -u -r1.34 -r1.35
--- IntrospectionHelper.java 20 Feb 2002 11:53:55 -0000 1.34
+++ IntrospectionHelper.java 20 Feb 2002 12:22:37 -0000 1.35
@@ -119,23 +119,26 @@
*/
private static Hashtable helpers = new Hashtable();
- /**
- * Map from primitive types to wrapper classes for use in
- * createAttributeSetter (Class to Class). Note that char
- * and boolean are in here even though they get special treatment
- * - this way we only need to test for the wrapper class.
- */
- private static final Hashtable PRIMITIVE_TYPE_MAP = new Hashtable(8);
-
- // 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};
- for (int i=0; i < primitives.length; i++)
- PRIMITIVE_TYPE_MAP.put (primitives[i], wrappers[i]);
- }
+ /**
+ * Map from primitive types to wrapper classes for use in
+ * createAttributeSetter (Class to Class). Note that char
+ * and boolean are in here even though they get special treatment
+ * - this way we only need to test for the wrapper class.
+ */
+ private static final Hashtable PRIMITIVE_TYPE_MAP = new Hashtable(8);
+
+ // 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};
+ for (int i=0; i < primitives.length; i++) {
+ PRIMITIVE_TYPE_MAP.put (primitives[i], wrappers[i]);
+ }
+ }
// XXX: (Jon Skeet) The documentation below doesn't draw a clear
// distinction between addConfigured and add. It's obvious what the
@@ -387,7 +390,7 @@
throws BuildException {
AttributeSetter as = (AttributeSetter)
attributeSetters.get(attributeName);
if (as == null) {
- String msg = getElementName(p, element) +
+ String msg = p.getElementName(element) +
//String msg = "Class " + element.getClass().getName() +
" doesn't support the \"" + attributeName + "\" attribute.";
throw new BuildException(msg);
@@ -432,7 +435,7 @@
}
else {
// Not whitespace - fail
- String msg = getElementName(project, element) +
+ String msg = project.getElementName(element) +
" doesn't support nested text data.";
throw new BuildException(msg);
}
@@ -476,7 +479,7 @@
throws BuildException {
NestedCreator nc = (NestedCreator) nestedCreators.get(elementName);
if (nc == null) {
- String msg = getElementName(project, parent) +
+ String msg = project.getElementName(parent) +
" doesn't support the nested \"" + elementName + "\"
element.";
throw new BuildException(msg);
}
@@ -655,9 +658,9 @@
*/
private AttributeSetter createAttributeSetter(final Method m,
Class arg) {
- // use wrappers for primitive classes, e.g. int and Integer are
treated identically
- final Class reflectedArg = PRIMITIVE_TYPE_MAP.containsKey (arg)
?
- (Class) PRIMITIVE_TYPE_MAP.get(arg) : arg;
+ // use wrappers for primitive classes, e.g. int and Integer are
treated identically
+ final Class reflectedArg = PRIMITIVE_TYPE_MAP.containsKey (arg)
+ ? (Class) PRIMITIVE_TYPE_MAP.get(arg) : arg;
// simplest case - setAttribute expects String
if (java.lang.String.class.equals(reflectedArg)) {
@@ -786,33 +789,7 @@
*/
protected String getElementName(Project project, Object element)
{
- Hashtable elements = project.getTaskDefinitions();
- String typeName = "task";
- if (!elements.contains( element.getClass() ))
- {
- elements = project.getDataTypeDefinitions();
- typeName = "data type";
- if (!elements.contains( element.getClass() ))
- {
- elements = null;
- }
- }
-
- if (elements != null)
- {
- Enumeration e = elements.keys();
- while (e.hasMoreElements())
- {
- String elementName = (String) e.nextElement();
- Class elementClass = (Class) elements.get( elementName );
- if ( element.getClass().equals( elementClass ) )
- {
- return "The <" + elementName + "> " + typeName;
- }
- }
- }
-
- return "Class " + element.getClass().getName();
+ return project.getElementName(element);
}
/**
1.95 +41 -0 jakarta-ant/src/main/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.94
retrieving revision 1.95
diff -u -r1.94 -r1.95
--- Project.java 19 Feb 2002 13:09:13 -0000 1.94
+++ Project.java 20 Feb 2002 12:22:37 -0000 1.95
@@ -79,6 +79,8 @@
* file paths at runtime as well as defining various project properties.
*
* @author [EMAIL PROTECTED]
+ *
+ * @version $Revision: 1.95 $
*/
public class Project {
@@ -1252,6 +1254,45 @@
*/
public Object getReference(String key) {
return references.get(key);
+ }
+
+ /**
+ * Returns a description of the type of the given element - with
+ * special handling for instances of tasks and data types.
+ *
+ * <p>This is useful for logging purposes.</p>
+ *
+ * @param element The element to describe.
+ * Must not be <code>null</code>.
+ *
+ * @return a description of the element type
+ *
+ * @since 1.95, Ant 1.5
+ */
+ public String getElementName(Object element) {
+ Hashtable elements = taskClassDefinitions;
+ Class elementClass = element.getClass();
+ String typeName = "task";
+ if (!elements.contains(elementClass)) {
+ elements = dataClassDefinitions;
+ typeName = "data type";
+ if (!elements.contains(elementClass)) {
+ elements = null;
+ }
+ }
+
+ if (elements != null) {
+ Enumeration e = elements.keys();
+ while (e.hasMoreElements()) {
+ String name = (String) e.nextElement();
+ Class clazz = (Class) elements.get(name);
+ if (elementClass.equals(clazz)) {
+ return "The <" + name + "> " + typeName;
+ }
+ }
+ }
+
+ return "Class " + elementClass.getName();
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>