Skip to content
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

Improve character index of token tracing information for better visualization of Java matches #1869

Merged
merged 4 commits into from
Jul 15, 2024

Conversation

tsaglam
Copy link
Member

@tsaglam tsaglam commented Jul 12, 2024

Fixes the tracing information for ASSIGN, VARDEF, NEWCLASS, and APPLY tokens in the Java language module.

Old:

31              int myVariable = 77777777;
                |VARDEF                 |

32              myVariable--;
                |assign

33              myVariable = myVariable - 1;
                |assign

34              int[] myArray = new int[7000];
                |VARDEF                     |
                                |NEWARRAY

35              System.out.print(myVariable + 200);
                |apply

(variable definition includes initialization, assignment has length 1, new array or class has length 1, apply not correct)

New:

31              int myVariable = 77777777;
                |VARDEF         |

32              myVariable--;
                |ASSIGN    |

33              myVariable = myVariable - 1;
                |ASSIGN    |

34              int[] myArray = new int[7000];
                |VARDEF        ||NEWARRAY   |

35              System.out.print(myVariable + 200);
                |APPLY         |

(context includes only what is necessary, no length 1 tokens)

Diff:

31              int myVariable = 77777777;
-                |VARDEF                 |
+                |VARDEF         |

32              myVariable--;
-               |assign
+               |ASSIGN    |

33              myVariable = myVariable - 1;
-               |assign
+               |ASSIGN    |

34              int[] myArray = new int[7000];
-               |VARDEF                     |
-                               |NEWARRAY
+               |VARDEF        ||NEWARRAY   |

35              System.out.print(myVariable + 200);
-               |apply
+               |APPLY         |

@tsaglam tsaglam added enhancement Issue/PR that involves features, improvements and other changes minor Minor issue/feature/contribution/change language PR / Issue deals (partly) with new and/or existing languages for JPlag labels Jul 12, 2024
@tsaglam tsaglam marked this pull request as ready for review July 12, 2024 13:43
@tsaglam tsaglam requested a review from a team July 12, 2024 13:44
Copy link
Contributor

@TwoOfTwelve TwoOfTwelve left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good.
I have tried the printer with an array with initializer and the tokens are generates as follows:

2           public int[] x = new int[]{Math.random(), Math.random(), Math.random()};
            |VARDEF         ||NEWARRAY                                            |
                                       |arrinit{
                                       |APPLY    |    |APPLY    |    |APPLY    |  |}arrinit

Maybe it would be better if NEWARRAY would close after [] instead of at the end of the statement. The visualization might be better if tokens don't overlap as much.

@tsaglam
Copy link
Member Author

tsaglam commented Jul 15, 2024

Yes, that would be better. I will fix it!

EDIT: THis is how is looks now...

54              int[] x = new Integer[] {Math.random(), Math.random(), Math.random()};
                |VARDEF  ||NEWARRAY |    |arrinit{
                                         |APPLY    |    |APPLY    |    |APPLY    | |}arrinit

55              int[] y = {Math.random(), Math.random(), Math.random()};
                |VARDEF  ||newarray
                           |arrinit{
                           |APPLY    |    |APPLY    |    |APPLY    | |}arrinit

56              int[] z = new Integer[3];
                |VARDEF  ||NEWARRAY |

57      
58              String text = new String("Hello, world!".getBytes("UTF-8"), 7, 5, "UTF-8");
                |VARDEF      ||NEWCLASS| |APPLY                 |

59              Boolean bool = new Boolean(false);
                |VARDEF       ||NEWCLASS |

Copy link

sonarcloud bot commented Jul 15, 2024

@tsaglam tsaglam merged commit 966ea65 into develop Jul 15, 2024
44 checks passed
@tsaglam tsaglam deleted the feature/token-tracing branch July 15, 2024 09:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Issue/PR that involves features, improvements and other changes language PR / Issue deals (partly) with new and/or existing languages for JPlag minor Minor issue/feature/contribution/change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants