Skip to content

support global replace (instead of once replacement) #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 15, 2024

Conversation

x2nie
Copy link

@x2nie x2nie commented Aug 16, 2024

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
    }
}

@x2nie
Copy link
Author

x2nie commented Aug 16, 2024

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.

@mike-lischke
Copy link
Owner

@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).

@x2nie
Copy link
Author

x2nie commented Aug 29, 2024

Okay, I might do that today or tomorrow.
I m sorry for slow response, I just installed another linux (for unrelated reason).

@x2nie
Copy link
Author

x2nie commented Sep 15, 2024

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

@mike-lischke
Copy link
Owner

When I first hit the DCO barrier I just followed the link beside the error (Details) and quickly found the necessary git commands.

@mike-lischke mike-lischke merged commit d2c6c8f into mike-lischke:master Sep 15, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants