mirror of
https://github.com/cincheo/jsweet.git
synced 2025-12-15 15:29:22 +00:00
Merge branch 'develop' of https://github.com/cincheo/jsweet into develop
This commit is contained in:
commit
76e45a0013
@ -67,6 +67,7 @@ import javax.lang.model.type.ArrayType;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
import com.sun.tools.javac.code.Type;
|
||||
import org.jsweet.transpiler.JSweetContext;
|
||||
import org.jsweet.transpiler.Java2TypeScriptTranslator;
|
||||
import org.jsweet.transpiler.ModuleKind;
|
||||
@ -1423,6 +1424,9 @@ public class RemoveJavaDependenciesAdapter extends Java2TypeScriptAdapter {
|
||||
printMacroName(targetMethodName);
|
||||
print(invocation.getTargetExpression());
|
||||
return true;
|
||||
case "valueOf":
|
||||
print(invocation.getArgument(0));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -1496,7 +1500,13 @@ public class RemoveJavaDependenciesAdapter extends Java2TypeScriptAdapter {
|
||||
case "java.lang.Float":
|
||||
case "java.long.Short":
|
||||
case "java.util.Byte":
|
||||
print("new Number(").print(newClass.getArgument(0)).print(").valueOf()");
|
||||
String argType = newClass.getArgument(0).getType().toString();
|
||||
boolean isCharArgument = Character.class.getName().equals(argType) || "char".equals(argType);
|
||||
if (isCharArgument) {
|
||||
print("new Number(").print(newClass.getArgument(0)).print(".charCodeAt(0)" + ").valueOf()");
|
||||
} else {
|
||||
print("new Number(").print(newClass.getArgument(0)).print(").valueOf()");
|
||||
}
|
||||
substitute = true;
|
||||
break;
|
||||
case "java.util.ArrayList":
|
||||
@ -1526,7 +1536,11 @@ public class RemoveJavaDependenciesAdapter extends Java2TypeScriptAdapter {
|
||||
case "java.util.Hashtable":
|
||||
case "java.util.WeakHashMap":
|
||||
case "java.util.LinkedHashMap":
|
||||
if (newClass.getArgumentCount() == 0) {
|
||||
if (newClass.getArgumentCount() == 0 ||
|
||||
!(newClass.getArgument(0).getType() instanceof Type.ClassType) ||
|
||||
!Util.isDeclarationOrSubClassDeclaration(
|
||||
types(), (Type.ClassType) newClass.getArgument(0).getType(), Map.class.getName())
|
||||
) {
|
||||
print("{}");
|
||||
} else {
|
||||
if (((DeclaredType) newClass.getType()).getTypeArguments().size() == 2 && types().isSameType(
|
||||
|
||||
@ -2,7 +2,9 @@ package source.nativestructures;
|
||||
|
||||
import static jsweet.util.Lang.$export;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
@ -118,7 +120,20 @@ public class Maps {
|
||||
assert m8.containsKey(3);
|
||||
assert m7.containsKey(1);
|
||||
assert !m7.containsKey(3);
|
||||
|
||||
|
||||
for (Map<String, Integer> map : Arrays.<Map<String, Integer>>asList(
|
||||
new HashMap<>(10),
|
||||
new HashMap<>(10, 11),
|
||||
new TreeMap<>(Comparator.comparingInt(String::hashCode))
|
||||
)) {
|
||||
map.put("a", 1);
|
||||
map.put("b", 2);
|
||||
assert map.size() == 2;
|
||||
assert map.get("a") == 1;
|
||||
assert map.get("b") == 2;
|
||||
assert map.get("c") == null;
|
||||
}
|
||||
|
||||
$export("trace", trace.join(","));
|
||||
|
||||
}
|
||||
|
||||
@ -14,12 +14,33 @@ public class Numbers {
|
||||
boolean knowPages = true;
|
||||
int pageMax = 1;
|
||||
trace.push(Integer.toString(knowPages ? pageMax : 0));
|
||||
$export("trace", trace.join(","));
|
||||
|
||||
Integer i1 = new Integer(Character.valueOf(' '));
|
||||
Integer i2 = new Integer('x');
|
||||
Integer i3 = new Integer("12");
|
||||
assert i1.intValue() == 32;
|
||||
assert i2.intValue() == 120;
|
||||
assert i3.intValue() == 12;
|
||||
|
||||
Long l1 = new Long(Character.valueOf(' '));
|
||||
Long l2 = new Long('x');
|
||||
Long l3 = new Long("12");
|
||||
assert l1.intValue() == 32;
|
||||
assert l2.intValue() == 120;
|
||||
assert l3.intValue() == 12;
|
||||
|
||||
Double d1 = new Double("2.30");
|
||||
assert d1.doubleValue() == 2.30;
|
||||
Double d2 = new Double(2.31);
|
||||
assert d2.doubleValue() == 2.31;
|
||||
|
||||
Double.valueOf("1.2");
|
||||
assert isNaN(Double.NaN);
|
||||
assert isNaN(Float.NaN);
|
||||
assert 1 != Double.NaN;
|
||||
assert 2 != Float.NaN;
|
||||
|
||||
$export("trace", trace.join(","));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user