[kaffe] CVS kaffe (robilad): Resynced with GNu Classpath: bean introspection fixes
Kaffe CVS
cvs-commits at kaffe.org
Wed Nov 10 18:27:21 PST 2004
PatchSet 5442
Date: 2004/11/11 02:20:51
Author: robilad
Branch: HEAD
Tag: (none)
Log:
Resynced with GNu Classpath: bean introspection fixes
2004-11-11 Dalibor Topic <robilad at kaffe.org>
* libraries/javalib/gnu/java/beans/IntrospectionIncubator.java:
Resynced with GNU Classpath.
2004-11-08 Robert Schuster <thebohemian at gmx.net>
Fixed regression:
* gnu/java/beans/IntrospectionIncubator.java:
(addMethod): corrected classification of normal and property methods
(capitalize): added documentation
(DoubleKey): [class] added documentation
(isReachable): new method, refactoring of a large expression
Members:
ChangeLog:1.2989->1.2990
libraries/javalib/gnu/java/beans/IntrospectionIncubator.java:1.5->1.6
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2989 kaffe/ChangeLog:1.2990
--- kaffe/ChangeLog:1.2989 Thu Nov 11 02:09:45 2004
+++ kaffe/ChangeLog Thu Nov 11 02:20:51 2004
@@ -1,5 +1,19 @@
2004-11-11 Dalibor Topic <robilad at kaffe.org>
+ * libraries/javalib/gnu/java/beans/IntrospectionIncubator.java:
+ Resynced with GNU Classpath.
+
+ 2004-11-08 Robert Schuster <thebohemian at gmx.net>
+
+ Fixed regression:
+ * gnu/java/beans/IntrospectionIncubator.java:
+ (addMethod): corrected classification of normal and property methods
+ (capitalize): added documentation
+ (DoubleKey): [class] added documentation
+ (isReachable): new method, refactoring of a large expression
+
+2004-11-11 Dalibor Topic <robilad at kaffe.org>
+
* libraries/javalib/java/net/URLStreamHandler.java:
Resynced with GNU Classpath.
Index: kaffe/libraries/javalib/gnu/java/beans/IntrospectionIncubator.java
diff -u kaffe/libraries/javalib/gnu/java/beans/IntrospectionIncubator.java:1.5 kaffe/libraries/javalib/gnu/java/beans/IntrospectionIncubator.java:1.6
--- kaffe/libraries/javalib/gnu/java/beans/IntrospectionIncubator.java:1.5 Mon Nov 8 10:13:14 2004
+++ kaffe/libraries/javalib/gnu/java/beans/IntrospectionIncubator.java Thu Nov 11 02:20:55 2004
@@ -57,11 +57,10 @@
/**
** IntrospectionIncubator takes in a bunch of Methods, and
- ** Introspects only those Methods you give it.
- **
- ** Non-public are silently discarded but it allows static method
- ** because they are valid in <code>MethodDescriptor</code>
- ** instances.
+ ** Introspects only those Methods you give it.<br/>
+ **
+ ** See {@link addMethod(Method)} for details which rules apply to
+ ** the methods.
**
** @author John Keiser
** @author Robert Schuster
@@ -81,7 +80,24 @@
public IntrospectionIncubator() {
}
- /* Paving the way for automatic Introspection */
+ /** Examines the given method and files it in a suitable collection.
+ * It files the method as a property method if it finds:
+ * <lu>
+ * <li>boolean "is" getter</li>
+ * <li>"get" style getter</li>
+ * <li>single argument setter</li>
+ * <li>indiced setter and getter</li>
+ * </ul>
+ * It files the method as a listener method if all of these rules apply:
+ * <lu>
+ * <li>the method name starts with "add" or "remove"</li>
+ * <li>there is only a single argument</li>
+ * <li>the argument type is a subclass of <code>java.util.EventListener</code></li>
+ * </ul>
+ * All public methods are filed as such.
+ *
+ * @param method The method instance to examine.
+ */
public void addMethod(Method method) {
if(Modifier.isPublic(method.getModifiers())) {
String name = ClassHelper.getTruncatedName(method.getName());
@@ -89,8 +105,13 @@
Class[] params = method.getParameterTypes();
boolean isVoid = retType.equals(java.lang.Void.TYPE);
Class methodClass = method.getDeclaringClass();
- if(propertyStopClass == null || (propertyStopClass.isAssignableFrom(methodClass) && !propertyStopClass.equals(methodClass))) {
- /* At this point a method may be regarded as a property's read or write method if its name
+
+ /* Accepts the method for examination if no stop class is given or the method is declared in a subclass of the stop class.
+ * The rules for this are described in {@link java.beans.Introspector.getBeanInfo(Class, Class)}.
+ * This block finds out whether the method is a suitable getter or setter method (or read/write method).
+ */
+ if(isReachable(propertyStopClass, methodClass)) {
+ /* At this point a method may regarded as a property's read or write method if its name
* starts with "is", "get" or "set". However, if a method is static it cannot be part
* of a property.
*/
@@ -100,26 +121,34 @@
} else if(name.startsWith("is")
&& retType.equals(java.lang.Boolean.TYPE)
&& params.length == 0) {
+ // files method as boolean "is" style getter
addToPropertyHash(name,method,IS);
} else if(name.startsWith("get") && !isVoid) {
if(params.length == 0) {
+ // files as legal non-argument getter
addToPropertyHash(name,method,GET);
} else if(params.length == 1 && params[0].equals(java.lang.Integer.TYPE)) {
+ // files as legal indiced getter
addToPropertyHash(name,method,GET_I);
} else {
+ // files as other because the method's signature is not Bean-like
otherMethods.addElement(method);
}
} else if(name.startsWith("set") && isVoid) {
if(params.length == 1) {
+ // files as legal single-argument setter method
addToPropertyHash(name,method,SET);
} else if(params.length == 2 && params[0].equals(java.lang.Integer.TYPE)) {
+ // files as legal indiced setter method
addToPropertyHash(name,method,SET_I);
} else {
+ // files as other because the method's signature is not Bean-like
otherMethods.addElement(method);
}
}
}
- if(eventStopClass == null || (eventStopClass.isAssignableFrom(methodClass) && !eventStopClass.equals(methodClass))) {
+
+ if(isReachable(eventStopClass, methodClass)) {
if(name.startsWith("add")
&& isVoid
&& params.length == 1
@@ -132,9 +161,12 @@
addToListenerHash(name,method,REMOVE);
}
}
- if(methodStopClass == null || (methodStopClass.isAssignableFrom(methodClass) && !methodStopClass.equals(methodClass))) {
+
+ if(isReachable(methodStopClass, methodClass)) {
+ // files as reachable public method
otherMethods.addElement(method);
}
+
}
}
@@ -328,15 +360,25 @@
methods[funcType] = method;
}
- /** Transforms a part of a method name into its corresponding
- * property name. E.g. "Value" becomes "value".
+ /* Determines whether <code>stopClass</code> is <code>null</code>
+ * or <code>declaringClass<code> is a true subclass of <code>stopClass</code>.
+ * This expression is useful to detect whether a method should be introspected or not.
+ * The rules for this are described in {@link java.beans.Introspector.getBeanInfo(Class, Class)}.
+ */
+ static boolean isReachable(Class stopClass, Class declaringClass) {
+ return stopClass == null || (stopClass.isAssignableFrom(declaringClass) && !stopClass.equals(declaringClass));
+ }
+
+ /** Transforms a property name into a part of a method name.
+ * E.g. "value" becomes "Value" which can then concatenated with
+ * "set", "get" or "is" to form a valid method name.
*
* Implementation notes:
* If "" is the argument, it is returned without changes.
* If <code>null</code> is the argument, <code>null</code> is returned.
*
- * @param name Part of a method name.
- * @return Corresponding property name.
+ * @param name Name of a property.
+ * @return Part of a method name of a property.
*/
static String capitalize(String name) {
try {
@@ -358,7 +400,7 @@
/** This class is a hashmap key that consists of a <code>Class</code> and a
* <code>String</code> element.
*
- * It is used to combine a property's or event's type with its name.
+ * It is used for XXX: find out what this is used for
*
* @author John Keiser
* @author Robert Schuster
More information about the kaffe
mailing list