support global replace (instead of once replacement)
supposed we have file:
package org.antlr.v4.tool;
public class Native2 {
double getLabeledNodeVoltage(String name) {
Integer node = LabeledNodeElm.getByName(name);
if (node == null || node == 0)
return 0;
// subtract one because ground is not included in nodeVoltages[]
return nodeVoltages[node.intValue() - 1];
}
native void callTimeStepHook() /*-{
var hook = $wnd.CircuitJS1.ontimestep;
if (hook)
hook($wnd.CircuitJS1);
}-*/;
native void callSVGRenderedHook(String svgData) /*-{
var hook = $wnd.CircuitJS1.onsvgrendered;
if (hook)
hook($wnd.CircuitJS1, svgData);
}-*/;
}
What expected output is :
import { java, JavaObject, type double } from "jree";
export class Native2 extends JavaObject {
protected getLabeledNodeVoltage(name: string): double {
let node: java.lang.Integer = LabeledNodeElm.getByName(name);
if (node === null || node === 0)
return 0;
// subtract one because ground is not included in nodeVoltages[]
return nodeVoltages[node.intValue() - 1];
}
/*-na-ti-ve-*/ protected callTimeStepHook(): void {
var hook = $wnd.CircuitJS1.ontimestep;
if (hook)
hook($wnd.CircuitJS1);
};
/*-na-ti-ve-*/ protected callSVGRenderedHook(svgData: string): void {
var hook = $wnd.CircuitJS1.onsvgrendered;
if (hook)
hook($wnd.CircuitJS1, svgData);
};
}
But without this PR, will generates :
import { java, JavaObject, type double } from "jree";
export class Native2 extends JavaObject {
protected getLabeledNodeVoltage(name: string): double {
let node: java.lang.Integer = LabeledNodeElm.getByName(name);
if (node === null || node === 0)
return 0;
// subtract one because ground is not included in nodeVoltages[]
return nodeVoltages[node.intValue() - 1];
}
/*-na-ti-ve-*/ protected callTimeStepHook(): void {
var hook = $wnd.CircuitJS1.ontimestep;
if (hook)
hook($wnd.CircuitJS1);
};
protected callSVGRenderedHook(svgData: java.lang.String): void /*-{
var hook = $wnd.CircuitJS1.onsvgrendered;
if (hook)
hook($wnd.CircuitJS1, svgData);
}-*/;
}
OPTIONS I am using :
{
"packageRoot": "./migration/simple",
"outputPath": "./output/simple/output",
"sourceReplace": {
"(native)": "/*-na-ti-ve-*/"
},
"targetReplace": {
"java\\.lang\\.Enum": "Enum",
"java\\.lang\\.String": "string",
"--\\/\\*-\\{[\\s\\S]*?\\}-\\*\\/": "{}",
"\\/\\*-\\{": "{",
"\\}-\\*\\/": "}"
},
"options": {
"addNullUnionType": false
}
}
simply put, my mod is to not stop replacing the string (if there are more than one match). Otherwise, the replacement still works for first replacement, then do not replace next matches.
@x2nie patch looks good, but don't forget to sign the patch (check out the DCO check, which contains a link to how you can sign it).
Okay, I might do that today or tomorrow. I m sorry for slow response, I just installed another linux (for unrelated reason).
Yeah, finally I did it. Apologize for long waiting.
Intermezzo: I was confusing of how to resolve this (the DCO), I planned to do that (DCO while committing) in another branch by start over modifying - testing - commiting with DCO - and then create new PR. However suddenly my disk is full, and I turn busy with the disk/ OS stuffs. But today, by asking AI (chatgpt) it actually can be done with very simple command:
git commit --amend -s
git push --force
When I first hit the DCO barrier I just followed the link beside the error (Details) and quickly found the necessary git commands.