4922835: DOC: Statement javadoc should indicate that target and methodName cannot be null

Reviewed-by: peterz
This commit is contained in:
Sergey Malenkov 2010-01-21 21:45:00 +03:00
parent e2c3e248e5
commit 559ad6f8f8
2 changed files with 63 additions and 29 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2000-2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -51,12 +51,19 @@ public class Expression extends Statement {
private Object value = unbound; private Object value = unbound;
/** /**
* Creates a new <code>Statement</code> object with a <code>target</code>, * Creates a new {@link Expression} object
* <code>methodName</code> and <code>arguments</code> as per the parameters. * for the specified target object to invoke the method
* specified by the name and by the array of arguments.
* <p>
* The {@code target} and the {@code methodName} values should not be {@code null}.
* Otherwise an attempt to execute this {@code Expression}
* will result in a {@code NullPointerException}.
* If the {@code arguments} value is {@code null},
* an empty array is used as the value of the {@code arguments} property.
* *
* @param target The target of this expression. * @param target the target object of this expression
* @param methodName The methodName of this expression. * @param methodName the name of the method to invoke on the specified target
* @param arguments The arguments of this expression. If <code>null</code> then an empty array will be used. * @param arguments the array of arguments to invoke the specified method
* *
* @see #getValue * @see #getValue
*/ */
@ -66,16 +73,23 @@ public class Expression extends Statement {
} }
/** /**
* Creates a new <code>Expression</code> object for a method * Creates a new {@link Expression} object with the specified value
* that returns a result. The result will never be calculated * for the specified target object to invoke the method
* however, since this constructor uses the <code>value</code> * specified by the name and by the array of arguments.
* parameter to set the value property by calling the * The {@code value} value is used as the value of the {@code value} property,
* <code>setValue</code> method. * so the {@link #getValue} method will return it
* without executing this {@code Expression}.
* <p>
* The {@code target} and the {@code methodName} values should not be {@code null}.
* Otherwise an attempt to execute this {@code Expression}
* will result in a {@code NullPointerException}.
* If the {@code arguments} value is {@code null},
* an empty array is used as the value of the {@code arguments} property.
* *
* @param value The value of this expression. * @param value the value of this expression
* @param target The target of this expression. * @param target the target object of this expression
* @param methodName The methodName of this expression. * @param methodName the name of the method to invoke on the specified target
* @param arguments The arguments of this expression. If <code>null</code> then an empty array will be used. * @param arguments the array of arguments to invoke the specified method
* *
* @see #setValue * @see #setValue
*/ */

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2000-2009 Sun Microsystems, Inc. All Rights Reserved. * Copyright 2000-2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -69,13 +69,19 @@ public class Statement {
ClassLoader loader; ClassLoader loader;
/** /**
* Creates a new <code>Statement</code> object with a <code>target</code>, * Creates a new {@link Statement} object
* <code>methodName</code> and <code>arguments</code> as per the parameters. * for the specified target object to invoke the method
* * specified by the name and by the array of arguments.
* @param target The target of this statement. * <p>
* @param methodName The methodName of this statement. * The {@code target} and the {@code methodName} values should not be {@code null}.
* @param arguments The arguments of this statement. If <code>null</code> then an empty array will be used. * Otherwise an attempt to execute this {@code Expression}
* will result in a {@code NullPointerException}.
* If the {@code arguments} value is {@code null},
* an empty array is used as the value of the {@code arguments} property.
* *
* @param target the target object of this statement
* @param methodName the name of the method to invoke on the specified target
* @param arguments the array of arguments to invoke the specified method
*/ */
@ConstructorProperties({"target", "methodName", "arguments"}) @ConstructorProperties({"target", "methodName", "arguments"})
public Statement(Object target, String methodName, Object[] arguments) { public Statement(Object target, String methodName, Object[] arguments) {
@ -85,27 +91,36 @@ public class Statement {
} }
/** /**
* Returns the target of this statement. * Returns the target object of this statement.
* If this method returns {@code null},
* the {@link #execute} method
* throws a {@code NullPointerException}.
* *
* @return The target of this statement. * @return the target object of this statement
*/ */
public Object getTarget() { public Object getTarget() {
return target; return target;
} }
/** /**
* Returns the name of the method. * Returns the name of the method to invoke.
* If this method returns {@code null},
* the {@link #execute} method
* throws a {@code NullPointerException}.
* *
* @return The name of the method. * @return the name of the method
*/ */
public String getMethodName() { public String getMethodName() {
return methodName; return methodName;
} }
/** /**
* Returns the arguments of this statement. * Returns the arguments for the method to invoke.
* The number of arguments and their types
* must match the method being called.
* {@code null} can be used as a synonym of an empty array.
* *
* @return the arguments of this statement. * @return the array of arguments
*/ */
public Object[] getArguments() { public Object[] getArguments() {
return arguments; return arguments;
@ -154,6 +169,9 @@ public class Statement {
} }
Object[] arguments = getArguments(); Object[] arguments = getArguments();
if (arguments == null) {
arguments = emptyArray;
}
// Class.forName() won't load classes outside // Class.forName() won't load classes outside
// of core from a class inside core. Special // of core from a class inside core. Special
// case this method. // case this method.
@ -285,7 +303,9 @@ public class Statement {
Object target = getTarget(); Object target = getTarget();
String methodName = getMethodName(); String methodName = getMethodName();
Object[] arguments = getArguments(); Object[] arguments = getArguments();
if (arguments == null) {
arguments = emptyArray;
}
StringBuffer result = new StringBuffer(instanceName(target) + "." + methodName + "("); StringBuffer result = new StringBuffer(instanceName(target) + "." + methodName + "(");
int n = arguments.length; int n = arguments.length;
for(int i = 0; i < n; i++) { for(int i = 0; i < n; i++) {