1
0
mirror of https://github.com/quinton-ashley/java2js synced 2024-12-29 10:11:54 +01:00
This commit is contained in:
Quinton Ashley 2022-02-26 12:45:03 -05:00
parent 2b9cc5bf44
commit a03efa965d
2 changed files with 12 additions and 13 deletions

23
jdk.js
View File

@ -218,9 +218,6 @@
return 'new Runnable("' + in0 + '")'; return 'new Runnable("' + in0 + '")';
}); });
// cast to int, truncates the number (just removes decimal value)
// file = file.replace(/\(int\)\s*/gm, 'Math.floor');
let packageName = (file.match(/package\s+([^;]+)/gm) || [])[1] || 'default'; let packageName = (file.match(/package\s+([^;]+)/gm) || [])[1] || 'default';
let trans = await java_to_javascript(file); let trans = await java_to_javascript(file);
@ -19187,22 +19184,24 @@
let cast = expr.type.primitiveTypeCode; let cast = expr.type.primitiveTypeCode;
if (cast == 'int') { if (cast == 'int') {
// if cast to int // if cast to int
if (type == 'char') { if (type == 'String') {
exp += '.charCodeAt(0)';
} else if (/(double|float|short|long)/.test(type)) {
exp = 'Math.floor(' + exp + ')';
} else {
castError = true; castError = true;
} else if (type == 'char') {
exp += '.charCodeAt(0)';
} else {
exp = 'Math.floor(' + exp + ')';
} }
} else if (cast == 'char') { } else if (cast == 'char') {
if (/(double|float|short|long)/.test(type)) { if (type == 'String') {
exp = 'String.fromCharCode(' + exp + ')';
} else {
castError = true; castError = true;
} else {
exp = 'String.fromCharCode(' + exp + ')';
} }
} }
if (castError) { if (castError) {
System.err.println(`error: incompatible types: ${type} cannot be converted to ${cast}: ${exp}`); let msg = `error: incompatible types: ${type} cannot be converted to ${cast}: ${exp}`;
console.log(msg);
System.err.println(msg);
return ''; return '';
} }
return exp; return exp;

View File

@ -1,6 +1,6 @@
{ {
"name": "java2js", "name": "java2js",
"version": "1.2.1", "version": "1.2.2",
"description": "Converts Java to JavaScript and runs it with a JS JDK", "description": "Converts Java to JavaScript and runs it with a JS JDK",
"main": "jdk.js", "main": "jdk.js",
"scripts": { "scripts": {