mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 07:19:22 +00:00
moved jsweet.util.Globals to jsweet.util.Lang
- keep but deprecate old API - code cleaning/formatting - test for #245
This commit is contained in:
parent
eaa9d656a6
commit
f04583b7cb
@ -103,25 +103,25 @@ public class Object {
|
||||
/**
|
||||
* Gets the value for the given key. Generates <code>this[key]</code>.
|
||||
*
|
||||
* @see jsweet.util.Globals#$get(java.lang.String)
|
||||
* @see jsweet.util.Globals#$set(java.lang.String,java.lang.Object)
|
||||
* @see jsweet.util.Globals#$delete(java.lang.String)
|
||||
* @see jsweet.util.Lang#$get(java.lang.String)
|
||||
* @see jsweet.util.Lang#$set(java.lang.String,java.lang.Object)
|
||||
* @see jsweet.util.Lang#$delete(java.lang.String)
|
||||
*/
|
||||
native public java.lang.Object $get(java.lang.String key);
|
||||
/**
|
||||
* Sets the value for the given key. Generates <code>this[key]=value</code>.
|
||||
*
|
||||
* @see jsweet.util.Globals#$get(java.lang.String)
|
||||
* @see jsweet.util.Globals#$set(java.lang.String,java.lang.Object)
|
||||
* @see jsweet.util.Globals#$delete(java.lang.String)
|
||||
* @see jsweet.util.Lang#$get(java.lang.String)
|
||||
* @see jsweet.util.Lang#$set(java.lang.String,java.lang.Object)
|
||||
* @see jsweet.util.Lang#$delete(java.lang.String)
|
||||
*/
|
||||
native public void $set(java.lang.String key, java.lang.Object value);
|
||||
/**
|
||||
* Deletes the value of the given key. Generates <code>delete this[key]</code>.
|
||||
*
|
||||
* @see jsweet.util.Globals#$get(java.lang.String)
|
||||
* @see jsweet.util.Globals#$set(java.lang.String,java.lang.Object)
|
||||
* @see jsweet.util.Globals#$delete(java.lang.String)
|
||||
* @see jsweet.util.Lang#$get(java.lang.String)
|
||||
* @see jsweet.util.Lang#$set(java.lang.String,java.lang.Object)
|
||||
* @see jsweet.util.Lang#$delete(java.lang.String)
|
||||
*/
|
||||
native public void $delete(java.lang.String key);
|
||||
native public java.lang.Object $super(java.lang.Object... params);
|
||||
|
||||
@ -51,8 +51,11 @@ import jsweet.util.union.Union4;
|
||||
* import static jsweet.util.Globals.*;
|
||||
* </pre>
|
||||
*
|
||||
* @deprecated Replaced with {@link Lang}
|
||||
*
|
||||
* @author Renaud Pawlak
|
||||
*/
|
||||
@Deprecated
|
||||
public final class Globals {
|
||||
|
||||
private static final ThreadLocal<Map<String, Object>> EXPORTED_VARS = new ThreadLocal<>();
|
||||
|
||||
651
core-lib/es5/src/main/java/jsweet/util/Lang.java
Normal file
651
core-lib/es5/src/main/java/jsweet/util/Lang.java
Normal file
@ -0,0 +1,651 @@
|
||||
/*
|
||||
* JSweet - http://www.jsweet.org
|
||||
* Copyright (C) 2015 CINCHEO SAS <renaud.pawlak@cincheo.fr>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package jsweet.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import jsweet.util.function.Consumer4;
|
||||
import jsweet.util.function.Consumer5;
|
||||
import jsweet.util.function.Consumer6;
|
||||
import jsweet.util.function.Function4;
|
||||
import jsweet.util.function.Function5;
|
||||
import jsweet.util.function.Function6;
|
||||
import jsweet.util.function.TriConsumer;
|
||||
import jsweet.util.function.TriFunction;
|
||||
import jsweet.util.union.Union;
|
||||
import jsweet.util.union.Union3;
|
||||
import jsweet.util.union.Union4;
|
||||
|
||||
/**
|
||||
* A set of helper methods for manipulating JavaScript core lang features and
|
||||
* relate them to the Java lang.
|
||||
*
|
||||
* <p>
|
||||
* Be aware that these functions have no corresponding implementation. They are
|
||||
* used mainly for typing purpose, and most of them can be seen as cast
|
||||
* functions, which will be erased during the generation process.
|
||||
*
|
||||
* <p>
|
||||
* Programmers should import these helpers most of the time:
|
||||
*
|
||||
* <pre>
|
||||
* import static jsweet.util.Lang.*;
|
||||
* </pre>
|
||||
*
|
||||
* @author Renaud Pawlak
|
||||
*/
|
||||
public final class Lang {
|
||||
|
||||
private static final ThreadLocal<Map<String, Object>> EXPORTED_VARS = new ThreadLocal<>();
|
||||
|
||||
private Lang() {
|
||||
}
|
||||
|
||||
/**
|
||||
* An accessor to the module id, only when using modules.
|
||||
*/
|
||||
public static final class module {
|
||||
public final static String id = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts a JavaScript array object to a native Java array.
|
||||
*
|
||||
* @param array
|
||||
* a JavaScript array
|
||||
* @return a Java array
|
||||
*/
|
||||
native public static <T> T[] array(def.js.Array<T> array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array to a JavaScript array object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static <T> def.js.Array<T> array(T[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive booleans to a JavaScript array
|
||||
* object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Boolean> array(boolean[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive ints to a JavaScript array object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Integer> array(int[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive doubles to a JavaScript array
|
||||
* object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Double> array(double[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive shorts to a JavaScript array
|
||||
* object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Short> array(short[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive bytes to a JavaScript array
|
||||
* object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Byte> array(byte[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive longs to a JavaScript array
|
||||
* object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Long> array(long[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive floats to a JavaScript array
|
||||
* object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Float> array(float[] array);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Runnable function);
|
||||
|
||||
/**
|
||||
* Casts a type to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Indeed, type references are functions in javascript.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Class<?> type);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Consumer<?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Supplier<?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(BiConsumer<?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(TriConsumer<?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Consumer4<?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Consumer5<?, ?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Consumer6<?, ?, ?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Function<?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(BiFunction<?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(TriFunction<?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Function4<?, ?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Function5<?, ?, ?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Function6<?, ?, ?, ?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a native Java Boolean to a JavaScript Boolean.
|
||||
*/
|
||||
native public static def.js.Boolean bool(Boolean bool);
|
||||
|
||||
/**
|
||||
* Casts back a JavaScript boolean to a Java boolean.
|
||||
*/
|
||||
native public static Boolean bool(def.js.Boolean bool);
|
||||
|
||||
/**
|
||||
* Casts a native Java number to a JavaScript Number.
|
||||
*/
|
||||
native public static def.js.Number number(Number number);
|
||||
|
||||
/**
|
||||
* Casts back a JavaScript number to a Java integer.
|
||||
*/
|
||||
native public static Integer integer(def.js.Number number);
|
||||
|
||||
/**
|
||||
* Casts back a JavaScript number to a Java integer.
|
||||
*/
|
||||
native public static Double number(def.js.Number number);
|
||||
|
||||
/**
|
||||
* Casts a native Java string to a JavaScript string.
|
||||
*
|
||||
* <p>
|
||||
* By default, JSweet API use plain Java strings so that the program can
|
||||
* easily use string literals. However, when the programmer needs to access
|
||||
* to runtime string manipulation functions, then need to cast to a
|
||||
* JavaScript string, which allows the access to the standard Web API.
|
||||
*/
|
||||
native public static def.js.String string(String string);
|
||||
|
||||
/**
|
||||
* Casts a native Java char to a JavaScript string.
|
||||
*/
|
||||
native public static def.js.String string(char c);
|
||||
|
||||
/**
|
||||
* Casts back a JavaScript string to a Java string.
|
||||
*
|
||||
* <p>
|
||||
* By default, JSweet API use plain Java strings so that the program can
|
||||
* easily use string literals. However, when the programmer needs to access
|
||||
* to runtime string manipulation functions, then need to cast to a
|
||||
* JavaScript string, which allows the access to the standard Web API.
|
||||
*/
|
||||
native public static String string(def.js.String string);
|
||||
|
||||
/**
|
||||
* Casts a native Java object to a JavaScript object.
|
||||
*
|
||||
* <p>
|
||||
* By default, JSweet API use plain Java objects. However, when the
|
||||
* programmer needs to access to the standard Web API, they need to cast
|
||||
* through this function.
|
||||
*/
|
||||
native public static def.js.Object object(Object object);
|
||||
|
||||
/**
|
||||
* This helper function allows the programmer to use indexed modification on
|
||||
* the target object.
|
||||
*
|
||||
* <p>
|
||||
* It is transpiled to:
|
||||
*
|
||||
* <pre>
|
||||
* target[key] = value
|
||||
* </pre>
|
||||
*
|
||||
* @param target
|
||||
* the target object
|
||||
* @param key
|
||||
* the key to be set
|
||||
* @param value
|
||||
* the new value
|
||||
* @return the new value
|
||||
*/
|
||||
native public static <T> T $set(Object target, String key, T value);
|
||||
|
||||
/**
|
||||
* This helper function allows the programmer to use indexed access on the
|
||||
* target object.
|
||||
*
|
||||
* <p>
|
||||
* It is transpiled to:
|
||||
*
|
||||
* <pre>
|
||||
* target[key]
|
||||
* </pre>
|
||||
*
|
||||
* @param target
|
||||
* the target object
|
||||
* @param key
|
||||
* the key to be set
|
||||
*/
|
||||
native public static <T> T $get(Object target, String key);
|
||||
|
||||
/**
|
||||
* This helper function allows the programmer to use indexed deletion on the
|
||||
* target object.
|
||||
*
|
||||
* <p>
|
||||
* It is transpiled to:
|
||||
*
|
||||
* <pre>
|
||||
* delete target[key]
|
||||
* </pre>
|
||||
*
|
||||
* @param target
|
||||
* the target object
|
||||
* @param key
|
||||
* the key to be deleted
|
||||
*/
|
||||
native public static void $delete(Object target, String key);
|
||||
|
||||
/**
|
||||
* This helper function is a shortcut to create an untyped JavaScript
|
||||
* object/map. It takes a list of key/value pairs, where the keys must be
|
||||
* string literals and values are objects.
|
||||
*
|
||||
* <p>
|
||||
* For instance, the expression:
|
||||
*
|
||||
* <pre>
|
||||
* $object("responsive", true, "defaultSize", "100px")
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* Will be transpiled to:
|
||||
*
|
||||
* <pre>
|
||||
* {responsive:true, defaultSize:"100px"}
|
||||
* </pre>
|
||||
*
|
||||
* @param keyValues
|
||||
* the key values pairs that initialize the object (keys must be
|
||||
* string literals)
|
||||
* @return an untyped object
|
||||
*/
|
||||
native public static def.js.Object $map(Object... keyValues);
|
||||
|
||||
/**
|
||||
* Uses the target object as a function and call it. This is not typesafe
|
||||
* and should be avoided.
|
||||
*
|
||||
* @param target
|
||||
* the functional object
|
||||
* @param arguments
|
||||
* the call arguments
|
||||
* @return the function result
|
||||
*/
|
||||
native public static <T> T $apply(Object target, Object... arguments);
|
||||
|
||||
/**
|
||||
* Uses the target object as a constructor and call it. This is not typesafe
|
||||
* and should be avoided.
|
||||
*
|
||||
* @param target
|
||||
* the constructor object
|
||||
* @param arguments
|
||||
* the call arguments
|
||||
* @return the constructor result
|
||||
*/
|
||||
native public static <T> T $new(Object target, Object... arguments);
|
||||
|
||||
/**
|
||||
* This helper casts an object to one of the types in a given union type.
|
||||
*
|
||||
* <p>
|
||||
* The JSweet transpiler will ensure that T is one of T1 and T2. If not, it
|
||||
* will raise an error.
|
||||
*
|
||||
* @param union
|
||||
* the object typed after a union type
|
||||
* @return the same object, but typed after one of the types of the union
|
||||
* type
|
||||
*/
|
||||
native public static <T1, T2, T> T union(Union<T1, T2> union);
|
||||
|
||||
/**
|
||||
* This helper casts an object to an union type.
|
||||
*
|
||||
* <p>
|
||||
* The JSweet transpiler will ensure that T is one of actual type elements
|
||||
* of U. If not, it will raise an error.
|
||||
*
|
||||
* @param union
|
||||
* the object typed after one of the types of the union type
|
||||
* @return the same object, but typed after a union type
|
||||
*/
|
||||
native public static <U extends Union<?, ?>, T> U union(T object);
|
||||
|
||||
/**
|
||||
* This helper casts an object to an union type.
|
||||
*
|
||||
* <p>
|
||||
* The JSweet transpiler will ensure that T is one of actual type elements
|
||||
* of U. If not, it will raise an error.
|
||||
*
|
||||
* @param union
|
||||
* the object typed after one of the types of the union type
|
||||
* @return the same object, but typed after a union type
|
||||
*/
|
||||
native public static <T> Union3<?, ?, ?> union3(T object);
|
||||
|
||||
/**
|
||||
* This helper casts an object to an union type.
|
||||
*
|
||||
* <p>
|
||||
* The JSweet transpiler will ensure that T is one of actual type elements
|
||||
* of U. If not, it will raise an error.
|
||||
*
|
||||
* @param union
|
||||
* the object typed after one of the types of the union type
|
||||
* @return the same object, but typed after a union type
|
||||
*/
|
||||
native public static <T> Union4<?, ?, ?, ?> union4(T object);
|
||||
|
||||
/**
|
||||
* This utility function allows using the <code>typeof</code> JavaScript
|
||||
* operator.
|
||||
*
|
||||
* The expression <code>typeof(o)</code> transpiles to <code>typeof o</code>
|
||||
* . See the JavaScript documentation for more details.
|
||||
*/
|
||||
native public static String typeof(Object o);
|
||||
|
||||
/**
|
||||
* This utility function allows using the <code>===</code> JavaScript
|
||||
* operator directly.
|
||||
*/
|
||||
native public static boolean equalsStrict(Object o1, Object o2);
|
||||
|
||||
/**
|
||||
* This utility function allows using the <code>!==</code> JavaScript
|
||||
* operator directly.
|
||||
*/
|
||||
native public static boolean notEqualsStrict(Object o1, Object o2);
|
||||
|
||||
/**
|
||||
* This utility function allows using the <code>==</code> JavaScript
|
||||
* operator.
|
||||
*
|
||||
* Since JSweet version 1.1, the Java expression <code>o1==o2</code>
|
||||
* transpiles to <code>o1===o2</code> to remain close to the Java strict
|
||||
* equality (except when equaling to the <code>null</code> literal where the
|
||||
* <code>==</code> operator is used). So, the expression
|
||||
* <code>equalsLoose(o1,o2)</code> transpiles to <code>o1==o2</code>. See
|
||||
* the JavaScript documentation for more details.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
native public static boolean equalsLoose(Object o1, Object o2);
|
||||
|
||||
/**
|
||||
* This utility function allows using the <code>!=</code> JavaScript
|
||||
* operator.
|
||||
*
|
||||
* Since JSweet version 1.1, the Java expression <code>o1!=o2</code>
|
||||
* transpiles to <code>o1!==o2</code> to remain close to the Java strict
|
||||
* inequality (except when diffing with the <code>null</code> literal where
|
||||
* the <code>==</code> operator is used). So, the expression
|
||||
* <code>notEqualsLoose(o1,o2)</code> transpiles to <code>o1!=o2</code>. See
|
||||
* the JavaScript documentation for more details.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
native public static boolean notEqualsLoose(Object o1, Object o2);
|
||||
|
||||
/**
|
||||
* Disable type checking on the target object (cast to any). This helper is
|
||||
* valid in Java.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T any(Object object) {
|
||||
return (T) object;
|
||||
}
|
||||
|
||||
/**
|
||||
* This helper function allows the programmer to reflectively set a global
|
||||
* variable named <code>"_exportedVar_"+name</code>.
|
||||
*
|
||||
* <p>
|
||||
* This function must only be used in specifically cases, typically to
|
||||
* define results when testing from Java.
|
||||
*
|
||||
* @param name
|
||||
* the base name of the exported global variable, necessarily as
|
||||
* a string literal
|
||||
* @param value
|
||||
* the value to set to the variable
|
||||
*/
|
||||
public static void $export(String name, Object value) {
|
||||
// default Java implementation when running in Java (usually for testing
|
||||
// purposes)
|
||||
EXPORTED_VARS.get().put("_exportedVar_" + name, value);
|
||||
}
|
||||
|
||||
}
|
||||
@ -237,18 +237,18 @@ public class Object {
|
||||
/**
|
||||
* Gets the value for the given key. Generates <code>this[key]</code>.
|
||||
*
|
||||
* @see jsweet.util.Globals#$get(java.lang.String)
|
||||
* @see jsweet.util.Globals#$set(java.lang.String,java.lang.Object)
|
||||
* @see jsweet.util.Globals#$delete(java.lang.String)
|
||||
* @see jsweet.util.Lang#$get(java.lang.String)
|
||||
* @see jsweet.util.Lang#$set(java.lang.String,java.lang.Object)
|
||||
* @see jsweet.util.Lang#$delete(java.lang.String)
|
||||
*/
|
||||
native public java.lang.Object $get(java.lang.String key);
|
||||
|
||||
/**
|
||||
* Sets the value for the given key. Generates <code>this[key]=value</code>.
|
||||
*
|
||||
* @see jsweet.util.Globals#$get(java.lang.String)
|
||||
* @see jsweet.util.Globals#$set(java.lang.String,java.lang.Object)
|
||||
* @see jsweet.util.Globals#$delete(java.lang.String)
|
||||
* @see jsweet.util.Lang#$get(java.lang.String)
|
||||
* @see jsweet.util.Lang#$set(java.lang.String,java.lang.Object)
|
||||
* @see jsweet.util.Lang#$delete(java.lang.String)
|
||||
*/
|
||||
native public void $set(java.lang.String key, java.lang.Object value);
|
||||
|
||||
@ -256,9 +256,9 @@ public class Object {
|
||||
* Deletes the value of the given key. Generates
|
||||
* <code>delete this[key]</code>.
|
||||
*
|
||||
* @see jsweet.util.Globals#$get(java.lang.String)
|
||||
* @see jsweet.util.Globals#$set(java.lang.String,java.lang.Object)
|
||||
* @see jsweet.util.Globals#$delete(java.lang.String)
|
||||
* @see jsweet.util.Lang#$get(java.lang.String)
|
||||
* @see jsweet.util.Lang#$set(java.lang.String,java.lang.Object)
|
||||
* @see jsweet.util.Lang#$delete(java.lang.String)
|
||||
*/
|
||||
native public void $delete(java.lang.String key);
|
||||
|
||||
|
||||
@ -51,8 +51,11 @@ import jsweet.util.union.Union4;
|
||||
* import static jsweet.util.Globals.*;
|
||||
* </pre>
|
||||
*
|
||||
* @deprecated Replaced with {@link Lang}
|
||||
*
|
||||
* @author Renaud Pawlak
|
||||
*/
|
||||
@Deprecated
|
||||
public final class Globals {
|
||||
|
||||
private static final ThreadLocal<Map<String, Object>> EXPORTED_VARS = new ThreadLocal<>();
|
||||
|
||||
651
core-lib/es6/src/main/java/jsweet/util/Lang.java
Normal file
651
core-lib/es6/src/main/java/jsweet/util/Lang.java
Normal file
@ -0,0 +1,651 @@
|
||||
/*
|
||||
* JSweet - http://www.jsweet.org
|
||||
* Copyright (C) 2015 CINCHEO SAS <renaud.pawlak@cincheo.fr>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package jsweet.util;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import jsweet.util.function.Consumer4;
|
||||
import jsweet.util.function.Consumer5;
|
||||
import jsweet.util.function.Consumer6;
|
||||
import jsweet.util.function.Function4;
|
||||
import jsweet.util.function.Function5;
|
||||
import jsweet.util.function.Function6;
|
||||
import jsweet.util.function.TriConsumer;
|
||||
import jsweet.util.function.TriFunction;
|
||||
import jsweet.util.union.Union;
|
||||
import jsweet.util.union.Union3;
|
||||
import jsweet.util.union.Union4;
|
||||
|
||||
/**
|
||||
* A set of helper methods for manipulating JavaScript core lang features and
|
||||
* relate them to the Java lang.
|
||||
*
|
||||
* <p>
|
||||
* Be aware that these functions have no corresponding implementation. They are
|
||||
* used mainly for typing purpose, and most of them can be seen as cast
|
||||
* functions, which will be erased during the generation process.
|
||||
*
|
||||
* <p>
|
||||
* Programmers should import these helpers most of the time:
|
||||
*
|
||||
* <pre>
|
||||
* import static jsweet.util.Lang.*;
|
||||
* </pre>
|
||||
*
|
||||
* @author Renaud Pawlak
|
||||
*/
|
||||
public final class Lang {
|
||||
|
||||
private static final ThreadLocal<Map<String, Object>> EXPORTED_VARS = new ThreadLocal<>();
|
||||
|
||||
private Lang() {
|
||||
}
|
||||
|
||||
/**
|
||||
* An accessor to the module id, only when using modules.
|
||||
*/
|
||||
public static final class module {
|
||||
public final static String id = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Casts a JavaScript array object to a native Java array.
|
||||
*
|
||||
* @param array
|
||||
* a JavaScript array
|
||||
* @return a Java array
|
||||
*/
|
||||
native public static <T> T[] array(def.js.Array<T> array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array to a JavaScript array object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static <T> def.js.Array<T> array(T[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive booleans to a JavaScript array
|
||||
* object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Boolean> array(boolean[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive ints to a JavaScript array object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Integer> array(int[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive doubles to a JavaScript array
|
||||
* object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Double> array(double[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive shorts to a JavaScript array
|
||||
* object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Short> array(short[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive bytes to a JavaScript array
|
||||
* object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Byte> array(byte[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive longs to a JavaScript array
|
||||
* object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Long> array(long[] array);
|
||||
|
||||
/**
|
||||
* Casts a native Java array of primitive floats to a JavaScript array
|
||||
* object.
|
||||
*
|
||||
* @param array
|
||||
* a Java array
|
||||
* @return a JavaScript array
|
||||
*/
|
||||
native public static def.js.Array<Float> array(float[] array);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Runnable function);
|
||||
|
||||
/**
|
||||
* Casts a type to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Indeed, type references are functions in javascript.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Class<?> type);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Consumer<?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Supplier<?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(BiConsumer<?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(TriConsumer<?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Consumer4<?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Consumer5<?, ?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Consumer6<?, ?, ?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Function<?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(BiFunction<?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(TriFunction<?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Function4<?, ?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Function5<?, ?, ?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a functional interface to a JavaScript function object.
|
||||
*
|
||||
* <p>
|
||||
* Note that this casts allows for a reflective access to the function as a
|
||||
* plain object, but it looses the actual function type. Various APIs take
|
||||
* function objects as arguments, and this function can be useful in such
|
||||
* circumstances.
|
||||
*
|
||||
* @see jsweet.util.function
|
||||
*/
|
||||
native public static def.js.Function function(Function6<?, ?, ?, ?, ?, ?, ?> function);
|
||||
|
||||
/**
|
||||
* Casts a native Java Boolean to a JavaScript Boolean.
|
||||
*/
|
||||
native public static def.js.Boolean bool(Boolean bool);
|
||||
|
||||
/**
|
||||
* Casts back a JavaScript boolean to a Java boolean.
|
||||
*/
|
||||
native public static Boolean bool(def.js.Boolean bool);
|
||||
|
||||
/**
|
||||
* Casts a native Java number to a JavaScript Number.
|
||||
*/
|
||||
native public static def.js.Number number(Number number);
|
||||
|
||||
/**
|
||||
* Casts back a JavaScript number to a Java integer.
|
||||
*/
|
||||
native public static Integer integer(def.js.Number number);
|
||||
|
||||
/**
|
||||
* Casts back a JavaScript number to a Java integer.
|
||||
*/
|
||||
native public static Double number(def.js.Number number);
|
||||
|
||||
/**
|
||||
* Casts a native Java string to a JavaScript string.
|
||||
*
|
||||
* <p>
|
||||
* By default, JSweet API use plain Java strings so that the program can
|
||||
* easily use string literals. However, when the programmer needs to access
|
||||
* to runtime string manipulation functions, then need to cast to a
|
||||
* JavaScript string, which allows the access to the standard Web API.
|
||||
*/
|
||||
native public static def.js.String string(String string);
|
||||
|
||||
/**
|
||||
* Casts a native Java char to a JavaScript string.
|
||||
*/
|
||||
native public static def.js.String string(char c);
|
||||
|
||||
/**
|
||||
* Casts back a JavaScript string to a Java string.
|
||||
*
|
||||
* <p>
|
||||
* By default, JSweet API use plain Java strings so that the program can
|
||||
* easily use string literals. However, when the programmer needs to access
|
||||
* to runtime string manipulation functions, then need to cast to a
|
||||
* JavaScript string, which allows the access to the standard Web API.
|
||||
*/
|
||||
native public static String string(def.js.String string);
|
||||
|
||||
/**
|
||||
* Casts a native Java object to a JavaScript object.
|
||||
*
|
||||
* <p>
|
||||
* By default, JSweet API use plain Java objects. However, when the
|
||||
* programmer needs to access to the standard Web API, they need to cast
|
||||
* through this function.
|
||||
*/
|
||||
native public static def.js.Object object(Object object);
|
||||
|
||||
/**
|
||||
* This helper function allows the programmer to use indexed modification on
|
||||
* the target object.
|
||||
*
|
||||
* <p>
|
||||
* It is transpiled to:
|
||||
*
|
||||
* <pre>
|
||||
* target[key] = value
|
||||
* </pre>
|
||||
*
|
||||
* @param target
|
||||
* the target object
|
||||
* @param key
|
||||
* the key to be set
|
||||
* @param value
|
||||
* the new value
|
||||
* @return the new value
|
||||
*/
|
||||
native public static <T> T $set(Object target, String key, T value);
|
||||
|
||||
/**
|
||||
* This helper function allows the programmer to use indexed access on the
|
||||
* target object.
|
||||
*
|
||||
* <p>
|
||||
* It is transpiled to:
|
||||
*
|
||||
* <pre>
|
||||
* target[key]
|
||||
* </pre>
|
||||
*
|
||||
* @param target
|
||||
* the target object
|
||||
* @param key
|
||||
* the key to be set
|
||||
*/
|
||||
native public static <T> T $get(Object target, String key);
|
||||
|
||||
/**
|
||||
* This helper function allows the programmer to use indexed deletion on the
|
||||
* target object.
|
||||
*
|
||||
* <p>
|
||||
* It is transpiled to:
|
||||
*
|
||||
* <pre>
|
||||
* delete target[key]
|
||||
* </pre>
|
||||
*
|
||||
* @param target
|
||||
* the target object
|
||||
* @param key
|
||||
* the key to be deleted
|
||||
*/
|
||||
native public static void $delete(Object target, String key);
|
||||
|
||||
/**
|
||||
* This helper function is a shortcut to create an untyped JavaScript
|
||||
* object/map. It takes a list of key/value pairs, where the keys must be
|
||||
* string literals and values are objects.
|
||||
*
|
||||
* <p>
|
||||
* For instance, the expression:
|
||||
*
|
||||
* <pre>
|
||||
* $object("responsive", true, "defaultSize", "100px")
|
||||
* </pre>
|
||||
*
|
||||
* <p>
|
||||
* Will be transpiled to:
|
||||
*
|
||||
* <pre>
|
||||
* {responsive:true, defaultSize:"100px"}
|
||||
* </pre>
|
||||
*
|
||||
* @param keyValues
|
||||
* the key values pairs that initialize the object (keys must be
|
||||
* string literals)
|
||||
* @return an untyped object
|
||||
*/
|
||||
native public static def.js.Object $map(Object... keyValues);
|
||||
|
||||
/**
|
||||
* Uses the target object as a function and call it. This is not typesafe
|
||||
* and should be avoided.
|
||||
*
|
||||
* @param target
|
||||
* the functional object
|
||||
* @param arguments
|
||||
* the call arguments
|
||||
* @return the function result
|
||||
*/
|
||||
native public static <T> T $apply(Object target, Object... arguments);
|
||||
|
||||
/**
|
||||
* Uses the target object as a constructor and call it. This is not typesafe
|
||||
* and should be avoided.
|
||||
*
|
||||
* @param target
|
||||
* the constructor object
|
||||
* @param arguments
|
||||
* the call arguments
|
||||
* @return the constructor result
|
||||
*/
|
||||
native public static <T> T $new(Object target, Object... arguments);
|
||||
|
||||
/**
|
||||
* This helper casts an object to one of the types in a given union type.
|
||||
*
|
||||
* <p>
|
||||
* The JSweet transpiler will ensure that T is one of T1 and T2. If not, it
|
||||
* will raise an error.
|
||||
*
|
||||
* @param union
|
||||
* the object typed after a union type
|
||||
* @return the same object, but typed after one of the types of the union
|
||||
* type
|
||||
*/
|
||||
native public static <T1, T2, T> T union(Union<T1, T2> union);
|
||||
|
||||
/**
|
||||
* This helper casts an object to an union type.
|
||||
*
|
||||
* <p>
|
||||
* The JSweet transpiler will ensure that T is one of actual type elements
|
||||
* of U. If not, it will raise an error.
|
||||
*
|
||||
* @param union
|
||||
* the object typed after one of the types of the union type
|
||||
* @return the same object, but typed after a union type
|
||||
*/
|
||||
native public static <U extends Union<?, ?>, T> U union(T object);
|
||||
|
||||
/**
|
||||
* This helper casts an object to an union type.
|
||||
*
|
||||
* <p>
|
||||
* The JSweet transpiler will ensure that T is one of actual type elements
|
||||
* of U. If not, it will raise an error.
|
||||
*
|
||||
* @param union
|
||||
* the object typed after one of the types of the union type
|
||||
* @return the same object, but typed after a union type
|
||||
*/
|
||||
native public static <T> Union3<?, ?, ?> union3(T object);
|
||||
|
||||
/**
|
||||
* This helper casts an object to an union type.
|
||||
*
|
||||
* <p>
|
||||
* The JSweet transpiler will ensure that T is one of actual type elements
|
||||
* of U. If not, it will raise an error.
|
||||
*
|
||||
* @param union
|
||||
* the object typed after one of the types of the union type
|
||||
* @return the same object, but typed after a union type
|
||||
*/
|
||||
native public static <T> Union4<?, ?, ?, ?> union4(T object);
|
||||
|
||||
/**
|
||||
* This utility function allows using the <code>typeof</code> JavaScript
|
||||
* operator.
|
||||
*
|
||||
* The expression <code>typeof(o)</code> transpiles to <code>typeof o</code>
|
||||
* . See the JavaScript documentation for more details.
|
||||
*/
|
||||
native public static String typeof(Object o);
|
||||
|
||||
/**
|
||||
* This utility function allows using the <code>===</code> JavaScript
|
||||
* operator directly.
|
||||
*/
|
||||
native public static boolean equalsStrict(Object o1, Object o2);
|
||||
|
||||
/**
|
||||
* This utility function allows using the <code>!==</code> JavaScript
|
||||
* operator directly.
|
||||
*/
|
||||
native public static boolean notEqualsStrict(Object o1, Object o2);
|
||||
|
||||
/**
|
||||
* This utility function allows using the <code>==</code> JavaScript
|
||||
* operator.
|
||||
*
|
||||
* Since JSweet version 1.1, the Java expression <code>o1==o2</code>
|
||||
* transpiles to <code>o1===o2</code> to remain close to the Java strict
|
||||
* equality (except when equaling to the <code>null</code> literal where the
|
||||
* <code>==</code> operator is used). So, the expression
|
||||
* <code>equalsLoose(o1,o2)</code> transpiles to <code>o1==o2</code>. See
|
||||
* the JavaScript documentation for more details.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
native public static boolean equalsLoose(Object o1, Object o2);
|
||||
|
||||
/**
|
||||
* This utility function allows using the <code>!=</code> JavaScript
|
||||
* operator.
|
||||
*
|
||||
* Since JSweet version 1.1, the Java expression <code>o1!=o2</code>
|
||||
* transpiles to <code>o1!==o2</code> to remain close to the Java strict
|
||||
* inequality (except when diffing with the <code>null</code> literal where
|
||||
* the <code>==</code> operator is used). So, the expression
|
||||
* <code>notEqualsLoose(o1,o2)</code> transpiles to <code>o1!=o2</code>. See
|
||||
* the JavaScript documentation for more details.
|
||||
*
|
||||
* @since 1.1
|
||||
*/
|
||||
native public static boolean notEqualsLoose(Object o1, Object o2);
|
||||
|
||||
/**
|
||||
* Disable type checking on the target object (cast to any). This helper is
|
||||
* valid in Java.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T any(Object object) {
|
||||
return (T) object;
|
||||
}
|
||||
|
||||
/**
|
||||
* This helper function allows the programmer to reflectively set a global
|
||||
* variable named <code>"_exportedVar_"+name</code>.
|
||||
*
|
||||
* <p>
|
||||
* This function must only be used in specifically cases, typically to
|
||||
* define results when testing from Java.
|
||||
*
|
||||
* @param name
|
||||
* the base name of the exported global variable, necessarily as
|
||||
* a string literal
|
||||
* @param value
|
||||
* the value to set to the variable
|
||||
*/
|
||||
public static void $export(String name, Object value) {
|
||||
// default Java implementation when running in Java (usually for testing
|
||||
// purposes)
|
||||
EXPORTED_VARS.get().put("_exportedVar_" + name, value);
|
||||
}
|
||||
|
||||
}
|
||||
@ -478,8 +478,14 @@ public class JSweetTranspiler implements JSweetOptions {
|
||||
};
|
||||
|
||||
private void initExportedVarMap() throws Exception {
|
||||
Field f = Thread.currentThread().getContextClassLoader().loadClass("jsweet.util.Globals")
|
||||
.getDeclaredField("EXPORTED_VARS");
|
||||
Field f = null;
|
||||
try {
|
||||
f = Thread.currentThread().getContextClassLoader().loadClass(JSweetConfig.UTIL_CLASSNAME)
|
||||
.getDeclaredField("EXPORTED_VARS");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
f = Thread.currentThread().getContextClassLoader().loadClass(JSweetConfig.DEPRECATED_UTIL_CLASSNAME)
|
||||
.getDeclaredField("EXPORTED_VARS");
|
||||
}
|
||||
f.setAccessible(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
ThreadLocal<Map<String, Object>> exportedVars = (ThreadLocal<Map<String, Object>>) f.get(null);
|
||||
@ -487,8 +493,14 @@ public class JSweetTranspiler implements JSweetOptions {
|
||||
}
|
||||
|
||||
private Map<String, Object> getExportedVarMap() throws Exception {
|
||||
Field f = Thread.currentThread().getContextClassLoader().loadClass("jsweet.util.Globals")
|
||||
.getDeclaredField("EXPORTED_VARS");
|
||||
Field f = null;
|
||||
try {
|
||||
f = Thread.currentThread().getContextClassLoader().loadClass(JSweetConfig.UTIL_CLASSNAME)
|
||||
.getDeclaredField("EXPORTED_VARS");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
f = Thread.currentThread().getContextClassLoader().loadClass(JSweetConfig.DEPRECATED_UTIL_CLASSNAME)
|
||||
.getDeclaredField("EXPORTED_VARS");
|
||||
}
|
||||
f.setAccessible(true);
|
||||
@SuppressWarnings("unchecked")
|
||||
ThreadLocal<Map<String, Object>> exportedVars = (ThreadLocal<Map<String, Object>>) f.get(null);
|
||||
@ -1798,7 +1810,8 @@ public class JSweetTranspiler implements JSweetOptions {
|
||||
+ " - http://www.jsweet.org */" };
|
||||
}
|
||||
if (context.options.isDebugMode()) {
|
||||
headerLines = ArrayUtils.add(headerLines, "declare function __debug_exec(className, functionName, argNames, target, args, generator);");
|
||||
headerLines = ArrayUtils.add(headerLines,
|
||||
"declare function __debug_exec(className, functionName, argNames, target, args, generator);");
|
||||
headerLines = ArrayUtils.add(headerLines, "declare function __debug_result(expression);");
|
||||
}
|
||||
return headerLines;
|
||||
|
||||
@ -319,7 +319,8 @@ public class Java2TypeScriptAdapter extends PrinterAdapter {
|
||||
}
|
||||
|
||||
private boolean isWithinGlobals(String targetClassName) {
|
||||
if (targetClassName == null || targetClassName.endsWith("." + GLOBALS_CLASS_NAME)) {
|
||||
if (targetClassName == null
|
||||
|| (targetClassName.equals(UTIL_CLASSNAME) || targetClassName.equals(DEPRECATED_UTIL_CLASSNAME))) {
|
||||
JCClassDecl c = getParent(JCClassDecl.class);
|
||||
return c != null && c.sym.getQualifiedName().toString().endsWith("." + GLOBALS_CLASS_NAME);
|
||||
} else {
|
||||
|
||||
@ -33,7 +33,7 @@ import org.jsweet.transpiler.JSweetTranspiler;
|
||||
public interface EvaluationResult {
|
||||
/**
|
||||
* Get access to the value of an exported variable (exported with a call to
|
||||
* the jsweet.util.Globals.$export function).
|
||||
* the jsweet.util.Lang.$export function).
|
||||
*
|
||||
* @param variableName
|
||||
* the variable to access
|
||||
|
||||
@ -20,6 +20,7 @@ import org.junit.Test;
|
||||
|
||||
import source.statics.AnonymousClasses;
|
||||
import source.statics.Classes;
|
||||
import source.statics.DefaultValues;
|
||||
import source.statics.InnerClasses;
|
||||
import source.statics.StaticsInInterfaces;
|
||||
import source.statics.StaticInitializer;
|
||||
@ -35,7 +36,7 @@ public class StaticsTests extends AbstractTest {
|
||||
public void testInnerClasses() {
|
||||
eval((h, r) -> {
|
||||
h.assertNoProblems();
|
||||
} , getSourceFile(InnerClasses.class));
|
||||
}, getSourceFile(InnerClasses.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -43,7 +44,7 @@ public class StaticsTests extends AbstractTest {
|
||||
eval((h, r) -> {
|
||||
h.assertNoProblems();
|
||||
Assert.assertTrue(r.get("m"));
|
||||
} , getSourceFile(AnonymousClasses.class));
|
||||
}, getSourceFile(AnonymousClasses.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -52,7 +53,7 @@ public class StaticsTests extends AbstractTest {
|
||||
h.assertNoProblems();
|
||||
Assert.assertEquals("name", r.get("name1"));
|
||||
Assert.assertEquals("name", r.get("name2"));
|
||||
} , getSourceFile(Classes.class));
|
||||
}, getSourceFile(Classes.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -60,7 +61,7 @@ public class StaticsTests extends AbstractTest {
|
||||
eval((h, r) -> {
|
||||
h.assertNoProblems();
|
||||
Assert.assertEquals(4, (int) r.get("result"));
|
||||
} , getSourceFile(StaticInitializer.class));
|
||||
}, getSourceFile(StaticInitializer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -68,17 +69,23 @@ public class StaticsTests extends AbstractTest {
|
||||
eval((h, r) -> {
|
||||
h.assertNoProblems();
|
||||
Assert.assertTrue(r.get("ok"));
|
||||
} , getSourceFile(StaticInitializerWithNoFields.class));
|
||||
}, getSourceFile(StaticInitializerWithNoFields.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStaticsInInterfaces() {
|
||||
eval((h, r) -> {
|
||||
h.assertNoProblems();
|
||||
Assert.assertEquals(1, (int)r.get("c1"));
|
||||
Assert.assertEquals(2, (int)r.get("c2"));
|
||||
} , getSourceFile(StaticsInInterfaces.class));
|
||||
Assert.assertEquals(1, (int) r.get("c1"));
|
||||
Assert.assertEquals(2, (int) r.get("c2"));
|
||||
}, getSourceFile(StaticsInInterfaces.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultValues() {
|
||||
eval((h, r) -> {
|
||||
h.assertNoProblems();
|
||||
}, getSourceFile(DefaultValues.class));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -2,8 +2,8 @@ package source.api;
|
||||
|
||||
import static def.js.JSON.stringify;
|
||||
import def.js.JSON;
|
||||
import static jsweet.util.Globals.$get;
|
||||
import jsweet.util.Globals;
|
||||
import static jsweet.util.Lang.$get;
|
||||
import jsweet.util.Lang;
|
||||
|
||||
public class AccessStaticMethod {
|
||||
|
||||
@ -13,8 +13,8 @@ public class AccessStaticMethod {
|
||||
stringify("test");
|
||||
Object o = null;
|
||||
$get(o, "f");
|
||||
Globals.$get(o, "f");
|
||||
jsweet.util.Globals.$get(o, "f");
|
||||
Lang.$get(o, "f");
|
||||
jsweet.util.Lang.$get(o, "f");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package source.api;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Globals.any;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static jsweet.util.Lang.any;
|
||||
|
||||
import def.js.Array;
|
||||
import def.js.ArrayBuffer;
|
||||
|
||||
@ -16,26 +16,26 @@
|
||||
*/
|
||||
package source.api;
|
||||
|
||||
import static jsweet.util.Globals.array;
|
||||
import static jsweet.util.Globals.bool;
|
||||
import static jsweet.util.Globals.object;
|
||||
import static jsweet.util.Lang.array;
|
||||
import static jsweet.util.Lang.bool;
|
||||
import static jsweet.util.Lang.object;
|
||||
|
||||
import def.js.Boolean;
|
||||
import def.js.Number;
|
||||
import jsweet.util.Globals;
|
||||
import jsweet.util.Lang;
|
||||
|
||||
public class CastMethods {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
void m() {
|
||||
Boolean b1 = Globals.bool(true);
|
||||
Boolean b1 = Lang.bool(true);
|
||||
b1 = bool(true);
|
||||
boolean b2 = Globals.bool(b1);
|
||||
boolean b2 = Lang.bool(b1);
|
||||
b2 = bool(b1);
|
||||
if (b2) {
|
||||
b1 = bool(b2);
|
||||
int[] array = {};
|
||||
Globals.array(array).push(1, 2, 3);
|
||||
Lang.array(array).push(1, 2, 3);
|
||||
array(array).push(1, 2, 3);
|
||||
int i = array(array(array))[1];
|
||||
m1(b1);
|
||||
@ -43,11 +43,11 @@ public class CastMethods {
|
||||
m2(bool(b1));
|
||||
m2(b2);
|
||||
}
|
||||
Number n = Globals.number(1);
|
||||
Number n = Lang.number(1);
|
||||
n.toLocaleString();
|
||||
n.toFixed();
|
||||
int i = Globals.integer(n);
|
||||
double d = Globals.number(n);
|
||||
int i = Lang.integer(n);
|
||||
double d = Lang.number(n);
|
||||
object("");
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.api;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.api;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
|
||||
@ -18,7 +18,7 @@ package source.api;
|
||||
|
||||
import def.js.Array;
|
||||
import def.js.IArguments;
|
||||
import jsweet.util.Globals;
|
||||
import jsweet.util.Lang;
|
||||
|
||||
public class ForeachIteration {
|
||||
|
||||
@ -29,7 +29,7 @@ public class ForeachIteration {
|
||||
for (String s : array) {
|
||||
seq+=s;
|
||||
}
|
||||
Globals.$export("out", seq);
|
||||
Lang.$export("out", seq);
|
||||
}
|
||||
|
||||
void m2(IArguments args) {
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.api;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class JdkInvocations {
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.api;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.api;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.assertion;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Error;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.assertion;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class PassingAssertion {
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.blocksgame;
|
||||
|
||||
import static jsweet.util.Globals.union;
|
||||
import static jsweet.util.Lang.union;
|
||||
|
||||
import def.dom.CanvasRenderingContext2D;
|
||||
import def.js.Math;
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
package source.blocksgame;
|
||||
|
||||
import static def.dom.Globals.document;
|
||||
import static jsweet.util.Globals.union;
|
||||
import static jsweet.util.Lang.union;
|
||||
|
||||
import def.dom.CanvasRenderingContext2D;
|
||||
import def.dom.HTMLImageElement;
|
||||
|
||||
@ -18,8 +18,8 @@ package source.blocksgame;
|
||||
|
||||
import static def.dom.Globals.console;
|
||||
import static def.dom.Globals.document;
|
||||
import static jsweet.util.Globals.array;
|
||||
import static jsweet.util.Globals.union;
|
||||
import static jsweet.util.Lang.array;
|
||||
import static jsweet.util.Lang.union;
|
||||
import static jsweet.util.StringTypes._2d;
|
||||
|
||||
import def.dom.CanvasRenderingContext2D;
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
package source.blocksgame;
|
||||
|
||||
import static def.dom.Globals.console;
|
||||
import static jsweet.util.Globals.union;
|
||||
import static jsweet.util.Lang.union;
|
||||
|
||||
import def.dom.CanvasRenderingContext2D;
|
||||
import def.js.Math;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.calculus;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class Chars {
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.calculus;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class Integers {
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.calculus;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Date;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.calculus;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import static java.lang.Math.abs;
|
||||
import static java.lang.Math.cbrt;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package source.calculus;
|
||||
|
||||
import static def.js.Globals.NaN;
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class Numbers {
|
||||
|
||||
|
||||
@ -17,8 +17,8 @@
|
||||
package source.candies;
|
||||
|
||||
import static def.angularjs.Globals.angular;
|
||||
import static jsweet.util.Globals.array;
|
||||
import static jsweet.util.Globals.union;
|
||||
import static jsweet.util.Lang.array;
|
||||
import static jsweet.util.Lang.union;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
package source.candies;
|
||||
|
||||
import static jsweet.util.Globals.function;
|
||||
import static jsweet.util.Globals.union;
|
||||
import static jsweet.util.Lang.function;
|
||||
import static jsweet.util.Lang.union;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import def.backbone.backbone.Collection;
|
||||
import def.backbone.backbone.Model;
|
||||
import def.backbone.backbone.ObjectHash;
|
||||
import jsweet.util.Globals;
|
||||
import jsweet.util.Lang;
|
||||
|
||||
public class BackboneCandy {
|
||||
|
||||
@ -88,7 +88,7 @@ class TodoList extends Collection<Todo> {
|
||||
// TODO: this is wrong... there is a problem with varargs... to be
|
||||
// investigated
|
||||
Todo[] remaining() {
|
||||
return this.without(Globals.any(this.done()));
|
||||
return this.without(Lang.any(this.done()));
|
||||
}
|
||||
|
||||
// We keep the Todos in sequential order, despite being saved by unordered
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package source.doc;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Globals.array;
|
||||
import static jsweet.util.Globals.string;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static jsweet.util.Lang.array;
|
||||
import static jsweet.util.Lang.string;
|
||||
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.enums;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.enums;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -16,8 +16,8 @@
|
||||
*/
|
||||
package source.enums;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Globals.array;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static jsweet.util.Lang.array;
|
||||
|
||||
import def.js.Error;
|
||||
import source.enums.other.EnumInOtherPackage;
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.generics;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.util.function.DoubleConsumer;
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package source.init;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Globals.array;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static jsweet.util.Lang.array;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.init;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.init;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class Constructor {
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.init;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class FieldDefaultValues {
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.init;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class Initializer {
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.init;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import jsweet.lang.Disabled;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.init;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import jsweet.lang.Interface;
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.init;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class StaticInitializer {
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package source.init;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Globals.$map;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static jsweet.util.Lang.$map;
|
||||
|
||||
import def.js.Object;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.init;
|
||||
|
||||
import static jsweet.util.Globals.$map;
|
||||
import static jsweet.util.Lang.$map;
|
||||
|
||||
import def.js.Object;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.nativestructures;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.Collator;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.nativestructures;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.nativestructures;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.nativestructures;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.nativestructures;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.nativestructures;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.nativestructures;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.nativestructures;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.nativestructures;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.nativestructures;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.nativestructures;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Map;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import def.js.Array;
|
||||
|
||||
class ASuperClass {
|
||||
|
||||
@ -16,8 +16,8 @@
|
||||
*/
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Globals.string;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static jsweet.util.Lang.string;
|
||||
|
||||
import def.js.Date;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class OverloadWithStaticAndInstanceMethods {
|
||||
|
||||
|
||||
@ -16,8 +16,8 @@
|
||||
*/
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Globals.array;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static jsweet.util.Lang.array;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.util.function.BinaryOperator;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class WrongOverloadWithArraysAndObjects {
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Globals.array;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static jsweet.util.Lang.array;
|
||||
|
||||
public class WrongOverloadWithGenerics {
|
||||
public static String[] trace = {};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
import def.js.Date;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -16,8 +16,8 @@
|
||||
*/
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Globals.array;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static jsweet.util.Lang.array;
|
||||
|
||||
class SuperClass {
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.overload;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.require.a;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class A {
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.require.a.b;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class B1 {
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.require.a.b;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class B2 {
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.require.b;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import source.require.a.A;
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.root.noroot.a;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static source.root.noroot.a.Globals.m2;
|
||||
|
||||
public class GlobalsInNoRoot {
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.root.root.a;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static source.root.root.a.Globals.m2;
|
||||
|
||||
public class GlobalsInRoot {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.statics;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class AnonymousClasses {
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.statics;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class Classes {
|
||||
|
||||
|
||||
17
transpiler/src/test/java/source/statics/DefaultValues.java
Normal file
17
transpiler/src/test/java/source/statics/DefaultValues.java
Normal file
@ -0,0 +1,17 @@
|
||||
package source.statics;
|
||||
|
||||
import jsweet.util.Lang;
|
||||
|
||||
public class DefaultValues {
|
||||
|
||||
static int i; // initialized to 0
|
||||
static boolean b; // to false
|
||||
static String s; // initialized to null
|
||||
|
||||
public static void main(String[] args) {
|
||||
assert i == 0;
|
||||
assert b == false;
|
||||
assert Lang.equalsStrict(s, null);
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,6 @@
|
||||
package source.statics;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class StaticInitializer {
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.statics;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class StaticInitializerWithNoFields {
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.statics;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class StaticsInInterfaces {
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.structural;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.structural;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class AutoImportClassesInSamePackageUsed {
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package source.structural;
|
||||
|
||||
import static source.structural.globalclasses.a.ClassWithStaticMethod.aStaticMethod;
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
import source.structural.globalclasses.a.ClassWithStaticMethod;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.structural;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.structural;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class GetClass {
|
||||
|
||||
|
||||
@ -16,8 +16,8 @@
|
||||
*/
|
||||
package source.structural;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Globals.string;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static jsweet.util.Lang.string;
|
||||
import static source.structural.Globals.toTitleCase;
|
||||
|
||||
import def.js.RegExp;
|
||||
|
||||
@ -16,8 +16,8 @@
|
||||
*/
|
||||
package source.structural;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Globals.$get;
|
||||
import static jsweet.util.Lang.$export;
|
||||
import static jsweet.util.Lang.$get;
|
||||
|
||||
import def.js.Array;
|
||||
import jsweet.lang.Interface;
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.structural;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class InnerClass {
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.structural;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import def.js.Array;
|
||||
|
||||
|
||||
@ -17,9 +17,9 @@
|
||||
package source.structural;
|
||||
|
||||
import static def.js.Globals.eval;
|
||||
import static jsweet.util.Globals.any;
|
||||
import static jsweet.util.Globals.equalsStrict;
|
||||
import static jsweet.util.Globals.typeof;
|
||||
import static jsweet.util.Lang.any;
|
||||
import static jsweet.util.Lang.equalsStrict;
|
||||
import static jsweet.util.Lang.typeof;
|
||||
|
||||
import def.js.Array;
|
||||
import jsweet.lang.Interface;
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
*/
|
||||
package source.structural;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.IntFunction;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package source.structural;
|
||||
|
||||
import static jsweet.util.Globals.$export;
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
public class NoNameClashesWithFields {
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user