src/share/classes/java/lang/reflect/Executable.java
Print this page
*** 24,33 ****
--- 24,34 ----
*/
package java.lang.reflect;
import java.lang.annotation.*;
+ import java.lang.ref.SoftReference;
import java.util.Map;
import sun.reflect.annotation.AnnotationParser;
import sun.reflect.generics.repository.ConstructorRepository;
/**
*** 53,62 ****
--- 54,65 ----
*/
abstract boolean hasGenericInformation();
abstract ConstructorRepository getGenericInfo();
+ private volatile transient SoftReference<Parameter[]> parameters;
+
boolean equalParamTypes(Class<?>[] params1, Class<?>[] params2) {
/* Avoid unnecessary cloning */
if (params1.length == params2.length) {
for (int i = 0; i < params1.length; i++) {
if (params1[i] != params2[i])
*** 221,230 ****
--- 224,242 ----
* represents
*/
public abstract Class<?>[] getParameterTypes();
/**
+ * Returns the number of formal parameters for the executable
+ * represented by this object.
+ *
+ * @return The number of formal parameters for the executable this
+ * object represents
+ */
+ public abstract int getNumParameters();
+
+ /**
* Returns an array of {@code Type} objects that represent the formal
* parameter types, in declaration order, of the executable represented by
* this object. Returns an array of length 0 if the
* underlying executable takes no parameters.
*
*** 254,263 ****
--- 266,316 ----
else
return getParameterTypes();
}
/**
+ * Returns an array of {@code Parameter} objects that represent
+ * all the parameters to the underlying executable represented by
+ * this object. Returns an array of length 0 if the executable
+ * has no parameters.
+ *
+ * @return an array of {@code Parameter} objects representing all
+ * the parameters to the executable this object represents
+ */
+ public Parameter[] getParameters() {
+ // TODO: This may eventually need to be guarded by security
+ // mechanisms similar to those in Field, Method, etc.
+ Parameter[] raw = privateGetParameters();
+ Parameter[] out = new Parameter[raw.length];
+ // Need to copy the cached array to prevent users from messing
+ // with it
+ for (int i = 0; i < raw.length; i++) {
+ out[i] = new Parameter(raw[i]);
+ }
+ return out;
+ }
+
+ private Parameter[] privateGetParameters() {
+ if (null != parameters)
+ return parameters.get();
+ Parameter[] res = getParameters0();
+
+ if (null == res) {
+ final int num = getNumParameters();
+ res = new Parameter[num];
+ for (int i = 0; i < num; i++)
+ // TODO: is there a way to synthetically derive the modifiers?
+ res[i] = new Parameter("arg" + i, 0, this, i);
+ }
+
+ parameters = new SoftReference<Parameter[]>(res);
+ return res;
+ }
+
+ private native Parameter[] getParameters0();
+
+ /**
* Returns an array of {@code Class} objects that represent the
* types of exceptions declared to be thrown by the underlying
* executable represented by this object. Returns an array of
* length 0 if the executable declares no exceptions in its {@code
* throws} clause.
*** 388,393 ****
--- 441,447 ----
getConstantPool(getDeclaringClass()),
getDeclaringClass());
}
return declaredAnnotations;
}
+
}