Almost done!
This commit is contained in:
parent
2c7c218471
commit
b4da547505
|
@ -36,7 +36,7 @@ reflect_%classname%_constructors.add(reflect_%classname%_constructor_%constructo
|
|||
`;
|
||||
const templateMethod = `
|
||||
BaseData reflect_%classname%_method_%methodname%_%idx% = new ModData();
|
||||
reflect_%classname%_method_%methodname%_%idx%.set("methodName", %methodname%);
|
||||
reflect_%classname%_method_%methodname%_%idx%.set("methodName", "%methodname%");
|
||||
reflect_%classname%_method_%methodname%_%idx%.set("returnType", %returntype%);
|
||||
reflect_%classname%_method_%methodname%_%idx%.set("static", %static%);
|
||||
reflect_%classname%_method_%methodname%_%idx%.set("argnames", %argkeys%);
|
||||
|
@ -82,6 +82,7 @@ function process(file, reader, classDataDump, className) {
|
|||
reader.addEventListener("load", ()=>{
|
||||
var output = reader.result;
|
||||
classDataDump[className] = (reconJ(output, className));
|
||||
console.log(classDataDump[className].usedClasses);
|
||||
res(output);
|
||||
});
|
||||
reader.readAsText(file);
|
||||
|
@ -92,9 +93,9 @@ function createManagerFile(managerTemplate, config, zip, dataDump) {
|
|||
var filePath = config.managerFile.replaceAll(".", "/") + ".java";
|
||||
|
||||
for (let i = 0; i < config.targetFiles.length; i++) {
|
||||
manager = `import ${config.targetFiles[i]}\n` + ";" + manager;
|
||||
manager = `import ${config.targetFiles[i]}` + ";\n" + manager;
|
||||
}
|
||||
manager = `package ${config.managerFile.match(/(.*)(?=\.[^.]*$)/g)[0]}\n` + ";" + manager;
|
||||
manager = `package ${config.managerFile.match(/(.*)(?=\.[^.]*$)/g)[0]}` + ";\n" + manager;
|
||||
|
||||
|
||||
var classText = "";
|
||||
|
@ -141,6 +142,45 @@ function createManagerFile(managerTemplate, config, zip, dataDump) {
|
|||
}
|
||||
tmpClassText = tmpClassText.replaceAll("%constructordefs%", constructorText);
|
||||
|
||||
|
||||
var methodText = "";
|
||||
for (let i = 0; i < dataDump[className].methods.length; i++) {
|
||||
const method = dataDump[className].methods[i];
|
||||
var tmpMethodText = templateMethod;
|
||||
tmpMethodText = tmpMethodText.replaceAll("%classname%", className);
|
||||
tmpMethodText = tmpMethodText.replaceAll("%idx%", method.idx);
|
||||
tmpMethodText = tmpMethodText.replaceAll("%static%", method.isStatic);
|
||||
tmpMethodText = tmpMethodText.replaceAll("%methodname%", method.name);
|
||||
tmpMethodText = tmpMethodText.replaceAll("%returntype%", "\""+className+"\"");
|
||||
tmpMethodText = tmpMethodText.replaceAll("%argkeys%", `new String[]{${(()=>{
|
||||
var txt = "";
|
||||
var argumentKeys = Object.keys(method.arguments);
|
||||
for (let i = 0; i < argumentKeys.length; i++) {
|
||||
const k = argumentKeys[i];
|
||||
txt += `"${k}"`;
|
||||
if (i !== argumentKeys.length - 1) {
|
||||
txt += ", ";
|
||||
}
|
||||
}
|
||||
return txt;
|
||||
})()}}`);
|
||||
tmpMethodText = tmpMethodText.replaceAll("%argvalues%", `new String[]{${(()=>{
|
||||
var txt = "";
|
||||
var argumentKeys = Object.keys(method.arguments);
|
||||
for (let i = 0; i < argumentKeys.length; i++) {
|
||||
const k = argumentKeys[i];
|
||||
txt += `"${method.arguments[k]}"`;
|
||||
if (i !== argumentKeys.length - 1) {
|
||||
txt += ", ";
|
||||
}
|
||||
}
|
||||
return txt;
|
||||
})()}}`);
|
||||
tmpMethodText = tmpMethodText.replaceAll("%methodimpl%", method.impl);
|
||||
methodText += tmpMethodText;
|
||||
}
|
||||
tmpClassText = tmpClassText.replaceAll("%methoddefs%", methodText);
|
||||
|
||||
classText += tmpClassText;
|
||||
}
|
||||
manager = manager.replaceAll("%classdefs%", classText);
|
||||
|
|
|
@ -54,6 +54,7 @@
|
|||
overflow-x: hidden;
|
||||
margin-top: 2rem;
|
||||
color: orange;
|
||||
text-shadow: 0px 0px 2px;
|
||||
}
|
||||
</style>
|
||||
<script src="FileSaver.js"></script>
|
||||
|
|
|
@ -7,12 +7,26 @@ const getStatements = {
|
|||
"char": "params.getChar(%s)",
|
||||
"double": "params.getDouble(%s)",
|
||||
}
|
||||
const callbackStatements = {
|
||||
"boolean": "setCallbackBooleanWithDataArg",
|
||||
"int": "setCallbackIntWithDataArg",
|
||||
"String": "setCallbackStringWithDataArg",
|
||||
"double": "setCallbackDoubleWithDataArg",
|
||||
"float": "setCallbackFloatWithDataArg",
|
||||
}
|
||||
const getStatementsTypes = Object.keys(getStatements);
|
||||
const callbackStatementsTypes = Object.keys(callbackStatements);
|
||||
function reconJ(java, className) {
|
||||
var usedClasses = [];
|
||||
var javaText = java;
|
||||
|
||||
javaText = javaText.replace(/\/\/.*$/gm, '');
|
||||
javaText = javaText.replace(/\/\*[\s\S]*?\*\//gm, '');
|
||||
|
||||
let constructorRegex = /(public|protected|private|static|\s) +(\w+) *\(([^)]*)\)/g;
|
||||
|
||||
let constructors = [...java.matchAll(constructorRegex).filter((line)=>{
|
||||
return !line.includes(" private ") || !line.includes(" protected ");
|
||||
let constructors = [...javaText.matchAll(constructorRegex).filter((line)=>{
|
||||
return !line[0].includes(" private ") && !line[0].includes(" protected ");
|
||||
})];
|
||||
|
||||
let constructorDetails = constructors.map((constructor) => {
|
||||
|
@ -32,7 +46,9 @@ function reconJ(java, className) {
|
|||
var argumentsKeys = Object.keys(arguments);
|
||||
for (let i = 0; i < argumentsKeys.length; i++) {
|
||||
const key = argumentsKeys[i];
|
||||
|
||||
if (!getStatementsTypes.includes(arguments[key])) {
|
||||
usedClasses.push(arguments[key]);
|
||||
}
|
||||
argStr += `(${arguments[key]}) ${getStatementsTypes.includes(arguments[key]) ? getStatements[arguments[key]].replaceAll("%s", "\""+key+"\"") : `params.getReflective("${key}")`}`;
|
||||
if (i !== argumentsKeys.length - 1) {
|
||||
argStr += ", "
|
||||
|
@ -40,9 +56,8 @@ function reconJ(java, className) {
|
|||
}
|
||||
|
||||
|
||||
let impl = `
|
||||
setCallbackReflectiveWithArgs("${constructorName}", (BaseData params) -> {
|
||||
return new ${className}(${argStr})
|
||||
let impl = `setCallbackReflectiveWithArgs("${constructorName}", (BaseData params) -> {
|
||||
return new ${className}(${argStr});
|
||||
});
|
||||
`;
|
||||
|
||||
|
@ -53,10 +68,74 @@ function reconJ(java, className) {
|
|||
impl: impl
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
let methodRegex = /(public|static|\s)* +([\w\<\>\[\]]+)\s+(\w+) *\(([^)]*)\)/g;
|
||||
|
||||
let methods = [...javaText.matchAll(methodRegex).filter((line)=>{
|
||||
return !line[0].includes("> ") && !line[0].startsWith(" else ") && !line[0].startsWith(" new ") && !line[0].includes(" private ") && !line[0].includes(" protected ");
|
||||
//Doesn't support Type<Subtype> yet
|
||||
})];
|
||||
|
||||
let methodDetails = methods.map((method) => {
|
||||
let isStatic = `${method[1]}`.includes("static");
|
||||
let returnType = method[2];
|
||||
let methodName = method[3];
|
||||
let argumentString = method[4];
|
||||
let arguments = {};
|
||||
|
||||
if (argumentString.trim().length > 0) {
|
||||
let argumentList = argumentString.split(",");
|
||||
argumentList.forEach((argument) => {
|
||||
let [type, name] = argument.trim().split(" ");
|
||||
arguments[name] = type;
|
||||
});
|
||||
}
|
||||
|
||||
let argStr = "";
|
||||
var argumentsKeys = Object.keys(arguments);
|
||||
for (let i = 0; i < argumentsKeys.length; i++) {
|
||||
const key = argumentsKeys[i];
|
||||
if (!getStatementsTypes.includes(arguments[key])) {
|
||||
usedClasses.push(arguments[key]);
|
||||
}
|
||||
argStr += `(${arguments[key]}) ${getStatementsTypes.includes(arguments[key]) ? getStatements[arguments[key]].replaceAll("%s", "\""+key+"\"") : `params.getReflective("${key}")`}`;
|
||||
if (i !== argumentsKeys.length - 1) {
|
||||
argStr += ", "
|
||||
}
|
||||
}
|
||||
|
||||
let impl;
|
||||
if (returnType === "void") {
|
||||
impl = `setCallbackVoidWithArgs("${methodName}", (BaseData params) -> {
|
||||
((${className}) params.get("_self")).${methodName}(${argStr});
|
||||
});
|
||||
`;
|
||||
} else if (callbackStatementsTypes.includes(returnType)) {
|
||||
impl = `${callbackStatements[returnType]}("${methodName}", (BaseData params) -> {
|
||||
return (${returnType}) ((${className}) params.get("_self")).${methodName}(${argStr});
|
||||
});
|
||||
`;
|
||||
} else {
|
||||
usedClasses.push(returnType);
|
||||
impl = `setCallbackReflectiveWithArgs("${methodName}", (BaseData params) -> {
|
||||
return (${returnType}) ((${className}) params.get("_self")).${methodName}(${argStr});
|
||||
});
|
||||
`;
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
name: methodName,
|
||||
returnType: returnType,
|
||||
isStatic: isStatic,
|
||||
arguments: arguments,
|
||||
impl: impl
|
||||
};
|
||||
});
|
||||
return {
|
||||
className: className,
|
||||
constructors: constructorDetails
|
||||
constructors: constructorDetails,
|
||||
methods: methodDetails,
|
||||
usedClasses: [...new Set(usedClasses)]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue