1.1 --- a/emul/src/main/java/java/lang/AbstractStringBuilder.java Fri Dec 07 15:02:35 2012 +0100
1.2 +++ b/emul/src/main/java/java/lang/AbstractStringBuilder.java Fri Dec 07 15:57:14 2012 +0100
1.3 @@ -25,8 +25,6 @@
1.4
1.5 package java.lang;
1.6
1.7 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.8 -
1.9 /**
1.10 * A mutable sequence of characters.
1.11 * <p>
1.12 @@ -600,22 +598,8 @@
1.13 * @param i an {@code int}.
1.14 * @return a reference to this object.
1.15 */
1.16 - @JavaScriptBody(
1.17 - args={ "self", "i" },
1.18 - body="return java_lang_AbstractStringBuilder(true).appendLjava_lang_AbstractStringBuilderLjava_lang_String(self,i.toString());"
1.19 - )
1.20 public AbstractStringBuilder append(int i) {
1.21 - if (i == Integer.MIN_VALUE) {
1.22 - append("-2147483648");
1.23 - return this;
1.24 - }
1.25 - int appendedLength = (i < 0) ? Integer.stringSize(-i) + 1
1.26 - : Integer.stringSize(i);
1.27 - int spaceNeeded = count + appendedLength;
1.28 - ensureCapacityInternal(spaceNeeded);
1.29 - Integer.getChars(i, spaceNeeded, value);
1.30 - count = spaceNeeded;
1.31 - return this;
1.32 + return append(Integer.toString(i));
1.33 }
1.34
1.35 /**
2.1 --- a/emul/src/main/java/java/lang/Class.java Fri Dec 07 15:02:35 2012 +0100
2.2 +++ b/emul/src/main/java/java/lang/Class.java Fri Dec 07 15:57:14 2012 +0100
2.3 @@ -25,8 +25,13 @@
2.4
2.5 package java.lang;
2.6
2.7 +import org.apidesign.bck2brwsr.emul.AnnotationImpl;
2.8 import java.io.InputStream;
2.9 import java.lang.annotation.Annotation;
2.10 +import java.lang.reflect.Field;
2.11 +import java.lang.reflect.Method;
2.12 +import java.lang.reflect.TypeVariable;
2.13 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
2.14
2.15 /**
2.16 * Instances of the class {@code Class} represent classes and
2.17 @@ -74,10 +79,10 @@
2.18 * @since JDK1.0
2.19 */
2.20 public final
2.21 - class Class<T> implements java.io.Serializable {
2.22 -// java.lang.reflect.GenericDeclaration,
2.23 -// java.lang.reflect.Type,
2.24 -// java.lang.reflect.AnnotatedElement {
2.25 + class Class<T> implements java.io.Serializable,
2.26 + java.lang.reflect.GenericDeclaration,
2.27 + java.lang.reflect.Type,
2.28 + java.lang.reflect.AnnotatedElement {
2.29 private static final int ANNOTATION= 0x00002000;
2.30 private static final int ENUM = 0x00004000;
2.31 private static final int SYNTHETIC = 0x00001000;
2.32 @@ -190,10 +195,15 @@
2.33 * </ul>
2.34 *
2.35 */
2.36 + @JavaScriptBody(args = "self", body =
2.37 + "var inst = self.cnstr();"
2.38 + + "inst.cons__V(inst);"
2.39 + + "return inst;"
2.40 + )
2.41 public T newInstance()
2.42 throws InstantiationException, IllegalAccessException
2.43 {
2.44 - throw new UnsupportedOperationException("Should be somehow supported");
2.45 + throw new UnsupportedOperationException();
2.46 }
2.47
2.48 /**
2.49 @@ -273,7 +283,9 @@
2.50 * {@code false} otherwise.
2.51 * @since JDK1.1
2.52 */
2.53 - public native boolean isArray();
2.54 + public boolean isArray() {
2.55 + return false;
2.56 + }
2.57
2.58
2.59 /**
2.60 @@ -382,13 +394,32 @@
2.61 * represented by this object.
2.62 */
2.63 public String getName() {
2.64 - throw new UnsupportedOperationException();
2.65 -// String name = this.name;
2.66 -// if (name == null)
2.67 -// this.name = name = getName0();
2.68 -// return name;
2.69 + return jvmName().replace('/', '.');
2.70 }
2.71
2.72 + @JavaScriptBody(args = "self", body = "return self.jvmName;")
2.73 + private native String jvmName();
2.74 +
2.75 +
2.76 + /**
2.77 + * Returns an array of {@code TypeVariable} objects that represent the
2.78 + * type variables declared by the generic declaration represented by this
2.79 + * {@code GenericDeclaration} object, in declaration order. Returns an
2.80 + * array of length 0 if the underlying generic declaration declares no type
2.81 + * variables.
2.82 + *
2.83 + * @return an array of {@code TypeVariable} objects that represent
2.84 + * the type variables declared by this generic declaration
2.85 + * @throws java.lang.reflect.GenericSignatureFormatError if the generic
2.86 + * signature of this generic declaration does not conform to
2.87 + * the format specified in
2.88 + * <cite>The Java™ Virtual Machine Specification</cite>
2.89 + * @since 1.5
2.90 + */
2.91 + public TypeVariable<Class<T>>[] getTypeParameters() {
2.92 + throw new UnsupportedOperationException();
2.93 + }
2.94 +
2.95 /**
2.96 * Returns the {@code Class} representing the superclass of the entity
2.97 * (class, interface, primitive type or void) represented by this
2.98 @@ -400,6 +431,7 @@
2.99 *
2.100 * @return the superclass of the class represented by this object.
2.101 */
2.102 + @JavaScriptBody(args = "self", body = "return self.superclass;")
2.103 public native Class<? super T> getSuperclass();
2.104
2.105 /**
2.106 @@ -445,37 +477,282 @@
2.107 * @since 1.5
2.108 */
2.109 public String getSimpleName() {
2.110 - throw new UnsupportedOperationException();
2.111 -//// if (isArray())
2.112 -//// return getComponentType().getSimpleName()+"[]";
2.113 -////
2.114 -//// String simpleName = getSimpleBinaryName();
2.115 -//// if (simpleName == null) { // top level class
2.116 -//// simpleName = getName();
2.117 -//// return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
2.118 -//// }
2.119 -//// // According to JLS3 "Binary Compatibility" (13.1) the binary
2.120 -//// // name of non-package classes (not top level) is the binary
2.121 -//// // name of the immediately enclosing class followed by a '$' followed by:
2.122 -//// // (for nested and inner classes): the simple name.
2.123 -//// // (for local classes): 1 or more digits followed by the simple name.
2.124 -//// // (for anonymous classes): 1 or more digits.
2.125 -////
2.126 -//// // Since getSimpleBinaryName() will strip the binary name of
2.127 -//// // the immediatly enclosing class, we are now looking at a
2.128 -//// // string that matches the regular expression "\$[0-9]*"
2.129 -//// // followed by a simple name (considering the simple of an
2.130 -//// // anonymous class to be the empty string).
2.131 -////
2.132 -//// // Remove leading "\$[0-9]*" from the name
2.133 -//// int length = simpleName.length();
2.134 -//// if (length < 1 || simpleName.charAt(0) != '$')
2.135 -//// throw new InternalError("Malformed class name");
2.136 -//// int index = 1;
2.137 -//// while (index < length && isAsciiDigit(simpleName.charAt(index)))
2.138 -//// index++;
2.139 -//// // Eventually, this is the empty string iff this is an anonymous class
2.140 -//// return simpleName.substring(index);
2.141 + if (isArray())
2.142 + return getComponentType().getSimpleName()+"[]";
2.143 +
2.144 + String simpleName = getSimpleBinaryName();
2.145 + if (simpleName == null) { // top level class
2.146 + simpleName = getName();
2.147 + return simpleName.substring(simpleName.lastIndexOf(".")+1); // strip the package name
2.148 + }
2.149 + // According to JLS3 "Binary Compatibility" (13.1) the binary
2.150 + // name of non-package classes (not top level) is the binary
2.151 + // name of the immediately enclosing class followed by a '$' followed by:
2.152 + // (for nested and inner classes): the simple name.
2.153 + // (for local classes): 1 or more digits followed by the simple name.
2.154 + // (for anonymous classes): 1 or more digits.
2.155 +
2.156 + // Since getSimpleBinaryName() will strip the binary name of
2.157 + // the immediatly enclosing class, we are now looking at a
2.158 + // string that matches the regular expression "\$[0-9]*"
2.159 + // followed by a simple name (considering the simple of an
2.160 + // anonymous class to be the empty string).
2.161 +
2.162 + // Remove leading "\$[0-9]*" from the name
2.163 + int length = simpleName.length();
2.164 + if (length < 1 || simpleName.charAt(0) != '$')
2.165 + throw new IllegalStateException("Malformed class name");
2.166 + int index = 1;
2.167 + while (index < length && isAsciiDigit(simpleName.charAt(index)))
2.168 + index++;
2.169 + // Eventually, this is the empty string iff this is an anonymous class
2.170 + return simpleName.substring(index);
2.171 + }
2.172 +
2.173 + /**
2.174 + * Returns the "simple binary name" of the underlying class, i.e.,
2.175 + * the binary name without the leading enclosing class name.
2.176 + * Returns {@code null} if the underlying class is a top level
2.177 + * class.
2.178 + */
2.179 + private String getSimpleBinaryName() {
2.180 + Class<?> enclosingClass = null; // XXX getEnclosingClass();
2.181 + if (enclosingClass == null) // top level class
2.182 + return null;
2.183 + // Otherwise, strip the enclosing class' name
2.184 + try {
2.185 + return getName().substring(enclosingClass.getName().length());
2.186 + } catch (IndexOutOfBoundsException ex) {
2.187 + throw new IllegalStateException("Malformed class name");
2.188 + }
2.189 + }
2.190 +
2.191 + /**
2.192 + * Returns an array containing {@code Field} objects reflecting all
2.193 + * the accessible public fields of the class or interface represented by
2.194 + * this {@code Class} object. The elements in the array returned are
2.195 + * not sorted and are not in any particular order. This method returns an
2.196 + * array of length 0 if the class or interface has no accessible public
2.197 + * fields, or if it represents an array class, a primitive type, or void.
2.198 + *
2.199 + * <p> Specifically, if this {@code Class} object represents a class,
2.200 + * this method returns the public fields of this class and of all its
2.201 + * superclasses. If this {@code Class} object represents an
2.202 + * interface, this method returns the fields of this interface and of all
2.203 + * its superinterfaces.
2.204 + *
2.205 + * <p> The implicit length field for array class is not reflected by this
2.206 + * method. User code should use the methods of class {@code Array} to
2.207 + * manipulate arrays.
2.208 + *
2.209 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
2.210 + *
2.211 + * @return the array of {@code Field} objects representing the
2.212 + * public fields
2.213 + * @exception SecurityException
2.214 + * If a security manager, <i>s</i>, is present and any of the
2.215 + * following conditions is met:
2.216 + *
2.217 + * <ul>
2.218 + *
2.219 + * <li> invocation of
2.220 + * {@link SecurityManager#checkMemberAccess
2.221 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
2.222 + * access to the fields within this class
2.223 + *
2.224 + * <li> the caller's class loader is not the same as or an
2.225 + * ancestor of the class loader for the current class and
2.226 + * invocation of {@link SecurityManager#checkPackageAccess
2.227 + * s.checkPackageAccess()} denies access to the package
2.228 + * of this class
2.229 + *
2.230 + * </ul>
2.231 + *
2.232 + * @since JDK1.1
2.233 + */
2.234 + public Field[] getFields() throws SecurityException {
2.235 + throw new SecurityException();
2.236 + }
2.237 +
2.238 + /**
2.239 + * Returns an array containing {@code Method} objects reflecting all
2.240 + * the public <em>member</em> methods of the class or interface represented
2.241 + * by this {@code Class} object, including those declared by the class
2.242 + * or interface and those inherited from superclasses and
2.243 + * superinterfaces. Array classes return all the (public) member methods
2.244 + * inherited from the {@code Object} class. The elements in the array
2.245 + * returned are not sorted and are not in any particular order. This
2.246 + * method returns an array of length 0 if this {@code Class} object
2.247 + * represents a class or interface that has no public member methods, or if
2.248 + * this {@code Class} object represents a primitive type or void.
2.249 + *
2.250 + * <p> The class initialization method {@code <clinit>} is not
2.251 + * included in the returned array. If the class declares multiple public
2.252 + * member methods with the same parameter types, they are all included in
2.253 + * the returned array.
2.254 + *
2.255 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
2.256 + *
2.257 + * @return the array of {@code Method} objects representing the
2.258 + * public methods of this class
2.259 + * @exception SecurityException
2.260 + * If a security manager, <i>s</i>, is present and any of the
2.261 + * following conditions is met:
2.262 + *
2.263 + * <ul>
2.264 + *
2.265 + * <li> invocation of
2.266 + * {@link SecurityManager#checkMemberAccess
2.267 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
2.268 + * access to the methods within this class
2.269 + *
2.270 + * <li> the caller's class loader is not the same as or an
2.271 + * ancestor of the class loader for the current class and
2.272 + * invocation of {@link SecurityManager#checkPackageAccess
2.273 + * s.checkPackageAccess()} denies access to the package
2.274 + * of this class
2.275 + *
2.276 + * </ul>
2.277 + *
2.278 + * @since JDK1.1
2.279 + */
2.280 + public Method[] getMethods() throws SecurityException {
2.281 + return Method.findMethods(this);
2.282 + }
2.283 +
2.284 + /**
2.285 + * Returns a {@code Field} object that reflects the specified public
2.286 + * member field of the class or interface represented by this
2.287 + * {@code Class} object. The {@code name} parameter is a
2.288 + * {@code String} specifying the simple name of the desired field.
2.289 + *
2.290 + * <p> The field to be reflected is determined by the algorithm that
2.291 + * follows. Let C be the class represented by this object:
2.292 + * <OL>
2.293 + * <LI> If C declares a public field with the name specified, that is the
2.294 + * field to be reflected.</LI>
2.295 + * <LI> If no field was found in step 1 above, this algorithm is applied
2.296 + * recursively to each direct superinterface of C. The direct
2.297 + * superinterfaces are searched in the order they were declared.</LI>
2.298 + * <LI> If no field was found in steps 1 and 2 above, and C has a
2.299 + * superclass S, then this algorithm is invoked recursively upon S.
2.300 + * If C has no superclass, then a {@code NoSuchFieldException}
2.301 + * is thrown.</LI>
2.302 + * </OL>
2.303 + *
2.304 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.3.
2.305 + *
2.306 + * @param name the field name
2.307 + * @return the {@code Field} object of this class specified by
2.308 + * {@code name}
2.309 + * @exception NoSuchFieldException if a field with the specified name is
2.310 + * not found.
2.311 + * @exception NullPointerException if {@code name} is {@code null}
2.312 + * @exception SecurityException
2.313 + * If a security manager, <i>s</i>, is present and any of the
2.314 + * following conditions is met:
2.315 + *
2.316 + * <ul>
2.317 + *
2.318 + * <li> invocation of
2.319 + * {@link SecurityManager#checkMemberAccess
2.320 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
2.321 + * access to the field
2.322 + *
2.323 + * <li> the caller's class loader is not the same as or an
2.324 + * ancestor of the class loader for the current class and
2.325 + * invocation of {@link SecurityManager#checkPackageAccess
2.326 + * s.checkPackageAccess()} denies access to the package
2.327 + * of this class
2.328 + *
2.329 + * </ul>
2.330 + *
2.331 + * @since JDK1.1
2.332 + */
2.333 + public Field getField(String name)
2.334 + throws SecurityException {
2.335 + throw new SecurityException();
2.336 + }
2.337 +
2.338 +
2.339 + /**
2.340 + * Returns a {@code Method} object that reflects the specified public
2.341 + * member method of the class or interface represented by this
2.342 + * {@code Class} object. The {@code name} parameter is a
2.343 + * {@code String} specifying the simple name of the desired method. The
2.344 + * {@code parameterTypes} parameter is an array of {@code Class}
2.345 + * objects that identify the method's formal parameter types, in declared
2.346 + * order. If {@code parameterTypes} is {@code null}, it is
2.347 + * treated as if it were an empty array.
2.348 + *
2.349 + * <p> If the {@code name} is "{@code <init>};"or "{@code <clinit>}" a
2.350 + * {@code NoSuchMethodException} is raised. Otherwise, the method to
2.351 + * be reflected is determined by the algorithm that follows. Let C be the
2.352 + * class represented by this object:
2.353 + * <OL>
2.354 + * <LI> C is searched for any <I>matching methods</I>. If no matching
2.355 + * method is found, the algorithm of step 1 is invoked recursively on
2.356 + * the superclass of C.</LI>
2.357 + * <LI> If no method was found in step 1 above, the superinterfaces of C
2.358 + * are searched for a matching method. If any such method is found, it
2.359 + * is reflected.</LI>
2.360 + * </OL>
2.361 + *
2.362 + * To find a matching method in a class C: If C declares exactly one
2.363 + * public method with the specified name and exactly the same formal
2.364 + * parameter types, that is the method reflected. If more than one such
2.365 + * method is found in C, and one of these methods has a return type that is
2.366 + * more specific than any of the others, that method is reflected;
2.367 + * otherwise one of the methods is chosen arbitrarily.
2.368 + *
2.369 + * <p>Note that there may be more than one matching method in a
2.370 + * class because while the Java language forbids a class to
2.371 + * declare multiple methods with the same signature but different
2.372 + * return types, the Java virtual machine does not. This
2.373 + * increased flexibility in the virtual machine can be used to
2.374 + * implement various language features. For example, covariant
2.375 + * returns can be implemented with {@linkplain
2.376 + * java.lang.reflect.Method#isBridge bridge methods}; the bridge
2.377 + * method and the method being overridden would have the same
2.378 + * signature but different return types.
2.379 + *
2.380 + * <p> See <em>The Java Language Specification</em>, sections 8.2 and 8.4.
2.381 + *
2.382 + * @param name the name of the method
2.383 + * @param parameterTypes the list of parameters
2.384 + * @return the {@code Method} object that matches the specified
2.385 + * {@code name} and {@code parameterTypes}
2.386 + * @exception NoSuchMethodException if a matching method is not found
2.387 + * or if the name is "<init>"or "<clinit>".
2.388 + * @exception NullPointerException if {@code name} is {@code null}
2.389 + * @exception SecurityException
2.390 + * If a security manager, <i>s</i>, is present and any of the
2.391 + * following conditions is met:
2.392 + *
2.393 + * <ul>
2.394 + *
2.395 + * <li> invocation of
2.396 + * {@link SecurityManager#checkMemberAccess
2.397 + * s.checkMemberAccess(this, Member.PUBLIC)} denies
2.398 + * access to the method
2.399 + *
2.400 + * <li> the caller's class loader is not the same as or an
2.401 + * ancestor of the class loader for the current class and
2.402 + * invocation of {@link SecurityManager#checkPackageAccess
2.403 + * s.checkPackageAccess()} denies access to the package
2.404 + * of this class
2.405 + *
2.406 + * </ul>
2.407 + *
2.408 + * @since JDK1.1
2.409 + */
2.410 + public Method getMethod(String name, Class<?>... parameterTypes)
2.411 + throws SecurityException {
2.412 + Method m = Method.findMethod(this, name, parameterTypes);
2.413 + if (m == null) {
2.414 + throw new SecurityException(); // XXX: NoSuchMethodException
2.415 + }
2.416 + return m;
2.417 }
2.418
2.419 /**
2.420 @@ -497,25 +774,25 @@
2.421 * @since 1.5
2.422 */
2.423 public String getCanonicalName() {
2.424 - throw new UnsupportedOperationException();
2.425 -// if (isArray()) {
2.426 -// String canonicalName = getComponentType().getCanonicalName();
2.427 -// if (canonicalName != null)
2.428 -// return canonicalName + "[]";
2.429 -// else
2.430 -// return null;
2.431 -// }
2.432 + if (isArray()) {
2.433 + String canonicalName = getComponentType().getCanonicalName();
2.434 + if (canonicalName != null)
2.435 + return canonicalName + "[]";
2.436 + else
2.437 + return null;
2.438 + }
2.439 // if (isLocalOrAnonymousClass())
2.440 // return null;
2.441 // Class<?> enclosingClass = getEnclosingClass();
2.442 -// if (enclosingClass == null) { // top level class
2.443 -// return getName();
2.444 -// } else {
2.445 -// String enclosingName = enclosingClass.getCanonicalName();
2.446 -// if (enclosingName == null)
2.447 -// return null;
2.448 -// return enclosingName + "." + getSimpleName();
2.449 -// }
2.450 + Class<?> enclosingClass = null;
2.451 + if (enclosingClass == null) { // top level class
2.452 + return getName();
2.453 + } else {
2.454 + String enclosingName = enclosingClass.getCanonicalName();
2.455 + if (enclosingName == null)
2.456 + return null;
2.457 + return enclosingName + "." + getSimpleName();
2.458 + }
2.459 }
2.460
2.461 /**
2.462 @@ -676,7 +953,9 @@
2.463 * @see java.lang.reflect.Array
2.464 * @since JDK1.1
2.465 */
2.466 - public native Class<?> getComponentType();
2.467 + public Class<?> getComponentType() {
2.468 + return null;
2.469 + }
2.470
2.471 /**
2.472 * Returns true if and only if this class was declared as an enum in the
2.473 @@ -743,18 +1022,32 @@
2.474 throw new ClassCastException(this.toString());
2.475 }
2.476
2.477 + @JavaScriptBody(args = { "self", "ac" },
2.478 + body =
2.479 + "if (self.anno) {"
2.480 + + " return self.anno['L' + ac.jvmName + ';'];"
2.481 + + "} else return null;"
2.482 + )
2.483 + private Object getAnnotationData(Class<?> annotationClass) {
2.484 + throw new UnsupportedOperationException();
2.485 + }
2.486 /**
2.487 * @throws NullPointerException {@inheritDoc}
2.488 * @since 1.5
2.489 */
2.490 public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
2.491 - throw new UnsupportedOperationException();
2.492 + Object data = getAnnotationData(annotationClass);
2.493 + return data == null ? null : AnnotationImpl.create(annotationClass, data);
2.494 }
2.495
2.496 /**
2.497 * @throws NullPointerException {@inheritDoc}
2.498 * @since 1.5
2.499 */
2.500 + @JavaScriptBody(args = { "self", "ac" },
2.501 + body = "if (self.anno && self.anno['L' + ac.jvmName + ';']) { return true; }"
2.502 + + "else return false;"
2.503 + )
2.504 public boolean isAnnotationPresent(
2.505 Class<? extends Annotation> annotationClass) {
2.506 if (annotationClass == null)
2.507 @@ -763,12 +1056,17 @@
2.508 return getAnnotation(annotationClass) != null;
2.509 }
2.510
2.511 + @JavaScriptBody(args = "self", body = "return self.anno;")
2.512 + private Object getAnnotationData() {
2.513 + throw new UnsupportedOperationException();
2.514 + }
2.515
2.516 /**
2.517 * @since 1.5
2.518 */
2.519 public Annotation[] getAnnotations() {
2.520 - throw new UnsupportedOperationException();
2.521 + Object data = getAnnotationData();
2.522 + return data == null ? new Annotation[0] : AnnotationImpl.create(data);
2.523 }
2.524
2.525 /**
3.1 --- a/emul/src/main/java/java/lang/Object.java Fri Dec 07 15:02:35 2012 +0100
3.2 +++ b/emul/src/main/java/java/lang/Object.java Fri Dec 07 15:57:14 2012 +0100
3.3 @@ -66,6 +66,7 @@
3.4 * @see Class Literals, section 15.8.2 of
3.5 * <cite>The Java™ Language Specification</cite>.
3.6 */
3.7 + @JavaScriptBody(args="self", body="return self.constructor.$class;")
3.8 public final native Class<?> getClass();
3.9
3.10 /**
4.1 --- a/emul/src/main/java/java/lang/String.java Fri Dec 07 15:02:35 2012 +0100
4.2 +++ b/emul/src/main/java/java/lang/String.java Fri Dec 07 15:57:14 2012 +0100
4.3 @@ -1691,6 +1691,10 @@
4.4 * than or equal to <code>fromIndex</code>, or <code>-1</code>
4.5 * if the character does not occur before that point.
4.6 */
4.7 + @JavaScriptBody(args = { "self", "ch", "from" }, body =
4.8 + "if (typeof ch === 'number') ch = String.fromCharCode(ch);\n" +
4.9 + "return self.toString().lastIndexOf(ch, from);"
4.10 + )
4.11 public int lastIndexOf(int ch, int fromIndex) {
4.12 if (ch < Character.MIN_SUPPLEMENTARY_CODE_POINT) {
4.13 // handle most cases here (ch is a BMP code point or a
4.14 @@ -1763,7 +1767,7 @@
4.15 * or {@code -1} if there is no such occurrence.
4.16 */
4.17 @JavaScriptBody(args = { "self", "str", "fromIndex" }, body =
4.18 - "return self.toString().indexOf(str.toString(), fromIndex) >= 0;"
4.19 + "return self.toString().indexOf(str.toString(), fromIndex);"
4.20 )
4.21 public int indexOf(String str, int fromIndex) {
4.22 return indexOf(toCharArray(), offset(), length(), str.toCharArray(), str.offset(), str.length(), fromIndex);
4.23 @@ -1855,6 +1859,9 @@
4.24 * searching backward from the specified index,
4.25 * or {@code -1} if there is no such occurrence.
4.26 */
4.27 + @JavaScriptBody(args = { "self", "s", "from" }, body =
4.28 + "return self.toString().lastIndexOf(s.toString(), from);"
4.29 + )
4.30 public int lastIndexOf(String str, int fromIndex) {
4.31 return lastIndexOf(toCharArray(), offset(), length(), str.toCharArray(), str.offset(), str.length(), fromIndex);
4.32 }
5.1 --- a/emul/src/main/java/java/lang/Throwable.java Fri Dec 07 15:02:35 2012 +0100
5.2 +++ b/emul/src/main/java/java/lang/Throwable.java Fri Dec 07 15:57:14 2012 +0100
5.3 @@ -25,6 +25,7 @@
5.4
5.5 package java.lang;
5.6 import java.io.*;
5.7 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
5.8
5.9 /**
5.10 * The {@code Throwable} class is the superclass of all errors and
5.11 @@ -782,6 +783,7 @@
5.12 return this;
5.13 }
5.14
5.15 + @JavaScriptBody(args = { "self", "dummy" }, body = "")
5.16 private native Throwable fillInStackTrace(int dummy);
5.17
5.18 /**
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/emul/src/main/java/java/lang/reflect/AccessibleObject.java Fri Dec 07 15:57:14 2012 +0100
6.3 @@ -0,0 +1,167 @@
6.4 +/*
6.5 + * Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved.
6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6.7 + *
6.8 + * This code is free software; you can redistribute it and/or modify it
6.9 + * under the terms of the GNU General Public License version 2 only, as
6.10 + * published by the Free Software Foundation. Oracle designates this
6.11 + * particular file as subject to the "Classpath" exception as provided
6.12 + * by Oracle in the LICENSE file that accompanied this code.
6.13 + *
6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6.17 + * version 2 for more details (a copy is included in the LICENSE file that
6.18 + * accompanied this code).
6.19 + *
6.20 + * You should have received a copy of the GNU General Public License version
6.21 + * 2 along with this work; if not, write to the Free Software Foundation,
6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6.23 + *
6.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6.25 + * or visit www.oracle.com if you need additional information or have any
6.26 + * questions.
6.27 + */
6.28 +
6.29 +package java.lang.reflect;
6.30 +
6.31 +import java.lang.annotation.Annotation;
6.32 +
6.33 +/**
6.34 + * The AccessibleObject class is the base class for Field, Method and
6.35 + * Constructor objects. It provides the ability to flag a reflected
6.36 + * object as suppressing default Java language access control checks
6.37 + * when it is used. The access checks--for public, default (package)
6.38 + * access, protected, and private members--are performed when Fields,
6.39 + * Methods or Constructors are used to set or get fields, to invoke
6.40 + * methods, or to create and initialize new instances of classes,
6.41 + * respectively.
6.42 + *
6.43 + * <p>Setting the {@code accessible} flag in a reflected object
6.44 + * permits sophisticated applications with sufficient privilege, such
6.45 + * as Java Object Serialization or other persistence mechanisms, to
6.46 + * manipulate objects in a manner that would normally be prohibited.
6.47 + *
6.48 + * <p>By default, a reflected object is <em>not</em> accessible.
6.49 + *
6.50 + * @see Field
6.51 + * @see Method
6.52 + * @see Constructor
6.53 + * @see ReflectPermission
6.54 + *
6.55 + * @since 1.2
6.56 + */
6.57 +public class AccessibleObject implements AnnotatedElement {
6.58 +
6.59 + /**
6.60 + * Convenience method to set the {@code accessible} flag for an
6.61 + * array of objects with a single security check (for efficiency).
6.62 + *
6.63 + * <p>First, if there is a security manager, its
6.64 + * {@code checkPermission} method is called with a
6.65 + * {@code ReflectPermission("suppressAccessChecks")} permission.
6.66 + *
6.67 + * <p>A {@code SecurityException} is raised if {@code flag} is
6.68 + * {@code true} but accessibility of any of the elements of the input
6.69 + * {@code array} may not be changed (for example, if the element
6.70 + * object is a {@link Constructor} object for the class {@link
6.71 + * java.lang.Class}). In the event of such a SecurityException, the
6.72 + * accessibility of objects is set to {@code flag} for array elements
6.73 + * upto (and excluding) the element for which the exception occurred; the
6.74 + * accessibility of elements beyond (and including) the element for which
6.75 + * the exception occurred is unchanged.
6.76 + *
6.77 + * @param array the array of AccessibleObjects
6.78 + * @param flag the new value for the {@code accessible} flag
6.79 + * in each object
6.80 + * @throws SecurityException if the request is denied.
6.81 + * @see SecurityManager#checkPermission
6.82 + * @see java.lang.RuntimePermission
6.83 + */
6.84 + public static void setAccessible(AccessibleObject[] array, boolean flag)
6.85 + throws SecurityException {
6.86 + throw new SecurityException();
6.87 + }
6.88 +
6.89 + /**
6.90 + * Set the {@code accessible} flag for this object to
6.91 + * the indicated boolean value. A value of {@code true} indicates that
6.92 + * the reflected object should suppress Java language access
6.93 + * checking when it is used. A value of {@code false} indicates
6.94 + * that the reflected object should enforce Java language access checks.
6.95 + *
6.96 + * <p>First, if there is a security manager, its
6.97 + * {@code checkPermission} method is called with a
6.98 + * {@code ReflectPermission("suppressAccessChecks")} permission.
6.99 + *
6.100 + * <p>A {@code SecurityException} is raised if {@code flag} is
6.101 + * {@code true} but accessibility of this object may not be changed
6.102 + * (for example, if this element object is a {@link Constructor} object for
6.103 + * the class {@link java.lang.Class}).
6.104 + *
6.105 + * <p>A {@code SecurityException} is raised if this object is a {@link
6.106 + * java.lang.reflect.Constructor} object for the class
6.107 + * {@code java.lang.Class}, and {@code flag} is true.
6.108 + *
6.109 + * @param flag the new value for the {@code accessible} flag
6.110 + * @throws SecurityException if the request is denied.
6.111 + * @see SecurityManager#checkPermission
6.112 + * @see java.lang.RuntimePermission
6.113 + */
6.114 + public void setAccessible(boolean flag) throws SecurityException {
6.115 + throw new SecurityException();
6.116 + }
6.117 +
6.118 + /**
6.119 + * Get the value of the {@code accessible} flag for this object.
6.120 + *
6.121 + * @return the value of the object's {@code accessible} flag
6.122 + */
6.123 + public boolean isAccessible() {
6.124 + return override;
6.125 + }
6.126 +
6.127 + /**
6.128 + * Constructor: only used by the Java Virtual Machine.
6.129 + */
6.130 + protected AccessibleObject() {}
6.131 +
6.132 + // Indicates whether language-level access checks are overridden
6.133 + // by this object. Initializes to "false". This field is used by
6.134 + // Field, Method, and Constructor.
6.135 + //
6.136 + // NOTE: for security purposes, this field must not be visible
6.137 + // outside this package.
6.138 + boolean override;
6.139 +
6.140 + /**
6.141 + * @throws NullPointerException {@inheritDoc}
6.142 + * @since 1.5
6.143 + */
6.144 + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
6.145 + throw new AssertionError("All subclasses should override this method");
6.146 + }
6.147 +
6.148 + /**
6.149 + * @throws NullPointerException {@inheritDoc}
6.150 + * @since 1.5
6.151 + */
6.152 + public boolean isAnnotationPresent(
6.153 + Class<? extends Annotation> annotationClass) {
6.154 + return getAnnotation(annotationClass) != null;
6.155 + }
6.156 +
6.157 + /**
6.158 + * @since 1.5
6.159 + */
6.160 + public Annotation[] getAnnotations() {
6.161 + return getDeclaredAnnotations();
6.162 + }
6.163 +
6.164 + /**
6.165 + * @since 1.5
6.166 + */
6.167 + public Annotation[] getDeclaredAnnotations() {
6.168 + throw new AssertionError("All subclasses should override this method");
6.169 + }
6.170 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/emul/src/main/java/java/lang/reflect/AnnotatedElement.java Fri Dec 07 15:57:14 2012 +0100
7.3 @@ -0,0 +1,112 @@
7.4 +/*
7.5 + * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7.7 + *
7.8 + * This code is free software; you can redistribute it and/or modify it
7.9 + * under the terms of the GNU General Public License version 2 only, as
7.10 + * published by the Free Software Foundation. Oracle designates this
7.11 + * particular file as subject to the "Classpath" exception as provided
7.12 + * by Oracle in the LICENSE file that accompanied this code.
7.13 + *
7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
7.17 + * version 2 for more details (a copy is included in the LICENSE file that
7.18 + * accompanied this code).
7.19 + *
7.20 + * You should have received a copy of the GNU General Public License version
7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7.23 + *
7.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7.25 + * or visit www.oracle.com if you need additional information or have any
7.26 + * questions.
7.27 + */
7.28 +
7.29 +package java.lang.reflect;
7.30 +
7.31 +import java.lang.annotation.Annotation;
7.32 +
7.33 +/**
7.34 + * Represents an annotated element of the program currently running in this
7.35 + * VM. This interface allows annotations to be read reflectively. All
7.36 + * annotations returned by methods in this interface are immutable and
7.37 + * serializable. It is permissible for the caller to modify the
7.38 + * arrays returned by accessors for array-valued enum members; it will
7.39 + * have no affect on the arrays returned to other callers.
7.40 + *
7.41 + * <p>If an annotation returned by a method in this interface contains
7.42 + * (directly or indirectly) a {@link Class}-valued member referring to
7.43 + * a class that is not accessible in this VM, attempting to read the class
7.44 + * by calling the relevant Class-returning method on the returned annotation
7.45 + * will result in a {@link TypeNotPresentException}.
7.46 + *
7.47 + * <p>Similarly, attempting to read an enum-valued member will result in
7.48 + * a {@link EnumConstantNotPresentException} if the enum constant in the
7.49 + * annotation is no longer present in the enum type.
7.50 + *
7.51 + * <p>Finally, Attempting to read a member whose definition has evolved
7.52 + * incompatibly will result in a {@link
7.53 + * java.lang.annotation.AnnotationTypeMismatchException} or an
7.54 + * {@link java.lang.annotation.IncompleteAnnotationException}.
7.55 + *
7.56 + * @see java.lang.EnumConstantNotPresentException
7.57 + * @see java.lang.TypeNotPresentException
7.58 + * @see java.lang.annotation.AnnotationFormatError
7.59 + * @see java.lang.annotation.AnnotationTypeMismatchException
7.60 + * @see java.lang.annotation.IncompleteAnnotationException
7.61 + * @since 1.5
7.62 + * @author Josh Bloch
7.63 + */
7.64 +public interface AnnotatedElement {
7.65 + /**
7.66 + * Returns true if an annotation for the specified type
7.67 + * is present on this element, else false. This method
7.68 + * is designed primarily for convenient access to marker annotations.
7.69 + *
7.70 + * @param annotationClass the Class object corresponding to the
7.71 + * annotation type
7.72 + * @return true if an annotation for the specified annotation
7.73 + * type is present on this element, else false
7.74 + * @throws NullPointerException if the given annotation class is null
7.75 + * @since 1.5
7.76 + */
7.77 + boolean isAnnotationPresent(Class<? extends Annotation> annotationClass);
7.78 +
7.79 + /**
7.80 + * Returns this element's annotation for the specified type if
7.81 + * such an annotation is present, else null.
7.82 + *
7.83 + * @param annotationClass the Class object corresponding to the
7.84 + * annotation type
7.85 + * @return this element's annotation for the specified annotation type if
7.86 + * present on this element, else null
7.87 + * @throws NullPointerException if the given annotation class is null
7.88 + * @since 1.5
7.89 + */
7.90 + <T extends Annotation> T getAnnotation(Class<T> annotationClass);
7.91 +
7.92 + /**
7.93 + * Returns all annotations present on this element. (Returns an array
7.94 + * of length zero if this element has no annotations.) The caller of
7.95 + * this method is free to modify the returned array; it will have no
7.96 + * effect on the arrays returned to other callers.
7.97 + *
7.98 + * @return all annotations present on this element
7.99 + * @since 1.5
7.100 + */
7.101 + Annotation[] getAnnotations();
7.102 +
7.103 + /**
7.104 + * Returns all annotations that are directly present on this
7.105 + * element. Unlike the other methods in this interface, this method
7.106 + * ignores inherited annotations. (Returns an array of length zero if
7.107 + * no annotations are directly present on this element.) The caller of
7.108 + * this method is free to modify the returned array; it will have no
7.109 + * effect on the arrays returned to other callers.
7.110 + *
7.111 + * @return All annotations directly present on this element
7.112 + * @since 1.5
7.113 + */
7.114 + Annotation[] getDeclaredAnnotations();
7.115 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/emul/src/main/java/java/lang/reflect/Field.java Fri Dec 07 15:57:14 2012 +0100
8.3 @@ -0,0 +1,953 @@
8.4 +/*
8.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8.7 + *
8.8 + * This code is free software; you can redistribute it and/or modify it
8.9 + * under the terms of the GNU General Public License version 2 only, as
8.10 + * published by the Free Software Foundation. Oracle designates this
8.11 + * particular file as subject to the "Classpath" exception as provided
8.12 + * by Oracle in the LICENSE file that accompanied this code.
8.13 + *
8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
8.17 + * version 2 for more details (a copy is included in the LICENSE file that
8.18 + * accompanied this code).
8.19 + *
8.20 + * You should have received a copy of the GNU General Public License version
8.21 + * 2 along with this work; if not, write to the Free Software Foundation,
8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8.23 + *
8.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8.25 + * or visit www.oracle.com if you need additional information or have any
8.26 + * questions.
8.27 + */
8.28 +
8.29 +package java.lang.reflect;
8.30 +
8.31 +import java.lang.annotation.Annotation;
8.32 +
8.33 +
8.34 +/**
8.35 + * A {@code Field} provides information about, and dynamic access to, a
8.36 + * single field of a class or an interface. The reflected field may
8.37 + * be a class (static) field or an instance field.
8.38 + *
8.39 + * <p>A {@code Field} permits widening conversions to occur during a get or
8.40 + * set access operation, but throws an {@code IllegalArgumentException} if a
8.41 + * narrowing conversion would occur.
8.42 + *
8.43 + * @see Member
8.44 + * @see java.lang.Class
8.45 + * @see java.lang.Class#getFields()
8.46 + * @see java.lang.Class#getField(String)
8.47 + * @see java.lang.Class#getDeclaredFields()
8.48 + * @see java.lang.Class#getDeclaredField(String)
8.49 + *
8.50 + * @author Kenneth Russell
8.51 + * @author Nakul Saraiya
8.52 + */
8.53 +public final
8.54 +class Field extends AccessibleObject implements Member {
8.55 +
8.56 + private Class<?> clazz;
8.57 + private int slot;
8.58 + // This is guaranteed to be interned by the VM in the 1.4
8.59 + // reflection implementation
8.60 + private String name;
8.61 + private Class<?> type;
8.62 + private int modifiers;
8.63 + // Generics and annotations support
8.64 + private transient String signature;
8.65 + private byte[] annotations;
8.66 + // For sharing of FieldAccessors. This branching structure is
8.67 + // currently only two levels deep (i.e., one root Field and
8.68 + // potentially many Field objects pointing to it.)
8.69 + private Field root;
8.70 +
8.71 + // Generics infrastructure
8.72 +
8.73 + private String getGenericSignature() {return signature;}
8.74 +
8.75 +
8.76 + /**
8.77 + * Package-private constructor used by ReflectAccess to enable
8.78 + * instantiation of these objects in Java code from the java.lang
8.79 + * package via sun.reflect.LangReflectAccess.
8.80 + */
8.81 + Field(Class<?> declaringClass,
8.82 + String name,
8.83 + Class<?> type,
8.84 + int modifiers,
8.85 + int slot,
8.86 + String signature,
8.87 + byte[] annotations)
8.88 + {
8.89 + this.clazz = declaringClass;
8.90 + this.name = name;
8.91 + this.type = type;
8.92 + this.modifiers = modifiers;
8.93 + this.slot = slot;
8.94 + this.signature = signature;
8.95 + this.annotations = annotations;
8.96 + }
8.97 +
8.98 + /**
8.99 + * Package-private routine (exposed to java.lang.Class via
8.100 + * ReflectAccess) which returns a copy of this Field. The copy's
8.101 + * "root" field points to this Field.
8.102 + */
8.103 + Field copy() {
8.104 + // This routine enables sharing of FieldAccessor objects
8.105 + // among Field objects which refer to the same underlying
8.106 + // method in the VM. (All of this contortion is only necessary
8.107 + // because of the "accessibility" bit in AccessibleObject,
8.108 + // which implicitly requires that new java.lang.reflect
8.109 + // objects be fabricated for each reflective call on Class
8.110 + // objects.)
8.111 + Field res = new Field(clazz, name, type, modifiers, slot, signature, annotations);
8.112 + res.root = this;
8.113 + return res;
8.114 + }
8.115 +
8.116 + /**
8.117 + * Returns the {@code Class} object representing the class or interface
8.118 + * that declares the field represented by this {@code Field} object.
8.119 + */
8.120 + public Class<?> getDeclaringClass() {
8.121 + return clazz;
8.122 + }
8.123 +
8.124 + /**
8.125 + * Returns the name of the field represented by this {@code Field} object.
8.126 + */
8.127 + public String getName() {
8.128 + return name;
8.129 + }
8.130 +
8.131 + /**
8.132 + * Returns the Java language modifiers for the field represented
8.133 + * by this {@code Field} object, as an integer. The {@code Modifier} class should
8.134 + * be used to decode the modifiers.
8.135 + *
8.136 + * @see Modifier
8.137 + */
8.138 + public int getModifiers() {
8.139 + return modifiers;
8.140 + }
8.141 +
8.142 + /**
8.143 + * Returns {@code true} if this field represents an element of
8.144 + * an enumerated type; returns {@code false} otherwise.
8.145 + *
8.146 + * @return {@code true} if and only if this field represents an element of
8.147 + * an enumerated type.
8.148 + * @since 1.5
8.149 + */
8.150 + public boolean isEnumConstant() {
8.151 + return (getModifiers() & Modifier.ENUM) != 0;
8.152 + }
8.153 +
8.154 + /**
8.155 + * Returns {@code true} if this field is a synthetic
8.156 + * field; returns {@code false} otherwise.
8.157 + *
8.158 + * @return true if and only if this field is a synthetic
8.159 + * field as defined by the Java Language Specification.
8.160 + * @since 1.5
8.161 + */
8.162 + public boolean isSynthetic() {
8.163 + return Modifier.isSynthetic(getModifiers());
8.164 + }
8.165 +
8.166 + /**
8.167 + * Returns a {@code Class} object that identifies the
8.168 + * declared type for the field represented by this
8.169 + * {@code Field} object.
8.170 + *
8.171 + * @return a {@code Class} object identifying the declared
8.172 + * type of the field represented by this object
8.173 + */
8.174 + public Class<?> getType() {
8.175 + return type;
8.176 + }
8.177 +
8.178 + /**
8.179 + * Returns a {@code Type} object that represents the declared type for
8.180 + * the field represented by this {@code Field} object.
8.181 + *
8.182 + * <p>If the {@code Type} is a parameterized type, the
8.183 + * {@code Type} object returned must accurately reflect the
8.184 + * actual type parameters used in the source code.
8.185 + *
8.186 + * <p>If the type of the underlying field is a type variable or a
8.187 + * parameterized type, it is created. Otherwise, it is resolved.
8.188 + *
8.189 + * @return a {@code Type} object that represents the declared type for
8.190 + * the field represented by this {@code Field} object
8.191 + * @throws GenericSignatureFormatError if the generic field
8.192 + * signature does not conform to the format specified in
8.193 + * <cite>The Java™ Virtual Machine Specification</cite>
8.194 + * @throws TypeNotPresentException if the generic type
8.195 + * signature of the underlying field refers to a non-existent
8.196 + * type declaration
8.197 + * @throws MalformedParameterizedTypeException if the generic
8.198 + * signature of the underlying field refers to a parameterized type
8.199 + * that cannot be instantiated for any reason
8.200 + * @since 1.5
8.201 + */
8.202 + public Type getGenericType() {
8.203 + throw new UnsupportedOperationException();
8.204 + }
8.205 +
8.206 +
8.207 + /**
8.208 + * Compares this {@code Field} against the specified object. Returns
8.209 + * true if the objects are the same. Two {@code Field} objects are the same if
8.210 + * they were declared by the same class and have the same name
8.211 + * and type.
8.212 + */
8.213 + public boolean equals(Object obj) {
8.214 + if (obj != null && obj instanceof Field) {
8.215 + Field other = (Field)obj;
8.216 + return (getDeclaringClass() == other.getDeclaringClass())
8.217 + && (getName() == other.getName())
8.218 + && (getType() == other.getType());
8.219 + }
8.220 + return false;
8.221 + }
8.222 +
8.223 + /**
8.224 + * Returns a hashcode for this {@code Field}. This is computed as the
8.225 + * exclusive-or of the hashcodes for the underlying field's
8.226 + * declaring class name and its name.
8.227 + */
8.228 + public int hashCode() {
8.229 + return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
8.230 + }
8.231 +
8.232 + /**
8.233 + * Returns a string describing this {@code Field}. The format is
8.234 + * the access modifiers for the field, if any, followed
8.235 + * by the field type, followed by a space, followed by
8.236 + * the fully-qualified name of the class declaring the field,
8.237 + * followed by a period, followed by the name of the field.
8.238 + * For example:
8.239 + * <pre>
8.240 + * public static final int java.lang.Thread.MIN_PRIORITY
8.241 + * private int java.io.FileDescriptor.fd
8.242 + * </pre>
8.243 + *
8.244 + * <p>The modifiers are placed in canonical order as specified by
8.245 + * "The Java Language Specification". This is {@code public},
8.246 + * {@code protected} or {@code private} first, and then other
8.247 + * modifiers in the following order: {@code static}, {@code final},
8.248 + * {@code transient}, {@code volatile}.
8.249 + */
8.250 + public String toString() {
8.251 + int mod = getModifiers();
8.252 + return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
8.253 + + getTypeName(getType()) + " "
8.254 + + getTypeName(getDeclaringClass()) + "."
8.255 + + getName());
8.256 + }
8.257 +
8.258 + /**
8.259 + * Returns a string describing this {@code Field}, including
8.260 + * its generic type. The format is the access modifiers for the
8.261 + * field, if any, followed by the generic field type, followed by
8.262 + * a space, followed by the fully-qualified name of the class
8.263 + * declaring the field, followed by a period, followed by the name
8.264 + * of the field.
8.265 + *
8.266 + * <p>The modifiers are placed in canonical order as specified by
8.267 + * "The Java Language Specification". This is {@code public},
8.268 + * {@code protected} or {@code private} first, and then other
8.269 + * modifiers in the following order: {@code static}, {@code final},
8.270 + * {@code transient}, {@code volatile}.
8.271 + *
8.272 + * @return a string describing this {@code Field}, including
8.273 + * its generic type
8.274 + *
8.275 + * @since 1.5
8.276 + */
8.277 + public String toGenericString() {
8.278 + int mod = getModifiers();
8.279 + Type fieldType = getGenericType();
8.280 + return (((mod == 0) ? "" : (Modifier.toString(mod) + " "))
8.281 + + ((fieldType instanceof Class) ?
8.282 + getTypeName((Class)fieldType): fieldType.toString())+ " "
8.283 + + getTypeName(getDeclaringClass()) + "."
8.284 + + getName());
8.285 + }
8.286 +
8.287 + /**
8.288 + * Returns the value of the field represented by this {@code Field}, on
8.289 + * the specified object. The value is automatically wrapped in an
8.290 + * object if it has a primitive type.
8.291 + *
8.292 + * <p>The underlying field's value is obtained as follows:
8.293 + *
8.294 + * <p>If the underlying field is a static field, the {@code obj} argument
8.295 + * is ignored; it may be null.
8.296 + *
8.297 + * <p>Otherwise, the underlying field is an instance field. If the
8.298 + * specified {@code obj} argument is null, the method throws a
8.299 + * {@code NullPointerException}. If the specified object is not an
8.300 + * instance of the class or interface declaring the underlying
8.301 + * field, the method throws an {@code IllegalArgumentException}.
8.302 + *
8.303 + * <p>If this {@code Field} object is enforcing Java language access control, and
8.304 + * the underlying field is inaccessible, the method throws an
8.305 + * {@code IllegalAccessException}.
8.306 + * If the underlying field is static, the class that declared the
8.307 + * field is initialized if it has not already been initialized.
8.308 + *
8.309 + * <p>Otherwise, the value is retrieved from the underlying instance
8.310 + * or static field. If the field has a primitive type, the value
8.311 + * is wrapped in an object before being returned, otherwise it is
8.312 + * returned as is.
8.313 + *
8.314 + * <p>If the field is hidden in the type of {@code obj},
8.315 + * the field's value is obtained according to the preceding rules.
8.316 + *
8.317 + * @param obj object from which the represented field's value is
8.318 + * to be extracted
8.319 + * @return the value of the represented field in object
8.320 + * {@code obj}; primitive values are wrapped in an appropriate
8.321 + * object before being returned
8.322 + *
8.323 + * @exception IllegalAccessException if this {@code Field} object
8.324 + * is enforcing Java language access control and the underlying
8.325 + * field is inaccessible.
8.326 + * @exception IllegalArgumentException if the specified object is not an
8.327 + * instance of the class or interface declaring the underlying
8.328 + * field (or a subclass or implementor thereof).
8.329 + * @exception NullPointerException if the specified object is null
8.330 + * and the field is an instance field.
8.331 + * @exception ExceptionInInitializerError if the initialization provoked
8.332 + * by this method fails.
8.333 + */
8.334 + public Object get(Object obj)
8.335 + throws IllegalArgumentException, IllegalAccessException
8.336 + {
8.337 + return getFieldAccessor(obj).get(obj);
8.338 + }
8.339 +
8.340 + /**
8.341 + * Gets the value of a static or instance {@code boolean} field.
8.342 + *
8.343 + * @param obj the object to extract the {@code boolean} value
8.344 + * from
8.345 + * @return the value of the {@code boolean} field
8.346 + *
8.347 + * @exception IllegalAccessException if this {@code Field} object
8.348 + * is enforcing Java language access control and the underlying
8.349 + * field is inaccessible.
8.350 + * @exception IllegalArgumentException if the specified object is not
8.351 + * an instance of the class or interface declaring the
8.352 + * underlying field (or a subclass or implementor
8.353 + * thereof), or if the field value cannot be
8.354 + * converted to the type {@code boolean} by a
8.355 + * widening conversion.
8.356 + * @exception NullPointerException if the specified object is null
8.357 + * and the field is an instance field.
8.358 + * @exception ExceptionInInitializerError if the initialization provoked
8.359 + * by this method fails.
8.360 + * @see Field#get
8.361 + */
8.362 + public boolean getBoolean(Object obj)
8.363 + throws IllegalArgumentException, IllegalAccessException
8.364 + {
8.365 + return getFieldAccessor(obj).getBoolean(obj);
8.366 + }
8.367 +
8.368 + /**
8.369 + * Gets the value of a static or instance {@code byte} field.
8.370 + *
8.371 + * @param obj the object to extract the {@code byte} value
8.372 + * from
8.373 + * @return the value of the {@code byte} field
8.374 + *
8.375 + * @exception IllegalAccessException if this {@code Field} object
8.376 + * is enforcing Java language access control and the underlying
8.377 + * field is inaccessible.
8.378 + * @exception IllegalArgumentException if the specified object is not
8.379 + * an instance of the class or interface declaring the
8.380 + * underlying field (or a subclass or implementor
8.381 + * thereof), or if the field value cannot be
8.382 + * converted to the type {@code byte} by a
8.383 + * widening conversion.
8.384 + * @exception NullPointerException if the specified object is null
8.385 + * and the field is an instance field.
8.386 + * @exception ExceptionInInitializerError if the initialization provoked
8.387 + * by this method fails.
8.388 + * @see Field#get
8.389 + */
8.390 + public byte getByte(Object obj)
8.391 + throws IllegalArgumentException, IllegalAccessException
8.392 + {
8.393 + return getFieldAccessor(obj).getByte(obj);
8.394 + }
8.395 +
8.396 + /**
8.397 + * Gets the value of a static or instance field of type
8.398 + * {@code char} or of another primitive type convertible to
8.399 + * type {@code char} via a widening conversion.
8.400 + *
8.401 + * @param obj the object to extract the {@code char} value
8.402 + * from
8.403 + * @return the value of the field converted to type {@code char}
8.404 + *
8.405 + * @exception IllegalAccessException if this {@code Field} object
8.406 + * is enforcing Java language access control and the underlying
8.407 + * field is inaccessible.
8.408 + * @exception IllegalArgumentException if the specified object is not
8.409 + * an instance of the class or interface declaring the
8.410 + * underlying field (or a subclass or implementor
8.411 + * thereof), or if the field value cannot be
8.412 + * converted to the type {@code char} by a
8.413 + * widening conversion.
8.414 + * @exception NullPointerException if the specified object is null
8.415 + * and the field is an instance field.
8.416 + * @exception ExceptionInInitializerError if the initialization provoked
8.417 + * by this method fails.
8.418 + * @see Field#get
8.419 + */
8.420 + public char getChar(Object obj)
8.421 + throws IllegalArgumentException, IllegalAccessException
8.422 + {
8.423 + return getFieldAccessor(obj).getChar(obj);
8.424 + }
8.425 +
8.426 + /**
8.427 + * Gets the value of a static or instance field of type
8.428 + * {@code short} or of another primitive type convertible to
8.429 + * type {@code short} via a widening conversion.
8.430 + *
8.431 + * @param obj the object to extract the {@code short} value
8.432 + * from
8.433 + * @return the value of the field converted to type {@code short}
8.434 + *
8.435 + * @exception IllegalAccessException if this {@code Field} object
8.436 + * is enforcing Java language access control and the underlying
8.437 + * field is inaccessible.
8.438 + * @exception IllegalArgumentException if the specified object is not
8.439 + * an instance of the class or interface declaring the
8.440 + * underlying field (or a subclass or implementor
8.441 + * thereof), or if the field value cannot be
8.442 + * converted to the type {@code short} by a
8.443 + * widening conversion.
8.444 + * @exception NullPointerException if the specified object is null
8.445 + * and the field is an instance field.
8.446 + * @exception ExceptionInInitializerError if the initialization provoked
8.447 + * by this method fails.
8.448 + * @see Field#get
8.449 + */
8.450 + public short getShort(Object obj)
8.451 + throws IllegalArgumentException, IllegalAccessException
8.452 + {
8.453 + return getFieldAccessor(obj).getShort(obj);
8.454 + }
8.455 +
8.456 + /**
8.457 + * Gets the value of a static or instance field of type
8.458 + * {@code int} or of another primitive type convertible to
8.459 + * type {@code int} via a widening conversion.
8.460 + *
8.461 + * @param obj the object to extract the {@code int} value
8.462 + * from
8.463 + * @return the value of the field converted to type {@code int}
8.464 + *
8.465 + * @exception IllegalAccessException if this {@code Field} object
8.466 + * is enforcing Java language access control and the underlying
8.467 + * field is inaccessible.
8.468 + * @exception IllegalArgumentException if the specified object is not
8.469 + * an instance of the class or interface declaring the
8.470 + * underlying field (or a subclass or implementor
8.471 + * thereof), or if the field value cannot be
8.472 + * converted to the type {@code int} by a
8.473 + * widening conversion.
8.474 + * @exception NullPointerException if the specified object is null
8.475 + * and the field is an instance field.
8.476 + * @exception ExceptionInInitializerError if the initialization provoked
8.477 + * by this method fails.
8.478 + * @see Field#get
8.479 + */
8.480 + public int getInt(Object obj)
8.481 + throws IllegalArgumentException, IllegalAccessException
8.482 + {
8.483 + return getFieldAccessor(obj).getInt(obj);
8.484 + }
8.485 +
8.486 + /**
8.487 + * Gets the value of a static or instance field of type
8.488 + * {@code long} or of another primitive type convertible to
8.489 + * type {@code long} via a widening conversion.
8.490 + *
8.491 + * @param obj the object to extract the {@code long} value
8.492 + * from
8.493 + * @return the value of the field converted to type {@code long}
8.494 + *
8.495 + * @exception IllegalAccessException if this {@code Field} object
8.496 + * is enforcing Java language access control and the underlying
8.497 + * field is inaccessible.
8.498 + * @exception IllegalArgumentException if the specified object is not
8.499 + * an instance of the class or interface declaring the
8.500 + * underlying field (or a subclass or implementor
8.501 + * thereof), or if the field value cannot be
8.502 + * converted to the type {@code long} by a
8.503 + * widening conversion.
8.504 + * @exception NullPointerException if the specified object is null
8.505 + * and the field is an instance field.
8.506 + * @exception ExceptionInInitializerError if the initialization provoked
8.507 + * by this method fails.
8.508 + * @see Field#get
8.509 + */
8.510 + public long getLong(Object obj)
8.511 + throws IllegalArgumentException, IllegalAccessException
8.512 + {
8.513 + return getFieldAccessor(obj).getLong(obj);
8.514 + }
8.515 +
8.516 + /**
8.517 + * Gets the value of a static or instance field of type
8.518 + * {@code float} or of another primitive type convertible to
8.519 + * type {@code float} via a widening conversion.
8.520 + *
8.521 + * @param obj the object to extract the {@code float} value
8.522 + * from
8.523 + * @return the value of the field converted to type {@code float}
8.524 + *
8.525 + * @exception IllegalAccessException if this {@code Field} object
8.526 + * is enforcing Java language access control and the underlying
8.527 + * field is inaccessible.
8.528 + * @exception IllegalArgumentException if the specified object is not
8.529 + * an instance of the class or interface declaring the
8.530 + * underlying field (or a subclass or implementor
8.531 + * thereof), or if the field value cannot be
8.532 + * converted to the type {@code float} by a
8.533 + * widening conversion.
8.534 + * @exception NullPointerException if the specified object is null
8.535 + * and the field is an instance field.
8.536 + * @exception ExceptionInInitializerError if the initialization provoked
8.537 + * by this method fails.
8.538 + * @see Field#get
8.539 + */
8.540 + public float getFloat(Object obj)
8.541 + throws IllegalArgumentException, IllegalAccessException
8.542 + {
8.543 + return getFieldAccessor(obj).getFloat(obj);
8.544 + }
8.545 +
8.546 + /**
8.547 + * Gets the value of a static or instance field of type
8.548 + * {@code double} or of another primitive type convertible to
8.549 + * type {@code double} via a widening conversion.
8.550 + *
8.551 + * @param obj the object to extract the {@code double} value
8.552 + * from
8.553 + * @return the value of the field converted to type {@code double}
8.554 + *
8.555 + * @exception IllegalAccessException if this {@code Field} object
8.556 + * is enforcing Java language access control and the underlying
8.557 + * field is inaccessible.
8.558 + * @exception IllegalArgumentException if the specified object is not
8.559 + * an instance of the class or interface declaring the
8.560 + * underlying field (or a subclass or implementor
8.561 + * thereof), or if the field value cannot be
8.562 + * converted to the type {@code double} by a
8.563 + * widening conversion.
8.564 + * @exception NullPointerException if the specified object is null
8.565 + * and the field is an instance field.
8.566 + * @exception ExceptionInInitializerError if the initialization provoked
8.567 + * by this method fails.
8.568 + * @see Field#get
8.569 + */
8.570 + public double getDouble(Object obj)
8.571 + throws IllegalArgumentException, IllegalAccessException
8.572 + {
8.573 + return getFieldAccessor(obj).getDouble(obj);
8.574 + }
8.575 +
8.576 + /**
8.577 + * Sets the field represented by this {@code Field} object on the
8.578 + * specified object argument to the specified new value. The new
8.579 + * value is automatically unwrapped if the underlying field has a
8.580 + * primitive type.
8.581 + *
8.582 + * <p>The operation proceeds as follows:
8.583 + *
8.584 + * <p>If the underlying field is static, the {@code obj} argument is
8.585 + * ignored; it may be null.
8.586 + *
8.587 + * <p>Otherwise the underlying field is an instance field. If the
8.588 + * specified object argument is null, the method throws a
8.589 + * {@code NullPointerException}. If the specified object argument is not
8.590 + * an instance of the class or interface declaring the underlying
8.591 + * field, the method throws an {@code IllegalArgumentException}.
8.592 + *
8.593 + * <p>If this {@code Field} object is enforcing Java language access control, and
8.594 + * the underlying field is inaccessible, the method throws an
8.595 + * {@code IllegalAccessException}.
8.596 + *
8.597 + * <p>If the underlying field is final, the method throws an
8.598 + * {@code IllegalAccessException} unless {@code setAccessible(true)}
8.599 + * has succeeded for this {@code Field} object
8.600 + * and the field is non-static. Setting a final field in this way
8.601 + * is meaningful only during deserialization or reconstruction of
8.602 + * instances of classes with blank final fields, before they are
8.603 + * made available for access by other parts of a program. Use in
8.604 + * any other context may have unpredictable effects, including cases
8.605 + * in which other parts of a program continue to use the original
8.606 + * value of this field.
8.607 + *
8.608 + * <p>If the underlying field is of a primitive type, an unwrapping
8.609 + * conversion is attempted to convert the new value to a value of
8.610 + * a primitive type. If this attempt fails, the method throws an
8.611 + * {@code IllegalArgumentException}.
8.612 + *
8.613 + * <p>If, after possible unwrapping, the new value cannot be
8.614 + * converted to the type of the underlying field by an identity or
8.615 + * widening conversion, the method throws an
8.616 + * {@code IllegalArgumentException}.
8.617 + *
8.618 + * <p>If the underlying field is static, the class that declared the
8.619 + * field is initialized if it has not already been initialized.
8.620 + *
8.621 + * <p>The field is set to the possibly unwrapped and widened new value.
8.622 + *
8.623 + * <p>If the field is hidden in the type of {@code obj},
8.624 + * the field's value is set according to the preceding rules.
8.625 + *
8.626 + * @param obj the object whose field should be modified
8.627 + * @param value the new value for the field of {@code obj}
8.628 + * being modified
8.629 + *
8.630 + * @exception IllegalAccessException if this {@code Field} object
8.631 + * is enforcing Java language access control and the underlying
8.632 + * field is either inaccessible or final.
8.633 + * @exception IllegalArgumentException if the specified object is not an
8.634 + * instance of the class or interface declaring the underlying
8.635 + * field (or a subclass or implementor thereof),
8.636 + * or if an unwrapping conversion fails.
8.637 + * @exception NullPointerException if the specified object is null
8.638 + * and the field is an instance field.
8.639 + * @exception ExceptionInInitializerError if the initialization provoked
8.640 + * by this method fails.
8.641 + */
8.642 + public void set(Object obj, Object value)
8.643 + throws IllegalArgumentException, IllegalAccessException
8.644 + {
8.645 + getFieldAccessor(obj).set(obj, value);
8.646 + }
8.647 +
8.648 + /**
8.649 + * Sets the value of a field as a {@code boolean} on the specified object.
8.650 + * This method is equivalent to
8.651 + * {@code set(obj, zObj)},
8.652 + * where {@code zObj} is a {@code Boolean} object and
8.653 + * {@code zObj.booleanValue() == z}.
8.654 + *
8.655 + * @param obj the object whose field should be modified
8.656 + * @param z the new value for the field of {@code obj}
8.657 + * being modified
8.658 + *
8.659 + * @exception IllegalAccessException if this {@code Field} object
8.660 + * is enforcing Java language access control and the underlying
8.661 + * field is either inaccessible or final.
8.662 + * @exception IllegalArgumentException if the specified object is not an
8.663 + * instance of the class or interface declaring the underlying
8.664 + * field (or a subclass or implementor thereof),
8.665 + * or if an unwrapping conversion fails.
8.666 + * @exception NullPointerException if the specified object is null
8.667 + * and the field is an instance field.
8.668 + * @exception ExceptionInInitializerError if the initialization provoked
8.669 + * by this method fails.
8.670 + * @see Field#set
8.671 + */
8.672 + public void setBoolean(Object obj, boolean z)
8.673 + throws IllegalArgumentException, IllegalAccessException
8.674 + {
8.675 + getFieldAccessor(obj).setBoolean(obj, z);
8.676 + }
8.677 +
8.678 + /**
8.679 + * Sets the value of a field as a {@code byte} on the specified object.
8.680 + * This method is equivalent to
8.681 + * {@code set(obj, bObj)},
8.682 + * where {@code bObj} is a {@code Byte} object and
8.683 + * {@code bObj.byteValue() == b}.
8.684 + *
8.685 + * @param obj the object whose field should be modified
8.686 + * @param b the new value for the field of {@code obj}
8.687 + * being modified
8.688 + *
8.689 + * @exception IllegalAccessException if this {@code Field} object
8.690 + * is enforcing Java language access control and the underlying
8.691 + * field is either inaccessible or final.
8.692 + * @exception IllegalArgumentException if the specified object is not an
8.693 + * instance of the class or interface declaring the underlying
8.694 + * field (or a subclass or implementor thereof),
8.695 + * or if an unwrapping conversion fails.
8.696 + * @exception NullPointerException if the specified object is null
8.697 + * and the field is an instance field.
8.698 + * @exception ExceptionInInitializerError if the initialization provoked
8.699 + * by this method fails.
8.700 + * @see Field#set
8.701 + */
8.702 + public void setByte(Object obj, byte b)
8.703 + throws IllegalArgumentException, IllegalAccessException
8.704 + {
8.705 + getFieldAccessor(obj).setByte(obj, b);
8.706 + }
8.707 +
8.708 + /**
8.709 + * Sets the value of a field as a {@code char} on the specified object.
8.710 + * This method is equivalent to
8.711 + * {@code set(obj, cObj)},
8.712 + * where {@code cObj} is a {@code Character} object and
8.713 + * {@code cObj.charValue() == c}.
8.714 + *
8.715 + * @param obj the object whose field should be modified
8.716 + * @param c the new value for the field of {@code obj}
8.717 + * being modified
8.718 + *
8.719 + * @exception IllegalAccessException if this {@code Field} object
8.720 + * is enforcing Java language access control and the underlying
8.721 + * field is either inaccessible or final.
8.722 + * @exception IllegalArgumentException if the specified object is not an
8.723 + * instance of the class or interface declaring the underlying
8.724 + * field (or a subclass or implementor thereof),
8.725 + * or if an unwrapping conversion fails.
8.726 + * @exception NullPointerException if the specified object is null
8.727 + * and the field is an instance field.
8.728 + * @exception ExceptionInInitializerError if the initialization provoked
8.729 + * by this method fails.
8.730 + * @see Field#set
8.731 + */
8.732 + public void setChar(Object obj, char c)
8.733 + throws IllegalArgumentException, IllegalAccessException
8.734 + {
8.735 + getFieldAccessor(obj).setChar(obj, c);
8.736 + }
8.737 +
8.738 + /**
8.739 + * Sets the value of a field as a {@code short} on the specified object.
8.740 + * This method is equivalent to
8.741 + * {@code set(obj, sObj)},
8.742 + * where {@code sObj} is a {@code Short} object and
8.743 + * {@code sObj.shortValue() == s}.
8.744 + *
8.745 + * @param obj the object whose field should be modified
8.746 + * @param s the new value for the field of {@code obj}
8.747 + * being modified
8.748 + *
8.749 + * @exception IllegalAccessException if this {@code Field} object
8.750 + * is enforcing Java language access control and the underlying
8.751 + * field is either inaccessible or final.
8.752 + * @exception IllegalArgumentException if the specified object is not an
8.753 + * instance of the class or interface declaring the underlying
8.754 + * field (or a subclass or implementor thereof),
8.755 + * or if an unwrapping conversion fails.
8.756 + * @exception NullPointerException if the specified object is null
8.757 + * and the field is an instance field.
8.758 + * @exception ExceptionInInitializerError if the initialization provoked
8.759 + * by this method fails.
8.760 + * @see Field#set
8.761 + */
8.762 + public void setShort(Object obj, short s)
8.763 + throws IllegalArgumentException, IllegalAccessException
8.764 + {
8.765 + getFieldAccessor(obj).setShort(obj, s);
8.766 + }
8.767 +
8.768 + /**
8.769 + * Sets the value of a field as an {@code int} on the specified object.
8.770 + * This method is equivalent to
8.771 + * {@code set(obj, iObj)},
8.772 + * where {@code iObj} is a {@code Integer} object and
8.773 + * {@code iObj.intValue() == i}.
8.774 + *
8.775 + * @param obj the object whose field should be modified
8.776 + * @param i the new value for the field of {@code obj}
8.777 + * being modified
8.778 + *
8.779 + * @exception IllegalAccessException if this {@code Field} object
8.780 + * is enforcing Java language access control and the underlying
8.781 + * field is either inaccessible or final.
8.782 + * @exception IllegalArgumentException if the specified object is not an
8.783 + * instance of the class or interface declaring the underlying
8.784 + * field (or a subclass or implementor thereof),
8.785 + * or if an unwrapping conversion fails.
8.786 + * @exception NullPointerException if the specified object is null
8.787 + * and the field is an instance field.
8.788 + * @exception ExceptionInInitializerError if the initialization provoked
8.789 + * by this method fails.
8.790 + * @see Field#set
8.791 + */
8.792 + public void setInt(Object obj, int i)
8.793 + throws IllegalArgumentException, IllegalAccessException
8.794 + {
8.795 + getFieldAccessor(obj).setInt(obj, i);
8.796 + }
8.797 +
8.798 + /**
8.799 + * Sets the value of a field as a {@code long} on the specified object.
8.800 + * This method is equivalent to
8.801 + * {@code set(obj, lObj)},
8.802 + * where {@code lObj} is a {@code Long} object and
8.803 + * {@code lObj.longValue() == l}.
8.804 + *
8.805 + * @param obj the object whose field should be modified
8.806 + * @param l the new value for the field of {@code obj}
8.807 + * being modified
8.808 + *
8.809 + * @exception IllegalAccessException if this {@code Field} object
8.810 + * is enforcing Java language access control and the underlying
8.811 + * field is either inaccessible or final.
8.812 + * @exception IllegalArgumentException if the specified object is not an
8.813 + * instance of the class or interface declaring the underlying
8.814 + * field (or a subclass or implementor thereof),
8.815 + * or if an unwrapping conversion fails.
8.816 + * @exception NullPointerException if the specified object is null
8.817 + * and the field is an instance field.
8.818 + * @exception ExceptionInInitializerError if the initialization provoked
8.819 + * by this method fails.
8.820 + * @see Field#set
8.821 + */
8.822 + public void setLong(Object obj, long l)
8.823 + throws IllegalArgumentException, IllegalAccessException
8.824 + {
8.825 + getFieldAccessor(obj).setLong(obj, l);
8.826 + }
8.827 +
8.828 + /**
8.829 + * Sets the value of a field as a {@code float} on the specified object.
8.830 + * This method is equivalent to
8.831 + * {@code set(obj, fObj)},
8.832 + * where {@code fObj} is a {@code Float} object and
8.833 + * {@code fObj.floatValue() == f}.
8.834 + *
8.835 + * @param obj the object whose field should be modified
8.836 + * @param f the new value for the field of {@code obj}
8.837 + * being modified
8.838 + *
8.839 + * @exception IllegalAccessException if this {@code Field} object
8.840 + * is enforcing Java language access control and the underlying
8.841 + * field is either inaccessible or final.
8.842 + * @exception IllegalArgumentException if the specified object is not an
8.843 + * instance of the class or interface declaring the underlying
8.844 + * field (or a subclass or implementor thereof),
8.845 + * or if an unwrapping conversion fails.
8.846 + * @exception NullPointerException if the specified object is null
8.847 + * and the field is an instance field.
8.848 + * @exception ExceptionInInitializerError if the initialization provoked
8.849 + * by this method fails.
8.850 + * @see Field#set
8.851 + */
8.852 + public void setFloat(Object obj, float f)
8.853 + throws IllegalArgumentException, IllegalAccessException
8.854 + {
8.855 + getFieldAccessor(obj).setFloat(obj, f);
8.856 + }
8.857 +
8.858 + /**
8.859 + * Sets the value of a field as a {@code double} on the specified object.
8.860 + * This method is equivalent to
8.861 + * {@code set(obj, dObj)},
8.862 + * where {@code dObj} is a {@code Double} object and
8.863 + * {@code dObj.doubleValue() == d}.
8.864 + *
8.865 + * @param obj the object whose field should be modified
8.866 + * @param d the new value for the field of {@code obj}
8.867 + * being modified
8.868 + *
8.869 + * @exception IllegalAccessException if this {@code Field} object
8.870 + * is enforcing Java language access control and the underlying
8.871 + * field is either inaccessible or final.
8.872 + * @exception IllegalArgumentException if the specified object is not an
8.873 + * instance of the class or interface declaring the underlying
8.874 + * field (or a subclass or implementor thereof),
8.875 + * or if an unwrapping conversion fails.
8.876 + * @exception NullPointerException if the specified object is null
8.877 + * and the field is an instance field.
8.878 + * @exception ExceptionInInitializerError if the initialization provoked
8.879 + * by this method fails.
8.880 + * @see Field#set
8.881 + */
8.882 + public void setDouble(Object obj, double d)
8.883 + throws IllegalArgumentException, IllegalAccessException
8.884 + {
8.885 + getFieldAccessor(obj).setDouble(obj, d);
8.886 + }
8.887 +
8.888 + // Convenience routine which performs security checks
8.889 + private FieldAccessor getFieldAccessor(Object obj)
8.890 + throws IllegalAccessException
8.891 + {
8.892 + throw new SecurityException();
8.893 + }
8.894 +
8.895 + private static abstract class FieldAccessor {
8.896 + abstract void setShort(Object obj, short s);
8.897 + abstract void setInt(Object obj, int i);
8.898 + abstract void setChar(Object obj, char c);
8.899 + abstract void setByte(Object obj, byte b);
8.900 + abstract void setBoolean(Object obj, boolean z);
8.901 + abstract void set(Object obj, Object value);
8.902 + abstract double getDouble(Object obj);
8.903 + abstract void setLong(Object obj, long l);
8.904 + abstract void setFloat(Object obj, float f);
8.905 + abstract void setDouble(Object obj, double d);
8.906 + abstract long getLong(Object obj);
8.907 + abstract int getInt(Object obj);
8.908 + abstract short getShort(Object obj);
8.909 + abstract char getChar(Object obj);
8.910 + abstract byte getByte(Object obj);
8.911 + abstract boolean getBoolean(Object obj);
8.912 + abstract Object get(Object obj);
8.913 + abstract float getFloat(Object obj);
8.914 + }
8.915 +
8.916 + /*
8.917 + * Utility routine to paper over array type names
8.918 + */
8.919 + static String getTypeName(Class<?> type) {
8.920 + if (type.isArray()) {
8.921 + try {
8.922 + Class<?> cl = type;
8.923 + int dimensions = 0;
8.924 + while (cl.isArray()) {
8.925 + dimensions++;
8.926 + cl = cl.getComponentType();
8.927 + }
8.928 + StringBuffer sb = new StringBuffer();
8.929 + sb.append(cl.getName());
8.930 + for (int i = 0; i < dimensions; i++) {
8.931 + sb.append("[]");
8.932 + }
8.933 + return sb.toString();
8.934 + } catch (Throwable e) { /*FALLTHRU*/ }
8.935 + }
8.936 + return type.getName();
8.937 + }
8.938 +
8.939 + /**
8.940 + * @throws NullPointerException {@inheritDoc}
8.941 + * @since 1.5
8.942 + */
8.943 + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
8.944 + if (annotationClass == null)
8.945 + throw new NullPointerException();
8.946 +
8.947 + throw new UnsupportedOperationException();
8.948 + }
8.949 +
8.950 + /**
8.951 + * @since 1.5
8.952 + */
8.953 + public Annotation[] getDeclaredAnnotations() {
8.954 + throw new UnsupportedOperationException();
8.955 + }
8.956 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
9.2 +++ b/emul/src/main/java/java/lang/reflect/GenericDeclaration.java Fri Dec 07 15:57:14 2012 +0100
9.3 @@ -0,0 +1,49 @@
9.4 +/*
9.5 + * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9.7 + *
9.8 + * This code is free software; you can redistribute it and/or modify it
9.9 + * under the terms of the GNU General Public License version 2 only, as
9.10 + * published by the Free Software Foundation. Oracle designates this
9.11 + * particular file as subject to the "Classpath" exception as provided
9.12 + * by Oracle in the LICENSE file that accompanied this code.
9.13 + *
9.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
9.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9.17 + * version 2 for more details (a copy is included in the LICENSE file that
9.18 + * accompanied this code).
9.19 + *
9.20 + * You should have received a copy of the GNU General Public License version
9.21 + * 2 along with this work; if not, write to the Free Software Foundation,
9.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9.23 + *
9.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9.25 + * or visit www.oracle.com if you need additional information or have any
9.26 + * questions.
9.27 + */
9.28 +
9.29 +package java.lang.reflect;
9.30 +
9.31 +/**
9.32 + * A common interface for all entities that declare type variables.
9.33 + *
9.34 + * @since 1.5
9.35 + */
9.36 +public interface GenericDeclaration {
9.37 + /**
9.38 + * Returns an array of {@code TypeVariable} objects that
9.39 + * represent the type variables declared by the generic
9.40 + * declaration represented by this {@code GenericDeclaration}
9.41 + * object, in declaration order. Returns an array of length 0 if
9.42 + * the underlying generic declaration declares no type variables.
9.43 + *
9.44 + * @return an array of {@code TypeVariable} objects that represent
9.45 + * the type variables declared by this generic declaration
9.46 + * @throws GenericSignatureFormatError if the generic
9.47 + * signature of this generic declaration does not conform to
9.48 + * the format specified in
9.49 + * <cite>The Java™ Virtual Machine Specification</cite>
9.50 + */
9.51 + public TypeVariable<?>[] getTypeParameters();
9.52 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
10.2 +++ b/emul/src/main/java/java/lang/reflect/InvocationTargetException.java Fri Dec 07 15:57:14 2012 +0100
10.3 @@ -0,0 +1,111 @@
10.4 +/*
10.5 + * Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
10.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
10.7 + *
10.8 + * This code is free software; you can redistribute it and/or modify it
10.9 + * under the terms of the GNU General Public License version 2 only, as
10.10 + * published by the Free Software Foundation. Oracle designates this
10.11 + * particular file as subject to the "Classpath" exception as provided
10.12 + * by Oracle in the LICENSE file that accompanied this code.
10.13 + *
10.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
10.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
10.17 + * version 2 for more details (a copy is included in the LICENSE file that
10.18 + * accompanied this code).
10.19 + *
10.20 + * You should have received a copy of the GNU General Public License version
10.21 + * 2 along with this work; if not, write to the Free Software Foundation,
10.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
10.23 + *
10.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
10.25 + * or visit www.oracle.com if you need additional information or have any
10.26 + * questions.
10.27 + */
10.28 +
10.29 +package java.lang.reflect;
10.30 +
10.31 +/**
10.32 + * InvocationTargetException is a checked exception that wraps
10.33 + * an exception thrown by an invoked method or constructor.
10.34 + *
10.35 + * <p>As of release 1.4, this exception has been retrofitted to conform to
10.36 + * the general purpose exception-chaining mechanism. The "target exception"
10.37 + * that is provided at construction time and accessed via the
10.38 + * {@link #getTargetException()} method is now known as the <i>cause</i>,
10.39 + * and may be accessed via the {@link Throwable#getCause()} method,
10.40 + * as well as the aforementioned "legacy method."
10.41 + *
10.42 + * @see Method
10.43 + * @see Constructor
10.44 + */
10.45 +public class InvocationTargetException extends ReflectiveOperationException {
10.46 + /**
10.47 + * Use serialVersionUID from JDK 1.1.X for interoperability
10.48 + */
10.49 + private static final long serialVersionUID = 4085088731926701167L;
10.50 +
10.51 + /**
10.52 + * This field holds the target if the
10.53 + * InvocationTargetException(Throwable target) constructor was
10.54 + * used to instantiate the object
10.55 + *
10.56 + * @serial
10.57 + *
10.58 + */
10.59 + private Throwable target;
10.60 +
10.61 + /**
10.62 + * Constructs an {@code InvocationTargetException} with
10.63 + * {@code null} as the target exception.
10.64 + */
10.65 + protected InvocationTargetException() {
10.66 + super((Throwable)null); // Disallow initCause
10.67 + }
10.68 +
10.69 + /**
10.70 + * Constructs a InvocationTargetException with a target exception.
10.71 + *
10.72 + * @param target the target exception
10.73 + */
10.74 + public InvocationTargetException(Throwable target) {
10.75 + super((Throwable)null); // Disallow initCause
10.76 + this.target = target;
10.77 + }
10.78 +
10.79 + /**
10.80 + * Constructs a InvocationTargetException with a target exception
10.81 + * and a detail message.
10.82 + *
10.83 + * @param target the target exception
10.84 + * @param s the detail message
10.85 + */
10.86 + public InvocationTargetException(Throwable target, String s) {
10.87 + super(s, null); // Disallow initCause
10.88 + this.target = target;
10.89 + }
10.90 +
10.91 + /**
10.92 + * Get the thrown target exception.
10.93 + *
10.94 + * <p>This method predates the general-purpose exception chaining facility.
10.95 + * The {@link Throwable#getCause()} method is now the preferred means of
10.96 + * obtaining this information.
10.97 + *
10.98 + * @return the thrown target exception (cause of this exception).
10.99 + */
10.100 + public Throwable getTargetException() {
10.101 + return target;
10.102 + }
10.103 +
10.104 + /**
10.105 + * Returns the cause of this exception (the thrown target exception,
10.106 + * which may be {@code null}).
10.107 + *
10.108 + * @return the cause of this exception.
10.109 + * @since 1.4
10.110 + */
10.111 + public Throwable getCause() {
10.112 + return target;
10.113 + }
10.114 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
11.2 +++ b/emul/src/main/java/java/lang/reflect/Member.java Fri Dec 07 15:57:14 2012 +0100
11.3 @@ -0,0 +1,93 @@
11.4 +/*
11.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
11.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
11.7 + *
11.8 + * This code is free software; you can redistribute it and/or modify it
11.9 + * under the terms of the GNU General Public License version 2 only, as
11.10 + * published by the Free Software Foundation. Oracle designates this
11.11 + * particular file as subject to the "Classpath" exception as provided
11.12 + * by Oracle in the LICENSE file that accompanied this code.
11.13 + *
11.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
11.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11.17 + * version 2 for more details (a copy is included in the LICENSE file that
11.18 + * accompanied this code).
11.19 + *
11.20 + * You should have received a copy of the GNU General Public License version
11.21 + * 2 along with this work; if not, write to the Free Software Foundation,
11.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
11.23 + *
11.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
11.25 + * or visit www.oracle.com if you need additional information or have any
11.26 + * questions.
11.27 + */
11.28 +
11.29 +package java.lang.reflect;
11.30 +
11.31 +/**
11.32 + * Member is an interface that reflects identifying information about
11.33 + * a single member (a field or a method) or a constructor.
11.34 + *
11.35 + * @see java.lang.Class
11.36 + * @see Field
11.37 + * @see Method
11.38 + * @see Constructor
11.39 + *
11.40 + * @author Nakul Saraiya
11.41 + */
11.42 +public
11.43 +interface Member {
11.44 +
11.45 + /**
11.46 + * Identifies the set of all public members of a class or interface,
11.47 + * including inherited members.
11.48 + * @see java.lang.SecurityManager#checkMemberAccess
11.49 + */
11.50 + public static final int PUBLIC = 0;
11.51 +
11.52 + /**
11.53 + * Identifies the set of declared members of a class or interface.
11.54 + * Inherited members are not included.
11.55 + * @see java.lang.SecurityManager#checkMemberAccess
11.56 + */
11.57 + public static final int DECLARED = 1;
11.58 +
11.59 + /**
11.60 + * Returns the Class object representing the class or interface
11.61 + * that declares the member or constructor represented by this Member.
11.62 + *
11.63 + * @return an object representing the declaring class of the
11.64 + * underlying member
11.65 + */
11.66 + public Class<?> getDeclaringClass();
11.67 +
11.68 + /**
11.69 + * Returns the simple name of the underlying member or constructor
11.70 + * represented by this Member.
11.71 + *
11.72 + * @return the simple name of the underlying member
11.73 + */
11.74 + public String getName();
11.75 +
11.76 + /**
11.77 + * Returns the Java language modifiers for the member or
11.78 + * constructor represented by this Member, as an integer. The
11.79 + * Modifier class should be used to decode the modifiers in
11.80 + * the integer.
11.81 + *
11.82 + * @return the Java language modifiers for the underlying member
11.83 + * @see Modifier
11.84 + */
11.85 + public int getModifiers();
11.86 +
11.87 + /**
11.88 + * Returns {@code true} if this member was introduced by
11.89 + * the compiler; returns {@code false} otherwise.
11.90 + *
11.91 + * @return true if and only if this member was introduced by
11.92 + * the compiler.
11.93 + * @since 1.5
11.94 + */
11.95 + public boolean isSynthetic();
11.96 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
12.2 +++ b/emul/src/main/java/java/lang/reflect/Method.java Fri Dec 07 15:57:14 2012 +0100
12.3 @@ -0,0 +1,655 @@
12.4 +/*
12.5 + * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
12.7 + *
12.8 + * This code is free software; you can redistribute it and/or modify it
12.9 + * under the terms of the GNU General Public License version 2 only, as
12.10 + * published by the Free Software Foundation. Oracle designates this
12.11 + * particular file as subject to the "Classpath" exception as provided
12.12 + * by Oracle in the LICENSE file that accompanied this code.
12.13 + *
12.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
12.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12.17 + * version 2 for more details (a copy is included in the LICENSE file that
12.18 + * accompanied this code).
12.19 + *
12.20 + * You should have received a copy of the GNU General Public License version
12.21 + * 2 along with this work; if not, write to the Free Software Foundation,
12.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
12.23 + *
12.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
12.25 + * or visit www.oracle.com if you need additional information or have any
12.26 + * questions.
12.27 + */
12.28 +
12.29 +package java.lang.reflect;
12.30 +
12.31 +import java.lang.annotation.Annotation;
12.32 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
12.33 +import org.apidesign.bck2brwsr.emul.AnnotationImpl;
12.34 +
12.35 +/**
12.36 + * A {@code Method} provides information about, and access to, a single method
12.37 + * on a class or interface. The reflected method may be a class method
12.38 + * or an instance method (including an abstract method).
12.39 + *
12.40 + * <p>A {@code Method} permits widening conversions to occur when matching the
12.41 + * actual parameters to invoke with the underlying method's formal
12.42 + * parameters, but it throws an {@code IllegalArgumentException} if a
12.43 + * narrowing conversion would occur.
12.44 + *
12.45 + * @see Member
12.46 + * @see java.lang.Class
12.47 + * @see java.lang.Class#getMethods()
12.48 + * @see java.lang.Class#getMethod(String, Class[])
12.49 + * @see java.lang.Class#getDeclaredMethods()
12.50 + * @see java.lang.Class#getDeclaredMethod(String, Class[])
12.51 + *
12.52 + * @author Kenneth Russell
12.53 + * @author Nakul Saraiya
12.54 + */
12.55 +public final
12.56 + class Method extends AccessibleObject implements GenericDeclaration,
12.57 + Member {
12.58 + private final Class<?> clazz;
12.59 + private final String name;
12.60 + private final Object data;
12.61 + private final String sig;
12.62 + private int modifiers;
12.63 +
12.64 + // Generics infrastructure
12.65 +
12.66 + private String getGenericSignature() {return null;}
12.67 +
12.68 + /**
12.69 + * Package-private constructor used by ReflectAccess to enable
12.70 + * instantiation of these objects in Java code from the java.lang
12.71 + * package via sun.reflect.LangReflectAccess.
12.72 + */
12.73 + Method(Class<?> declaringClass, String name, Object data, String sig)
12.74 + {
12.75 + this.clazz = declaringClass;
12.76 + this.name = name;
12.77 + this.data = data;
12.78 + this.sig = sig;
12.79 + }
12.80 +
12.81 + /**
12.82 + * Package-private routine (exposed to java.lang.Class via
12.83 + * ReflectAccess) which returns a copy of this Method. The copy's
12.84 + * "root" field points to this Method.
12.85 + */
12.86 + Method copy() {
12.87 + return this;
12.88 + }
12.89 +
12.90 + /**
12.91 + * Returns the {@code Class} object representing the class or interface
12.92 + * that declares the method represented by this {@code Method} object.
12.93 + */
12.94 + public Class<?> getDeclaringClass() {
12.95 + return clazz;
12.96 + }
12.97 +
12.98 + /**
12.99 + * Returns the name of the method represented by this {@code Method}
12.100 + * object, as a {@code String}.
12.101 + */
12.102 + public String getName() {
12.103 + return name;
12.104 + }
12.105 +
12.106 + /**
12.107 + * Returns the Java language modifiers for the method represented
12.108 + * by this {@code Method} object, as an integer. The {@code Modifier} class should
12.109 + * be used to decode the modifiers.
12.110 + *
12.111 + * @see Modifier
12.112 + */
12.113 + public int getModifiers() {
12.114 + return modifiers;
12.115 + }
12.116 +
12.117 + /**
12.118 + * Returns an array of {@code TypeVariable} objects that represent the
12.119 + * type variables declared by the generic declaration represented by this
12.120 + * {@code GenericDeclaration} object, in declaration order. Returns an
12.121 + * array of length 0 if the underlying generic declaration declares no type
12.122 + * variables.
12.123 + *
12.124 + * @return an array of {@code TypeVariable} objects that represent
12.125 + * the type variables declared by this generic declaration
12.126 + * @throws GenericSignatureFormatError if the generic
12.127 + * signature of this generic declaration does not conform to
12.128 + * the format specified in
12.129 + * <cite>The Java™ Virtual Machine Specification</cite>
12.130 + * @since 1.5
12.131 + */
12.132 + public TypeVariable<Method>[] getTypeParameters() {
12.133 + throw new UnsupportedOperationException();
12.134 + }
12.135 +
12.136 + /**
12.137 + * Returns a {@code Class} object that represents the formal return type
12.138 + * of the method represented by this {@code Method} object.
12.139 + *
12.140 + * @return the return type for the method this object represents
12.141 + */
12.142 + public Class<?> getReturnType() {
12.143 + throw new UnsupportedOperationException();
12.144 + }
12.145 +
12.146 + /**
12.147 + * Returns a {@code Type} object that represents the formal return
12.148 + * type of the method represented by this {@code Method} object.
12.149 + *
12.150 + * <p>If the return type is a parameterized type,
12.151 + * the {@code Type} object returned must accurately reflect
12.152 + * the actual type parameters used in the source code.
12.153 + *
12.154 + * <p>If the return type is a type variable or a parameterized type, it
12.155 + * is created. Otherwise, it is resolved.
12.156 + *
12.157 + * @return a {@code Type} object that represents the formal return
12.158 + * type of the underlying method
12.159 + * @throws GenericSignatureFormatError
12.160 + * if the generic method signature does not conform to the format
12.161 + * specified in
12.162 + * <cite>The Java™ Virtual Machine Specification</cite>
12.163 + * @throws TypeNotPresentException if the underlying method's
12.164 + * return type refers to a non-existent type declaration
12.165 + * @throws MalformedParameterizedTypeException if the
12.166 + * underlying method's return typed refers to a parameterized
12.167 + * type that cannot be instantiated for any reason
12.168 + * @since 1.5
12.169 + */
12.170 + public Type getGenericReturnType() {
12.171 + throw new UnsupportedOperationException();
12.172 + }
12.173 +
12.174 +
12.175 + /**
12.176 + * Returns an array of {@code Class} objects that represent the formal
12.177 + * parameter types, in declaration order, of the method
12.178 + * represented by this {@code Method} object. Returns an array of length
12.179 + * 0 if the underlying method takes no parameters.
12.180 + *
12.181 + * @return the parameter types for the method this object
12.182 + * represents
12.183 + */
12.184 + public Class<?>[] getParameterTypes() {
12.185 + throw new UnsupportedOperationException();
12.186 + //return (Class<?>[]) parameterTypes.clone();
12.187 + }
12.188 +
12.189 + /**
12.190 + * Returns an array of {@code Type} objects that represent the formal
12.191 + * parameter types, in declaration order, of the method represented by
12.192 + * this {@code Method} object. Returns an array of length 0 if the
12.193 + * underlying method takes no parameters.
12.194 + *
12.195 + * <p>If a formal parameter type is a parameterized type,
12.196 + * the {@code Type} object returned for it must accurately reflect
12.197 + * the actual type parameters used in the source code.
12.198 + *
12.199 + * <p>If a formal parameter type is a type variable or a parameterized
12.200 + * type, it is created. Otherwise, it is resolved.
12.201 + *
12.202 + * @return an array of Types that represent the formal
12.203 + * parameter types of the underlying method, in declaration order
12.204 + * @throws GenericSignatureFormatError
12.205 + * if the generic method signature does not conform to the format
12.206 + * specified in
12.207 + * <cite>The Java™ Virtual Machine Specification</cite>
12.208 + * @throws TypeNotPresentException if any of the parameter
12.209 + * types of the underlying method refers to a non-existent type
12.210 + * declaration
12.211 + * @throws MalformedParameterizedTypeException if any of
12.212 + * the underlying method's parameter types refer to a parameterized
12.213 + * type that cannot be instantiated for any reason
12.214 + * @since 1.5
12.215 + */
12.216 + public Type[] getGenericParameterTypes() {
12.217 + throw new UnsupportedOperationException();
12.218 + }
12.219 +
12.220 +
12.221 + /**
12.222 + * Returns an array of {@code Class} objects that represent
12.223 + * the types of the exceptions declared to be thrown
12.224 + * by the underlying method
12.225 + * represented by this {@code Method} object. Returns an array of length
12.226 + * 0 if the method declares no exceptions in its {@code throws} clause.
12.227 + *
12.228 + * @return the exception types declared as being thrown by the
12.229 + * method this object represents
12.230 + */
12.231 + public Class<?>[] getExceptionTypes() {
12.232 + throw new UnsupportedOperationException();
12.233 + //return (Class<?>[]) exceptionTypes.clone();
12.234 + }
12.235 +
12.236 + /**
12.237 + * Returns an array of {@code Type} objects that represent the
12.238 + * exceptions declared to be thrown by this {@code Method} object.
12.239 + * Returns an array of length 0 if the underlying method declares
12.240 + * no exceptions in its {@code throws} clause.
12.241 + *
12.242 + * <p>If an exception type is a type variable or a parameterized
12.243 + * type, it is created. Otherwise, it is resolved.
12.244 + *
12.245 + * @return an array of Types that represent the exception types
12.246 + * thrown by the underlying method
12.247 + * @throws GenericSignatureFormatError
12.248 + * if the generic method signature does not conform to the format
12.249 + * specified in
12.250 + * <cite>The Java™ Virtual Machine Specification</cite>
12.251 + * @throws TypeNotPresentException if the underlying method's
12.252 + * {@code throws} clause refers to a non-existent type declaration
12.253 + * @throws MalformedParameterizedTypeException if
12.254 + * the underlying method's {@code throws} clause refers to a
12.255 + * parameterized type that cannot be instantiated for any reason
12.256 + * @since 1.5
12.257 + */
12.258 + public Type[] getGenericExceptionTypes() {
12.259 + throw new UnsupportedOperationException();
12.260 + }
12.261 +
12.262 + /**
12.263 + * Compares this {@code Method} against the specified object. Returns
12.264 + * true if the objects are the same. Two {@code Methods} are the same if
12.265 + * they were declared by the same class and have the same name
12.266 + * and formal parameter types and return type.
12.267 + */
12.268 + public boolean equals(Object obj) {
12.269 + if (obj != null && obj instanceof Method) {
12.270 + Method other = (Method)obj;
12.271 + return data == other.data;
12.272 + }
12.273 + return false;
12.274 + }
12.275 +
12.276 + /**
12.277 + * Returns a hashcode for this {@code Method}. The hashcode is computed
12.278 + * as the exclusive-or of the hashcodes for the underlying
12.279 + * method's declaring class name and the method's name.
12.280 + */
12.281 + public int hashCode() {
12.282 + return getDeclaringClass().getName().hashCode() ^ getName().hashCode();
12.283 + }
12.284 +
12.285 + /**
12.286 + * Returns a string describing this {@code Method}. The string is
12.287 + * formatted as the method access modifiers, if any, followed by
12.288 + * the method return type, followed by a space, followed by the
12.289 + * class declaring the method, followed by a period, followed by
12.290 + * the method name, followed by a parenthesized, comma-separated
12.291 + * list of the method's formal parameter types. If the method
12.292 + * throws checked exceptions, the parameter list is followed by a
12.293 + * space, followed by the word throws followed by a
12.294 + * comma-separated list of the thrown exception types.
12.295 + * For example:
12.296 + * <pre>
12.297 + * public boolean java.lang.Object.equals(java.lang.Object)
12.298 + * </pre>
12.299 + *
12.300 + * <p>The access modifiers are placed in canonical order as
12.301 + * specified by "The Java Language Specification". This is
12.302 + * {@code public}, {@code protected} or {@code private} first,
12.303 + * and then other modifiers in the following order:
12.304 + * {@code abstract}, {@code static}, {@code final},
12.305 + * {@code synchronized}, {@code native}, {@code strictfp}.
12.306 + */
12.307 + public String toString() {
12.308 + try {
12.309 + StringBuilder sb = new StringBuilder();
12.310 + int mod = getModifiers() & Modifier.methodModifiers();
12.311 + if (mod != 0) {
12.312 + sb.append(Modifier.toString(mod)).append(' ');
12.313 + }
12.314 + sb.append(Field.getTypeName(getReturnType())).append(' ');
12.315 + sb.append(Field.getTypeName(getDeclaringClass())).append('.');
12.316 + sb.append(getName()).append('(');
12.317 + /*
12.318 + Class<?>[] params = parameterTypes; // avoid clone
12.319 + for (int j = 0; j < params.length; j++) {
12.320 + sb.append(Field.getTypeName(params[j]));
12.321 + if (j < (params.length - 1))
12.322 + sb.append(',');
12.323 + }
12.324 + sb.append(')');
12.325 + Class<?>[] exceptions = exceptionTypes; // avoid clone
12.326 + if (exceptions.length > 0) {
12.327 + sb.append(" throws ");
12.328 + for (int k = 0; k < exceptions.length; k++) {
12.329 + sb.append(exceptions[k].getName());
12.330 + if (k < (exceptions.length - 1))
12.331 + sb.append(',');
12.332 + }
12.333 + }
12.334 + */
12.335 + return sb.toString();
12.336 + } catch (Exception e) {
12.337 + return "<" + e + ">";
12.338 + }
12.339 + }
12.340 +
12.341 + /**
12.342 + * Returns a string describing this {@code Method}, including
12.343 + * type parameters. The string is formatted as the method access
12.344 + * modifiers, if any, followed by an angle-bracketed
12.345 + * comma-separated list of the method's type parameters, if any,
12.346 + * followed by the method's generic return type, followed by a
12.347 + * space, followed by the class declaring the method, followed by
12.348 + * a period, followed by the method name, followed by a
12.349 + * parenthesized, comma-separated list of the method's generic
12.350 + * formal parameter types.
12.351 + *
12.352 + * If this method was declared to take a variable number of
12.353 + * arguments, instead of denoting the last parameter as
12.354 + * "<tt><i>Type</i>[]</tt>", it is denoted as
12.355 + * "<tt><i>Type</i>...</tt>".
12.356 + *
12.357 + * A space is used to separate access modifiers from one another
12.358 + * and from the type parameters or return type. If there are no
12.359 + * type parameters, the type parameter list is elided; if the type
12.360 + * parameter list is present, a space separates the list from the
12.361 + * class name. If the method is declared to throw exceptions, the
12.362 + * parameter list is followed by a space, followed by the word
12.363 + * throws followed by a comma-separated list of the generic thrown
12.364 + * exception types. If there are no type parameters, the type
12.365 + * parameter list is elided.
12.366 + *
12.367 + * <p>The access modifiers are placed in canonical order as
12.368 + * specified by "The Java Language Specification". This is
12.369 + * {@code public}, {@code protected} or {@code private} first,
12.370 + * and then other modifiers in the following order:
12.371 + * {@code abstract}, {@code static}, {@code final},
12.372 + * {@code synchronized}, {@code native}, {@code strictfp}.
12.373 + *
12.374 + * @return a string describing this {@code Method},
12.375 + * include type parameters
12.376 + *
12.377 + * @since 1.5
12.378 + */
12.379 + public String toGenericString() {
12.380 + try {
12.381 + StringBuilder sb = new StringBuilder();
12.382 + int mod = getModifiers() & Modifier.methodModifiers();
12.383 + if (mod != 0) {
12.384 + sb.append(Modifier.toString(mod)).append(' ');
12.385 + }
12.386 + TypeVariable<?>[] typeparms = getTypeParameters();
12.387 + if (typeparms.length > 0) {
12.388 + boolean first = true;
12.389 + sb.append('<');
12.390 + for(TypeVariable<?> typeparm: typeparms) {
12.391 + if (!first)
12.392 + sb.append(',');
12.393 + // Class objects can't occur here; no need to test
12.394 + // and call Class.getName().
12.395 + sb.append(typeparm.toString());
12.396 + first = false;
12.397 + }
12.398 + sb.append("> ");
12.399 + }
12.400 +
12.401 + Type genRetType = getGenericReturnType();
12.402 + sb.append( ((genRetType instanceof Class<?>)?
12.403 + Field.getTypeName((Class<?>)genRetType):genRetType.toString()))
12.404 + .append(' ');
12.405 +
12.406 + sb.append(Field.getTypeName(getDeclaringClass())).append('.');
12.407 + sb.append(getName()).append('(');
12.408 + Type[] params = getGenericParameterTypes();
12.409 + for (int j = 0; j < params.length; j++) {
12.410 + String param = (params[j] instanceof Class)?
12.411 + Field.getTypeName((Class)params[j]):
12.412 + (params[j].toString());
12.413 + if (isVarArgs() && (j == params.length - 1)) // replace T[] with T...
12.414 + param = param.replaceFirst("\\[\\]$", "...");
12.415 + sb.append(param);
12.416 + if (j < (params.length - 1))
12.417 + sb.append(',');
12.418 + }
12.419 + sb.append(')');
12.420 + Type[] exceptions = getGenericExceptionTypes();
12.421 + if (exceptions.length > 0) {
12.422 + sb.append(" throws ");
12.423 + for (int k = 0; k < exceptions.length; k++) {
12.424 + sb.append((exceptions[k] instanceof Class)?
12.425 + ((Class)exceptions[k]).getName():
12.426 + exceptions[k].toString());
12.427 + if (k < (exceptions.length - 1))
12.428 + sb.append(',');
12.429 + }
12.430 + }
12.431 + return sb.toString();
12.432 + } catch (Exception e) {
12.433 + return "<" + e + ">";
12.434 + }
12.435 + }
12.436 +
12.437 + /**
12.438 + * Invokes the underlying method represented by this {@code Method}
12.439 + * object, on the specified object with the specified parameters.
12.440 + * Individual parameters are automatically unwrapped to match
12.441 + * primitive formal parameters, and both primitive and reference
12.442 + * parameters are subject to method invocation conversions as
12.443 + * necessary.
12.444 + *
12.445 + * <p>If the underlying method is static, then the specified {@code obj}
12.446 + * argument is ignored. It may be null.
12.447 + *
12.448 + * <p>If the number of formal parameters required by the underlying method is
12.449 + * 0, the supplied {@code args} array may be of length 0 or null.
12.450 + *
12.451 + * <p>If the underlying method is an instance method, it is invoked
12.452 + * using dynamic method lookup as documented in The Java Language
12.453 + * Specification, Second Edition, section 15.12.4.4; in particular,
12.454 + * overriding based on the runtime type of the target object will occur.
12.455 + *
12.456 + * <p>If the underlying method is static, the class that declared
12.457 + * the method is initialized if it has not already been initialized.
12.458 + *
12.459 + * <p>If the method completes normally, the value it returns is
12.460 + * returned to the caller of invoke; if the value has a primitive
12.461 + * type, it is first appropriately wrapped in an object. However,
12.462 + * if the value has the type of an array of a primitive type, the
12.463 + * elements of the array are <i>not</i> wrapped in objects; in
12.464 + * other words, an array of primitive type is returned. If the
12.465 + * underlying method return type is void, the invocation returns
12.466 + * null.
12.467 + *
12.468 + * @param obj the object the underlying method is invoked from
12.469 + * @param args the arguments used for the method call
12.470 + * @return the result of dispatching the method represented by
12.471 + * this object on {@code obj} with parameters
12.472 + * {@code args}
12.473 + *
12.474 + * @exception IllegalAccessException if this {@code Method} object
12.475 + * is enforcing Java language access control and the underlying
12.476 + * method is inaccessible.
12.477 + * @exception IllegalArgumentException if the method is an
12.478 + * instance method and the specified object argument
12.479 + * is not an instance of the class or interface
12.480 + * declaring the underlying method (or of a subclass
12.481 + * or implementor thereof); if the number of actual
12.482 + * and formal parameters differ; if an unwrapping
12.483 + * conversion for primitive arguments fails; or if,
12.484 + * after possible unwrapping, a parameter value
12.485 + * cannot be converted to the corresponding formal
12.486 + * parameter type by a method invocation conversion.
12.487 + * @exception InvocationTargetException if the underlying method
12.488 + * throws an exception.
12.489 + * @exception NullPointerException if the specified object is null
12.490 + * and the method is an instance method.
12.491 + * @exception ExceptionInInitializerError if the initialization
12.492 + * provoked by this method fails.
12.493 + */
12.494 + @JavaScriptBody(args = { "method", "self", "args" }, body =
12.495 + "if (args.length > 0) throw 'unsupported now';"
12.496 + + "return method.fld_data(self);"
12.497 + )
12.498 + public Object invoke(Object obj, Object... args)
12.499 + throws IllegalAccessException, IllegalArgumentException,
12.500 + InvocationTargetException
12.501 + {
12.502 + throw new UnsupportedOperationException();
12.503 + }
12.504 +
12.505 + /**
12.506 + * Returns {@code true} if this method is a bridge
12.507 + * method; returns {@code false} otherwise.
12.508 + *
12.509 + * @return true if and only if this method is a bridge
12.510 + * method as defined by the Java Language Specification.
12.511 + * @since 1.5
12.512 + */
12.513 + public boolean isBridge() {
12.514 + return (getModifiers() & Modifier.BRIDGE) != 0;
12.515 + }
12.516 +
12.517 + /**
12.518 + * Returns {@code true} if this method was declared to take
12.519 + * a variable number of arguments; returns {@code false}
12.520 + * otherwise.
12.521 + *
12.522 + * @return {@code true} if an only if this method was declared to
12.523 + * take a variable number of arguments.
12.524 + * @since 1.5
12.525 + */
12.526 + public boolean isVarArgs() {
12.527 + return (getModifiers() & Modifier.VARARGS) != 0;
12.528 + }
12.529 +
12.530 + /**
12.531 + * Returns {@code true} if this method is a synthetic
12.532 + * method; returns {@code false} otherwise.
12.533 + *
12.534 + * @return true if and only if this method is a synthetic
12.535 + * method as defined by the Java Language Specification.
12.536 + * @since 1.5
12.537 + */
12.538 + public boolean isSynthetic() {
12.539 + return Modifier.isSynthetic(getModifiers());
12.540 + }
12.541 +
12.542 + @JavaScriptBody(args = { "self", "ac" },
12.543 + body =
12.544 + "if (self.fld_data.anno) {"
12.545 + + " return self.fld_data.anno['L' + ac.jvmName + ';'];"
12.546 + + "} else return null;"
12.547 + )
12.548 + private Object getAnnotationData(Class<?> annotationClass) {
12.549 + throw new UnsupportedOperationException();
12.550 + }
12.551 +
12.552 + /**
12.553 + * @throws NullPointerException {@inheritDoc}
12.554 + * @since 1.5
12.555 + */
12.556 + public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
12.557 + Object data = getAnnotationData(annotationClass);
12.558 + return data == null ? null : AnnotationImpl.create(annotationClass, data);
12.559 + }
12.560 +
12.561 + /**
12.562 + * @since 1.5
12.563 + */
12.564 + public Annotation[] getDeclaredAnnotations() {
12.565 + throw new UnsupportedOperationException();
12.566 + }
12.567 +
12.568 + /**
12.569 + * Returns the default value for the annotation member represented by
12.570 + * this {@code Method} instance. If the member is of a primitive type,
12.571 + * an instance of the corresponding wrapper type is returned. Returns
12.572 + * null if no default is associated with the member, or if the method
12.573 + * instance does not represent a declared member of an annotation type.
12.574 + *
12.575 + * @return the default value for the annotation member represented
12.576 + * by this {@code Method} instance.
12.577 + * @throws TypeNotPresentException if the annotation is of type
12.578 + * {@link Class} and no definition can be found for the
12.579 + * default class value.
12.580 + * @since 1.5
12.581 + */
12.582 + public Object getDefaultValue() {
12.583 + throw new UnsupportedOperationException();
12.584 + }
12.585 +
12.586 + /**
12.587 + * Returns an array of arrays that represent the annotations on the formal
12.588 + * parameters, in declaration order, of the method represented by
12.589 + * this {@code Method} object. (Returns an array of length zero if the
12.590 + * underlying method is parameterless. If the method has one or more
12.591 + * parameters, a nested array of length zero is returned for each parameter
12.592 + * with no annotations.) The annotation objects contained in the returned
12.593 + * arrays are serializable. The caller of this method is free to modify
12.594 + * the returned arrays; it will have no effect on the arrays returned to
12.595 + * other callers.
12.596 + *
12.597 + * @return an array of arrays that represent the annotations on the formal
12.598 + * parameters, in declaration order, of the method represented by this
12.599 + * Method object
12.600 + * @since 1.5
12.601 + */
12.602 + public Annotation[][] getParameterAnnotations() {
12.603 + throw new UnsupportedOperationException();
12.604 + }
12.605 +
12.606 + //
12.607 + // bck2brwsr implementation
12.608 + //
12.609 +
12.610 + @JavaScriptBody(args = { "clazz", "prefix" },
12.611 + body = ""
12.612 + + "var c = clazz.cnstr.prototype;"
12.613 + + "var arr = new Array();\n"
12.614 + + "for (m in c) {\n"
12.615 + + " if (m.indexOf(prefix) === 0) {\n"
12.616 + + " arr.push(m);\n"
12.617 + + " arr.push(c[m]);\n"
12.618 + + " }"
12.619 + + "}\n"
12.620 + + "return arr;"
12.621 + )
12.622 + private static native Object[] findMethodData(
12.623 + Class<?> clazz, String prefix
12.624 + );
12.625 +
12.626 + // XXX should not be public
12.627 + public static Method findMethod(
12.628 + Class<?> clazz, String name, Class<?>... parameterTypes
12.629 + ) {
12.630 + Object[] data = findMethodData(clazz, name + "__");
12.631 + if (data.length == 0) {
12.632 + return null;
12.633 + }
12.634 + String sig = ((String)data[0]).substring(name.length() + 2);
12.635 + return new Method(clazz, name, data[1], sig);
12.636 + }
12.637 +
12.638 + public static Method[] findMethods(Class<?> clazz) {
12.639 + Object[] namesAndData = findMethodData(clazz, "");
12.640 + int cnt = 0;
12.641 + for (int i = 0; i < namesAndData.length; i += 2) {
12.642 + String sig = (String) namesAndData[i];
12.643 + Object data = namesAndData[i + 1];
12.644 + int middle = sig.indexOf("__");
12.645 + if (middle == -1) {
12.646 + continue;
12.647 + }
12.648 + String name = sig.substring(0, middle);
12.649 + sig = sig.substring(middle + 2);
12.650 + namesAndData[cnt++] = new Method(clazz, name, data, sig);
12.651 + }
12.652 + Method[] arr = new Method[cnt];
12.653 + for (int i = 0; i < cnt; i++) {
12.654 + arr[i] = (Method)namesAndData[i];
12.655 + }
12.656 + return arr;
12.657 + }
12.658 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
13.2 +++ b/emul/src/main/java/java/lang/reflect/Modifier.java Fri Dec 07 15:57:14 2012 +0100
13.3 @@ -0,0 +1,437 @@
13.4 +/*
13.5 + * Copyright (c) 1996, 2008, Oracle and/or its affiliates. All rights reserved.
13.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
13.7 + *
13.8 + * This code is free software; you can redistribute it and/or modify it
13.9 + * under the terms of the GNU General Public License version 2 only, as
13.10 + * published by the Free Software Foundation. Oracle designates this
13.11 + * particular file as subject to the "Classpath" exception as provided
13.12 + * by Oracle in the LICENSE file that accompanied this code.
13.13 + *
13.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
13.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13.17 + * version 2 for more details (a copy is included in the LICENSE file that
13.18 + * accompanied this code).
13.19 + *
13.20 + * You should have received a copy of the GNU General Public License version
13.21 + * 2 along with this work; if not, write to the Free Software Foundation,
13.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
13.23 + *
13.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
13.25 + * or visit www.oracle.com if you need additional information or have any
13.26 + * questions.
13.27 + */
13.28 +
13.29 +package java.lang.reflect;
13.30 +
13.31 +/**
13.32 + * The Modifier class provides {@code static} methods and
13.33 + * constants to decode class and member access modifiers. The sets of
13.34 + * modifiers are represented as integers with distinct bit positions
13.35 + * representing different modifiers. The values for the constants
13.36 + * representing the modifiers are taken from the tables in sections 4.1, 4.4, 4.5, and 4.7 of
13.37 + * <cite>The Java™ Virtual Machine Specification</cite>.
13.38 + *
13.39 + * @see Class#getModifiers()
13.40 + * @see Member#getModifiers()
13.41 + *
13.42 + * @author Nakul Saraiya
13.43 + * @author Kenneth Russell
13.44 + */
13.45 +public
13.46 +class Modifier {
13.47 +
13.48 + /**
13.49 + * Return {@code true} if the integer argument includes the
13.50 + * {@code public} modifier, {@code false} otherwise.
13.51 + *
13.52 + * @param mod a set of modifiers
13.53 + * @return {@code true} if {@code mod} includes the
13.54 + * {@code public} modifier; {@code false} otherwise.
13.55 + */
13.56 + public static boolean isPublic(int mod) {
13.57 + return (mod & PUBLIC) != 0;
13.58 + }
13.59 +
13.60 + /**
13.61 + * Return {@code true} if the integer argument includes the
13.62 + * {@code private} modifier, {@code false} otherwise.
13.63 + *
13.64 + * @param mod a set of modifiers
13.65 + * @return {@code true} if {@code mod} includes the
13.66 + * {@code private} modifier; {@code false} otherwise.
13.67 + */
13.68 + public static boolean isPrivate(int mod) {
13.69 + return (mod & PRIVATE) != 0;
13.70 + }
13.71 +
13.72 + /**
13.73 + * Return {@code true} if the integer argument includes the
13.74 + * {@code protected} modifier, {@code false} otherwise.
13.75 + *
13.76 + * @param mod a set of modifiers
13.77 + * @return {@code true} if {@code mod} includes the
13.78 + * {@code protected} modifier; {@code false} otherwise.
13.79 + */
13.80 + public static boolean isProtected(int mod) {
13.81 + return (mod & PROTECTED) != 0;
13.82 + }
13.83 +
13.84 + /**
13.85 + * Return {@code true} if the integer argument includes the
13.86 + * {@code static} modifier, {@code false} otherwise.
13.87 + *
13.88 + * @param mod a set of modifiers
13.89 + * @return {@code true} if {@code mod} includes the
13.90 + * {@code static} modifier; {@code false} otherwise.
13.91 + */
13.92 + public static boolean isStatic(int mod) {
13.93 + return (mod & STATIC) != 0;
13.94 + }
13.95 +
13.96 + /**
13.97 + * Return {@code true} if the integer argument includes the
13.98 + * {@code final} modifier, {@code false} otherwise.
13.99 + *
13.100 + * @param mod a set of modifiers
13.101 + * @return {@code true} if {@code mod} includes the
13.102 + * {@code final} modifier; {@code false} otherwise.
13.103 + */
13.104 + public static boolean isFinal(int mod) {
13.105 + return (mod & FINAL) != 0;
13.106 + }
13.107 +
13.108 + /**
13.109 + * Return {@code true} if the integer argument includes the
13.110 + * {@code synchronized} modifier, {@code false} otherwise.
13.111 + *
13.112 + * @param mod a set of modifiers
13.113 + * @return {@code true} if {@code mod} includes the
13.114 + * {@code synchronized} modifier; {@code false} otherwise.
13.115 + */
13.116 + public static boolean isSynchronized(int mod) {
13.117 + return (mod & SYNCHRONIZED) != 0;
13.118 + }
13.119 +
13.120 + /**
13.121 + * Return {@code true} if the integer argument includes the
13.122 + * {@code volatile} modifier, {@code false} otherwise.
13.123 + *
13.124 + * @param mod a set of modifiers
13.125 + * @return {@code true} if {@code mod} includes the
13.126 + * {@code volatile} modifier; {@code false} otherwise.
13.127 + */
13.128 + public static boolean isVolatile(int mod) {
13.129 + return (mod & VOLATILE) != 0;
13.130 + }
13.131 +
13.132 + /**
13.133 + * Return {@code true} if the integer argument includes the
13.134 + * {@code transient} modifier, {@code false} otherwise.
13.135 + *
13.136 + * @param mod a set of modifiers
13.137 + * @return {@code true} if {@code mod} includes the
13.138 + * {@code transient} modifier; {@code false} otherwise.
13.139 + */
13.140 + public static boolean isTransient(int mod) {
13.141 + return (mod & TRANSIENT) != 0;
13.142 + }
13.143 +
13.144 + /**
13.145 + * Return {@code true} if the integer argument includes the
13.146 + * {@code native} modifier, {@code false} otherwise.
13.147 + *
13.148 + * @param mod a set of modifiers
13.149 + * @return {@code true} if {@code mod} includes the
13.150 + * {@code native} modifier; {@code false} otherwise.
13.151 + */
13.152 + public static boolean isNative(int mod) {
13.153 + return (mod & NATIVE) != 0;
13.154 + }
13.155 +
13.156 + /**
13.157 + * Return {@code true} if the integer argument includes the
13.158 + * {@code interface} modifier, {@code false} otherwise.
13.159 + *
13.160 + * @param mod a set of modifiers
13.161 + * @return {@code true} if {@code mod} includes the
13.162 + * {@code interface} modifier; {@code false} otherwise.
13.163 + */
13.164 + public static boolean isInterface(int mod) {
13.165 + return (mod & INTERFACE) != 0;
13.166 + }
13.167 +
13.168 + /**
13.169 + * Return {@code true} if the integer argument includes the
13.170 + * {@code abstract} modifier, {@code false} otherwise.
13.171 + *
13.172 + * @param mod a set of modifiers
13.173 + * @return {@code true} if {@code mod} includes the
13.174 + * {@code abstract} modifier; {@code false} otherwise.
13.175 + */
13.176 + public static boolean isAbstract(int mod) {
13.177 + return (mod & ABSTRACT) != 0;
13.178 + }
13.179 +
13.180 + /**
13.181 + * Return {@code true} if the integer argument includes the
13.182 + * {@code strictfp} modifier, {@code false} otherwise.
13.183 + *
13.184 + * @param mod a set of modifiers
13.185 + * @return {@code true} if {@code mod} includes the
13.186 + * {@code strictfp} modifier; {@code false} otherwise.
13.187 + */
13.188 + public static boolean isStrict(int mod) {
13.189 + return (mod & STRICT) != 0;
13.190 + }
13.191 +
13.192 + /**
13.193 + * Return a string describing the access modifier flags in
13.194 + * the specified modifier. For example:
13.195 + * <blockquote><pre>
13.196 + * public final synchronized strictfp
13.197 + * </pre></blockquote>
13.198 + * The modifier names are returned in an order consistent with the
13.199 + * suggested modifier orderings given in sections 8.1.1, 8.3.1, 8.4.3, 8.8.3, and 9.1.1 of
13.200 + * <cite>The Java™ Language Specification</cite>.
13.201 + * The full modifier ordering used by this method is:
13.202 + * <blockquote> {@code
13.203 + * public protected private abstract static final transient
13.204 + * volatile synchronized native strictfp
13.205 + * interface } </blockquote>
13.206 + * The {@code interface} modifier discussed in this class is
13.207 + * not a true modifier in the Java language and it appears after
13.208 + * all other modifiers listed by this method. This method may
13.209 + * return a string of modifiers that are not valid modifiers of a
13.210 + * Java entity; in other words, no checking is done on the
13.211 + * possible validity of the combination of modifiers represented
13.212 + * by the input.
13.213 + *
13.214 + * Note that to perform such checking for a known kind of entity,
13.215 + * such as a constructor or method, first AND the argument of
13.216 + * {@code toString} with the appropriate mask from a method like
13.217 + * {@link #constructorModifiers} or {@link #methodModifiers}.
13.218 + *
13.219 + * @param mod a set of modifiers
13.220 + * @return a string representation of the set of modifiers
13.221 + * represented by {@code mod}
13.222 + */
13.223 + public static String toString(int mod) {
13.224 + StringBuffer sb = new StringBuffer();
13.225 + int len;
13.226 +
13.227 + if ((mod & PUBLIC) != 0) sb.append("public ");
13.228 + if ((mod & PROTECTED) != 0) sb.append("protected ");
13.229 + if ((mod & PRIVATE) != 0) sb.append("private ");
13.230 +
13.231 + /* Canonical order */
13.232 + if ((mod & ABSTRACT) != 0) sb.append("abstract ");
13.233 + if ((mod & STATIC) != 0) sb.append("static ");
13.234 + if ((mod & FINAL) != 0) sb.append("final ");
13.235 + if ((mod & TRANSIENT) != 0) sb.append("transient ");
13.236 + if ((mod & VOLATILE) != 0) sb.append("volatile ");
13.237 + if ((mod & SYNCHRONIZED) != 0) sb.append("synchronized ");
13.238 + if ((mod & NATIVE) != 0) sb.append("native ");
13.239 + if ((mod & STRICT) != 0) sb.append("strictfp ");
13.240 + if ((mod & INTERFACE) != 0) sb.append("interface ");
13.241 +
13.242 + if ((len = sb.length()) > 0) /* trim trailing space */
13.243 + return sb.toString().substring(0, len-1);
13.244 + return "";
13.245 + }
13.246 +
13.247 + /*
13.248 + * Access modifier flag constants from tables 4.1, 4.4, 4.5, and 4.7 of
13.249 + * <cite>The Java™ Virtual Machine Specification</cite>
13.250 + */
13.251 +
13.252 + /**
13.253 + * The {@code int} value representing the {@code public}
13.254 + * modifier.
13.255 + */
13.256 + public static final int PUBLIC = 0x00000001;
13.257 +
13.258 + /**
13.259 + * The {@code int} value representing the {@code private}
13.260 + * modifier.
13.261 + */
13.262 + public static final int PRIVATE = 0x00000002;
13.263 +
13.264 + /**
13.265 + * The {@code int} value representing the {@code protected}
13.266 + * modifier.
13.267 + */
13.268 + public static final int PROTECTED = 0x00000004;
13.269 +
13.270 + /**
13.271 + * The {@code int} value representing the {@code static}
13.272 + * modifier.
13.273 + */
13.274 + public static final int STATIC = 0x00000008;
13.275 +
13.276 + /**
13.277 + * The {@code int} value representing the {@code final}
13.278 + * modifier.
13.279 + */
13.280 + public static final int FINAL = 0x00000010;
13.281 +
13.282 + /**
13.283 + * The {@code int} value representing the {@code synchronized}
13.284 + * modifier.
13.285 + */
13.286 + public static final int SYNCHRONIZED = 0x00000020;
13.287 +
13.288 + /**
13.289 + * The {@code int} value representing the {@code volatile}
13.290 + * modifier.
13.291 + */
13.292 + public static final int VOLATILE = 0x00000040;
13.293 +
13.294 + /**
13.295 + * The {@code int} value representing the {@code transient}
13.296 + * modifier.
13.297 + */
13.298 + public static final int TRANSIENT = 0x00000080;
13.299 +
13.300 + /**
13.301 + * The {@code int} value representing the {@code native}
13.302 + * modifier.
13.303 + */
13.304 + public static final int NATIVE = 0x00000100;
13.305 +
13.306 + /**
13.307 + * The {@code int} value representing the {@code interface}
13.308 + * modifier.
13.309 + */
13.310 + public static final int INTERFACE = 0x00000200;
13.311 +
13.312 + /**
13.313 + * The {@code int} value representing the {@code abstract}
13.314 + * modifier.
13.315 + */
13.316 + public static final int ABSTRACT = 0x00000400;
13.317 +
13.318 + /**
13.319 + * The {@code int} value representing the {@code strictfp}
13.320 + * modifier.
13.321 + */
13.322 + public static final int STRICT = 0x00000800;
13.323 +
13.324 + // Bits not (yet) exposed in the public API either because they
13.325 + // have different meanings for fields and methods and there is no
13.326 + // way to distinguish between the two in this class, or because
13.327 + // they are not Java programming language keywords
13.328 + static final int BRIDGE = 0x00000040;
13.329 + static final int VARARGS = 0x00000080;
13.330 + static final int SYNTHETIC = 0x00001000;
13.331 + static final int ANNOTATION= 0x00002000;
13.332 + static final int ENUM = 0x00004000;
13.333 + static boolean isSynthetic(int mod) {
13.334 + return (mod & SYNTHETIC) != 0;
13.335 + }
13.336 +
13.337 + /**
13.338 + * See JLSv3 section 8.1.1.
13.339 + */
13.340 + private static final int CLASS_MODIFIERS =
13.341 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
13.342 + Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
13.343 + Modifier.STRICT;
13.344 +
13.345 + /**
13.346 + * See JLSv3 section 9.1.1.
13.347 + */
13.348 + private static final int INTERFACE_MODIFIERS =
13.349 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
13.350 + Modifier.ABSTRACT | Modifier.STATIC | Modifier.STRICT;
13.351 +
13.352 +
13.353 + /**
13.354 + * See JLSv3 section 8.8.3.
13.355 + */
13.356 + private static final int CONSTRUCTOR_MODIFIERS =
13.357 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE;
13.358 +
13.359 + /**
13.360 + * See JLSv3 section 8.4.3.
13.361 + */
13.362 + private static final int METHOD_MODIFIERS =
13.363 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
13.364 + Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL |
13.365 + Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT;
13.366 +
13.367 + /**
13.368 + * See JLSv3 section 8.3.1.
13.369 + */
13.370 + private static final int FIELD_MODIFIERS =
13.371 + Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE |
13.372 + Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT |
13.373 + Modifier.VOLATILE;
13.374 +
13.375 + /**
13.376 + * Return an {@code int} value OR-ing together the source language
13.377 + * modifiers that can be applied to a class.
13.378 + * @return an {@code int} value OR-ing together the source language
13.379 + * modifiers that can be applied to a class.
13.380 + *
13.381 + * @jls 8.1.1 Class Modifiers
13.382 + * @since 1.7
13.383 + */
13.384 + public static int classModifiers() {
13.385 + return CLASS_MODIFIERS;
13.386 + }
13.387 +
13.388 + /**
13.389 + * Return an {@code int} value OR-ing together the source language
13.390 + * modifiers that can be applied to an interface.
13.391 + * @return an {@code int} value OR-ing together the source language
13.392 + * modifiers that can be applied to an inteface.
13.393 + *
13.394 + * @jls 9.1.1 Interface Modifiers
13.395 + * @since 1.7
13.396 + */
13.397 + public static int interfaceModifiers() {
13.398 + return INTERFACE_MODIFIERS;
13.399 + }
13.400 +
13.401 + /**
13.402 + * Return an {@code int} value OR-ing together the source language
13.403 + * modifiers that can be applied to a constructor.
13.404 + * @return an {@code int} value OR-ing together the source language
13.405 + * modifiers that can be applied to a constructor.
13.406 + *
13.407 + * @jls 8.8.3 Constructor Modifiers
13.408 + * @since 1.7
13.409 + */
13.410 + public static int constructorModifiers() {
13.411 + return CONSTRUCTOR_MODIFIERS;
13.412 + }
13.413 +
13.414 + /**
13.415 + * Return an {@code int} value OR-ing together the source language
13.416 + * modifiers that can be applied to a method.
13.417 + * @return an {@code int} value OR-ing together the source language
13.418 + * modifiers that can be applied to a method.
13.419 + *
13.420 + * @jls 8.4.3 Method Modifiers
13.421 + * @since 1.7
13.422 + */
13.423 + public static int methodModifiers() {
13.424 + return METHOD_MODIFIERS;
13.425 + }
13.426 +
13.427 +
13.428 + /**
13.429 + * Return an {@code int} value OR-ing together the source language
13.430 + * modifiers that can be applied to a field.
13.431 + * @return an {@code int} value OR-ing together the source language
13.432 + * modifiers that can be applied to a field.
13.433 + *
13.434 + * @jls 8.3.1 Field Modifiers
13.435 + * @since 1.7
13.436 + */
13.437 + public static int fieldModifiers() {
13.438 + return FIELD_MODIFIERS;
13.439 + }
13.440 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
14.2 +++ b/emul/src/main/java/java/lang/reflect/Type.java Fri Dec 07 15:57:14 2012 +0100
14.3 @@ -0,0 +1,37 @@
14.4 +/*
14.5 + * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
14.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
14.7 + *
14.8 + * This code is free software; you can redistribute it and/or modify it
14.9 + * under the terms of the GNU General Public License version 2 only, as
14.10 + * published by the Free Software Foundation. Oracle designates this
14.11 + * particular file as subject to the "Classpath" exception as provided
14.12 + * by Oracle in the LICENSE file that accompanied this code.
14.13 + *
14.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
14.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14.17 + * version 2 for more details (a copy is included in the LICENSE file that
14.18 + * accompanied this code).
14.19 + *
14.20 + * You should have received a copy of the GNU General Public License version
14.21 + * 2 along with this work; if not, write to the Free Software Foundation,
14.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
14.23 + *
14.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
14.25 + * or visit www.oracle.com if you need additional information or have any
14.26 + * questions.
14.27 + */
14.28 +
14.29 +package java.lang.reflect;
14.30 +
14.31 +/**
14.32 + * Type is the common superinterface for all types in the Java
14.33 + * programming language. These include raw types, parameterized types,
14.34 + * array types, type variables and primitive types.
14.35 + *
14.36 + * @since 1.5
14.37 + */
14.38 +
14.39 +public interface Type {
14.40 +}
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
15.2 +++ b/emul/src/main/java/java/lang/reflect/TypeVariable.java Fri Dec 07 15:57:14 2012 +0100
15.3 @@ -0,0 +1,89 @@
15.4 +/*
15.5 + * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
15.7 + *
15.8 + * This code is free software; you can redistribute it and/or modify it
15.9 + * under the terms of the GNU General Public License version 2 only, as
15.10 + * published by the Free Software Foundation. Oracle designates this
15.11 + * particular file as subject to the "Classpath" exception as provided
15.12 + * by Oracle in the LICENSE file that accompanied this code.
15.13 + *
15.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
15.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15.17 + * version 2 for more details (a copy is included in the LICENSE file that
15.18 + * accompanied this code).
15.19 + *
15.20 + * You should have received a copy of the GNU General Public License version
15.21 + * 2 along with this work; if not, write to the Free Software Foundation,
15.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
15.23 + *
15.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
15.25 + * or visit www.oracle.com if you need additional information or have any
15.26 + * questions.
15.27 + */
15.28 +
15.29 +package java.lang.reflect;
15.30 +
15.31 +/**
15.32 + * TypeVariable is the common superinterface for type variables of kinds.
15.33 + * A type variable is created the first time it is needed by a reflective
15.34 + * method, as specified in this package. If a type variable t is referenced
15.35 + * by a type (i.e, class, interface or annotation type) T, and T is declared
15.36 + * by the nth enclosing class of T (see JLS 8.1.2), then the creation of t
15.37 + * requires the resolution (see JVMS 5) of the ith enclosing class of T,
15.38 + * for i = 0 to n, inclusive. Creating a type variable must not cause the
15.39 + * creation of its bounds. Repeated creation of a type variable has no effect.
15.40 + *
15.41 + * <p>Multiple objects may be instantiated at run-time to
15.42 + * represent a given type variable. Even though a type variable is
15.43 + * created only once, this does not imply any requirement to cache
15.44 + * instances representing the type variable. However, all instances
15.45 + * representing a type variable must be equal() to each other.
15.46 + * As a consequence, users of type variables must not rely on the identity
15.47 + * of instances of classes implementing this interface.
15.48 + *
15.49 + * @param <D> the type of generic declaration that declared the
15.50 + * underlying type variable.
15.51 + *
15.52 + * @since 1.5
15.53 + */
15.54 +public interface TypeVariable<D extends GenericDeclaration> extends Type {
15.55 + /**
15.56 + * Returns an array of {@code Type} objects representing the
15.57 + * upper bound(s) of this type variable. Note that if no upper bound is
15.58 + * explicitly declared, the upper bound is {@code Object}.
15.59 + *
15.60 + * <p>For each upper bound B: <ul> <li>if B is a parameterized
15.61 + * type or a type variable, it is created, (see {@link
15.62 + * java.lang.reflect.ParameterizedType ParameterizedType} for the
15.63 + * details of the creation process for parameterized types).
15.64 + * <li>Otherwise, B is resolved. </ul>
15.65 + *
15.66 + * @throws TypeNotPresentException if any of the
15.67 + * bounds refers to a non-existent type declaration
15.68 + * @throws MalformedParameterizedTypeException if any of the
15.69 + * bounds refer to a parameterized type that cannot be instantiated
15.70 + * for any reason
15.71 + * @return an array of {@code Type}s representing the upper
15.72 + * bound(s) of this type variable
15.73 + */
15.74 + Type[] getBounds();
15.75 +
15.76 + /**
15.77 + * Returns the {@code GenericDeclaration} object representing the
15.78 + * generic declaration declared this type variable.
15.79 + *
15.80 + * @return the generic declaration declared for this type variable.
15.81 + *
15.82 + * @since 1.5
15.83 + */
15.84 + D getGenericDeclaration();
15.85 +
15.86 + /**
15.87 + * Returns the name of this type variable, as it occurs in the source code.
15.88 + *
15.89 + * @return the name of this type variable, as it appears in the source code
15.90 + */
15.91 + String getName();
15.92 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
16.2 +++ b/emul/src/main/java/java/lang/reflect/package-info.java Fri Dec 07 15:57:14 2012 +0100
16.3 @@ -0,0 +1,49 @@
16.4 +/*
16.5 + * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
16.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
16.7 + *
16.8 + * This code is free software; you can redistribute it and/or modify it
16.9 + * under the terms of the GNU General Public License version 2 only, as
16.10 + * published by the Free Software Foundation. Oracle designates this
16.11 + * particular file as subject to the "Classpath" exception as provided
16.12 + * by Oracle in the LICENSE file that accompanied this code.
16.13 + *
16.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
16.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16.17 + * version 2 for more details (a copy is included in the LICENSE file that
16.18 + * accompanied this code).
16.19 + *
16.20 + * You should have received a copy of the GNU General Public License version
16.21 + * 2 along with this work; if not, write to the Free Software Foundation,
16.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
16.23 + *
16.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
16.25 + * or visit www.oracle.com if you need additional information or have any
16.26 + * questions.
16.27 + */
16.28 +
16.29 +/**
16.30 + * Provides classes and interfaces for obtaining reflective
16.31 + * information about classes and objects. Reflection allows
16.32 + * programmatic access to information about the fields, methods and
16.33 + * constructors of loaded classes, and the use of reflected fields,
16.34 + * methods, and constructors to operate on their underlying
16.35 + * counterparts, within security restrictions.
16.36 + *
16.37 + * <p>{@code AccessibleObject} allows suppression of access checks if
16.38 + * the necessary {@code ReflectPermission} is available.
16.39 + *
16.40 + * <p>{@code Array} provides static methods to dynamically create and
16.41 + * access arrays.
16.42 + *
16.43 + * <p>Classes in this package, along with {@code java.lang.Class}
16.44 + * accommodate applications such as debuggers, interpreters, object
16.45 + * inspectors, class browsers, and services such as Object
16.46 + * Serialization and JavaBeans that need access to either the public
16.47 + * members of a target object (based on its runtime class) or the
16.48 + * members declared by a given class.
16.49 + *
16.50 + * @since JDK1.1
16.51 + */
16.52 +package java.lang.reflect;
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
17.2 +++ b/emul/src/main/java/org/apidesign/bck2brwsr/emul/AnnotationImpl.java Fri Dec 07 15:57:14 2012 +0100
17.3 @@ -0,0 +1,68 @@
17.4 +/*
17.5 + * To change this template, choose Tools | Templates
17.6 + * and open the template in the editor.
17.7 + */
17.8 +package org.apidesign.bck2brwsr.emul;
17.9 +
17.10 +import java.lang.annotation.Annotation;
17.11 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
17.12 +
17.13 +/**
17.14 + *
17.15 + * @author Jaroslav Tulach <jtulach@netbeans.org>
17.16 + */
17.17 +public final class AnnotationImpl implements Annotation {
17.18 + public Class<? extends Annotation> annotationType() {
17.19 + return getClass();
17.20 + }
17.21 +
17.22 + @JavaScriptBody(args = { "a", "n", "values" }, body = ""
17.23 + + "function f(v, p) {\n"
17.24 + + " var val = v;\n"
17.25 + + " var prop = p;\n"
17.26 + + " return function() {\n"
17.27 + + " return val[prop];\n"
17.28 + + " };\n"
17.29 + + "}\n"
17.30 + + "var props = Object.getOwnPropertyNames(values);\n"
17.31 + + "for (var i = 0; i < props.length; i++) {\n"
17.32 + + " var p = props[i];\n"
17.33 + + " a[p] = new f(values, p);\n"
17.34 + + "}\n"
17.35 + + "a['$instOf_' + n] = true;\n"
17.36 + + "return a;"
17.37 + )
17.38 + private static <T extends Annotation> T create(AnnotationImpl a, String n, Object values) {
17.39 + return null;
17.40 + }
17.41 + public static <T extends Annotation> T create(Class<T> annoClass, Object values) {
17.42 + return create(new AnnotationImpl(), annoClass.getName().replace('.', '_'), values);
17.43 + }
17.44 +
17.45 + public static Annotation[] create(Object anno) {
17.46 + String[] names = findNames(anno);
17.47 + Annotation[] ret = new Annotation[names.length];
17.48 + for (int i = 0; i < names.length; i++) {
17.49 + String n = names[i].substring(1, names[i].length() - 1).replace('/', '_');
17.50 + ret[i] = create(new AnnotationImpl(), n, findData(anno, names[i]));
17.51 + }
17.52 + return ret;
17.53 + }
17.54 + @JavaScriptBody(args = "anno", body =
17.55 + "var arr = new Array();"
17.56 + + "var props = Object.getOwnPropertyNames(anno);\n"
17.57 + + "for (var i = 0; i < props.length; i++) {\n"
17.58 + + " var p = props[i];\n"
17.59 + + " arr.push(p);"
17.60 + + "}"
17.61 + + "return arr;"
17.62 + )
17.63 + private static String[] findNames(Object anno) {
17.64 + throw new UnsupportedOperationException();
17.65 + }
17.66 +
17.67 + @JavaScriptBody(args={ "anno", "p"}, body="return anno[p];")
17.68 + private static Object findData(Object anno, String p) {
17.69 + throw new UnsupportedOperationException();
17.70 + }
17.71 +}
18.1 --- a/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js Fri Dec 07 15:02:35 2012 +0100
18.2 +++ b/emul/src/main/resources/org/apidesign/vm4brwsr/emul/java_lang_String.js Fri Dec 07 15:57:14 2012 +0100
18.3 @@ -1,2 +1,9 @@
18.4 // initialize methods on String constants
18.5 -java_lang_String(false)
18.6 +java_lang_String(false);
18.7 +
18.8 +// we need initialized arrays
18.9 +Array.prototype.fillNulls = function() {
18.10 + for(var i = 0; i < this.length; i++) this[i] = null;
18.11 + return this;
18.12 +};
18.13 +
19.1 --- a/javap/src/main/java/org/apidesign/javap/AnnotationParser.java Fri Dec 07 15:02:35 2012 +0100
19.2 +++ b/javap/src/main/java/org/apidesign/javap/AnnotationParser.java Fri Dec 07 15:57:14 2012 +0100
19.3 @@ -34,10 +34,21 @@
19.4 * @author Jaroslav Tulach <jtulach@netbeans.org>
19.5 */
19.6 public class AnnotationParser {
19.7 - protected AnnotationParser() {
19.8 + private final boolean textual;
19.9 +
19.10 + protected AnnotationParser(boolean textual) {
19.11 + this.textual = textual;
19.12 }
19.13
19.14 - protected void visitAttr(String type, String attr, String value) {
19.15 + protected void visitAnnotationStart(String type) throws IOException {
19.16 + }
19.17 +
19.18 + protected void visitAnnotationEnd(String type) throws IOException {
19.19 + }
19.20 +
19.21 + protected void visitAttr(
19.22 + String annoType, String attr, String attrType, String value
19.23 + ) throws IOException {
19.24 }
19.25
19.26 /** Initialize the parsing with constant pool from <code>cd</code>.
19.27 @@ -66,13 +77,15 @@
19.28 private void readAnno(DataInputStream dis, ClassData cd) throws IOException {
19.29 int type = dis.readUnsignedShort();
19.30 String typeName = cd.StringValue(type);
19.31 + visitAnnotationStart(typeName);
19.32 int cnt = dis.readUnsignedShort();
19.33 for (int i = 0; i < cnt; i++) {
19.34 String attrName = cd.StringValue(dis.readUnsignedShort());
19.35 readValue(dis, cd, typeName, attrName);
19.36 }
19.37 + visitAnnotationEnd(typeName);
19.38 if (cnt == 0) {
19.39 - visitAttr(typeName, null, null);
19.40 + visitAttr(typeName, null, null, null);
19.41 }
19.42 }
19.43
19.44 @@ -83,7 +96,17 @@
19.45 readAnno(dis, cd);
19.46 } else if ("CFJZsSIDB".indexOf(type) >= 0) { // NOI18N
19.47 int primitive = dis.readUnsignedShort();
19.48 - visitAttr(typeName, attrName, cd.StringValue(primitive));
19.49 + String val = cd.stringValue(primitive, textual);
19.50 + String attrType;
19.51 + if (type == 's') {
19.52 + attrType = "Ljava_lang_String_2";
19.53 + if (textual) {
19.54 + val = '"' + val + '"';
19.55 + }
19.56 + } else {
19.57 + attrType = "" + type;
19.58 + }
19.59 + visitAttr(typeName, attrName, attrType, val);
19.60 } else if (type == 'c') {
19.61 int cls = dis.readUnsignedShort();
19.62 } else if (type == '[') {
20.1 --- a/javap/src/main/java/org/apidesign/javap/ClassData.java Fri Dec 07 15:02:35 2012 +0100
20.2 +++ b/javap/src/main/java/org/apidesign/javap/ClassData.java Fri Dec 07 15:57:14 2012 +0100
20.3 @@ -488,6 +488,12 @@
20.4 return stringValue(cpx, false);
20.5 }
20.6 public String stringValue(int cpx, boolean textual) {
20.7 + return stringValue(cpx, textual, null);
20.8 + }
20.9 + public String stringValue(int cpx, String[] classRefs) {
20.10 + return stringValue(cpx, true, classRefs);
20.11 + }
20.12 + private String stringValue(int cpx, boolean textual, String[] refs) {
20.13 if (cpx==0) return "#0";
20.14 int tag;
20.15 Object x;
20.16 @@ -548,10 +554,14 @@
20.17 return in.toString();
20.18 }
20.19 case CONSTANT_CLASS:
20.20 + String jn = javaName(getClassName(cpx));
20.21 if (textual) {
20.22 - return "new java_lang_Class"; // XXX temporary JS
20.23 + if (refs != null) {
20.24 + refs[0] = jn;
20.25 + }
20.26 + return jn.replace('/', '_') + "(false).constructor.$class";
20.27 }
20.28 - return javaName(getClassName(cpx));
20.29 + return jn;
20.30 case CONSTANT_STRING:
20.31 String sv = stringValue(((CPX)x).cpx, textual);
20.32 if (textual) {
21.1 --- a/javap/src/main/java/org/apidesign/javap/FieldData.java Fri Dec 07 15:02:35 2012 +0100
21.2 +++ b/javap/src/main/java/org/apidesign/javap/FieldData.java Fri Dec 07 15:57:14 2012 +0100
21.3 @@ -130,13 +130,6 @@
21.4 }
21.5
21.6 /**
21.7 - * Returns java type signature of a field.
21.8 - */
21.9 - public String getType(){
21.10 - return new TypeSignature(getInternalSig()).getFieldType();
21.11 - }
21.12 -
21.13 - /**
21.14 * Returns true if field is synthetic.
21.15 */
21.16 public boolean isSynthetic(){
22.1 --- a/javap/src/main/java/org/apidesign/javap/MethodData.java Fri Dec 07 15:02:35 2012 +0100
22.2 +++ b/javap/src/main/java/org/apidesign/javap/MethodData.java Fri Dec 07 15:57:14 2012 +0100
22.3 @@ -268,24 +268,6 @@
22.4 }
22.5
22.6 /**
22.7 - * Return java return type signature of method.
22.8 - */
22.9 - public String getReturnType(){
22.10 -
22.11 - String rttype = (new TypeSignature(getInternalSig())).getReturnType();
22.12 - return rttype;
22.13 - }
22.14 -
22.15 - /**
22.16 - * Return java type parameter signature.
22.17 - */
22.18 - public String getParameters(){
22.19 - String ptype = (new TypeSignature(getInternalSig())).getParameters();
22.20 -
22.21 - return ptype;
22.22 - }
22.23 -
22.24 - /**
22.25 * Return code attribute data of a method.
22.26 */
22.27 public byte[] getCode(){
22.28 @@ -340,13 +322,6 @@
22.29 }
22.30
22.31 /**
22.32 - * Return number of arguments of that method.
22.33 - */
22.34 - public int getArgumentlength(){
22.35 - return new TypeSignature(getInternalSig()).getArgumentlength();
22.36 - }
22.37 -
22.38 - /**
22.39 * Return true if method is static
22.40 */
22.41 public boolean isStatic(){
23.1 --- a/javap/src/main/java/org/apidesign/javap/TypeSignature.java Fri Dec 07 15:02:35 2012 +0100
23.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
23.3 @@ -1,295 +0,0 @@
23.4 -/*
23.5 - * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
23.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
23.7 - *
23.8 - * This code is free software; you can redistribute it and/or modify it
23.9 - * under the terms of the GNU General Public License version 2 only, as
23.10 - * published by the Free Software Foundation. Oracle designates this
23.11 - * particular file as subject to the "Classpath" exception as provided
23.12 - * by Oracle in the LICENSE file that accompanied this code.
23.13 - *
23.14 - * This code is distributed in the hope that it will be useful, but WITHOUT
23.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23.17 - * version 2 for more details (a copy is included in the LICENSE file that
23.18 - * accompanied this code).
23.19 - *
23.20 - * You should have received a copy of the GNU General Public License version
23.21 - * 2 along with this work; if not, write to the Free Software Foundation,
23.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
23.23 - *
23.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
23.25 - * or visit www.oracle.com if you need additional information or have any
23.26 - * questions.
23.27 - */
23.28 -
23.29 -
23.30 -package org.apidesign.javap;
23.31 -
23.32 -import java.util.*;
23.33 -import java.io.*;
23.34 -
23.35 -/**
23.36 - * Returns java type signature.
23.37 - *
23.38 - * @author Sucheta Dambalkar
23.39 - */
23.40 -public class TypeSignature {
23.41 -
23.42 - String parameters = null;
23.43 - String returntype = null;
23.44 - String fieldtype = null;
23.45 - int argumentlength = 0;
23.46 -
23.47 - public TypeSignature(String JVMSignature){
23.48 -
23.49 - if(JVMSignature != null){
23.50 - if(JVMSignature.indexOf("(") == -1){
23.51 - //This is a field type.
23.52 - this.fieldtype = getFieldTypeSignature(JVMSignature);
23.53 - }else {
23.54 - String parameterdes = null;
23.55 - if((JVMSignature.indexOf(")")-1) > (JVMSignature.indexOf("("))){
23.56 - //Get parameter signature.
23.57 - parameterdes =
23.58 - JVMSignature.substring(JVMSignature.indexOf("(")+1,
23.59 - JVMSignature.indexOf(")"));
23.60 - this.parameters = getParametersHelper(parameterdes);
23.61 - }else this.parameters = "()";
23.62 - //Get return type signature.
23.63 - String returndes = JVMSignature.substring(JVMSignature.lastIndexOf(")")+1);
23.64 - this.returntype = getReturnTypeHelper(returndes);
23.65 - }
23.66 - }
23.67 - }
23.68 -
23.69 - /**
23.70 - * Returns java type signature of a field.
23.71 - */
23.72 - public String getFieldTypeSignature(String fielddes){
23.73 - if(fielddes.startsWith("L")){
23.74 - return(getObjectType(fielddes));
23.75 - }else if(fielddes.startsWith("[")){
23.76 - return(getArrayType(fielddes));
23.77 - }else
23.78 - return(getBaseType(fielddes));
23.79 - }
23.80 -
23.81 - /**
23.82 - * Returns java type signature of a parameter.
23.83 - */
23.84 - public String getParametersHelper(String parameterdes){
23.85 - Vector parameters = new Vector();
23.86 - int startindex = -1;
23.87 - int endindex = -1;
23.88 - String param = "";
23.89 -
23.90 - while(parameterdes != null){
23.91 -
23.92 - if(parameterdes.startsWith("L")){
23.93 - //parameter is a object.
23.94 - startindex = parameterdes.indexOf("L");
23.95 - endindex = parameterdes.indexOf(";");
23.96 - if(startindex < parameterdes.length()) {
23.97 - if(endindex == parameterdes.length()-1) {
23.98 - //last parameter
23.99 - param = parameterdes.substring(startindex);
23.100 - parameterdes = null;
23.101 - }else if(endindex+1 < parameterdes.length()){
23.102 - //rest parameters
23.103 - param = parameterdes.substring(startindex, endindex+1);
23.104 - parameterdes = parameterdes.substring(endindex+1);
23.105 -
23.106 - }
23.107 - parameters.add(getObjectType(param));
23.108 - }
23.109 - }else if(parameterdes.startsWith("[")){
23.110 - //parameter is an array.
23.111 - String componentType = "";
23.112 - int enddim = -1;
23.113 - int st = 0;
23.114 - while(true){
23.115 - if(st < parameterdes.length()){
23.116 - if(parameterdes.charAt(st) == '['){
23.117 -
23.118 - enddim = st;
23.119 - st++;
23.120 - }
23.121 - else break;
23.122 - }
23.123 - else break;
23.124 - }
23.125 -
23.126 - if(enddim+1 < parameterdes.length()){
23.127 - /* Array dimension.*/
23.128 - param = parameterdes.substring(0,enddim+1);
23.129 -
23.130 - }
23.131 -
23.132 - int stotherparam = param.lastIndexOf("[")+1;
23.133 -
23.134 - if(stotherparam < parameterdes.length()){
23.135 - componentType = parameterdes.substring(stotherparam);
23.136 - }
23.137 -
23.138 - if(componentType.startsWith("L")){
23.139 - //parameter is array of objects.
23.140 - startindex = parameterdes.indexOf("L");
23.141 - endindex = parameterdes.indexOf(";");
23.142 -
23.143 - if(endindex == parameterdes.length()-1){
23.144 - //last parameter
23.145 - param += parameterdes.substring(startindex);
23.146 - parameterdes = null;
23.147 - }else if(endindex+1 < parameterdes.length()){
23.148 - //rest parameters
23.149 - param += parameterdes.substring(startindex, endindex+1);
23.150 - parameterdes = parameterdes.substring(endindex+1);
23.151 - }
23.152 - }else{
23.153 - //parameter is array of base type.
23.154 - if(componentType.length() == 1){
23.155 - //last parameter.
23.156 - param += componentType;
23.157 - parameterdes = null;
23.158 - }
23.159 - else if (componentType.length() > 1) {
23.160 - //rest parameters.
23.161 - param += componentType.substring(0,1);
23.162 - parameterdes = componentType.substring(1);
23.163 - }
23.164 - }
23.165 - parameters.add(getArrayType(param));
23.166 -
23.167 -
23.168 - }else {
23.169 -
23.170 - //parameter is of base type.
23.171 - if(parameterdes.length() == 1){
23.172 - //last parameter
23.173 - param = parameterdes;
23.174 - parameterdes = null;
23.175 - }
23.176 - else if (parameterdes.length() > 1) {
23.177 - //rest parameters.
23.178 - param = parameterdes.substring(0,1);
23.179 - parameterdes = parameterdes.substring(1);
23.180 - }
23.181 - parameters.add(getBaseType(param));
23.182 - }
23.183 - }
23.184 -
23.185 - /* number of arguments of a method.*/
23.186 - argumentlength = parameters.size();
23.187 -
23.188 - /* java type signature.*/
23.189 - String parametersignature = "(";
23.190 - int i;
23.191 -
23.192 - for(i = 0; i < parameters.size(); i++){
23.193 - parametersignature += (String)parameters.elementAt(i);
23.194 - if(i != parameters.size()-1){
23.195 - parametersignature += ", ";
23.196 - }
23.197 - }
23.198 - parametersignature += ")";
23.199 - return parametersignature;
23.200 - }
23.201 -
23.202 - /**
23.203 - * Returns java type signature for a return type.
23.204 - */
23.205 - public String getReturnTypeHelper(String returndes){
23.206 - return getFieldTypeSignature(returndes);
23.207 - }
23.208 -
23.209 - /**
23.210 - * Returns java type signature for a base type.
23.211 - */
23.212 - public String getBaseType(String baseType){
23.213 - if(baseType != null){
23.214 - if(baseType.equals("B")) return "byte";
23.215 - else if(baseType.equals("C")) return "char";
23.216 - else if(baseType.equals("D")) return "double";
23.217 - else if(baseType.equals("F")) return "float";
23.218 - else if(baseType.equals("I")) return "int";
23.219 - else if(baseType.equals("J")) return "long";
23.220 - else if(baseType.equals("S")) return "short";
23.221 - else if(baseType.equals("Z")) return "boolean";
23.222 - else if(baseType.equals("V")) return "void";
23.223 - }
23.224 - return null;
23.225 - }
23.226 -
23.227 - /**
23.228 - * Returns java type signature for a object type.
23.229 - */
23.230 - public String getObjectType(String JVMobjectType) {
23.231 - String objectType = "";
23.232 - int startindex = JVMobjectType.indexOf("L")+1;
23.233 - int endindex = JVMobjectType.indexOf(";");
23.234 - if((startindex != -1) && (endindex != -1)){
23.235 - if((startindex < JVMobjectType.length()) && (endindex < JVMobjectType.length())){
23.236 - objectType = JVMobjectType.substring(startindex, endindex);
23.237 - }
23.238 - objectType = objectType.replace('/','.');
23.239 - return objectType;
23.240 - }
23.241 - return null;
23.242 - }
23.243 -
23.244 - /**
23.245 - * Returns java type signature for array type.
23.246 - */
23.247 - public String getArrayType(String arrayType) {
23.248 - if(arrayType != null){
23.249 - String dimention = "";
23.250 -
23.251 - while(arrayType.indexOf("[") != -1){
23.252 - dimention += "[]";
23.253 -
23.254 - int startindex = arrayType.indexOf("[")+1;
23.255 - if(startindex <= arrayType.length()){
23.256 - arrayType = arrayType.substring(startindex);
23.257 - }
23.258 - }
23.259 -
23.260 - String componentType = "";
23.261 - if(arrayType.startsWith("L")){
23.262 - componentType = getObjectType(arrayType);
23.263 - }else {
23.264 - componentType = getBaseType(arrayType);
23.265 - }
23.266 - return componentType+dimention;
23.267 - }
23.268 - return null;
23.269 - }
23.270 -
23.271 - /**
23.272 - * Returns java type signature for parameters.
23.273 - */
23.274 - public String getParameters(){
23.275 - return parameters;
23.276 - }
23.277 -
23.278 - /**
23.279 - * Returns java type signature for return type.
23.280 - */
23.281 - public String getReturnType(){
23.282 - return returntype;
23.283 - }
23.284 -
23.285 - /**
23.286 - * Returns java type signature for field type.
23.287 - */
23.288 - public String getFieldType(){
23.289 - return fieldtype;
23.290 - }
23.291 -
23.292 - /**
23.293 - * Return number of arguments of a method.
23.294 - */
23.295 - public int getArgumentlength(){
23.296 - return argumentlength;
23.297 - }
23.298 -}
24.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Fri Dec 07 15:02:35 2012 +0100
24.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Fri Dec 07 15:57:14 2012 +0100
24.3 @@ -57,7 +57,7 @@
24.4 @JavaScriptBody(
24.5 args={"el", "r"},
24.6 body="var e = window.document.getElementById(el.fld_id);\n"
24.7 - + "e.onclick = function() { r.runV(); };\n"
24.8 + + "e.onclick = function() { r.run__V(); };\n"
24.9 )
24.10 public final void addOnClick(Runnable r) {
24.11 throw new UnsupportedOperationException("Needs JavaScript!");
25.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Dec 07 15:02:35 2012 +0100
25.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Fri Dec 07 15:57:14 2012 +0100
25.3 @@ -32,7 +32,7 @@
25.4 */
25.5 public abstract class ByteCodeToJavaScript {
25.6 private ClassData jc;
25.7 - private final Appendable out;
25.8 + final Appendable out;
25.9
25.10 protected ByteCodeToJavaScript(Appendable out) {
25.11 this.out = out;
25.12 @@ -99,12 +99,15 @@
25.13 }
25.14 if (proto == null) {
25.15 String sc = jc.getSuperClassName(); // with _
25.16 - out.append("\n var p = CLS.prototype = ").
25.17 + out.append("\n var pp = ").
25.18 append(sc.replace('/', '_')).append("(true);");
25.19 + out.append("\n var p = CLS.prototype = pp;");
25.20 out.append("\n var c = p;");
25.21 + out.append("\n var sprcls = pp.constructor.$class;");
25.22 } else {
25.23 out.append("\n var p = CLS.prototype = ").append(proto[1]).append(";");
25.24 out.append("\n var c = ").append(proto[0]).append(";");
25.25 + out.append("\n var sprcls = null;");
25.26 }
25.27 for (MethodData m : jc.getMethods()) {
25.28 byte[] onlyArr = m.findAnnotationData(true);
25.29 @@ -119,10 +122,17 @@
25.30 }
25.31 continue;
25.32 }
25.33 + String mn;
25.34 if (m.isStatic()) {
25.35 - generateStaticMethod("\n c.", m, toInitilize);
25.36 + mn = generateStaticMethod("\n c.", m, toInitilize);
25.37 } else {
25.38 - generateInstanceMethod("\n c.", m);
25.39 + mn = generateInstanceMethod("\n c.", m);
25.40 + }
25.41 + byte[] runAnno = m.findAnnotationData(false);
25.42 + if (runAnno != null) {
25.43 + out.append("\n c.").append(mn).append(".anno = {");
25.44 + generateAnno(jc, out, runAnno);
25.45 + out.append("\n };");
25.46 }
25.47 }
25.48 out.append("\n c.constructor = CLS;");
25.49 @@ -130,6 +140,16 @@
25.50 for (String superInterface : jc.getSuperInterfaces()) {
25.51 out.append("\n c.$instOf_").append(superInterface.replace('/', '_')).append(" = true;");
25.52 }
25.53 + out.append("\n CLS.$class = java_lang_Class(true);");
25.54 + out.append("\n CLS.$class.jvmName = '").append(jc.getClassName()).append("';");
25.55 + out.append("\n CLS.$class.superclass = sprcls;");
25.56 + out.append("\n CLS.$class.cnstr = CLS;");
25.57 + byte[] classAnno = jc.findAnnotationData(false);
25.58 + if (classAnno != null) {
25.59 + out.append("\n CLS.$class.anno = {");
25.60 + generateAnno(jc, out, classAnno);
25.61 + out.append("\n };");
25.62 + }
25.63 out.append("\n }");
25.64 out.append("\n if (arguments.length === 0) {");
25.65 out.append("\n if (!(this instanceof CLS)) {");
25.66 @@ -163,14 +183,15 @@
25.67 }
25.68 return sb.toString();
25.69 }
25.70 - private void generateStaticMethod(String prefix, MethodData m, StringArray toInitilize) throws IOException {
25.71 - if (javaScriptBody(prefix, m, true)) {
25.72 - return;
25.73 + private String generateStaticMethod(String prefix, MethodData m, StringArray toInitilize) throws IOException {
25.74 + String jsb = javaScriptBody(prefix, m, true);
25.75 + if (jsb != null) {
25.76 + return jsb;
25.77 }
25.78 StringBuilder argsCnt = new StringBuilder();
25.79 final String mn = findMethodName(m, argsCnt);
25.80 out.append(prefix).append(mn).append(" = function");
25.81 - if (mn.equals("classV")) {
25.82 + if (mn.equals("class__V")) {
25.83 toInitilize.add(className(jc) + "(false)." + mn);
25.84 }
25.85 out.append('(');
25.86 @@ -198,11 +219,13 @@
25.87 out.append(" throw 'no code found for ").append(m.getInternalSig()).append("';\n");
25.88 }
25.89 out.append("};");
25.90 + return mn;
25.91 }
25.92
25.93 - private void generateInstanceMethod(String prefix, MethodData m) throws IOException {
25.94 - if (javaScriptBody(prefix, m, false)) {
25.95 - return;
25.96 + private String generateInstanceMethod(String prefix, MethodData m) throws IOException {
25.97 + String jsb = javaScriptBody(prefix, m, false);
25.98 + if (jsb != null) {
25.99 + return jsb;
25.100 }
25.101 StringBuilder argsCnt = new StringBuilder();
25.102 final String mn = findMethodName(m, argsCnt);
25.103 @@ -230,6 +253,7 @@
25.104 out.append(" throw 'no code found for ").append(m.getInternalSig()).append("';\n");
25.105 }
25.106 out.append("};");
25.107 + return mn;
25.108 }
25.109
25.110 private void produceCode(MethodData m) throws IOException {
25.111 @@ -1288,6 +1312,7 @@
25.112 int i = 0;
25.113 Boolean count = null;
25.114 boolean array = false;
25.115 + sig.append("__");
25.116 int firstPos = sig.length();
25.117 while (i < descriptor.length()) {
25.118 char ch = descriptor.charAt(i++);
25.119 @@ -1298,9 +1323,6 @@
25.120 case ')':
25.121 count = false;
25.122 continue;
25.123 - case 'A':
25.124 - array = true;
25.125 - break;
25.126 case 'B':
25.127 case 'C':
25.128 case 'D':
25.129 @@ -1311,7 +1333,7 @@
25.130 case 'Z':
25.131 if (count) {
25.132 if (array) {
25.133 - sig.append('A');
25.134 + sig.append("_3");
25.135 }
25.136 sig.append(ch);
25.137 if (ch == 'J' || ch == 'D') {
25.138 @@ -1323,7 +1345,7 @@
25.139 sig.insert(firstPos, ch);
25.140 if (array) {
25.141 returnType[0] = '[';
25.142 - sig.insert(firstPos, 'A');
25.143 + sig.insert(firstPos, "_3");
25.144 } else {
25.145 returnType[0] = ch;
25.146 }
25.147 @@ -1337,33 +1359,47 @@
25.148 continue;
25.149 case 'L':
25.150 int next = descriptor.indexOf(';', i);
25.151 + String realSig = mangleSig(descriptor, i - 1, next + 1);
25.152 if (count) {
25.153 if (array) {
25.154 - sig.append('A');
25.155 + sig.append("_3");
25.156 }
25.157 - sig.append(ch);
25.158 - sig.append(descriptor.substring(i, next).replace('/', '_'));
25.159 + sig.append(realSig);
25.160 cnt.append('0');
25.161 } else {
25.162 - sig.insert(firstPos, descriptor.substring(i, next).replace('/', '_'));
25.163 - sig.insert(firstPos, ch);
25.164 + sig.insert(firstPos, realSig);
25.165 if (array) {
25.166 - sig.insert(firstPos, 'A');
25.167 + sig.insert(firstPos, "_3");
25.168 }
25.169 returnType[0] = 'L';
25.170 }
25.171 i = next + 1;
25.172 continue;
25.173 case '[':
25.174 - //arrays++;
25.175 + array = true;
25.176 continue;
25.177 default:
25.178 - break; // invalid character
25.179 + throw new IllegalStateException("Invalid char: " + ch);
25.180 }
25.181 }
25.182 }
25.183 +
25.184 + private static String mangleSig(String txt, int first, int last) {
25.185 + StringBuilder sb = new StringBuilder();
25.186 + for (int i = first; i < last; i++) {
25.187 + final char ch = txt.charAt(i);
25.188 + switch (ch) {
25.189 + case '/': sb.append('_'); break;
25.190 + case '_': sb.append("_1"); break;
25.191 + case ';': sb.append("_2"); break;
25.192 + case '[': sb.append("_3"); break;
25.193 + default: sb.append(ch); break;
25.194 + }
25.195 + }
25.196 + return sb.toString();
25.197 + }
25.198
25.199 - private String findMethodName(MethodData m, StringBuilder cnt) {
25.200 + private static String findMethodName(MethodData m, StringBuilder cnt) {
25.201 StringBuilder name = new StringBuilder();
25.202 if ("<init>".equals(m.getName())) { // NOI18N
25.203 name.append("cons"); // NOI18N
25.204 @@ -1373,11 +1409,11 @@
25.205 name.append(m.getName());
25.206 }
25.207
25.208 - countArgs(findDescriptor(m.getInternalSig()), new char[1], name, cnt);
25.209 + countArgs(m.getInternalSig(), new char[1], name, cnt);
25.210 return name.toString();
25.211 }
25.212
25.213 - private String findMethodName(String[] mi, StringBuilder cnt, char[] returnType) {
25.214 + static String findMethodName(String[] mi, StringBuilder cnt, char[] returnType) {
25.215 StringBuilder name = new StringBuilder();
25.216 String descr = mi[2];//mi.getDescriptor();
25.217 String nm= mi[1];
25.218 @@ -1386,7 +1422,7 @@
25.219 } else {
25.220 name.append(nm);
25.221 }
25.222 - countArgs(findDescriptor(descr), returnType, name, cnt);
25.223 + countArgs(descr, returnType, name, cnt);
25.224 return name.toString();
25.225 }
25.226
25.227 @@ -1480,28 +1516,32 @@
25.228 }
25.229 }
25.230
25.231 - private String encodeConstant(int entryIndex) {
25.232 - String s = jc.stringValue(entryIndex, true);
25.233 + private String encodeConstant(int entryIndex) throws IOException {
25.234 + String[] classRef = { null };
25.235 + String s = jc.stringValue(entryIndex, classRef);
25.236 + if (classRef[0] != null) {
25.237 + addReference(classRef[0]);
25.238 + }
25.239 return s;
25.240 }
25.241
25.242 - private String findDescriptor(String d) {
25.243 - return d.replace('[', 'A');
25.244 - }
25.245 -
25.246 - private boolean javaScriptBody(String prefix, MethodData m, boolean isStatic) throws IOException {
25.247 + private String javaScriptBody(String prefix, MethodData m, boolean isStatic) throws IOException {
25.248 byte[] arr = m.findAnnotationData(true);
25.249 if (arr == null) {
25.250 - return false;
25.251 + return null;
25.252 }
25.253 final String jvmType = "Lorg/apidesign/bck2brwsr/core/JavaScriptBody;";
25.254 class P extends AnnotationParser {
25.255 + public P() {
25.256 + super(false);
25.257 + }
25.258 +
25.259 int cnt;
25.260 String[] args = new String[30];
25.261 String body;
25.262
25.263 @Override
25.264 - protected void visitAttr(String type, String attr, String value) {
25.265 + protected void visitAttr(String type, String attr, String at, String value) {
25.266 if (type.equals(jvmType)) {
25.267 if ("body".equals(attr)) {
25.268 body = value;
25.269 @@ -1516,10 +1556,11 @@
25.270 P p = new P();
25.271 p.parse(arr, jc);
25.272 if (p.body == null) {
25.273 - return false;
25.274 + return null;
25.275 }
25.276 StringBuilder cnt = new StringBuilder();
25.277 - out.append(prefix).append(findMethodName(m, cnt));
25.278 + final String mn = findMethodName(m, cnt);
25.279 + out.append(prefix).append(mn);
25.280 out.append(" = function(");
25.281 String space;
25.282 int index;
25.283 @@ -1540,7 +1581,7 @@
25.284 out.append(") {").append("\n");
25.285 out.append(p.body);
25.286 out.append("\n}\n");
25.287 - return true;
25.288 + return mn;
25.289 }
25.290 private static String className(ClassData jc) {
25.291 //return jc.getName().getInternalName().replace('/', '_');
25.292 @@ -1557,9 +1598,9 @@
25.293 final String[] values = new String[attrNames.length];
25.294 final boolean[] found = { false };
25.295 final String jvmType = "L" + className.replace('.', '/') + ";";
25.296 - AnnotationParser ap = new AnnotationParser() {
25.297 + AnnotationParser ap = new AnnotationParser(false) {
25.298 @Override
25.299 - protected void visitAttr(String type, String attr, String value) {
25.300 + protected void visitAttr(String type, String attr, String at, String value) {
25.301 if (type.equals(jvmType)) {
25.302 found[0] = true;
25.303 for (int i = 0; i < attrNames.length; i++) {
25.304 @@ -1594,6 +1635,40 @@
25.305 return " = null;";
25.306 }
25.307
25.308 + private static void generateAnno(ClassData cd, final Appendable out, byte[] data) throws IOException {
25.309 + AnnotationParser ap = new AnnotationParser(true) {
25.310 + int anno;
25.311 + int cnt;
25.312 +
25.313 + @Override
25.314 + protected void visitAnnotationStart(String type) throws IOException {
25.315 + if (anno++ > 0) {
25.316 + out.append(",");
25.317 + }
25.318 + out.append('"').append(type).append("\" : {\n");
25.319 + cnt = 0;
25.320 + }
25.321 +
25.322 + @Override
25.323 + protected void visitAnnotationEnd(String type) throws IOException {
25.324 + out.append("\n}\n");
25.325 + }
25.326 +
25.327 + @Override
25.328 + protected void visitAttr(String type, String attr, String attrType, String value)
25.329 + throws IOException {
25.330 + if (attr == null) {
25.331 + return;
25.332 + }
25.333 + if (cnt++ > 0) {
25.334 + out.append(",\n");
25.335 + }
25.336 + out.append(attr).append("__").append(attrType).append(" : ").append(value);
25.337 + }
25.338 + };
25.339 + ap.parse(data, cd);
25.340 + }
25.341 +
25.342 private static int constantToVariableType(final byte constantTag) {
25.343 switch (constantTag) {
25.344 case CONSTANT_INTEGER:
26.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java Fri Dec 07 15:02:35 2012 +0100
26.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/GenJS.java Fri Dec 07 15:57:14 2012 +0100
26.3 @@ -26,7 +26,7 @@
26.4 *
26.5 * @author Jaroslav Tulach <jtulach@netbeans.org>
26.6 */
26.7 -final class GenJS extends ByteCodeToJavaScript {
26.8 +class GenJS extends ByteCodeToJavaScript {
26.9 public GenJS(Appendable out) {
26.10 super(out);
26.11 }
26.12 @@ -41,22 +41,16 @@
26.13 compile(GenJS.class.getClassLoader(), out, names);
26.14 }
26.15 static void compile(ClassLoader l, Appendable out, StringArray names) throws IOException {
26.16 - out.append("Array.prototype.fillNulls = function() {\n" +
26.17 - " for(var i = 0; i < this.length; i++) {\n" +
26.18 - " this[i] = null;\n" +
26.19 - " }\n" +
26.20 - " return this;\n" +
26.21 - "};");
26.22 -
26.23 -
26.24 + new GenJS(out).doCompile(l, names);
26.25 + }
26.26 + protected void doCompile(ClassLoader l, StringArray names) throws IOException {
26.27 StringArray processed = new StringArray();
26.28 StringArray initCode = new StringArray();
26.29 for (String baseClass : names.toArray()) {
26.30 - GenJS js = new GenJS(out);
26.31 - js.references.add(baseClass);
26.32 + references.add(baseClass);
26.33 for (;;) {
26.34 String name = null;
26.35 - for (String n : js.references.toArray()) {
26.36 + for (String n : references.toArray()) {
26.37 if (processed.contains(n)) {
26.38 continue;
26.39 }
26.40 @@ -70,7 +64,7 @@
26.41 throw new IOException("Can't find class " + name);
26.42 }
26.43 try {
26.44 - String ic = js.compile(is);
26.45 + String ic = compile(is);
26.46 processed.add(name);
26.47 initCode.add(ic == null ? "" : ic);
26.48 } catch (RuntimeException ex) {
26.49 @@ -91,20 +85,21 @@
26.50 );
26.51 }
26.52 }
26.53 - for (String resource : js.scripts.toArray()) {
26.54 - while (resource.startsWith("/")) {
26.55 - resource = resource.substring(1);
26.56 - }
26.57 - InputStream emul = l.getResourceAsStream(resource);
26.58 - if (emul == null) {
26.59 - throw new IOException("Can't find " + resource);
26.60 - }
26.61 - readResource(emul, out);
26.62 - }
26.63 - js.scripts = new StringArray();
26.64 }
26.65
26.66 - StringArray toInit = StringArray.asList(js.references.toArray());
26.67 + for (String resource : scripts.toArray()) {
26.68 + while (resource.startsWith("/")) {
26.69 + resource = resource.substring(1);
26.70 + }
26.71 + InputStream emul = l.getResourceAsStream(resource);
26.72 + if (emul == null) {
26.73 + throw new IOException("Can't find " + resource);
26.74 + }
26.75 + readResource(emul, out);
26.76 + }
26.77 + scripts = new StringArray();
26.78 +
26.79 + StringArray toInit = StringArray.asList(references.toArray());
26.80 toInit.reverse();
26.81
26.82 for (String ic : toInit.toArray()) {
27.1 --- a/vm/src/main/java/org/apidesign/vm4brwsr/StringArray.java Fri Dec 07 15:02:35 2012 +0100
27.2 +++ b/vm/src/main/java/org/apidesign/vm4brwsr/StringArray.java Fri Dec 07 15:57:14 2012 +0100
27.3 @@ -48,7 +48,7 @@
27.4 return arr == null ? new String[0] : arr;
27.5 }
27.6
27.7 - static StringArray asList(String[] names) {
27.8 + static StringArray asList(String... names) {
27.9 return new StringArray(names);
27.10 }
27.11
27.12 @@ -73,16 +73,16 @@
27.13 }
27.14
27.15 void delete(int indx) {
27.16 - if (arr == null) {
27.17 + if (arr == null || indx < 0 || indx >= arr.length) {
27.18 return;
27.19 }
27.20 String[] tmp = new String[arr.length - 1];
27.21 for (int i = 0, j = 0; i < arr.length; i++) {
27.22 - tmp[j] = arr[i];
27.23 - if (j == indx) {
27.24 - continue;
27.25 + if (i != indx) {
27.26 + tmp[j++] = arr[i];
27.27 }
27.28 }
27.29 + arr = tmp;
27.30 }
27.31
27.32 int indexOf(String ic) {
28.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java Fri Dec 07 15:02:35 2012 +0100
28.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ArrayTest.java Fri Dec 07 15:57:14 2012 +0100
28.3 @@ -29,7 +29,7 @@
28.4 */
28.5 public class ArrayTest {
28.6 @Test public void verifySimpleIntOperation() throws Exception {
28.7 - assertExec("CheckTheSum", Array.class, "simpleI",
28.8 + assertExec("CheckTheSum", Array.class, "simple__I",
28.9 Double.valueOf(15)
28.10 );
28.11 }
28.12 @@ -39,13 +39,13 @@
28.13 }
28.14
28.15 @Test public void verifyOperationsOnArrays() throws Exception {
28.16 - assertExec("The sum is 105", Array.class, "sumD",
28.17 + assertExec("The sum is 105", Array.class, "sum__D",
28.18 Double.valueOf(105)
28.19 );
28.20 }
28.21
28.22 @Test public void doesCopyArrayWork() throws Exception {
28.23 - assertExec("Returns 'a'", Array.class, "copyArrayC", Double.valueOf('a'));
28.24 + assertExec("Returns 'a'", Array.class, "copyArray__C", Double.valueOf('a'));
28.25 }
28.26
28.27 private static CharSequence codeSeq;
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
29.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ByteCodeToJavaScriptTest.java Fri Dec 07 15:57:14 2012 +0100
29.3 @@ -0,0 +1,55 @@
29.4 +/**
29.5 + * Back 2 Browser Bytecode Translator
29.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
29.7 + *
29.8 + * This program is free software: you can redistribute it and/or modify
29.9 + * it under the terms of the GNU General Public License as published by
29.10 + * the Free Software Foundation, version 2 of the License.
29.11 + *
29.12 + * This program is distributed in the hope that it will be useful,
29.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29.15 + * GNU General Public License for more details.
29.16 + *
29.17 + * You should have received a copy of the GNU General Public License
29.18 + * along with this program. Look for COPYING file in the top folder.
29.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
29.20 + */
29.21 +package org.apidesign.vm4brwsr;
29.22 +
29.23 +import static org.testng.Assert.*;
29.24 +import org.testng.annotations.Test;
29.25 +
29.26 +/**
29.27 + *
29.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
29.29 + */
29.30 +public class ByteCodeToJavaScriptTest {
29.31 +
29.32 + public ByteCodeToJavaScriptTest() {
29.33 + }
29.34 +
29.35 + @Test
29.36 + public void findMethodNameManglesObjectsCorrectly() {
29.37 + StringBuilder cnt = new StringBuilder();
29.38 + char[] returnType = { 'V' };
29.39 + String ret = ByteCodeToJavaScript.findMethodName(new String[] {
29.40 + "StringTest", "replace", "(Ljava/lang/String;CC)Ljava/lang/String;"
29.41 + }, cnt, returnType);
29.42 + assertEquals(cnt.toString(), "000", "No doubles or longs");
29.43 + assertTrue(returnType[0] != 'V', "Returns string");
29.44 + assertEquals(ret, "replace__Ljava_lang_String_2Ljava_lang_String_2CC");
29.45 + }
29.46 +
29.47 + @Test
29.48 + public void manglingArrays() {
29.49 + StringBuilder cnt = new StringBuilder();
29.50 + char[] returnType = { 'V' };
29.51 + String ret = ByteCodeToJavaScript.findMethodName(new String[] {
29.52 + "VMinVM", "toJavaScript", "([B)Ljava/lang/String;"
29.53 + }, cnt, returnType);
29.54 + assertEquals(cnt.toString(), "0", "No doubles or longs");
29.55 + assertTrue(returnType[0] != 'V', "Returns string");
29.56 + assertEquals(ret, "toJavaScript__Ljava_lang_String_2_3B");
29.57 + }
29.58 +}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
30.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ClassTest.java Fri Dec 07 15:57:14 2012 +0100
30.3 @@ -0,0 +1,132 @@
30.4 +/**
30.5 + * Back 2 Browser Bytecode Translator
30.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
30.7 + *
30.8 + * This program is free software: you can redistribute it and/or modify
30.9 + * it under the terms of the GNU General Public License as published by
30.10 + * the Free Software Foundation, version 2 of the License.
30.11 + *
30.12 + * This program is distributed in the hope that it will be useful,
30.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
30.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30.15 + * GNU General Public License for more details.
30.16 + *
30.17 + * You should have received a copy of the GNU General Public License
30.18 + * along with this program. Look for COPYING file in the top folder.
30.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
30.20 + */
30.21 +package org.apidesign.vm4brwsr;
30.22 +
30.23 +import javax.script.Invocable;
30.24 +import org.testng.annotations.Test;
30.25 +import static org.testng.Assert.*;
30.26 +import org.testng.annotations.BeforeClass;
30.27 +
30.28 +/**
30.29 + *
30.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
30.31 + */
30.32 +public class ClassTest {
30.33 +
30.34 + @Test public void superClassEqualsGetSuperclass() {
30.35 + assertTrue(Classes.equalsClassesOfExceptions(), "Classes are equal");
30.36 + }
30.37 +
30.38 + @Test public void jsSuperClassEqualsGetSuperclass() throws Exception {
30.39 + assertExec("Classes are equal", Classes.class, "equalsClassesOfExceptions__Z", Double.valueOf(1.0));
30.40 + }
30.41 +
30.42 + @Test public void classesAreDifferent() {
30.43 + assertTrue(Classes.differenceInClasses(), "Classes are not equal");
30.44 + }
30.45 +
30.46 + @Test public void jsClassesAreDifferent() throws Exception {
30.47 + assertExec("Classes are not equal", Classes.class, "differenceInClasses__Z", Double.valueOf(1.0));
30.48 + }
30.49 +
30.50 + @Test public void javaInstanceName() throws Exception {
30.51 + assertEquals(Classes.classForInstance(), "java.io.IOException");
30.52 + }
30.53 + @Test public void jsInstanceName() throws Exception {
30.54 + assertExec("I/O name", Classes.class, "classForInstance__Ljava_lang_String_2", "java.io.IOException");
30.55 + }
30.56 + @Test public void javaName() throws Exception {
30.57 + assertEquals(Classes.name(), "java.io.IOException");
30.58 + }
30.59 + @Test public void jsName() throws Exception {
30.60 + assertExec("I/O name", Classes.class, "name__Ljava_lang_String_2", "java.io.IOException");
30.61 + }
30.62 + @Test public void javaSimpleName() throws Exception {
30.63 + assertEquals(Classes.simpleName(), "IOException");
30.64 + }
30.65 + @Test public void jsGetsSimpleName() throws Exception {
30.66 + assertExec("I/O simple name", Classes.class, "simpleName__Ljava_lang_String_2", "IOException");
30.67 + }
30.68 + @Test public void javaCanonicalName() {
30.69 + assertEquals(Classes.canonicalName(), "java.io.IOException");
30.70 + }
30.71 + @Test public void jsCanonicalName() throws Exception {
30.72 + assertExec("I/O simple name", Classes.class, "canonicalName__Ljava_lang_String_2", "java.io.IOException");
30.73 + }
30.74 + @Test public void javaNewInstance() throws Exception {
30.75 + assertTrue(Classes.newInstance());
30.76 + }
30.77 + @Test public void jsNewInstance() throws Exception {
30.78 + assertExec("Check new instance", Classes.class, "newInstance__Z", Double.valueOf(1));
30.79 + }
30.80 + @Test public void jsAnnotation() throws Exception {
30.81 + assertExec("Check class annotation", Classes.class, "getMarker__I", Double.valueOf(10));
30.82 + }
30.83 + @Test public void jsStringAnnotation() throws Exception {
30.84 + assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", true);
30.85 + }
30.86 + @Test public void jsStringAnnotationFromArray() throws Exception {
30.87 + assertExec("Check class annotation", Classes.class, "getNamer__Ljava_lang_String_2Z", "my text", false);
30.88 + }
30.89 + @Test public void javaInvokeMethod() throws Exception {
30.90 + assertEquals(Classes.reflectiveMethodCall(true, "name"), "java.io.IOException", "Calls the name() method via reflection");
30.91 + }
30.92 + @Test public void jsInvokeMethod() throws Exception {
30.93 + assertExec("Calls the name() method via reflection", Classes.class,
30.94 + "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2",
30.95 + "java.io.IOException", true, "name"
30.96 + );
30.97 + }
30.98 + @Test public void javaFindMethod() throws Exception {
30.99 + assertEquals(Classes.reflectiveMethodCall(false, "name"), "java.io.IOException", "Calls the name() method via reflection");
30.100 + }
30.101 + @Test public void jsFindMethod() throws Exception {
30.102 + assertExec("Calls the name() method via reflection", Classes.class,
30.103 + "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2",
30.104 + "java.io.IOException", false, "name"
30.105 + );
30.106 + }
30.107 + @Test public void javaAnnotatedMethod() throws Exception {
30.108 + assertEquals(Classes.reflectiveMethodCall(false, null), "java.io.IOException", "Calls the name() method via reflection");
30.109 + }
30.110 + @Test public void jsAnnotatedMethod() throws Exception {
30.111 + assertExec("Calls the name() method via reflection", Classes.class,
30.112 + "reflectiveMethodCall__Ljava_lang_Object_2ZLjava_lang_String_2",
30.113 + "java.io.IOException", false, null
30.114 + );
30.115 + }
30.116 +
30.117 + private static CharSequence codeSeq;
30.118 + private static Invocable code;
30.119 +
30.120 + @BeforeClass
30.121 + public void compileTheCode() throws Exception {
30.122 + if (codeSeq == null) {
30.123 + StringBuilder sb = new StringBuilder();
30.124 + code = StaticMethodTest.compileClass(sb, "org/apidesign/vm4brwsr/Classes");
30.125 + codeSeq = sb;
30.126 + }
30.127 + }
30.128 +
30.129 + private void assertExec(
30.130 + String msg, Class clazz, String method, Object expRes, Object... args
30.131 + ) throws Exception {
30.132 + StaticMethodTest.assertExec(code, codeSeq, msg, clazz, method, expRes, args);
30.133 + }
30.134 +
30.135 +}
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
31.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Classes.java Fri Dec 07 15:57:14 2012 +0100
31.3 @@ -0,0 +1,114 @@
31.4 +/**
31.5 + * Back 2 Browser Bytecode Translator
31.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
31.7 + *
31.8 + * This program is free software: you can redistribute it and/or modify
31.9 + * it under the terms of the GNU General Public License as published by
31.10 + * the Free Software Foundation, version 2 of the License.
31.11 + *
31.12 + * This program is distributed in the hope that it will be useful,
31.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
31.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31.15 + * GNU General Public License for more details.
31.16 + *
31.17 + * You should have received a copy of the GNU General Public License
31.18 + * along with this program. Look for COPYING file in the top folder.
31.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
31.20 + */
31.21 +package org.apidesign.vm4brwsr;
31.22 +
31.23 +import java.io.IOException;
31.24 +import java.lang.annotation.Annotation;
31.25 +import java.lang.reflect.Method;
31.26 +import java.net.MalformedURLException;
31.27 +import org.apidesign.bck2brwsr.core.JavaScriptBody;
31.28 +
31.29 +/**
31.30 + *
31.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
31.32 + */
31.33 +@ClassesMarker(number = 10)
31.34 +@ClassesNamer(name = "my text")
31.35 +public class Classes {
31.36 + public static boolean equalsClassesOfExceptions() {
31.37 + return MalformedURLException.class.getSuperclass() == IOException.class;
31.38 + }
31.39 + public static boolean differenceInClasses() {
31.40 + Class<?> c1 = MalformedURLException.class;
31.41 + Class<?> c2 = IOException.class;
31.42 + return c1 != c2;
31.43 + }
31.44 +
31.45 + public static String classForInstance() {
31.46 + return new IOException().getClass().getName().toString();
31.47 + }
31.48 +
31.49 + @ClassesMarker(number = 1)
31.50 + public static String name() {
31.51 + return IOException.class.getName().toString();
31.52 + }
31.53 + public static String simpleName() {
31.54 + return IOException.class.getSimpleName();
31.55 + }
31.56 + public static String canonicalName() {
31.57 + return IOException.class.getCanonicalName();
31.58 + }
31.59 + public static boolean newInstance() throws Exception {
31.60 + IOException ioe = IOException.class.newInstance();
31.61 + if (ioe instanceof IOException) {
31.62 + return ioe.getClass() == IOException.class;
31.63 + }
31.64 + throw new IllegalStateException("Not a subtype: " + ioe);
31.65 + }
31.66 + public static int getMarker() {
31.67 + if (!Classes.class.isAnnotationPresent(ClassesMarker.class)) {
31.68 + return -2;
31.69 + }
31.70 + ClassesMarker cm = Classes.class.getAnnotation(ClassesMarker.class);
31.71 + return cm == null ? -1 : cm.number();
31.72 + }
31.73 + public static String getNamer(boolean direct) {
31.74 + if (direct) {
31.75 + ClassesNamer cm = Classes.class.getAnnotation(ClassesNamer.class);
31.76 + return cm == null ? null : cm.name();
31.77 + }
31.78 + for (Annotation a : Classes.class.getAnnotations()) {
31.79 + if (a instanceof ClassesNamer) {
31.80 + return ((ClassesNamer)a).name();
31.81 + }
31.82 + }
31.83 + return null;
31.84 + }
31.85 +
31.86 + @JavaScriptBody(args = "msg", body = "throw msg;")
31.87 + private static native void thrw(String msg);
31.88 +
31.89 + public static Object reflectiveMethodCall(boolean direct, String mn) throws Exception {
31.90 + Method find = null;
31.91 + StringBuilder sb = new StringBuilder();
31.92 + if (!direct) {
31.93 + final Class<? extends Annotation> v = ClassesMarker.class;
31.94 + for (Method m : Classes.class.getMethods()) {
31.95 + sb.append("\n").append(m.getName());
31.96 + if (mn != null) {
31.97 + if (m.getName().equals(mn)) {
31.98 + find = m;
31.99 + break;
31.100 + }
31.101 + } else {
31.102 + if (m.getAnnotation(v) != null) {
31.103 + find = m;
31.104 + break;
31.105 + }
31.106 + }
31.107 + }
31.108 + } else {
31.109 + find = Classes.class.getMethod(mn);
31.110 + }
31.111 + if (find == null) {
31.112 + thrw(sb.toString());
31.113 + throw new NullPointerException(sb.toString());
31.114 + }
31.115 + return find.invoke(null);
31.116 + }
31.117 +}
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
32.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ClassesMarker.java Fri Dec 07 15:57:14 2012 +0100
32.3 @@ -0,0 +1,30 @@
32.4 +/**
32.5 + * Back 2 Browser Bytecode Translator
32.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
32.7 + *
32.8 + * This program is free software: you can redistribute it and/or modify
32.9 + * it under the terms of the GNU General Public License as published by
32.10 + * the Free Software Foundation, version 2 of the License.
32.11 + *
32.12 + * This program is distributed in the hope that it will be useful,
32.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
32.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32.15 + * GNU General Public License for more details.
32.16 + *
32.17 + * You should have received a copy of the GNU General Public License
32.18 + * along with this program. Look for COPYING file in the top folder.
32.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
32.20 + */
32.21 +package org.apidesign.vm4brwsr;
32.22 +
32.23 +import java.lang.annotation.Retention;
32.24 +import java.lang.annotation.RetentionPolicy;
32.25 +
32.26 +/**
32.27 + *
32.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
32.29 + */
32.30 +@Retention(RetentionPolicy.RUNTIME)
32.31 +public @interface ClassesMarker {
32.32 + int number();
32.33 +}
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
33.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/ClassesNamer.java Fri Dec 07 15:57:14 2012 +0100
33.3 @@ -0,0 +1,30 @@
33.4 +/**
33.5 + * Back 2 Browser Bytecode Translator
33.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
33.7 + *
33.8 + * This program is free software: you can redistribute it and/or modify
33.9 + * it under the terms of the GNU General Public License as published by
33.10 + * the Free Software Foundation, version 2 of the License.
33.11 + *
33.12 + * This program is distributed in the hope that it will be useful,
33.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
33.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33.15 + * GNU General Public License for more details.
33.16 + *
33.17 + * You should have received a copy of the GNU General Public License
33.18 + * along with this program. Look for COPYING file in the top folder.
33.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
33.20 + */
33.21 +package org.apidesign.vm4brwsr;
33.22 +
33.23 +import java.lang.annotation.Retention;
33.24 +import java.lang.annotation.RetentionPolicy;
33.25 +
33.26 +/**
33.27 + *
33.28 + * @author Jaroslav Tulach <jtulach@netbeans.org>
33.29 + */
33.30 +@Retention(RetentionPolicy.RUNTIME)
33.31 +public @interface ClassesNamer {
33.32 + String name();
33.33 +}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
34.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/Compare.java Fri Dec 07 15:57:14 2012 +0100
34.3 @@ -0,0 +1,36 @@
34.4 +/**
34.5 + * Back 2 Browser Bytecode Translator
34.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
34.7 + *
34.8 + * This program is free software: you can redistribute it and/or modify
34.9 + * it under the terms of the GNU General Public License as published by
34.10 + * the Free Software Foundation, version 2 of the License.
34.11 + *
34.12 + * This program is distributed in the hope that it will be useful,
34.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
34.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34.15 + * GNU General Public License for more details.
34.16 + *
34.17 + * You should have received a copy of the GNU General Public License
34.18 + * along with this program. Look for COPYING file in the top folder.
34.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
34.20 + */
34.21 +package org.apidesign.vm4brwsr;
34.22 +
34.23 +import java.lang.annotation.ElementType;
34.24 +import java.lang.annotation.Retention;
34.25 +import java.lang.annotation.RetentionPolicy;
34.26 +import java.lang.annotation.Target;
34.27 +
34.28 +/** Can be applied on a method that yields a return value.
34.29 + * Together with {@link VMCompare#create} it can be used to write
34.30 + * methods which are executed in real as well as JavaScript VMs and
34.31 + * their results are compared.
34.32 + *
34.33 + * @author Jaroslav Tulach <jtulach@netbeans.org>
34.34 + */
34.35 +@Retention(RetentionPolicy.RUNTIME)
34.36 +@Target(ElementType.METHOD)
34.37 +public @interface Compare {
34.38 +
34.39 +}
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
35.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/CompareVMs.java Fri Dec 07 15:57:14 2012 +0100
35.3 @@ -0,0 +1,146 @@
35.4 +/**
35.5 + * Back 2 Browser Bytecode Translator
35.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
35.7 + *
35.8 + * This program is free software: you can redistribute it and/or modify
35.9 + * it under the terms of the GNU General Public License as published by
35.10 + * the Free Software Foundation, version 2 of the License.
35.11 + *
35.12 + * This program is distributed in the hope that it will be useful,
35.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
35.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35.15 + * GNU General Public License for more details.
35.16 + *
35.17 + * You should have received a copy of the GNU General Public License
35.18 + * along with this program. Look for COPYING file in the top folder.
35.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
35.20 + */
35.21 +package org.apidesign.vm4brwsr;
35.22 +
35.23 +import java.lang.reflect.Method;
35.24 +import javax.script.Invocable;
35.25 +import javax.script.ScriptEngine;
35.26 +import javax.script.ScriptEngineManager;
35.27 +import org.testng.Assert;
35.28 +import org.testng.ITest;
35.29 +import org.testng.annotations.Factory;
35.30 +import org.testng.annotations.Test;
35.31 +
35.32 +/** A TestNG {@link Factory} that seeks for {@link Compare} annotations
35.33 + * in provided class and builds set of tests that compare the computations
35.34 + * in real as well as JavaScript virtual machines. Use as:<pre>
35.35 + * {@code @}{@link Factory} public static create() {
35.36 + * return @{link CompareVMs}.{@link #create(YourClass.class);
35.37 + * }</pre>
35.38 + *
35.39 + * @author Jaroslav Tulach <jtulach@netbeans.org>
35.40 + */
35.41 +public final class CompareVMs implements ITest {
35.42 + private final Run first, second;
35.43 + private final Method m;
35.44 +
35.45 + private CompareVMs(Method m, Run first, Run second) {
35.46 + this.first = first;
35.47 + this.second = second;
35.48 + this.m = m;
35.49 + }
35.50 +
35.51 + public static Object[] create(Class<?> clazz) {
35.52 + Method[] arr = clazz.getMethods();
35.53 + Object[] ret = new Object[3 * arr.length];
35.54 + int cnt = 0;
35.55 + for (Method m : arr) {
35.56 + Compare c = m.getAnnotation(Compare.class);
35.57 + if (c == null) {
35.58 + continue;
35.59 + }
35.60 + final Run real = new Run(m, false);
35.61 + final Run js = new Run(m, true);
35.62 + ret[cnt++] = real;
35.63 + ret[cnt++] = js;
35.64 + ret[cnt++] = new CompareVMs(m, real, js);
35.65 + }
35.66 + Object[] r = new Object[cnt];
35.67 + for (int i = 0; i < cnt; i++) {
35.68 + r[i] = ret[i];
35.69 + }
35.70 + return r;
35.71 + }
35.72 +
35.73 + @Test(dependsOnGroups = "run") public void compareResults() throws Throwable {
35.74 + Object v1 = first.value;
35.75 + Object v2 = second.value;
35.76 + if (v1 instanceof Number) {
35.77 + v1 = ((Number)v1).doubleValue();
35.78 + }
35.79 + Assert.assertEquals(v1, v2, "Comparing results");
35.80 + }
35.81 +
35.82 + @Override
35.83 + public String getTestName() {
35.84 + return m.getName() + "[Compare]";
35.85 + }
35.86 +
35.87 + public static final class Run implements ITest {
35.88 + private final Method m;
35.89 + private final boolean js;
35.90 + Object value;
35.91 + private static Invocable code;
35.92 + private static CharSequence codeSeq;
35.93 +
35.94 + private Run(Method m, boolean js) {
35.95 + this.m = m;
35.96 + this.js = js;
35.97 + }
35.98 +
35.99 + private static void compileTheCode(Class<?> clazz) throws Exception {
35.100 + if (code != null) {
35.101 + return;
35.102 + }
35.103 + StringBuilder sb = new StringBuilder();
35.104 + class SkipMe extends GenJS {
35.105 +
35.106 + public SkipMe(Appendable out) {
35.107 + super(out);
35.108 + }
35.109 +
35.110 + @Override
35.111 + protected boolean requireReference(String cn) {
35.112 + if (cn.contains("CompareVMs")) {
35.113 + return true;
35.114 + }
35.115 + return super.requireReference(cn);
35.116 + }
35.117 + }
35.118 + SkipMe sm = new SkipMe(sb);
35.119 + sm.doCompile(CompareVMs.class.getClassLoader(), StringArray.asList(
35.120 + clazz.getName().replace('.', '/')));
35.121 +
35.122 + ScriptEngineManager sem = new ScriptEngineManager();
35.123 + ScriptEngine js = sem.getEngineByExtension("js");
35.124 +
35.125 + Object res = js.eval(sb.toString());
35.126 + Assert.assertTrue(js instanceof Invocable, "It is invocable object: " + res);
35.127 + code = (Invocable) js;
35.128 + codeSeq = sb;
35.129 + }
35.130 +
35.131 + @Test(groups = "run") public void executeCode() throws Throwable {
35.132 + if (js) {
35.133 + try {
35.134 + compileTheCode(m.getDeclaringClass());
35.135 + Object inst = code.invokeFunction(m.getDeclaringClass().getName().replace('.', '_'), false);
35.136 + value = code.invokeMethod(inst, m.getName() + "__I");
35.137 + } catch (Exception ex) {
35.138 + throw new AssertionError(StaticMethodTest.dumpJS(codeSeq)).initCause(ex);
35.139 + }
35.140 + } else {
35.141 + value = m.invoke(m.getDeclaringClass().newInstance());
35.142 + }
35.143 + }
35.144 + @Override
35.145 + public String getTestName() {
35.146 + return m.getName() + (js ? "[JavaScript]" : "[Java]");
35.147 + }
35.148 + }
35.149 +}
36.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java Fri Dec 07 15:02:35 2012 +0100
36.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/InstanceTest.java Fri Dec 07 15:57:14 2012 +0100
36.3 @@ -29,42 +29,42 @@
36.4 @Test public void verifyDefaultDoubleValue() throws Exception {
36.5 assertExec(
36.6 "Will be zero",
36.7 - Instance.class, "defaultDblValueD",
36.8 + Instance.class, "defaultDblValue__D",
36.9 Double.valueOf(0)
36.10 );
36.11 }
36.12 @Test public void verifyStaticMethodCall() throws Exception {
36.13 assertExec(
36.14 "Will be zero",
36.15 - InstanceSub.class, "recallDblD",
36.16 + InstanceSub.class, "recallDbl__D",
36.17 Double.valueOf(0)
36.18 );
36.19 }
36.20 @Test public void verifyAssignedByteValue() throws Exception {
36.21 assertExec(
36.22 "Will one thirty one",
36.23 - Instance.class, "assignedByteValueB",
36.24 + Instance.class, "assignedByteValue__B",
36.25 Double.valueOf(31)
36.26 );
36.27 }
36.28 @Test public void verifyMagicOne() throws Exception {
36.29 assertExec(
36.30 "Should be three and something",
36.31 - Instance.class, "magicOneD",
36.32 + Instance.class, "magicOne__D",
36.33 Double.valueOf(3.3)
36.34 );
36.35 }
36.36 @Test public void verifyInstanceMethods() throws Exception {
36.37 assertExec(
36.38 "Should be eleven as we invoke overwritten method, plus 44",
36.39 - Instance.class, "virtualBytesI",
36.40 + Instance.class, "virtualBytes__I",
36.41 Double.valueOf(55)
36.42 );
36.43 }
36.44 @Test public void verifyInterfaceMethods() throws Exception {
36.45 assertExec(
36.46 "Retruns default value",
36.47 - Instance.class, "interfaceBytesF",
36.48 + Instance.class, "interfaceBytes__F",
36.49 Double.valueOf(31)
36.50 );
36.51 }
36.52 @@ -72,7 +72,7 @@
36.53 @Test public void isNull() throws Exception {
36.54 assertExec(
36.55 "Yes, we are instance",
36.56 - Instance.class, "isNullZ",
36.57 + Instance.class, "isNull__Z",
36.58 Double.valueOf(0.0)
36.59 );
36.60 }
36.61 @@ -80,7 +80,7 @@
36.62 @Test public void isInstanceOf() throws Exception {
36.63 assertExec(
36.64 "Yes, we are instance",
36.65 - Instance.class, "instanceOfZZ",
36.66 + Instance.class, "instanceOf__ZZ",
36.67 Double.valueOf(1.0), true
36.68 );
36.69 }
36.70 @@ -88,7 +88,7 @@
36.71 @Test public void notInstanceOf() throws Exception {
36.72 assertExec(
36.73 "No, we are not an instance",
36.74 - Instance.class, "instanceOfZZ",
36.75 + Instance.class, "instanceOf__ZZ",
36.76 Double.valueOf(0.0), false
36.77 );
36.78 }
36.79 @@ -96,14 +96,14 @@
36.80 @Test public void verifyCastToClass() throws Exception {
36.81 assertExec(
36.82 "Five signals all is good",
36.83 - Instance.class, "castsWorkIZ",
36.84 + Instance.class, "castsWork__IZ",
36.85 Double.valueOf(5.0), false
36.86 );
36.87 }
36.88 @Test public void verifyCastToInterface() throws Exception {
36.89 assertExec(
36.90 "Five signals all is good",
36.91 - Instance.class, "castsWorkIZ",
36.92 + Instance.class, "castsWork__IZ",
36.93 Double.valueOf(5.0), true
36.94 );
36.95 }
36.96 @@ -111,7 +111,7 @@
36.97 @Test public void sharedConstructor() throws Exception {
36.98 assertExec(
36.99 "Constructor of first and 2nd instance should be the same",
36.100 - Instance.class, "sharedConstructorZ",
36.101 + Instance.class, "sharedConstructor__Z",
36.102 Double.valueOf(1.0)
36.103 );
36.104 }
36.105 @@ -119,7 +119,7 @@
36.106 @Test public void differentConstructor() throws Exception {
36.107 assertExec(
36.108 "Constructor of X and Y should be the different",
36.109 - Instance.class, "differentConstructorZ",
36.110 + Instance.class, "differentConstructor__Z",
36.111 Double.valueOf(0)
36.112 );
36.113 }
36.114 @@ -127,7 +127,7 @@
36.115 @Test public void jsObjectIsLikeJavaObject() throws Exception {
36.116 assertExec(
36.117 "JavaScript object is instance of Java Object",
36.118 - Instance.class, "iofObjectZ",
36.119 + Instance.class, "iofObject__Z",
36.120 Double.valueOf(1)
36.121 );
36.122 }
37.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Fri Dec 07 15:02:35 2012 +0100
37.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Fri Dec 07 15:57:14 2012 +0100
37.3 @@ -29,19 +29,19 @@
37.4 */
37.5 public class NumberTest {
37.6 @Test public void integerFromString() throws Exception {
37.7 - assertExec("Can convert string to integer", Integer.class, "parseIntILjava_lang_String",
37.8 + assertExec("Can convert string to integer", Integer.class, "parseInt__ILjava_lang_String_2",
37.9 Double.valueOf(333), "333"
37.10 );
37.11 }
37.12
37.13 @Test public void doubleFromString() throws Exception {
37.14 - assertExec("Can convert string to double", Double.class, "parseDoubleDLjava_lang_String",
37.15 + assertExec("Can convert string to double", Double.class, "parseDouble__DLjava_lang_String_2",
37.16 Double.valueOf(33.3), "33.3"
37.17 );
37.18 }
37.19
37.20 @Test public void autoboxDouble() throws Exception {
37.21 - assertExec("Autoboxing of doubles is OK", Numbers.class, "autoboxDblToStringLjava_lang_String",
37.22 + assertExec("Autoboxing of doubles is OK", Numbers.class, "autoboxDblToString__Ljava_lang_String_2",
37.23 "3.3"
37.24 );
37.25 }
37.26 @@ -51,7 +51,7 @@
37.27 }
37.28
37.29 @Test public void jslog1000() throws Exception {
37.30 - assertExec("log_10(1000) == 3", Math.class, "log10DD",
37.31 + assertExec("log_10(1000) == 3", Math.class, "log10__DD",
37.32 Double.valueOf(3.0), 1000.0
37.33 );
37.34 }
37.35 @@ -60,20 +60,20 @@
37.36 assertEquals(3, Numbers.rem(303, 10));
37.37 }
37.38 @Test public void jsRem() throws Exception {
37.39 - assertExec("Should be three", Numbers.class, "remIII",
37.40 + assertExec("Should be three", Numbers.class, "rem__III",
37.41 Double.valueOf(3.0), 303, 10
37.42 );
37.43 }
37.44
37.45 @Test public void deserializeInt() throws Exception {
37.46 int exp = Numbers.deserInt();
37.47 - assertExec("Should be the same", Numbers.class, "deserIntI",
37.48 + assertExec("Should be the same", Numbers.class, "deserInt__I",
37.49 Double.valueOf(exp)
37.50 );
37.51 }
37.52
37.53 @Test public void deserializeSimpleLong() throws Exception {
37.54 - assertExec("Should be 3454", Numbers.class, "deserLongJAB",
37.55 + assertExec("Should be 3454", Numbers.class, "deserLong__J_3B",
37.56 Double.valueOf(3454),
37.57 new byte[] { (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)13, (byte)126 }
37.58 );
37.59 @@ -84,7 +84,7 @@
37.60 (byte)64, (byte)8, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0, (byte)0
37.61 };
37.62 long exp = Numbers.deserLong(arr);
37.63 - assertExec("Should be " + exp, "org_apidesign_vm4brwsr_Numbers_deserLongJAB",
37.64 + assertExec("Should be " + exp, "org_apidesign_vm4brwsr_Numbers_deserLong__JAB",
37.65 Double.valueOf(exp), arr);
37.66 }
37.67 */
37.68 @@ -97,7 +97,7 @@
37.69
37.70 @Test public void deserializeFloatInJS() throws Exception {
37.71 float f = 54324.32423f;
37.72 - assertExec("Should be the same", Numbers.class, "deserFloatF",
37.73 + assertExec("Should be the same", Numbers.class, "deserFloat__F",
37.74 Double.valueOf(f)
37.75 );
37.76 }
37.77 @@ -110,7 +110,7 @@
37.78
37.79 @Test public void deserializeDoubleInJS() throws Exception {
37.80 double f = 3.0;
37.81 - assertExec("Should be the same", Numbers.class, "deserDoubleD", f);
37.82 + assertExec("Should be the same", Numbers.class, "deserDouble__D", f);
37.83 }
37.84 /*
37.85 @Test public void serDouble() throws IOException {
37.86 @@ -131,7 +131,7 @@
37.87 @Test public void fiveInStringJS() throws Exception {
37.88 String s = Numbers.intToString();
37.89 assertExec("Should be the same: " + s,
37.90 - Numbers.class, "intToStringLjava_lang_String",
37.91 + Numbers.class, "intToString__Ljava_lang_String_2",
37.92 s
37.93 );
37.94 }
37.95 @@ -139,7 +139,7 @@
37.96 @Test public void sevenInStringJS() throws Exception {
37.97 String s = Numbers.floatToString();
37.98 assertExec("Should be the same: " + s,
37.99 - Numbers.class, "floatToStringLjava_lang_String",
37.100 + Numbers.class, "floatToString__Ljava_lang_String_2",
37.101 s
37.102 );
37.103 }
38.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java Fri Dec 07 15:02:35 2012 +0100
38.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StaticMethodTest.java Fri Dec 07 15:57:14 2012 +0100
38.3 @@ -36,7 +36,7 @@
38.4 @Test public void threePlusFour() throws Exception {
38.5 assertExec(
38.6 "Should be seven",
38.7 - StaticMethod.class, "sumIII",
38.8 + StaticMethod.class, "sum__III",
38.9 Double.valueOf(7),
38.10 3, 4
38.11 );
38.12 @@ -45,7 +45,7 @@
38.13 @Test public void checkReallyInitializedValues() throws Exception {
38.14 assertExec(
38.15 "Return true",
38.16 - StaticMethod.class, "isNullZ",
38.17 + StaticMethod.class, "isNull__Z",
38.18 Double.valueOf(1)
38.19 );
38.20 }
38.21 @@ -53,7 +53,7 @@
38.22 @Test public void powerOfThree() throws Exception {
38.23 assertExec(
38.24 "Should be nine",
38.25 - StaticMethod.class, "powerFF",
38.26 + StaticMethod.class, "power__FF",
38.27 Double.valueOf(9),
38.28 3.0f
38.29 );
38.30 @@ -62,7 +62,7 @@
38.31 @Test public void minusOne() throws Exception {
38.32 assertExec(
38.33 "Should be minus one",
38.34 - StaticMethod.class, "minusOneI",
38.35 + StaticMethod.class, "minusOne__I",
38.36 Double.valueOf(-1)
38.37 );
38.38 }
38.39 @@ -70,7 +70,7 @@
38.40 @Test public void doubleWithoutLong() throws Exception {
38.41 assertExec(
38.42 "Should be two",
38.43 - StaticMethod.class, "minusDDJ",
38.44 + StaticMethod.class, "minus__DDJ",
38.45 Double.valueOf(2),
38.46 3.0d, 1l
38.47 );
38.48 @@ -79,7 +79,7 @@
38.49 @Test public void divAndRound() throws Exception {
38.50 assertExec(
38.51 "Should be rounded to one",
38.52 - StaticMethod.class, "divIBD",
38.53 + StaticMethod.class, "div__IBD",
38.54 Double.valueOf(1),
38.55 3, 3.75
38.56 );
38.57 @@ -87,7 +87,7 @@
38.58 @Test public void mixedMethodFourParams() throws Exception {
38.59 assertExec(
38.60 "Should be two",
38.61 - StaticMethod.class, "mixIIJBD",
38.62 + StaticMethod.class, "mix__IIJBD",
38.63 Double.valueOf(20),
38.64 2, 10l, 5, 2.0
38.65 );
38.66 @@ -95,7 +95,7 @@
38.67 @Test public void factRec() throws Exception {
38.68 assertExec(
38.69 "Factorial of 5 is 120",
38.70 - StaticMethod.class, "factRecJI",
38.71 + StaticMethod.class, "factRec__JI",
38.72 Double.valueOf(120),
38.73 5
38.74 );
38.75 @@ -103,7 +103,7 @@
38.76 @Test public void factIter() throws Exception {
38.77 assertExec(
38.78 "Factorial of 5 is 120",
38.79 - StaticMethod.class, "factIterJI",
38.80 + StaticMethod.class, "factIter__JI",
38.81 Double.valueOf(120),
38.82 5
38.83 );
38.84 @@ -112,7 +112,7 @@
38.85 @Test public void xor() throws Exception {
38.86 assertExec(
38.87 "Xor is 4",
38.88 - StaticMethod.class, "xorJIJ",
38.89 + StaticMethod.class, "xor__JIJ",
38.90 Double.valueOf(4),
38.91 7,
38.92 3
38.93 @@ -122,7 +122,7 @@
38.94 @Test public void or() throws Exception {
38.95 assertExec(
38.96 "Or will be 7",
38.97 - StaticMethod.class, "orOrAndJZII",
38.98 + StaticMethod.class, "orOrAnd__JZII",
38.99 Double.valueOf(7),
38.100 true,
38.101 4,
38.102 @@ -132,14 +132,14 @@
38.103 @Test public void nullCheck() throws Exception {
38.104 assertExec(
38.105 "Returns nothing",
38.106 - StaticMethod.class, "noneLjava_lang_ObjectII",
38.107 + StaticMethod.class, "none__Ljava_lang_Object_2II",
38.108 null, 1, 3
38.109 );
38.110 }
38.111 @Test public void and() throws Exception {
38.112 assertExec(
38.113 "And will be 3",
38.114 - StaticMethod.class, "orOrAndJZII",
38.115 + StaticMethod.class, "orOrAnd__JZII",
38.116 Double.valueOf(3),
38.117 false,
38.118 7,
38.119 @@ -149,7 +149,7 @@
38.120 @Test public void inc4() throws Exception {
38.121 assertExec(
38.122 "It will be 4",
38.123 - StaticMethod.class, "inc4I",
38.124 + StaticMethod.class, "inc4__I",
38.125 Double.valueOf(4)
38.126 );
38.127 }
38.128 @@ -162,7 +162,7 @@
38.129 @Test public void shiftLeftInJS() throws Exception {
38.130 assertExec(
38.131 "Setting 9th bit",
38.132 - StaticMethod.class, "shiftLeftIII",
38.133 + StaticMethod.class, "shiftLeft__III",
38.134 Double.valueOf(256),
38.135 1, 8
38.136 );
38.137 @@ -176,7 +176,7 @@
38.138 @Test public void shiftRightInJS() throws Exception {
38.139 assertExec(
38.140 "Get -1",
38.141 - StaticMethod.class, "shiftArithmRightIIIZ",
38.142 + StaticMethod.class, "shiftArithmRight__IIIZ",
38.143 Double.valueOf(-1),
38.144 -8, 3, true
38.145 );
38.146 @@ -189,7 +189,7 @@
38.147 @Test public void unsignedShiftRightInJS() throws Exception {
38.148 assertExec(
38.149 "Get -1",
38.150 - StaticMethod.class, "shiftArithmRightIIIZ",
38.151 + StaticMethod.class, "shiftArithmRight__IIIZ",
38.152 Double.valueOf(1),
38.153 8, 3, false
38.154 );
38.155 @@ -198,7 +198,7 @@
38.156 @Test public void javaScriptBody() throws Exception {
38.157 assertExec(
38.158 "JavaScript string",
38.159 - StaticMethod.class, "i2sLjava_lang_StringII",
38.160 + StaticMethod.class, "i2s__Ljava_lang_String_2II",
38.161 "333",
38.162 330, 3
38.163 );
38.164 @@ -207,7 +207,7 @@
38.165 @Test public void switchJarda() throws Exception {
38.166 assertExec(
38.167 "The expected value",
38.168 - StaticMethod.class, "swtchLjava_lang_StringI",
38.169 + StaticMethod.class, "swtch__Ljava_lang_String_2I",
38.170 "Jarda",
38.171 0
38.172 );
38.173 @@ -216,7 +216,7 @@
38.174 @Test public void switchDarda() throws Exception {
38.175 assertExec(
38.176 "The expected value",
38.177 - StaticMethod.class, "swtchLjava_lang_StringI",
38.178 + StaticMethod.class, "swtch__Ljava_lang_String_2I",
38.179 "Darda",
38.180 1
38.181 );
38.182 @@ -224,7 +224,7 @@
38.183 @Test public void switchParda() throws Exception {
38.184 assertExec(
38.185 "The expected value",
38.186 - StaticMethod.class, "swtch2Ljava_lang_StringI",
38.187 + StaticMethod.class, "swtch2__Ljava_lang_String_2I",
38.188 "Parda",
38.189 22
38.190 );
38.191 @@ -232,7 +232,7 @@
38.192 @Test public void switchMarda() throws Exception {
38.193 assertExec(
38.194 "The expected value",
38.195 - StaticMethod.class, "swtchLjava_lang_StringI",
38.196 + StaticMethod.class, "swtch__Ljava_lang_String_2I",
38.197 "Marda",
38.198 -433
38.199 );
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
39.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringArrayTest.java Fri Dec 07 15:57:14 2012 +0100
39.3 @@ -0,0 +1,50 @@
39.4 +/**
39.5 + * Back 2 Browser Bytecode Translator
39.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
39.7 + *
39.8 + * This program is free software: you can redistribute it and/or modify
39.9 + * it under the terms of the GNU General Public License as published by
39.10 + * the Free Software Foundation, version 2 of the License.
39.11 + *
39.12 + * This program is distributed in the hope that it will be useful,
39.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
39.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39.15 + * GNU General Public License for more details.
39.16 + *
39.17 + * You should have received a copy of the GNU General Public License
39.18 + * along with this program. Look for COPYING file in the top folder.
39.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
39.20 + */
39.21 +package org.apidesign.vm4brwsr;
39.22 +
39.23 +import org.testng.annotations.Test;
39.24 +import static org.testng.Assert.*;
39.25 +
39.26 +public class StringArrayTest {
39.27 + @Test public void deleteMinusIndex() throws Exception {
39.28 + String[] arr = { "Ahoj", "Kluci" };
39.29 + StringArray list = StringArray.asList(arr);
39.30 + list.delete(-1);
39.31 + assertEquals(list.toArray().length, 2, "No element removed");
39.32 + }
39.33 + @Test public void deleteTooHighIndex() throws Exception {
39.34 + String[] arr = { "Ahoj", "Kluci" };
39.35 + StringArray list = StringArray.asList(arr);
39.36 + list.delete(5);
39.37 + assertEquals(list.toArray().length, 2, "No element removed");
39.38 + }
39.39 + @Test public void deleteFirst() throws Exception {
39.40 + String[] arr = { "Ahoj", "Kluci" };
39.41 + StringArray list = StringArray.asList(arr);
39.42 + list.delete(0);
39.43 + assertEquals(list.toArray().length, 1, "First element removed");
39.44 + assertEquals(list.toArray()[0], "Kluci");
39.45 + }
39.46 + @Test public void deleteSecond() throws Exception {
39.47 + String[] arr = { "Ahoj", "Kluci" };
39.48 + StringArray list = StringArray.asList(arr);
39.49 + list.delete(1);
39.50 + assertEquals(list.toArray().length, 1, "Second element removed");
39.51 + assertEquals(list.toArray()[0], "Ahoj");
39.52 + }
39.53 +}
40.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Fri Dec 07 15:02:35 2012 +0100
40.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/StringTest.java Fri Dec 07 15:57:14 2012 +0100
40.3 @@ -18,7 +18,6 @@
40.4 package org.apidesign.vm4brwsr;
40.5
40.6 import javax.script.Invocable;
40.7 -import javax.script.ScriptException;
40.8 import org.testng.annotations.Test;
40.9 import static org.testng.Assert.*;
40.10 import org.testng.annotations.BeforeClass;
40.11 @@ -31,7 +30,7 @@
40.12 @Test public void firstChar() throws Exception {
40.13 assertExec(
40.14 "First char in Hello is H",
40.15 - StringSample.class, "sayHelloCI",
40.16 + StringSample.class, "sayHello__CI",
40.17 72, 0
40.18 );
40.19 }
40.20 @@ -39,7 +38,7 @@
40.21 @Test public void fromChars() throws Exception {
40.22 assertExec(
40.23 "First char in Hello is ABC",
40.24 - StringSample.class, "fromCharsLjava_lang_StringCCC",
40.25 + StringSample.class, "fromChars__Ljava_lang_String_2CCC",
40.26 "ABC", 'A', 'B', 'C'
40.27 );
40.28 }
40.29 @@ -47,7 +46,7 @@
40.30 @Test public void concatChars() throws Exception {
40.31 assertExec(
40.32 "Composing yields ABC",
40.33 - StringSample.class, "charsLjava_lang_StringCCC",
40.34 + StringSample.class, "chars__Ljava_lang_String_2CCC",
40.35 "ABC", 'A', 'B', 'C'
40.36 );
40.37 }
40.38 @@ -55,7 +54,7 @@
40.39 @Test public void concatCharsFromInts() throws Exception {
40.40 assertExec(
40.41 "Composing yields ABC",
40.42 - StringSample.class, "charsFromNumbersLjava_lang_String",
40.43 + StringSample.class, "charsFromNumbers__Ljava_lang_String_2",
40.44 "ABC"
40.45 );
40.46 }
40.47 @@ -63,7 +62,7 @@
40.48 @Test public void concatCharsFromChars() throws Exception {
40.49 assertExec(
40.50 "Composing yields ABC",
40.51 - StringSample.class, "charsFromCharsLjava_lang_String",
40.52 + StringSample.class, "charsFromChars__Ljava_lang_String_2",
40.53 "ABC"
40.54 );
40.55 }
40.56 @@ -71,7 +70,7 @@
40.57 @Test public void instanceOfWorks() throws Exception {
40.58 assertExec(
40.59 "It is string",
40.60 - StringSample.class, "isStringInstanceZ",
40.61 + StringSample.class, "isStringInstance__Z",
40.62 Double.valueOf(1.0)
40.63 );
40.64 }
40.65 @@ -79,7 +78,7 @@
40.66 @Test(timeOut=10000) public void toStringConcatenation() throws Exception {
40.67 assertExec(
40.68 "Five executions should generate 5Hello World!",
40.69 - StringSample.class, "toStringTestLjava_lang_StringI",
40.70 + StringSample.class, "toStringTest__Ljava_lang_String_2I",
40.71 "Hello World!5", 5
40.72 );
40.73 }
40.74 @@ -90,7 +89,7 @@
40.75 @Test(timeOut=10000) public void stringStringConcat() throws Exception {
40.76 assertExec(
40.77 "Composes strings OK",
40.78 - StringSample.class, "concatStringsLjava_lang_String",
40.79 + StringSample.class, "concatStrings__Ljava_lang_String_2",
40.80 "Hello World!1" + "\\\n\r\t"
40.81 );
40.82 }
40.83 @@ -98,21 +97,21 @@
40.84 @Test public void equalsAndSubstring() throws Exception {
40.85 assertExec(
40.86 "Composes are OK",
40.87 - StringSample.class, "equalToHelloZII",
40.88 + StringSample.class, "equalToHello__ZII",
40.89 true, 0, 5
40.90 );
40.91 }
40.92 @Test public void replaceChars() throws Exception {
40.93 assertExec(
40.94 "Can replace slashes by underscores",
40.95 - StringSample.class, "replaceLjava_lang_StringLjava_lang_StringCC",
40.96 + StringSample.class, "replace__Ljava_lang_String_2Ljava_lang_String_2CC",
40.97 "x_y_z", "x/y/z", '/', '_'
40.98 );
40.99 }
40.100 @Test public void replaceIntChars() throws Exception {
40.101 assertExec(
40.102 "Can replace slashes by underscores",
40.103 - StringSample.class, "replaceLjava_lang_StringLjava_lang_StringCC",
40.104 + StringSample.class, "replace__Ljava_lang_String_2Ljava_lang_String_2CC",
40.105 "x_y_z", "x/y/z", (int)'/', (int)'_'
40.106 );
40.107 }
40.108 @@ -120,7 +119,7 @@
40.109 @Test public void insertBuilder() throws Exception {
40.110 assertExec(
40.111 "Can insert something into a buffer?",
40.112 - StringSample.class, "insertBufferLjava_lang_String",
40.113 + StringSample.class, "insertBuffer__Ljava_lang_String_2",
40.114 "Ahojdo!"
40.115 );
40.116 }
40.117 @@ -130,7 +129,7 @@
40.118 int jh = StringSample.hashCode(j);
40.119 assertExec(
40.120 "Hashcode is the same " +jh,
40.121 - StringSample.class, "hashCodeILjava_lang_String",
40.122 + StringSample.class, "hashCode__ILjava_lang_String_2",
40.123 Double.valueOf(jh), j
40.124 );
40.125 }
40.126 @@ -139,28 +138,28 @@
40.127 int jh = StringSample.hashCode(j);
40.128 assertExec(
40.129 "Hashcode is the same " + jh,
40.130 - StringSample.class, "hashCodeILjava_lang_String",
40.131 + StringSample.class, "hashCode__ILjava_lang_String_2",
40.132 Double.valueOf(jh), j
40.133 );
40.134 }
40.135 @Test public void stringSwitch1() throws Exception {
40.136 assertExec(
40.137 "Get one",
40.138 - StringSample.class, "stringSwitchILjava_lang_String",
40.139 + StringSample.class, "stringSwitch__ILjava_lang_String_2",
40.140 Double.valueOf(1), "jedna"
40.141 );
40.142 }
40.143 @Test public void stringSwitch2() throws Exception {
40.144 assertExec(
40.145 "Get two",
40.146 - StringSample.class, "stringSwitchILjava_lang_String",
40.147 + StringSample.class, "stringSwitch__ILjava_lang_String_2",
40.148 Double.valueOf(2), "dve"
40.149 );
40.150 }
40.151 @Test public void stringSwitchDefault() throws Exception {
40.152 assertExec(
40.153 "Get -1",
40.154 - StringSample.class, "stringSwitchILjava_lang_String",
40.155 + StringSample.class, "stringSwitch__ILjava_lang_String_2",
40.156 Double.valueOf(-1), "none"
40.157 );
40.158 }
40.159 @@ -169,7 +168,7 @@
40.160 assertEquals(StringSample.countAB("Ahoj Bedo!"), 3, "Verify Java code is sane");
40.161 assertExec(
40.162 "One A and one B adds to 3",
40.163 - StringSample.class, "countABILjava_lang_String",
40.164 + StringSample.class, "countAB__ILjava_lang_String_2",
40.165 Double.valueOf(3), "Ahoj Bedo!"
40.166 );
40.167
41.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMLazy.java Fri Dec 07 15:02:35 2012 +0100
41.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMLazy.java Fri Dec 07 15:57:14 2012 +0100
41.3 @@ -43,7 +43,7 @@
41.4
41.5 @JavaScriptBody(args = { "self", "n" },
41.6 body=
41.7 - "var cls = n.replaceLjava_lang_StringCC(n,'/','_').toString();"
41.8 + "var cls = n.replace__Ljava_lang_String_2CC(n,'/','_').toString();"
41.9 + "var glb = self.fld_global;"
41.10 + "var vm = self.fld_vm;"
41.11 + "if (glb[cls]) return false;"
42.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java Fri Dec 07 15:02:35 2012 +0100
42.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMLazyTest.java Fri Dec 07 15:57:14 2012 +0100
42.3 @@ -53,7 +53,7 @@
42.4 sb.append("\n var glb = global;");
42.5 sb.append("\n lazyVM.prototype.loadClass = function(res, name) {");
42.6 sb.append("\n var script = org_apidesign_vm4brwsr_VMLazy(true)."
42.7 - + "toJavaScriptLjava_lang_StringLjava_lang_ObjectLjava_lang_ObjectAB("
42.8 + + "toJavaScript__Ljava_lang_String_2Ljava_lang_Object_2Ljava_lang_Object_2_3B("
42.9 + " glb, self,"
42.10 + " loader.get(res + '.class')"
42.11 + ");");
42.12 @@ -77,13 +77,13 @@
42.13
42.14 @Test public void invokeStaticMethod() throws Exception {
42.15 assertExec("Trying to get -1", "test", Double.valueOf(-1),
42.16 - "org/apidesign/vm4brwsr/StaticMethod", "org_apidesign_vm4brwsr_StaticMethod", "minusOneI"
42.17 + "org/apidesign/vm4brwsr/StaticMethod", "org_apidesign_vm4brwsr_StaticMethod", "minusOne__I"
42.18 );
42.19 }
42.20
42.21 @Test public void loadDependantClass() throws Exception {
42.22 assertExec("Trying to get zero", "test", Double.valueOf(0),
42.23 - "org/apidesign/vm4brwsr/InstanceSub", "org_apidesign_vm4brwsr_InstanceSub", "recallDblD"
42.24 + "org/apidesign/vm4brwsr/InstanceSub", "org_apidesign_vm4brwsr_InstanceSub", "recallDbl__D"
42.25 );
42.26 }
42.27
43.1 --- a/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java Fri Dec 07 15:02:35 2012 +0100
43.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/VMinVMTest.java Fri Dec 07 15:57:14 2012 +0100
43.3 @@ -42,7 +42,7 @@
43.4 Object ret;
43.5 try {
43.6 ret = code.invokeFunction(VMinVM.class.getName().replace('.', '_'), true);
43.7 - ret = code.invokeMethod(ret, "toJavaScriptLjava_lang_StringAB", arr);
43.8 + ret = code.invokeMethod(ret, "toJavaScript__Ljava_lang_String_2_3B", arr);
43.9 } catch (Exception ex) {
43.10 File f = File.createTempFile("execution", ".js");
43.11 FileWriter w = new FileWriter(f);
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
44.2 +++ b/vm/src/test/java/org/apidesign/vm4brwsr/tck/CompareHashTest.java Fri Dec 07 15:57:14 2012 +0100
44.3 @@ -0,0 +1,37 @@
44.4 +/**
44.5 + * Back 2 Browser Bytecode Translator
44.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
44.7 + *
44.8 + * This program is free software: you can redistribute it and/or modify
44.9 + * it under the terms of the GNU General Public License as published by
44.10 + * the Free Software Foundation, version 2 of the License.
44.11 + *
44.12 + * This program is distributed in the hope that it will be useful,
44.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
44.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44.15 + * GNU General Public License for more details.
44.16 + *
44.17 + * You should have received a copy of the GNU General Public License
44.18 + * along with this program. Look for COPYING file in the top folder.
44.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
44.20 + */
44.21 +package org.apidesign.vm4brwsr.tck;
44.22 +
44.23 +import org.apidesign.vm4brwsr.Compare;
44.24 +import org.apidesign.vm4brwsr.CompareVMs;
44.25 +import org.testng.annotations.Factory;
44.26 +
44.27 +/**
44.28 + *
44.29 + * @author Jaroslav Tulach <jtulach@netbeans.org>
44.30 + */
44.31 +public class CompareHashTest {
44.32 + @Compare public int hashOfString() {
44.33 + return "Ahoj".hashCode();
44.34 + }
44.35 +
44.36 + @Factory
44.37 + public static Object[] create() {
44.38 + return CompareVMs.create(CompareHashTest.class);
44.39 + }
44.40 +}