emul/src/main/java/java/lang/reflect/Method.java
branchreflection
changeset 648 77735e75d6dc
parent 266 2e2e6f946208
parent 636 8d0be6a9a809
child 649 4b16b7e23cab
     1.1 --- a/emul/src/main/java/java/lang/reflect/Method.java	Wed Dec 05 10:03:58 2012 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,655 +0,0 @@
     1.4 -/*
     1.5 - * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
     1.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 - *
     1.8 - * This code is free software; you can redistribute it and/or modify it
     1.9 - * under the terms of the GNU General Public License version 2 only, as
    1.10 - * published by the Free Software Foundation.  Oracle designates this
    1.11 - * particular file as subject to the "Classpath" exception as provided
    1.12 - * by Oracle in the LICENSE file that accompanied this code.
    1.13 - *
    1.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 - * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 - * version 2 for more details (a copy is included in the LICENSE file that
    1.18 - * accompanied this code).
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License version
    1.21 - * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 - *
    1.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 - * or visit www.oracle.com if you need additional information or have any
    1.26 - * questions.
    1.27 - */
    1.28 -
    1.29 -package java.lang.reflect;
    1.30 -
    1.31 -import java.lang.annotation.Annotation;
    1.32 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
    1.33 -import org.apidesign.bck2brwsr.emul.AnnotationImpl;
    1.34 -
    1.35 -/**
    1.36 - * A {@code Method} provides information about, and access to, a single method
    1.37 - * on a class or interface.  The reflected method may be a class method
    1.38 - * or an instance method (including an abstract method).
    1.39 - *
    1.40 - * <p>A {@code Method} permits widening conversions to occur when matching the
    1.41 - * actual parameters to invoke with the underlying method's formal
    1.42 - * parameters, but it throws an {@code IllegalArgumentException} if a
    1.43 - * narrowing conversion would occur.
    1.44 - *
    1.45 - * @see Member
    1.46 - * @see java.lang.Class
    1.47 - * @see java.lang.Class#getMethods()
    1.48 - * @see java.lang.Class#getMethod(String, Class[])
    1.49 - * @see java.lang.Class#getDeclaredMethods()
    1.50 - * @see java.lang.Class#getDeclaredMethod(String, Class[])
    1.51 - *
    1.52 - * @author Kenneth Russell
    1.53 - * @author Nakul Saraiya
    1.54 - */
    1.55 -public final
    1.56 -    class Method extends AccessibleObject implements GenericDeclaration,
    1.57 -                                                     Member {
    1.58 -    private final Class<?> clazz;
    1.59 -    private final String name;
    1.60 -    private final Object data;
    1.61 -    private final String sig;
    1.62 -    private int modifiers;
    1.63 -
    1.64 -   // Generics infrastructure
    1.65 -
    1.66 -    private String getGenericSignature() {return null;}
    1.67 -
    1.68 -    /**
    1.69 -     * Package-private constructor used by ReflectAccess to enable
    1.70 -     * instantiation of these objects in Java code from the java.lang
    1.71 -     * package via sun.reflect.LangReflectAccess.
    1.72 -     */
    1.73 -    Method(Class<?> declaringClass, String name, Object data, String sig)
    1.74 -    {
    1.75 -        this.clazz = declaringClass;
    1.76 -        this.name = name;
    1.77 -        this.data = data;
    1.78 -        this.sig = sig;
    1.79 -    }
    1.80 -
    1.81 -    /**
    1.82 -     * Package-private routine (exposed to java.lang.Class via
    1.83 -     * ReflectAccess) which returns a copy of this Method. The copy's
    1.84 -     * "root" field points to this Method.
    1.85 -     */
    1.86 -    Method copy() {
    1.87 -        return this;
    1.88 -    }
    1.89 -
    1.90 -    /**
    1.91 -     * Returns the {@code Class} object representing the class or interface
    1.92 -     * that declares the method represented by this {@code Method} object.
    1.93 -     */
    1.94 -    public Class<?> getDeclaringClass() {
    1.95 -        return clazz;
    1.96 -    }
    1.97 -
    1.98 -    /**
    1.99 -     * Returns the name of the method represented by this {@code Method}
   1.100 -     * object, as a {@code String}.
   1.101 -     */
   1.102 -    public String getName() {
   1.103 -        return name;
   1.104 -    }
   1.105 -
   1.106 -    /**
   1.107 -     * Returns the Java language modifiers for the method represented
   1.108 -     * by this {@code Method} object, as an integer. The {@code Modifier} class should
   1.109 -     * be used to decode the modifiers.
   1.110 -     *
   1.111 -     * @see Modifier
   1.112 -     */
   1.113 -    public int getModifiers() {
   1.114 -        return modifiers;
   1.115 -    }
   1.116 -
   1.117 -    /**
   1.118 -     * Returns an array of {@code TypeVariable} objects that represent the
   1.119 -     * type variables declared by the generic declaration represented by this
   1.120 -     * {@code GenericDeclaration} object, in declaration order.  Returns an
   1.121 -     * array of length 0 if the underlying generic declaration declares no type
   1.122 -     * variables.
   1.123 -     *
   1.124 -     * @return an array of {@code TypeVariable} objects that represent
   1.125 -     *     the type variables declared by this generic declaration
   1.126 -     * @throws GenericSignatureFormatError if the generic
   1.127 -     *     signature of this generic declaration does not conform to
   1.128 -     *     the format specified in
   1.129 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
   1.130 -     * @since 1.5
   1.131 -     */
   1.132 -    public TypeVariable<Method>[] getTypeParameters() {
   1.133 -        throw new UnsupportedOperationException();
   1.134 -    }
   1.135 -
   1.136 -    /**
   1.137 -     * Returns a {@code Class} object that represents the formal return type
   1.138 -     * of the method represented by this {@code Method} object.
   1.139 -     *
   1.140 -     * @return the return type for the method this object represents
   1.141 -     */
   1.142 -    public Class<?> getReturnType() {
   1.143 -        throw new UnsupportedOperationException();
   1.144 -    }
   1.145 -
   1.146 -    /**
   1.147 -     * Returns a {@code Type} object that represents the formal return
   1.148 -     * type of the method represented by this {@code Method} object.
   1.149 -     *
   1.150 -     * <p>If the return type is a parameterized type,
   1.151 -     * the {@code Type} object returned must accurately reflect
   1.152 -     * the actual type parameters used in the source code.
   1.153 -     *
   1.154 -     * <p>If the return type is a type variable or a parameterized type, it
   1.155 -     * is created. Otherwise, it is resolved.
   1.156 -     *
   1.157 -     * @return  a {@code Type} object that represents the formal return
   1.158 -     *     type of the underlying  method
   1.159 -     * @throws GenericSignatureFormatError
   1.160 -     *     if the generic method signature does not conform to the format
   1.161 -     *     specified in
   1.162 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
   1.163 -     * @throws TypeNotPresentException if the underlying method's
   1.164 -     *     return type refers to a non-existent type declaration
   1.165 -     * @throws MalformedParameterizedTypeException if the
   1.166 -     *     underlying method's return typed refers to a parameterized
   1.167 -     *     type that cannot be instantiated for any reason
   1.168 -     * @since 1.5
   1.169 -     */
   1.170 -    public Type getGenericReturnType() {
   1.171 -        throw new UnsupportedOperationException();
   1.172 -    }
   1.173 -
   1.174 -
   1.175 -    /**
   1.176 -     * Returns an array of {@code Class} objects that represent the formal
   1.177 -     * parameter types, in declaration order, of the method
   1.178 -     * represented by this {@code Method} object.  Returns an array of length
   1.179 -     * 0 if the underlying method takes no parameters.
   1.180 -     *
   1.181 -     * @return the parameter types for the method this object
   1.182 -     * represents
   1.183 -     */
   1.184 -    public Class<?>[] getParameterTypes() {
   1.185 -        throw new UnsupportedOperationException();
   1.186 -        //return (Class<?>[]) parameterTypes.clone();
   1.187 -    }
   1.188 -
   1.189 -    /**
   1.190 -     * Returns an array of {@code Type} objects that represent the formal
   1.191 -     * parameter types, in declaration order, of the method represented by
   1.192 -     * this {@code Method} object. Returns an array of length 0 if the
   1.193 -     * underlying method takes no parameters.
   1.194 -     *
   1.195 -     * <p>If a formal parameter type is a parameterized type,
   1.196 -     * the {@code Type} object returned for it must accurately reflect
   1.197 -     * the actual type parameters used in the source code.
   1.198 -     *
   1.199 -     * <p>If a formal parameter type is a type variable or a parameterized
   1.200 -     * type, it is created. Otherwise, it is resolved.
   1.201 -     *
   1.202 -     * @return an array of Types that represent the formal
   1.203 -     *     parameter types of the underlying method, in declaration order
   1.204 -     * @throws GenericSignatureFormatError
   1.205 -     *     if the generic method signature does not conform to the format
   1.206 -     *     specified in
   1.207 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
   1.208 -     * @throws TypeNotPresentException if any of the parameter
   1.209 -     *     types of the underlying method refers to a non-existent type
   1.210 -     *     declaration
   1.211 -     * @throws MalformedParameterizedTypeException if any of
   1.212 -     *     the underlying method's parameter types refer to a parameterized
   1.213 -     *     type that cannot be instantiated for any reason
   1.214 -     * @since 1.5
   1.215 -     */
   1.216 -    public Type[] getGenericParameterTypes() {
   1.217 -        throw new UnsupportedOperationException();
   1.218 -    }
   1.219 -
   1.220 -
   1.221 -    /**
   1.222 -     * Returns an array of {@code Class} objects that represent
   1.223 -     * the types of the exceptions declared to be thrown
   1.224 -     * by the underlying method
   1.225 -     * represented by this {@code Method} object.  Returns an array of length
   1.226 -     * 0 if the method declares no exceptions in its {@code throws} clause.
   1.227 -     *
   1.228 -     * @return the exception types declared as being thrown by the
   1.229 -     * method this object represents
   1.230 -     */
   1.231 -    public Class<?>[] getExceptionTypes() {
   1.232 -        throw new UnsupportedOperationException();
   1.233 -        //return (Class<?>[]) exceptionTypes.clone();
   1.234 -    }
   1.235 -
   1.236 -    /**
   1.237 -     * Returns an array of {@code Type} objects that represent the
   1.238 -     * exceptions declared to be thrown by this {@code Method} object.
   1.239 -     * Returns an array of length 0 if the underlying method declares
   1.240 -     * no exceptions in its {@code throws} clause.
   1.241 -     *
   1.242 -     * <p>If an exception type is a type variable or a parameterized
   1.243 -     * type, it is created. Otherwise, it is resolved.
   1.244 -     *
   1.245 -     * @return an array of Types that represent the exception types
   1.246 -     *     thrown by the underlying method
   1.247 -     * @throws GenericSignatureFormatError
   1.248 -     *     if the generic method signature does not conform to the format
   1.249 -     *     specified in
   1.250 -     *     <cite>The Java&trade; Virtual Machine Specification</cite>
   1.251 -     * @throws TypeNotPresentException if the underlying method's
   1.252 -     *     {@code throws} clause refers to a non-existent type declaration
   1.253 -     * @throws MalformedParameterizedTypeException if
   1.254 -     *     the underlying method's {@code throws} clause refers to a
   1.255 -     *     parameterized type that cannot be instantiated for any reason
   1.256 -     * @since 1.5
   1.257 -     */
   1.258 -      public Type[] getGenericExceptionTypes() {
   1.259 -        throw new UnsupportedOperationException();
   1.260 -      }
   1.261 -
   1.262 -    /**
   1.263 -     * Compares this {@code Method} against the specified object.  Returns
   1.264 -     * true if the objects are the same.  Two {@code Methods} are the same if
   1.265 -     * they were declared by the same class and have the same name
   1.266 -     * and formal parameter types and return type.
   1.267 -     */
   1.268 -    public boolean equals(Object obj) {
   1.269 -        if (obj != null && obj instanceof Method) {
   1.270 -            Method other = (Method)obj;
   1.271 -            return data == other.data;
   1.272 -        }
   1.273 -        return false;
   1.274 -    }
   1.275 -
   1.276 -    /**
   1.277 -     * Returns a hashcode for this {@code Method}.  The hashcode is computed
   1.278 -     * as the exclusive-or of the hashcodes for the underlying
   1.279 -     * method's declaring class name and the method's name.
   1.280 -     */
   1.281 -    public int hashCode() {
   1.282 -        return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
   1.283 -    }
   1.284 -
   1.285 -    /**
   1.286 -     * Returns a string describing this {@code Method}.  The string is
   1.287 -     * formatted as the method access modifiers, if any, followed by
   1.288 -     * the method return type, followed by a space, followed by the
   1.289 -     * class declaring the method, followed by a period, followed by
   1.290 -     * the method name, followed by a parenthesized, comma-separated
   1.291 -     * list of the method's formal parameter types. If the method
   1.292 -     * throws checked exceptions, the parameter list is followed by a
   1.293 -     * space, followed by the word throws followed by a
   1.294 -     * comma-separated list of the thrown exception types.
   1.295 -     * For example:
   1.296 -     * <pre>
   1.297 -     *    public boolean java.lang.Object.equals(java.lang.Object)
   1.298 -     * </pre>
   1.299 -     *
   1.300 -     * <p>The access modifiers are placed in canonical order as
   1.301 -     * specified by "The Java Language Specification".  This is
   1.302 -     * {@code public}, {@code protected} or {@code private} first,
   1.303 -     * and then other modifiers in the following order:
   1.304 -     * {@code abstract}, {@code static}, {@code final},
   1.305 -     * {@code synchronized}, {@code native}, {@code strictfp}.
   1.306 -     */
   1.307 -    public String toString() {
   1.308 -        try {
   1.309 -            StringBuilder sb = new StringBuilder();
   1.310 -            int mod = getModifiers() & Modifier.methodModifiers();
   1.311 -            if (mod != 0) {
   1.312 -                sb.append(Modifier.toString(mod)).append(' ');
   1.313 -            }
   1.314 -            sb.append(Field.getTypeName(getReturnType())).append(' ');
   1.315 -            sb.append(Field.getTypeName(getDeclaringClass())).append('.');
   1.316 -            sb.append(getName()).append('(');
   1.317 -            /*
   1.318 -            Class<?>[] params = parameterTypes; // avoid clone
   1.319 -            for (int j = 0; j < params.length; j++) {
   1.320 -                sb.append(Field.getTypeName(params[j]));
   1.321 -                if (j < (params.length - 1))
   1.322 -                    sb.append(',');
   1.323 -            }
   1.324 -            sb.append(')');
   1.325 -            Class<?>[] exceptions = exceptionTypes; // avoid clone
   1.326 -            if (exceptions.length > 0) {
   1.327 -                sb.append(" throws ");
   1.328 -                for (int k = 0; k < exceptions.length; k++) {
   1.329 -                    sb.append(exceptions[k].getName());
   1.330 -                    if (k < (exceptions.length - 1))
   1.331 -                        sb.append(',');
   1.332 -                }
   1.333 -            }
   1.334 -            */
   1.335 -            return sb.toString();
   1.336 -        } catch (Exception e) {
   1.337 -            return "<" + e + ">";
   1.338 -        }
   1.339 -    }
   1.340 -
   1.341 -    /**
   1.342 -     * Returns a string describing this {@code Method}, including
   1.343 -     * type parameters.  The string is formatted as the method access
   1.344 -     * modifiers, if any, followed by an angle-bracketed
   1.345 -     * comma-separated list of the method's type parameters, if any,
   1.346 -     * followed by the method's generic return type, followed by a
   1.347 -     * space, followed by the class declaring the method, followed by
   1.348 -     * a period, followed by the method name, followed by a
   1.349 -     * parenthesized, comma-separated list of the method's generic
   1.350 -     * formal parameter types.
   1.351 -     *
   1.352 -     * If this method was declared to take a variable number of
   1.353 -     * arguments, instead of denoting the last parameter as
   1.354 -     * "<tt><i>Type</i>[]</tt>", it is denoted as
   1.355 -     * "<tt><i>Type</i>...</tt>".
   1.356 -     *
   1.357 -     * A space is used to separate access modifiers from one another
   1.358 -     * and from the type parameters or return type.  If there are no
   1.359 -     * type parameters, the type parameter list is elided; if the type
   1.360 -     * parameter list is present, a space separates the list from the
   1.361 -     * class name.  If the method is declared to throw exceptions, the
   1.362 -     * parameter list is followed by a space, followed by the word
   1.363 -     * throws followed by a comma-separated list of the generic thrown
   1.364 -     * exception types.  If there are no type parameters, the type
   1.365 -     * parameter list is elided.
   1.366 -     *
   1.367 -     * <p>The access modifiers are placed in canonical order as
   1.368 -     * specified by "The Java Language Specification".  This is
   1.369 -     * {@code public}, {@code protected} or {@code private} first,
   1.370 -     * and then other modifiers in the following order:
   1.371 -     * {@code abstract}, {@code static}, {@code final},
   1.372 -     * {@code synchronized}, {@code native}, {@code strictfp}.
   1.373 -     *
   1.374 -     * @return a string describing this {@code Method},
   1.375 -     * include type parameters
   1.376 -     *
   1.377 -     * @since 1.5
   1.378 -     */
   1.379 -    public String toGenericString() {
   1.380 -        try {
   1.381 -            StringBuilder sb = new StringBuilder();
   1.382 -            int mod = getModifiers() & Modifier.methodModifiers();
   1.383 -            if (mod != 0) {
   1.384 -                sb.append(Modifier.toString(mod)).append(' ');
   1.385 -            }
   1.386 -            TypeVariable<?>[] typeparms = getTypeParameters();
   1.387 -            if (typeparms.length > 0) {
   1.388 -                boolean first = true;
   1.389 -                sb.append('<');
   1.390 -                for(TypeVariable<?> typeparm: typeparms) {
   1.391 -                    if (!first)
   1.392 -                        sb.append(',');
   1.393 -                    // Class objects can't occur here; no need to test
   1.394 -                    // and call Class.getName().
   1.395 -                    sb.append(typeparm.toString());
   1.396 -                    first = false;
   1.397 -                }
   1.398 -                sb.append("> ");
   1.399 -            }
   1.400 -
   1.401 -            Type genRetType = getGenericReturnType();
   1.402 -            sb.append( ((genRetType instanceof Class<?>)?
   1.403 -                        Field.getTypeName((Class<?>)genRetType):genRetType.toString()))
   1.404 -                    .append(' ');
   1.405 -
   1.406 -            sb.append(Field.getTypeName(getDeclaringClass())).append('.');
   1.407 -            sb.append(getName()).append('(');
   1.408 -            Type[] params = getGenericParameterTypes();
   1.409 -            for (int j = 0; j < params.length; j++) {
   1.410 -                String param = (params[j] instanceof Class)?
   1.411 -                    Field.getTypeName((Class)params[j]):
   1.412 -                    (params[j].toString());
   1.413 -                if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
   1.414 -                    param = param.replaceFirst("\\[\\]$", "...");
   1.415 -                sb.append(param);
   1.416 -                if (j < (params.length - 1))
   1.417 -                    sb.append(',');
   1.418 -            }
   1.419 -            sb.append(')');
   1.420 -            Type[] exceptions = getGenericExceptionTypes();
   1.421 -            if (exceptions.length > 0) {
   1.422 -                sb.append(" throws ");
   1.423 -                for (int k = 0; k < exceptions.length; k++) {
   1.424 -                    sb.append((exceptions[k] instanceof Class)?
   1.425 -                              ((Class)exceptions[k]).getName():
   1.426 -                              exceptions[k].toString());
   1.427 -                    if (k < (exceptions.length - 1))
   1.428 -                        sb.append(',');
   1.429 -                }
   1.430 -            }
   1.431 -            return sb.toString();
   1.432 -        } catch (Exception e) {
   1.433 -            return "<" + e + ">";
   1.434 -        }
   1.435 -    }
   1.436 -
   1.437 -    /**
   1.438 -     * Invokes the underlying method represented by this {@code Method}
   1.439 -     * object, on the specified object with the specified parameters.
   1.440 -     * Individual parameters are automatically unwrapped to match
   1.441 -     * primitive formal parameters, and both primitive and reference
   1.442 -     * parameters are subject to method invocation conversions as
   1.443 -     * necessary.
   1.444 -     *
   1.445 -     * <p>If the underlying method is static, then the specified {@code obj}
   1.446 -     * argument is ignored. It may be null.
   1.447 -     *
   1.448 -     * <p>If the number of formal parameters required by the underlying method is
   1.449 -     * 0, the supplied {@code args} array may be of length 0 or null.
   1.450 -     *
   1.451 -     * <p>If the underlying method is an instance method, it is invoked
   1.452 -     * using dynamic method lookup as documented in The Java Language
   1.453 -     * Specification, Second Edition, section 15.12.4.4; in particular,
   1.454 -     * overriding based on the runtime type of the target object will occur.
   1.455 -     *
   1.456 -     * <p>If the underlying method is static, the class that declared
   1.457 -     * the method is initialized if it has not already been initialized.
   1.458 -     *
   1.459 -     * <p>If the method completes normally, the value it returns is
   1.460 -     * returned to the caller of invoke; if the value has a primitive
   1.461 -     * type, it is first appropriately wrapped in an object. However,
   1.462 -     * if the value has the type of an array of a primitive type, the
   1.463 -     * elements of the array are <i>not</i> wrapped in objects; in
   1.464 -     * other words, an array of primitive type is returned.  If the
   1.465 -     * underlying method return type is void, the invocation returns
   1.466 -     * null.
   1.467 -     *
   1.468 -     * @param obj  the object the underlying method is invoked from
   1.469 -     * @param args the arguments used for the method call
   1.470 -     * @return the result of dispatching the method represented by
   1.471 -     * this object on {@code obj} with parameters
   1.472 -     * {@code args}
   1.473 -     *
   1.474 -     * @exception IllegalAccessException    if this {@code Method} object
   1.475 -     *              is enforcing Java language access control and the underlying
   1.476 -     *              method is inaccessible.
   1.477 -     * @exception IllegalArgumentException  if the method is an
   1.478 -     *              instance method and the specified object argument
   1.479 -     *              is not an instance of the class or interface
   1.480 -     *              declaring the underlying method (or of a subclass
   1.481 -     *              or implementor thereof); if the number of actual
   1.482 -     *              and formal parameters differ; if an unwrapping
   1.483 -     *              conversion for primitive arguments fails; or if,
   1.484 -     *              after possible unwrapping, a parameter value
   1.485 -     *              cannot be converted to the corresponding formal
   1.486 -     *              parameter type by a method invocation conversion.
   1.487 -     * @exception InvocationTargetException if the underlying method
   1.488 -     *              throws an exception.
   1.489 -     * @exception NullPointerException      if the specified object is null
   1.490 -     *              and the method is an instance method.
   1.491 -     * @exception ExceptionInInitializerError if the initialization
   1.492 -     * provoked by this method fails.
   1.493 -     */
   1.494 -    @JavaScriptBody(args = { "method", "self", "args" }, body =
   1.495 -          "if (args.length > 0) throw 'unsupported now';"
   1.496 -        + "return method.fld_data(self);"
   1.497 -    )
   1.498 -    public Object invoke(Object obj, Object... args)
   1.499 -        throws IllegalAccessException, IllegalArgumentException,
   1.500 -           InvocationTargetException
   1.501 -    {
   1.502 -        throw new UnsupportedOperationException();
   1.503 -    }
   1.504 -
   1.505 -    /**
   1.506 -     * Returns {@code true} if this method is a bridge
   1.507 -     * method; returns {@code false} otherwise.
   1.508 -     *
   1.509 -     * @return true if and only if this method is a bridge
   1.510 -     * method as defined by the Java Language Specification.
   1.511 -     * @since 1.5
   1.512 -     */
   1.513 -    public boolean isBridge() {
   1.514 -        return (getModifiers() & Modifier.BRIDGE) != 0;
   1.515 -    }
   1.516 -
   1.517 -    /**
   1.518 -     * Returns {@code true} if this method was declared to take
   1.519 -     * a variable number of arguments; returns {@code false}
   1.520 -     * otherwise.
   1.521 -     *
   1.522 -     * @return {@code true} if an only if this method was declared to
   1.523 -     * take a variable number of arguments.
   1.524 -     * @since 1.5
   1.525 -     */
   1.526 -    public boolean isVarArgs() {
   1.527 -        return (getModifiers() & Modifier.VARARGS) != 0;
   1.528 -    }
   1.529 -
   1.530 -    /**
   1.531 -     * Returns {@code true} if this method is a synthetic
   1.532 -     * method; returns {@code false} otherwise.
   1.533 -     *
   1.534 -     * @return true if and only if this method is a synthetic
   1.535 -     * method as defined by the Java Language Specification.
   1.536 -     * @since 1.5
   1.537 -     */
   1.538 -    public boolean isSynthetic() {
   1.539 -        return Modifier.isSynthetic(getModifiers());
   1.540 -    }
   1.541 -
   1.542 -    @JavaScriptBody(args = { "self", "ac" }, 
   1.543 -        body = 
   1.544 -          "if (self.fld_data.anno) {"
   1.545 -        + "  return self.fld_data.anno['L' + ac.jvmName + ';'];"
   1.546 -        + "} else return null;"
   1.547 -    )
   1.548 -    private Object getAnnotationData(Class<?> annotationClass) {
   1.549 -        throw new UnsupportedOperationException();
   1.550 -    }
   1.551 -    
   1.552 -    /**
   1.553 -     * @throws NullPointerException {@inheritDoc}
   1.554 -     * @since 1.5
   1.555 -     */
   1.556 -    public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
   1.557 -        Object data = getAnnotationData(annotationClass);
   1.558 -        return data == null ? null : AnnotationImpl.create(annotationClass, data);
   1.559 -    }
   1.560 -
   1.561 -    /**
   1.562 -     * @since 1.5
   1.563 -     */
   1.564 -    public Annotation[] getDeclaredAnnotations()  {
   1.565 -        throw new UnsupportedOperationException();
   1.566 -    }
   1.567 -
   1.568 -    /**
   1.569 -     * Returns the default value for the annotation member represented by
   1.570 -     * this {@code Method} instance.  If the member is of a primitive type,
   1.571 -     * an instance of the corresponding wrapper type is returned. Returns
   1.572 -     * null if no default is associated with the member, or if the method
   1.573 -     * instance does not represent a declared member of an annotation type.
   1.574 -     *
   1.575 -     * @return the default value for the annotation member represented
   1.576 -     *     by this {@code Method} instance.
   1.577 -     * @throws TypeNotPresentException if the annotation is of type
   1.578 -     *     {@link Class} and no definition can be found for the
   1.579 -     *     default class value.
   1.580 -     * @since  1.5
   1.581 -     */
   1.582 -    public Object getDefaultValue() {
   1.583 -        throw new UnsupportedOperationException();
   1.584 -    }
   1.585 -
   1.586 -    /**
   1.587 -     * Returns an array of arrays that represent the annotations on the formal
   1.588 -     * parameters, in declaration order, of the method represented by
   1.589 -     * this {@code Method} object. (Returns an array of length zero if the
   1.590 -     * underlying method is parameterless.  If the method has one or more
   1.591 -     * parameters, a nested array of length zero is returned for each parameter
   1.592 -     * with no annotations.) The annotation objects contained in the returned
   1.593 -     * arrays are serializable.  The caller of this method is free to modify
   1.594 -     * the returned arrays; it will have no effect on the arrays returned to
   1.595 -     * other callers.
   1.596 -     *
   1.597 -     * @return an array of arrays that represent the annotations on the formal
   1.598 -     *    parameters, in declaration order, of the method represented by this
   1.599 -     *    Method object
   1.600 -     * @since 1.5
   1.601 -     */
   1.602 -    public Annotation[][] getParameterAnnotations() {
   1.603 -        throw new UnsupportedOperationException();
   1.604 -    }
   1.605 -    
   1.606 -    //
   1.607 -    // bck2brwsr implementation
   1.608 -    //
   1.609 -
   1.610 -    @JavaScriptBody(args = { "clazz", "prefix" },
   1.611 -        body = ""
   1.612 -        + "var c = clazz.cnstr.prototype;"
   1.613 -        + "var arr = new Array();\n"
   1.614 -        + "for (m in c) {\n"
   1.615 -        + "  if (m.indexOf(prefix) === 0) {\n"
   1.616 -        + "     arr.push(m);\n"
   1.617 -        + "     arr.push(c[m]);\n"
   1.618 -        + "  }"
   1.619 -        + "}\n"
   1.620 -        + "return arr;"
   1.621 -    )
   1.622 -    private static native Object[] findMethodData(
   1.623 -        Class<?> clazz, String prefix
   1.624 -    );
   1.625 -
   1.626 -    // XXX should not be public
   1.627 -    public static Method findMethod(
   1.628 -        Class<?> clazz, String name, Class<?>... parameterTypes
   1.629 -    ) {
   1.630 -        Object[] data = findMethodData(clazz, name + "__");
   1.631 -        if (data.length == 0) {
   1.632 -            return null;
   1.633 -        }
   1.634 -        String sig = ((String)data[0]).substring(name.length() + 2);
   1.635 -        return new Method(clazz, name, data[1], sig);
   1.636 -    }
   1.637 -    
   1.638 -    public static Method[] findMethods(Class<?> clazz) {
   1.639 -        Object[] namesAndData = findMethodData(clazz, "");
   1.640 -        int cnt = 0;
   1.641 -        for (int i = 0; i < namesAndData.length; i += 2) {
   1.642 -            String sig = (String) namesAndData[i];
   1.643 -            Object data = namesAndData[i + 1];
   1.644 -            int middle = sig.indexOf("__");
   1.645 -            if (middle == -1) {
   1.646 -                continue;
   1.647 -            }
   1.648 -            String name = sig.substring(0, middle);
   1.649 -            sig = sig.substring(middle + 2);
   1.650 -            namesAndData[cnt++] = new Method(clazz, name, data, sig);
   1.651 -        }
   1.652 -        Method[] arr = new Method[cnt];
   1.653 -        for (int i = 0; i < cnt; i++) {
   1.654 -            arr[i] = (Method)namesAndData[i];
   1.655 -        }
   1.656 -        return arr;
   1.657 -    }
   1.658 -}