Update of /cvsroot/xdoclet/xdoclet2/src/java/xdoclet/util/predicates
In directory sc8-pr-cvs1:/tmp/cvs-serv27037/src/java/xdoclet/util/predicates
Modified Files:
ReflectionPredicate.java
Log Message:
Hardened and slightly refactored ReflectionPredicate.
Index: ReflectionPredicate.java
===================================================================
RCS file:
/cvsroot/xdoclet/xdoclet2/src/java/xdoclet/util/predicates/ReflectionPredicate.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** ReflectionPredicate.java 8 Mar 2003 16:43:50 -0000 1.1
--- ReflectionPredicate.java 9 Mar 2003 16:16:36 -0000 1.2
***************
*** 9,13 ****
* Predicate that uses reflection to call a no-argument method that returns a
boolean.
* This is so we don't have to write one Predicate for all the different
! * isXxx() methods in the XJavadoc API.
*
* @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Hellesøy</a>
--- 9,13 ----
* Predicate that uses reflection to call a no-argument method that returns a
boolean.
* This is so we don't have to write one Predicate for all the different
! * <code>isXxx()</code> methods in the XJavaDoc API.
*
* @author <a href="mailto:aslak.hellesoy at bekk.no">Aslak Hellesøy</a>
***************
*** 18,37 ****
private boolean _negation;
protected boolean evaluate(XProgramElement programElement) {
// Find the method. We only support methods with no arguments that return a
boolean.
Method method = null;
try {
! method = programElement.getClass().getMethod( _methodName, null );
! } catch (Exception e) {
! throw new IllegalStateException(_methodName + " should be a no-arg
method");
}
Class returnType = method.getReturnType();
! if( returnType != Boolean.TYPE ) {
! throw new IllegalStateException(_methodName + " should return boolean.");
}
Boolean bool = null;
try {
bool = (Boolean) method.invoke(programElement, null);
! } catch (Exception e) {
e.printStackTrace();
throw new IllegalStateException("Failed to invoke " + _methodName);
--- 18,51 ----
private boolean _negation;
+ /**
+ * Constructs a new ReflectionPredicate.
+ *
+ * @param methodName the method name to evaluate
+ */
+ public ReflectionPredicate(String methodName) {
+ setMethodName(methodName);
+ }
+
protected boolean evaluate(XProgramElement programElement) {
// Find the method. We only support methods with no arguments that return a
boolean.
Method method = null;
try {
! method = programElement.getClass().getMethod(_methodName, null);
! }
! catch (Exception e) {
! throw new IllegalStateException(_methodName + " should be a no-arg
method (" + e.getMessage() + ")");
}
+
+ assert method != null : "method is null";
+
Class returnType = method.getReturnType();
! if (returnType != Boolean.TYPE) {
! throw new IllegalStateException(_methodName + " should return boolean");
}
Boolean bool = null;
try {
bool = (Boolean) method.invoke(programElement, null);
! }
! catch (Exception e) {
e.printStackTrace();
throw new IllegalStateException("Failed to invoke " + _methodName);
***************
*** 42,59 ****
}
! public ReflectionPredicate() {
! }
! public ReflectionPredicate(String method) {
! setMethod(method);
! }
!
! public void setMethod(String method) {
! if( method.charAt(0) == '!' ) {
_negation = true;
! _methodName = method.substring(1);
! } else {
_negation = false;
! _methodName = method;
}
}
--- 56,75 ----
}
! /**
! * Sets the method name. Sets negation if methodName starts with !.
! *
! * @param methodName the method name
! */
! public void setMethodName(String methodName) {
! if (methodName == null) throw new IllegalArgumentException("methodName
cannot be null");
! if (methodName.trim().length() == 0) throw new
IllegalArgumentException("methodName cannot be empty");
! if (methodName.charAt(0) == '!') {
_negation = true;
! _methodName = methodName.substring(1);
! }
! else {
_negation = false;
! _methodName = methodName;
}
}
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The debugger
for complex code. Debugging C/C++ programs can leave you feeling lost and
disoriented. TotalView can help you find your way. Available on major UNIX
and Linux platforms. Try it free. www.etnus.com
_______________________________________________
xdoclet-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xdoclet-devel