mirror of
https://github.com/quinton-ashley/java2js
synced 2024-12-29 10:11:54 +01:00
1.1.1
This commit is contained in:
parent
103aafc683
commit
2803cbff25
@ -18,10 +18,16 @@ This function imports much of the standard Java lang classes into the global sco
|
||||
|
||||
returns the Java file translated into JavaScript
|
||||
|
||||
### jdk.run(translatedJSFile)
|
||||
### jdk.load(translatedJSFile)
|
||||
|
||||
- translatedJSFile is the translated JS class to run
|
||||
|
||||
Loads the JS class file but doesn't run the main method.
|
||||
|
||||
### jdk.run(jvmArgs)
|
||||
|
||||
Runs the main method with the given JVM arguments.
|
||||
|
||||
## Known limitations
|
||||
|
||||
- casting to int truncation workaround requires parenthesis around the number being cast
|
||||
|
20
jdk.js
20
jdk.js
@ -187,10 +187,10 @@
|
||||
});
|
||||
|
||||
// hacky support for Array literals
|
||||
file = file.replace(/new\s*\w*\s*\[\s*\]\s*\{(.*)\}/gm, 'new Array($1)');
|
||||
file = file.replace(/new\s*\w*\s*\[\s*\]\s*\{([^}]*)}/gm, 'Array.of($1)');
|
||||
|
||||
file = file.replace(/new\s*\w*(\s*\[\s*\])*\s*\{(.*)\}/gm, (match, p1, p2) => {
|
||||
return 'new Array(' + p2.replace(/\{([^\}]*)\}/gm, 'new Array($1)') + ')';
|
||||
file = file.replace(/new\s*\w*(\s*\[\s*\])*\s*\{([^}]*)\}/gm, (match, p1, p2) => {
|
||||
return 'Array.of(' + p2.replace(/\{([^\}]*)\}/gm, 'Array.of($1)') + ')';
|
||||
});
|
||||
|
||||
file = file.replace(/new\s*\w*\s*\[\s*(\d)+\s*\]\s*/gm, 'new Array($1)');
|
||||
@ -19129,7 +19129,14 @@
|
||||
const classVarsMap = {};
|
||||
|
||||
const assignParent = (name) => {
|
||||
if (name in classVarsMap) return `this.${name}`;
|
||||
if (name in classVarsMap) {
|
||||
let v = classData.vars.find((x) => x.name == name);
|
||||
if (!v || !v.static) {
|
||||
return `this.${name}`;
|
||||
} else {
|
||||
return `${classData.name}.${name}`;
|
||||
}
|
||||
}
|
||||
const mapped = opts.globalVars[name];
|
||||
if (mapped) {
|
||||
const newName = typeof mapped === 'string' ? mapped : name;
|
||||
@ -19374,8 +19381,9 @@
|
||||
|
||||
for (const var_ of vars) {
|
||||
if (var_.value === undefined) var_.value = literalInitializers[var_.type] || 'null';
|
||||
if (var_.static) staticVars.push(`${className}.${var_.name}=${var_.value};`);
|
||||
else {
|
||||
if (var_.static) {
|
||||
staticVars.push(`${className}.${var_.name}=${var_.value};`);
|
||||
} else {
|
||||
if (typeof var_.value == 'string') {
|
||||
for (const vv of vars) {
|
||||
var_.value = var_.value.replaceAll(vv.name, 'this.' + vv.name);
|
||||
|
@ -16,6 +16,9 @@ jdk.imports['java.io.PrintStream'].load = async () => {
|
||||
}
|
||||
|
||||
_printArray(arr) {
|
||||
console.error(
|
||||
'ERROR: In Java, printing a primitive array prints the memory location of that array in the Java Virtual Machine. To print the contents of the array use a loop!'
|
||||
);
|
||||
let md = MessageDigest.getInstance();
|
||||
let str = '[Ljava.lang.';
|
||||
let hash = md.digest(arr.toString()).slice(0, 8);
|
||||
|
@ -2,80 +2,82 @@ jdk.imports['java.util.AbstractList'].load = async () => {
|
||||
const Itr = await jdk.import('java.util.Itr');
|
||||
|
||||
class AbstractList {
|
||||
constructor(content) {
|
||||
constructor(arr) {
|
||||
// TODO
|
||||
this.content = content || [];
|
||||
this.arr = arr || [];
|
||||
}
|
||||
|
||||
addAll(index, vals) {
|
||||
const tempArray = vals.toArray(null);
|
||||
for (let i = 0; i < tempArray.length; i++) {
|
||||
this.content.push(tempArray[i]);
|
||||
}
|
||||
return false;
|
||||
this.arr.splice(index, 0, ...vals);
|
||||
}
|
||||
|
||||
clear() {
|
||||
this.content = [];
|
||||
this.arr = [];
|
||||
}
|
||||
|
||||
poll() {
|
||||
return this.content.shift();
|
||||
return this.arr.shift();
|
||||
}
|
||||
|
||||
remove(indexOrElem) {
|
||||
this.content.splice(indexOrElem, 1);
|
||||
return true;
|
||||
let index = indexOrElem;
|
||||
if (typeof indexOrElem != 'number') {
|
||||
index = this.arr.indexOf(indexOrElem);
|
||||
}
|
||||
return this.arr.splice(index, 1);
|
||||
}
|
||||
|
||||
removeAll() {
|
||||
this.content = [];
|
||||
this.arr = [];
|
||||
return true;
|
||||
}
|
||||
|
||||
toArray(a) {
|
||||
return this.content;
|
||||
toArray() {
|
||||
return this.arr;
|
||||
}
|
||||
|
||||
toString() {
|
||||
return '[' + this.arr.toString() + ']';
|
||||
}
|
||||
|
||||
size() {
|
||||
return this.content.length;
|
||||
return this.arr.length;
|
||||
}
|
||||
|
||||
add(index, elem) {
|
||||
if (typeof elem !== 'undefined') {
|
||||
this.content.splice(index, 0, elem);
|
||||
if (typeof elem == 'undefined') {
|
||||
return this.arr.push(index);
|
||||
} else {
|
||||
this.content.push(index);
|
||||
return this.arr.splice(index, 0, elem);
|
||||
}
|
||||
}
|
||||
|
||||
get(index) {
|
||||
return this.content[index];
|
||||
return this.arr[index];
|
||||
}
|
||||
|
||||
contains(val) {
|
||||
return this.content.indexOf(val) != -1;
|
||||
return this.arr.indexOf(val) != -1;
|
||||
}
|
||||
|
||||
containsAll(elems) {
|
||||
return false;
|
||||
}
|
||||
// containsAll(elems) {
|
||||
// }
|
||||
|
||||
isEmpty() {
|
||||
return this.content.length == 0;
|
||||
return this.arr.length == 0;
|
||||
}
|
||||
|
||||
set(index, element) {
|
||||
this.content[index] = element;
|
||||
this.arr[index] = element;
|
||||
return element;
|
||||
}
|
||||
|
||||
indexOf(element) {
|
||||
return this.content.indexOf(element);
|
||||
return this.arr.indexOf(element);
|
||||
}
|
||||
|
||||
lastIndexOf(element) {
|
||||
return this.content.lastIndexOf(element);
|
||||
return this.arr.lastIndexOf(element);
|
||||
}
|
||||
|
||||
iterator() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "java2js",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.1",
|
||||
"description": "Converts Java to JavaScript with support for p5.js and QuintOS.",
|
||||
"main": "jdk.js",
|
||||
"scripts": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user