Merge pull request #26 from ZXMushroom63/main
Update NoReflect to add searcher functions
This commit is contained in:
commit
ef3e8657fc
|
@ -19,6 +19,7 @@ for (int i = 0; i < reflect_%classname%_methods_arr.length; i++) {
|
||||||
reflect_%classname%.set("constructors", reflect_%classname%_constructors_arr);
|
reflect_%classname%.set("constructors", reflect_%classname%_constructors_arr);
|
||||||
reflect_%classname%.set("methods", reflect_%classname%_methods_arr);
|
reflect_%classname%.set("methods", reflect_%classname%_methods_arr);
|
||||||
reflect_%classname%.set("className", "%classname%");
|
reflect_%classname%.set("className", "%classname%");
|
||||||
|
reflect_%classname%.set("classId", "%classid%");
|
||||||
reflect_%classname%.set("class", %classname%.class);
|
reflect_%classname%.set("class", %classname%.class);
|
||||||
reflectProfiles.add(reflect_%classname%);
|
reflectProfiles.add(reflect_%classname%);
|
||||||
|
|
||||||
|
@ -50,13 +51,16 @@ const templateManager = `
|
||||||
import net.eaglerforge.api.*;
|
import net.eaglerforge.api.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.lang.Exception;
|
import java.lang.Exception;
|
||||||
|
import org.teavm.jso.JSBody;
|
||||||
|
import org.teavm.jso.JSObject;
|
||||||
|
import org.teavm.jso.JSFunctor;
|
||||||
|
|
||||||
//AUTOGENERATED BY NOREFLECT
|
//AUTOGENERATED BY NOREFLECT
|
||||||
//Made by ZXMushroom63
|
//Made by ZXMushroom63
|
||||||
|
|
||||||
public class PLReflect {
|
public class PLReflect extends ModData {
|
||||||
public static ModData makeModData() {
|
public static PLReflect makeModData() {
|
||||||
ModData plReflectGlobal = new ModData();
|
PLReflect plReflectGlobal = new PLReflect();
|
||||||
ArrayList<BaseData> reflectProfiles = new ArrayList<BaseData>();
|
ArrayList<BaseData> reflectProfiles = new ArrayList<BaseData>();
|
||||||
%classdefs%
|
%classdefs%
|
||||||
BaseData[] reflectProfilesArr = new BaseData[reflectProfiles.size()];
|
BaseData[] reflectProfilesArr = new BaseData[reflectProfiles.size()];
|
||||||
|
@ -64,6 +68,25 @@ public class PLReflect {
|
||||||
reflectProfilesArr[i] = reflectProfiles.get(i);
|
reflectProfilesArr[i] = reflectProfiles.get(i);
|
||||||
}
|
}
|
||||||
plReflectGlobal.set("classes", reflectProfilesArr);
|
plReflectGlobal.set("classes", reflectProfilesArr);
|
||||||
|
|
||||||
|
plReflectGlobal.setCallbackClassFinder("getClassByName", (String className)->{
|
||||||
|
for (int i = 0; i < reflectProfilesArr.length; i++) {
|
||||||
|
if (reflectProfilesArr[i].getString("className").equals(className)) {
|
||||||
|
return reflectProfilesArr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
plReflectGlobal.setCallbackClassFinder("getClassById", (String classId)->{
|
||||||
|
for (int i = 0; i < reflectProfilesArr.length; i++) {
|
||||||
|
if (reflectProfilesArr[i].getString("classId").equals(classId)) {
|
||||||
|
return reflectProfilesArr[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
return plReflectGlobal;
|
return plReflectGlobal;
|
||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
@ -83,11 +106,12 @@ function logTxt(txt) {
|
||||||
}
|
}
|
||||||
document.querySelector("#logs").scrollTop = document.querySelector("#logs").scrollHeight;
|
document.querySelector("#logs").scrollTop = document.querySelector("#logs").scrollHeight;
|
||||||
}
|
}
|
||||||
function process(file, reader, classDataDump, className) {
|
function process(file, reader, classDataDump, className, classId) {
|
||||||
return new Promise((res, rej)=>{
|
return new Promise((res, rej)=>{
|
||||||
reader.addEventListener("load", ()=>{
|
reader.addEventListener("load", ()=>{
|
||||||
var output = reader.result;
|
var output = reader.result;
|
||||||
classDataDump[className] = (reconJ(output, className));
|
classDataDump[className] = (reconJ(output, className));
|
||||||
|
classDataDump[className].classId = classId;
|
||||||
res(output);
|
res(output);
|
||||||
});
|
});
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
|
@ -110,6 +134,7 @@ function createManagerFile(managerTemplate, config, zip, dataDump, classIdMap) {
|
||||||
|
|
||||||
var tmpClassText = templateClassdef;
|
var tmpClassText = templateClassdef;
|
||||||
tmpClassText = tmpClassText.replaceAll("%classname%", className);
|
tmpClassText = tmpClassText.replaceAll("%classname%", className);
|
||||||
|
tmpClassText = tmpClassText.replaceAll("%classid%", dataDump[className].classId);
|
||||||
|
|
||||||
var constructorText = "";
|
var constructorText = "";
|
||||||
for (let i = 0; i < dataDump[className].constructors.length; i++) {
|
for (let i = 0; i < dataDump[className].constructors.length; i++) {
|
||||||
|
@ -238,7 +263,7 @@ async function generate(fileList) {
|
||||||
classToLocationMap.set(className, classId);
|
classToLocationMap.set(className, classId);
|
||||||
if (cfg.targetFiles.includes(classId)) {
|
if (cfg.targetFiles.includes(classId)) {
|
||||||
logTxt("Found "+classId+" ["+file.name+"], processing...");
|
logTxt("Found "+classId+" ["+file.name+"], processing...");
|
||||||
var javaFileContent = await process(file, new FileReader(), classDataDump, className);
|
var javaFileContent = await process(file, new FileReader(), classDataDump, className, classId);
|
||||||
if (cfg.includeReadFiles) {
|
if (cfg.includeReadFiles) {
|
||||||
output.file(file.webkitRelativePath.replaceAll("java/", ""), javaFileContent);
|
output.file(file.webkitRelativePath.replaceAll("java/", ""), javaFileContent);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,7 +65,7 @@ function reconJ(java, className) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let impl = `setCallbackReflectiveWithDataArg("${constructorName}", (BaseData params) -> {
|
let impl = `setCallbackReflectiveWithDataArg("exec", (BaseData params) -> {
|
||||||
return new ${className}(${argStr});
|
return new ${className}(${argStr});
|
||||||
});
|
});
|
||||||
`;
|
`;
|
||||||
|
@ -116,7 +116,7 @@ function reconJ(java, className) {
|
||||||
let prefix = isStatic ? className : `((${className}) params.getReflective("_self"))`;
|
let prefix = isStatic ? className : `((${className}) params.getReflective("_self"))`;
|
||||||
let impl;
|
let impl;
|
||||||
if (returnType === "void") {
|
if (returnType === "void") {
|
||||||
impl = `setCallbackVoidWithDataArg("${methodName}", (BaseData params) -> {
|
impl = `setCallbackVoidWithDataArg("exec", (BaseData params) -> {
|
||||||
try {
|
try {
|
||||||
${prefix}.${methodName}(${argStr});
|
${prefix}.${methodName}(${argStr});
|
||||||
} catch (Exception _exception_reflect_) {
|
} catch (Exception _exception_reflect_) {
|
||||||
|
@ -125,7 +125,7 @@ function reconJ(java, className) {
|
||||||
});
|
});
|
||||||
`;
|
`;
|
||||||
} else if (callbackStatementsTypes.includes(returnType)) {
|
} else if (callbackStatementsTypes.includes(returnType)) {
|
||||||
impl = `${callbackStatements[returnType]}("${methodName}", (BaseData params) -> {
|
impl = `${callbackStatements[returnType]}("exec", (BaseData params) -> {
|
||||||
try {
|
try {
|
||||||
return (${returnType}) ${prefix}.${methodName}(${argStr});
|
return (${returnType}) ${prefix}.${methodName}(${argStr});
|
||||||
} catch (Exception _exception_reflect_) {
|
} catch (Exception _exception_reflect_) {
|
||||||
|
@ -135,7 +135,7 @@ function reconJ(java, className) {
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
usedClasses.push(returnType);
|
usedClasses.push(returnType);
|
||||||
impl = `setCallbackReflectiveWithDataArg("${methodName}", (BaseData params) -> {
|
impl = `setCallbackReflectiveWithDataArg("exec", (BaseData params) -> {
|
||||||
try {
|
try {
|
||||||
return (${returnType}) ${prefix}.${methodName}(${argStr});
|
return (${returnType}) ${prefix}.${methodName}(${argStr});
|
||||||
} catch (Exception _exception_reflect_) {
|
} catch (Exception _exception_reflect_) {
|
||||||
|
|
Loading…
Reference in New Issue