001 
002 /*
003  *  JScripter Standard 1.0 - To Script In Java
004  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
005  *  
006  *  This program is free software: you can redistribute it and/or modify
007  *  it under the terms of the GNU Affero General Public License as published by
008  *  the Free Software Foundation, either version 3 of the License, or
009  *  (at your option) any later version.
010  *  
011  *  This program is distributed in the hope that it will be useful,
012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014  *  GNU Affero General Public License for more details.
015  *  
016  *  You should have received a copy of the GNU Affero General Public License
017  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
018  */
019 
020 package js;
021 
022 import java.util.HashMap;
023 import java.util.Map;
024 
025 import js.core.*;
026 
027 /**
028  * <p>An <b>opaque</b> class, resembling JavaScript variables, with subclasses being 
029  * <b>normal</b> by default.</p>
030  * <p>This class, its members and its enclosed classes are all <b>opaque</b>. However, 
031  * without specified, its subclass and the concrete method overriding {@link Var#var()} 
032  * method are <b>normal</b> to make late-evaluating expressions.
033  * </p>
034  *
035  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
036  * 
037  * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be 
038  * generated into the target codes. Re-compilers must exit with error on the operations of 
039  * accessing that kind of class objects.
040  * The <tt>checkcast</tt> operation to the class literal of this class must be ignored 
041  * and <tt>instanceof</tt> to it always <tt>true</tt>.
042  */
043 
044 public abstract class Var<T> extends Disposable
045 {
046     /**
047      * <p>Default constructor.</p>
048      * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> or 
049      * <b>internal</b> classes or class members.</p>
050      * @since 1.0
051      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
052      */
053     protected Var() {}
054 
055     /**
056      * <p>Evaluates the current variable instance.</p>
057      * <p>The concrete method overriding this one and the subclass are <b>normal</b> by 
058      * default to make late-evaluating expressions.
059      * late.
060      * @return The value of the current instance itself.
061      * @since 1.0
062      * @javascript Re-compilers must replace this instance invocation with the current variable 
063      * instance of this invocation.
064      */
065     public abstract T var();
066 
067     /**
068      * <p>Gets the hash code of the current variable instance.</p>
069      * @return The hash code of the current variable instance.
070      * @since 1.0
071      * @javascript Re-compilers must replace the instance invocation of this method with the 
072      * JavaScript expression converted from the Java static invocation:
073      * <pre>System.identityHashCode(v)</pre>
074      * where <tt>v</tt> is the current instance of the invocation of this method.
075      */
076     @Override
077     public final int hashCode() {
078         return Js.s().hashCode(var());
079     }
080 
081     /**
082      * <p>Checks if the current variable instance equals another object.</p>
083      * @param o Any value
084      * @return <tt>true</tt> if the current variable instance equals <tt>o</tt>; 
085      * false, otherwise;
086      * @since 1.0
087      * @javascript Re-compilers must replace the instance invocation of this method with the 
088      * JavaScript expression converted from the Java special instance invocation:
089      * <pre>super.equals(o)</pre>.
090      */
091     @Override
092     public final boolean equals(Object o) {
093         return Js.s().equals(var(), o);
094     }
095 
096     /**
097      * <p>Gets the string representation of the current variable instance.</p>
098      * @return The string representation of the current variable instance.
099      * @since 1.0
100      * @javascript Re-compilers must convert the instance invocation of this method directly 
101      * into a JavaScript invocation on its current instance without changing the method 
102      * name, but expanding variable arguments, if any, into comma-separated values. 
103      */
104     @Override
105     public String toString() {
106         return Js.toString(var());
107     }
108 
109     /**
110      * <p>Returns a string indicating the data-type of the current variable instance.</p>
111      * <p>Simulating the JavaScript <tt>typeof</tt> operator and <tt>typeof()</tt> 
112      * function, this invocation evaluates to "number", "string", or "boolean" if the current 
113      * instance is a number, string, or boolean value. It evaluates to "object" for objects, 
114      * arrays. It evaluates to "function" for function instance and to "undefined" if the 
115      * current instance is undefined.</p>
116      * @return A string indicating the data-type of the instance.
117      * @see #valueOf()
118      * @see #undefined()
119      * @since 1.0
120      * @javascript Re-compilers must convert the instance invocation of this method into the 
121      * JavaScript expression: 
122      * <pre>typeof v</pre>
123      * where <tt>v</tt> is the current variable instance of the invocation.
124      */
125     public String typeof() {
126         return Js.typeof(var());
127     }
128 
129     /**
130      * <p>Checks if the current variable instance is undefined.</p>
131      * @return <tt>true</tt> if the current instance is undefined; <tt>false</tt> otherwise.
132      * @see #valueOf()
133      * @see #undefined()
134      * @since 1.0
135      * @javascript Re-compilers must convert the instance invocation of this method into the 
136      * JavaScript expression: 
137      * <pre>(v === undefined)</pre>
138      * where <tt>v</tt> is the current variable instance of the invocation.
139      */
140     public boolean undefined() {
141         return Js.undefined(var());
142     }
143 
144     /**
145      * <p>Returns the primitive value associated with the current instance, if there is one.</p>
146      * @return The primitive value associated with the current instance.
147      * @see #toString()
148      * @since 1.0
149      * @javascript Re-compilers must convert the instance invocation of this method directly 
150      * into a JavaScript invocation on its current instance without changing the method 
151      * name, but expanding variable arguments, if any, into comma-separated values. 
152      */
153     public Object valueOf() {
154         return Js.valueOf(var());
155     }
156 
157     /**
158      * <p>An <b>opaque</b> class representing member IDs.</p>
159      * <p>Note that, this class is <b>opaque</b> but its members are private or <b>internal</b>.</p>
160      *
161      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
162      * 
163      * @javascript Re-compilers must report error on resolving an <tt>internal</tt> class. 
164      */
165     public static final class Mid
166     {
167         private final String name;
168 
169         private Mid(String name) {
170             this.name = name;
171         }
172 
173         /**
174          * <p>Returns the name of the member as a string.</p>
175          * <p>This method is <b>internal</b> and only called inside of <b>opaque</b> or 
176          * <b>internal</b> classes or class members.</p>
177          *
178          * @return The name of the member.
179          * @since 1.0
180          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
181          */
182         @Override
183         public final String toString() {
184             return name;
185         }
186     }
187 
188     /**
189      * <p>An <b>internal</b> class containing membership data for its enclosing 
190      * opaque class.</p>
191      * <p>This class is only used inside of <b>opaque</b> or <b>internal</b> classes or 
192      * class members.</p>
193      *
194      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
195      * 
196      * @javascript Re-compilers must report error on resolving an <b>internal</b> class. 
197      */
198     protected static abstract class Members
199     {
200         private final static Map<String, Mid> members = new HashMap<String, Mid>();
201 
202         /**
203          * <p>Construct membership data for the enclosing <b>opaque</b> class.</p>
204          * 
205          * @since 1.0
206          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
207          */
208         protected Members() {
209             throw new Error("No instance allowed.");
210         }
211 
212         /**
213          * <p>Gets a member ID by the specified member name.</p>
214          * 
215          * @param name The name of the member
216          * @return The member ID
217          * @since 1.0
218          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
219          */
220         public final static Mid id(String name) {
221             if (!members.containsKey(name)) {
222                 members.put(name, new Mid(name));
223             }
224             return members.get(name);
225         }
226     }
227 
228     /**
229      * <p>An <b>opaque</b> class representing members of its enclosing <b>opaque</b> type.</p>
230      * <p>Note that, this class is <b>opaque</b> but its constructors are all <b>internal</b>. 
231      * This class and the subclasses of this class are used to declare either <b>opaque</b> 
232      * <tt>public</tt> instance fields of the opaque type {@link js.Var.Member} or the 
233      * <b>opaque</b> <tt>public</tt> static fields of other <b>opaque</b> types while their 
234      * constructors are used to define the fields inside <b>opaque</b> classes. Under 
235      * either circumstance, the field names must be exactly same as the member names, as 
236      * the <b>opaque</b> fields of <b>opaque</b> types are resolved by re-compilers directly 
237      * based on the field names.</p>
238      *
239      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
240      * 
241      * @javascript <b>Opaque</b> types can be resolved but no class objects for them can be created 
242      * in the target codes. Re-compilers must exit with error on operations accessing that kind 
243      * of class objects.
244      * Re-compilers must resolve an <b>opaque</b> instance field declared by this class in 
245      * {@link js.Var.Member} or its subclasses to the JavaScript identifier: 
246      * <pre>q.m</pre>
247      * where <tt>m</tt> is the identifier of the field name and <tt>q</tt> is the identifier 
248      * resolved from the instance of the enclosing member. Re-compilers must resolve an 
249      * <b>opaque</b> static field declared by this class in <b>opaque</b> types other than 
250      * {@link js.Var.Member} and its subclasses to the JavaScript identifier: 
251      * <pre>m</pre>
252      * where <tt>m</tt> is the identifier of the field name. And re-compilers must report 
253      * error on the access to <b>opaque</b> fields declared by this class under any other 
254      * circumstances.
255      */
256     protected static abstract class Member<T>
257     {
258         private final JsObject.Member q;
259         private final Mid mid;
260 
261         /**
262          * <p>Internally constructs a member based on a qualifying member.</p>
263          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> 
264          * or <b>internal</b> classes or class members.</p>
265          * <p>Note that, this constructor is <b>internal</b> but its declaring class is 
266          * <b>opaque</b>. This constructor is used to define <b>opaque</b> instance fields 
267          * declared in the declaring class of this constructor itself or its subclasses. 
268          * Under this circumstance, the field names must be exactly same as the member 
269          * names, as the <b>opaque</b> instance fields of the <b>opaque</b> type 
270          * {@link js.Var.Member} or its subclasses are resolved by re-compilers directly 
271          * to their names appending to the name resolved from the specified qualifying 
272          * member with a dot in between.</p>
273          * @param q A qualifying member
274          * @param mid The ID of the member to construct
275          * @since 1.0
276          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
277          */
278         protected Member(JsObject.Member q, Mid mid) {
279             this.q = q;
280             this.mid = mid;
281         }
282         /**
283          * <p>Internally constructs a member without a qualifying member.</p>
284          * <p>This constructor is <b>internal</b> and only called inside of <b>opaque</b> 
285          * or <b>internal</b> classes or class members.</p>
286          * <p>Note that, this constructor is <b>internal</b> but its declaring class is 
287          * <b>opaque</b>. This constructor is used to define <b>opaque</b> static fields, 
288          * declared in <b>opaque</b> types other than the declaring class of this constructor 
289          * itself and its subclasses. Under this circumstance, the field names must be 
290          * exactly same as the member names, as the <b>opaque</b> static fields of <b>opaque</b> 
291          * types are generally resolved by re-compilers directly to identifiers of their names.</p>
292          * @param mid The ID of the member to construct
293          * @since 1.0
294          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> constructor. 
295          */
296         protected Member(Mid mid) {
297             this(null, mid);
298         }
299 
300         /**
301          * <p>Gets the ID of a member.</p>
302          * @return The member ID
303          * @since 1.0
304          * @javascript Re-compilers must ignore the instance invocation of this method, that is, 
305          * replacing it with its current instance.
306          */
307         public final Mid mid() {
308             return mid;
309         }
310 
311         /**
312          * <p>Gets the string representation of a member.</p>
313          * <p>This method is <b>internal</b> and only called inside of <b>opaque</b> or 
314          * <b>internal</b> classes or class members.</p>
315          * @return The string representation of the member.
316          * @since 1.0
317          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
318          */
319         @Override
320         public final String toString() {
321             return q == null ? mid.toString() : q.toString() + "." + mid.toString();
322         }
323 
324         /**
325          * <p>Evaluates the qualifier of the member based on an object.</p>
326          * <p>If the current member instance does not have a qualifying member, this method 
327          * simply returns the argument object; Otherwise, the method evaluates the qualifying 
328          * member based on the argument object and returns the result value.</p>
329          * <p>This method is scarcely used as a <tt>public</tt> <b>opaque</b> method but 
330          * definitely used inside other <b>opaque</b> types, somewhat like an <b>internal</b> 
331          * method.</p>
332          * @param o The base object instance
333          * @return The qualifier of the current member based on the object.
334          * @since 1.0
335          * @javascript Re-compilers must convert the instance invocation of this method into 
336          * the JavaScript expression: 
337          * <pre>o.q</pre>
338          * where <tt>q</tt> is the qualifying identifier of the member identifier resolved 
339          * from the current member instance, or:
340          * <pre>o</pre>
341          * if the member identifier resolved from the current member instance does not have 
342          * the qualifying identifier, that is it does not have a dot in between.
343          */
344         public final ObjectLike var(ObjectLike o) {
345             return q == null ? o : q.with(o);
346         }
347         /**
348          * <p>Sets a new value to the property, represented by the current member instance, 
349          * of an object.</p>
350          * @param o The base object
351          * @param v The new value to set
352          * @return The new value
353          * @since 1.0
354          * @javascript Re-compilers must convert the instance invocation of this method into 
355          * the JavaScript expression: 
356          * <pre>o.m = v</pre>
357          * where <tt>m</tt> is the identifier name resolved from the current member 
358          * instance of the invocation.
359          */
360         public final T with(ObjectLike o, T v) {
361             return o.var(this, v);
362         }
363         /**
364          * <p>Evaluates the property, represented by the current member instance, of the 
365          * argument object.</p>
366          * @param o The argument object
367          * @return The value of the current member based on the object argument.
368          * @since 1.0
369          * @javascript Re-compilers must convert the instance invocation of this method into 
370          * the JavaScript expression: 
371          * <pre>o.m</pre>
372          * where <tt>m</tt> is the identifier name resolved from the current member 
373          * instance of the invocation.
374          */
375         public abstract T with(ObjectLike o);
376     }
377 
378     /**
379      * <p>Internally casts an object to array type.</p>
380      * <p>This method is <b>internal</b> and only called inside of <b>opaque</b> or 
381      * <b>internal</b> classes or class members.</p>
382      * @param o The object
383      * @param dummy A dummy object to tell the type being down cast to
384      * @return The array representation of an object
385      * @since 1.0
386      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
387      */
388     protected static final JsArray var(JsObject o, JsArray dummy) {
389         return Js.s().toJsArray(o);
390     }
391     /**
392      * <p>Internally casts an object to boolean type.</p>
393      * <p>This method is <b>internal</b> and only called inside of <b>opaque</b> or 
394      * <b>internal</b> classes or class members.</p>
395      * @param o The object
396      * @param dummy A dummy object to tell the type being down cast to
397      * @return The boolean representation of an object
398      * @since 1.0
399      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
400      */
401     protected static final JsBoolean var(JsObject o, JsBoolean dummy) {
402         return Js.s().toJsBoolean(o);
403     }
404     /**
405      * <p>Internally casts an object to date type.</p>
406      * <p>This method is <b>internal</b> and only called inside of <b>opaque</b> or 
407      * <b>internal</b> classes or class members.</p>
408      * @param o The object
409      * @param dummy A dummy object to tell the type being down cast to
410      * @return The date representation of an object
411      * @since 1.0
412      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
413      */
414     protected static final JsDate var(JsObject o, JsDate dummy) {
415         return Js.s().toJsDate(o);
416     }
417     /**
418      * <p>Internally casts an object to function type.</p>
419      * <p>This method is <b>internal</b> and only called inside of <b>opaque</b> or 
420      * <b>internal</b> classes or class members.</p>
421      * @param o The object
422      * @param dummy A dummy object to tell the type being down cast to
423      * @return The function representation of an object
424      * @since 1.0
425      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
426      */
427     protected static final <S> JsFunction<S> var(JsObject o, JsFunction<S> dummy) {
428         return Js.s().toJsFunction(o);
429     }
430     /**
431      * <p>Internally casts an object to function type.</p>
432      * <p>This method is <b>internal</b> and only called inside of <b>opaque</b> or 
433      * <b>internal</b> classes or class members.</p>
434      * @param o The object
435      * @param w A wrapper to perform the cast
436      * @return The function representation of an object
437      * @since 1.0
438      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
439      */
440     protected static final <S> JsFunction<S> var(JsObject o, Generic<S> w) {
441         return Js.s().toJsFunction(o, w);
442     }
443     /**
444      * <p>Internally casts an object to number type.</p>
445      * <p>This method is <b>internal</b> and only called inside of <b>opaque</b> or 
446      * <b>internal</b> classes or class members.</p>
447      * @param o The object
448      * @param dummy A dummy object to tell the type being down cast to
449      * @return The number representation of an object
450      * @since 1.0
451      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
452      */
453     protected static final JsNumber var(JsObject o, JsNumber dummy) {
454         return Js.s().toJsNumber(o);
455     }
456     /**
457      * <p>Internally casts an object to regular expression type.</p>
458      * <p>This method is <b>internal</b> and only called inside of <b>opaque</b> or 
459      * <b>internal</b> classes or class members.</p>
460      * @param o The object
461      * @param dummy A dummy object to tell the type being down cast to
462      * @return The regular expression representation of an object
463      * @since 1.0
464      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
465      */
466     protected static final JsRegExp var(JsObject o, JsRegExp dummy) {
467         return Js.s().toJsRegExp(o);
468     }
469     /**
470      * <p>Internally casts an object to string type.</p>
471      * <p>This method is <b>internal</b> and only called inside of <b>opaque</b> or 
472      * <b>internal</b> classes or class members.</p>
473      * @param o The object
474      * @param dummy A dummy object to tell the type being down cast to
475      * @return The string representation of an object
476      * @since 1.0
477      * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
478      */
479     protected static final JsString var(JsObject o, JsString dummy) {
480         return Js.s().toJsString(o);
481     }
482 
483     /**
484      * <p>An <b>internal</b> class providing the facilities of arbitrary <b>opaque</b> 
485      * type casting, especially over JavaScript objects in JS Embed Simulation mode, with 
486      * the help of the opaque wrapping technology.</p>
487      * <p>This class is only used inside of <b>opaque</b> or <b>internal</b> classes or 
488      * class members.</p>
489      *
490      * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
491      * 
492      * @javascript Re-compilers must report error on resolving an <b>internal</b> class. 
493      */
494 
495     protected static abstract class Generic<T extends Object>
496     {
497         private Generic() {}
498 
499         /**
500          * <p>Wraps an object.</p>
501          * @param o The object
502          * @return The new representation of an object
503          * @since 1.0
504          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
505          */
506         public abstract T wrap(Object o);
507 
508         private final static Map<Class<? extends JsObject>, Generic<? extends JsObject>> objWrappers =
509                      new HashMap<Class<? extends JsObject>, Generic<? extends JsObject>>();
510 
511         /**
512          * <p>Gets an object wrapper for a type.</p>
513          * @param cls The type to get an object wrapper for.
514          * @return The object wrapper that can down cast an object to the specified type.
515          * @since 1.0
516          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
517          */
518         @SuppressWarnings("unchecked")
519         public final static synchronized <T extends JsObject> Generic<T> get(final Class<T> cls) {
520             if (!objWrappers.containsKey(cls)) {
521                 objWrappers.put(
522                         cls,
523                         new Generic<T>() {
524                             @Override
525                             public T wrap(Object o) {
526                                 if (o != null) {
527                                     Class<?> c = o.getClass();
528                                     if (JsObject.class.isAssignableFrom(cls) &&
529                                             !cls.isAssignableFrom(c)) {
530                                         try {
531                                             o = cls.getConstructor(
532                                                     JsObject.class
533                                             ).newInstance(o);
534                                         } catch (Exception e) {
535                                             e.printStackTrace();
536                                         }
537                                     }
538                                 }
539                                 return (T)o;
540                             }
541                         }
542                 );
543             }
544             return (Generic<T>)objWrappers.get(cls);
545         }
546 
547         private final static Map<Class<? extends JsObject>, Map<Generic<?>, Generic<? extends JsObject>>> genWrappers =
548                      new HashMap<Class<? extends JsObject>, Map<Generic<?>, Generic<? extends JsObject>>>();
549 
550         /**
551          * <p>Gets a generic wrapper for a type with a wrapper for generic wrapping.</p>
552          * @param cls The type to get a wrapper for.
553          * @param eWrapper The wrapper for generic.
554          * @return The wrapper that can down cast a generic object to the specified type.
555          * @since 1.0
556          * @javascript Re-compilers must report error on the invocation to an <b>internal</b> method. 
557          */
558         @SuppressWarnings("unchecked")
559         public final static synchronized <T extends JsObject> Generic<T> get(
560                 final Class<T> cls, final Generic<?> eWrapper) {
561             if (!genWrappers.containsKey(cls)) {
562                 genWrappers.put(cls, new HashMap<Generic<?>, Generic<? extends JsObject>>());
563             }
564             Map<Generic<?>, Generic<? extends JsObject>> wrappers = genWrappers.get(cls);
565             if (!wrappers.containsKey(eWrapper)) {
566                 wrappers.put(
567                         eWrapper,
568                         new Generic<T>() {
569                             @Override
570                             public T wrap(Object o) {
571                                 if (o != null) {
572                                     if (JsObject.class.isAssignableFrom(cls)) {
573                                         try {
574                                             o = cls.getConstructor(
575                                                     JsObject.class, Generic.class
576                                             ).newInstance(o, eWrapper);
577                                         } catch (Exception e) {
578                                             e.printStackTrace();
579                                         }
580                                     }
581                                 }
582                                 return (T)o;
583                             }
584                         }
585                 );
586             }
587             return (Generic<T>)wrappers.get(eWrapper);
588         }
589 
590         /**
591          * <p>The character wrapper.</p>
592          * @since 1.0
593          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
594          */
595         public final static Generic<Character> CHARACTER = new Generic<Character>() {
596             @Override
597             public Character wrap(Object o) {
598                 return (char)((Number)o).shortValue();
599             }
600         };
601         /**
602          * <p>The byte wrapper.</p>
603          * @since 1.0
604          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
605          */
606         public final static Generic<Byte> BYTE = new Generic<Byte>() {
607             @Override
608             public Byte wrap(Object o) {
609                 return ((Number)o).byteValue();
610             }
611         };
612         /**
613          * <p>The short wrapper.</p>
614          * @since 1.0
615          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
616          */
617         public final static Generic<Short> SHORT = new Generic<Short>() {
618             @Override
619             public Short wrap(Object o) {
620                 return ((Number)o).shortValue();
621             }
622         };
623         /**
624          * <p>The long wrapper.</p>
625          * @since 1.0
626          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
627          */
628         public final static Generic<Long> LONG = new Generic<Long>() {
629             @Override
630             public Long wrap(Object o) {
631                 return ((Number)o).longValue();
632             }
633         };
634         /**
635          * <p>The float wrapper.</p>
636          * @since 1.0
637          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
638          */
639         public final static Generic<Float> FLOAT = new Generic<Float>() {
640             @Override
641             public Float wrap(Object o) {
642                 return ((Number)o).floatValue();
643             }
644         };
645         /**
646          * <p>The boolean value wrapper.</p>
647          * @since 1.0
648          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
649          */
650         public final static Generic<Value.Boolean> VALUE_BOOLEAN = new Generic<Value.Boolean>() {
651             @Override
652             public Value.Boolean wrap(Object o) {
653                 return new Value.Boolean((Boolean)o);
654             }
655         };
656         /**
657          * <p>The character value wrapper.</p>
658          * @since 1.0
659          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
660          */
661         public final static Generic<Value.Character> VALUE_CHARACTER = new Generic<Value.Character>() {
662             @Override
663             public Value.Character wrap(Object o) {
664                 return new Value.Character(((Number)o));
665             }
666         };
667         /**
668          * <p>The number value wrapper.</p>
669          * @since 1.0
670          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
671          */
672         public final static Generic<Value.Number> VALUE_NUMBER = new Generic<Value.Number>() {
673             @Override
674             public Value.Number wrap(Object o) {
675                 return new Value.Number(((Number)o));
676             }
677         };
678         /**
679          * <p>The byte value wrapper.</p>
680          * @since 1.0
681          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
682          */
683         public final static Generic<Value.Byte> VALUE_BYTE = new Generic<Value.Byte>() {
684             @Override
685             public Value.Byte wrap(Object o) {
686                 return new Value.Byte(((Number)o));
687             }
688         };
689         /**
690          * <p>The short value wrapper.</p>
691          * @since 1.0
692          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
693          */
694         public final static Generic<Value.Short> VALUE_SHORT = new Generic<Value.Short>() {
695             @Override
696             public Value.Short wrap(Object o) {
697                 return new Value.Short(((Number)o));
698             }
699         };
700         /**
701          * <p>The integer value wrapper.</p>
702          * @since 1.0
703          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
704          */
705         public final static Generic<Value.Integer> VALUE_INTEGER = new Generic<Value.Integer>() {
706             @Override
707             public Value.Integer wrap(Object o) {
708                 return new Value.Integer(((Number)o));
709             }
710         };
711         /**
712          * <p>The long value wrapper.</p>
713          * @since 1.0
714          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
715          */
716         public final static Generic<Value.Long> VALUE_LONG = new Generic<Value.Long>() {
717             @Override
718             public Value.Long wrap(Object o) {
719                 return new Value.Long(((Number)o));
720             }
721         };
722         /**
723          * <p>The float value wrapper.</p>
724          * @since 1.0
725          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
726          */
727         public final static Generic<Value.Float> VALUE_FLOAT = new Generic<Value.Float>() {
728             @Override
729             public Value.Float wrap(Object o) {
730                 return new Value.Float(((Number)o));
731             }
732         };
733         /**
734          * <p>The double value wrapper.</p>
735          * @since 1.0
736          * @javascript Re-compilers must report error on the access to an <b>internal</b> field. 
737          */
738         public final static Generic<Value.Double> VALUE_DOUBLE = new Generic<Value.Double>() {
739             @Override
740             public Value.Double wrap(Object o) {
741                 return new Value.Double(((Number)o));
742             }
743         };
744     }
745 }