3 ms·
> but the workaround is trivial. If you have a trivial solution to rename hundreds of Java classes and their references en masse without breaking the build and
by thangalin 4y ago
> but the workaround is trivial.
If you have a trivial solution to rename hundreds of Java classes and their references en masse without breaking the build and without renaming each file one-at-a-time, do tell. You can find more details about potential solutions I've tried here:
https://stackoverflow.com/questions/75154524/bulk-rename-of-java-classes/ https://stackoverflow.com/questions/75154524/bulk-rename-of-...
FYI, the following plug-in for IDEA supports regular expressions (as of Jan 20, 2023), so it may be a viable solution:
https://plugins.jetbrains.com/plugin/17455-rename-files-refactor-batch https://plugins.jetbrains.com/plugin/17455-rename-files-refa...
- counttheforks 4y agoPosted a solution on your other comment: https://news.ycombinator.com/item?id=34493760 https://news.ycombinator.com/item?id=34493760
- playingalong 4y agoI bet Open Rewrite can handle that quite easily: https://docs.openrewrite.org/ https://docs.openrewrite.org/
- thangalin 4y agoI wasn't able to find a recipe that performs a regular expression rename. That is, there doesn't seem to be anything like: --- type: specs.openrewrite.org/v1beta/recipe name: com.yourorg.ChangeTypeExample displayName: Change type example recipeList: - org.openrewrite.java.ChangeType: oldFullyQualifiedTypeName: (.+) newFullyQualifiedTypeName: Kt$1
- Someone 4y agoI would do that the hacker way: - build the current TeX.jar - jar tf TeX.jar | grep whatever to get a list of to-be-renamed classes - use sed or manual editing to generate a large list of recipes - run those recipes Instead of jar tf, grep for “^package foo.bar.baz” and “class (complex regex)” in the source code to get a list of package and class names, or use the directory structure. Maybe do all of them, and compare the results for robustness. That list will be large and it may not go perfect in one go, but it’s a one-off job, and you‘ll get there.
- deleted 4y ago[deleted]
- dangerlibrary 4y agoThis feels like something where the right solution is to drop down to the terminal and use the old standbys - sed/grep/find, etc. Could probably wrap it all up in `make` or `just` if this is something you do regularly.
- thangalin 4y agoIt's not trivial. Some class names are substrings of other classes. I'm pretty sure this requires loading and parsing the source code's AST to accomplish without breaking the build. The SO thread goes into more gnarly details.
- dangerlibrary 4y agoSorry, I didn't mean to imply it was trivial, by any means. Just that there are powerful tools for "manipulating many line-delimited text files at once" and those tools seem likely to fit your goal. It's possible you do in fact need to parse the AST for your goals - I haven't spent the requisite time to deeply understand the problem.
- dcminter 4y agoEdit: Never mind, whartung enlightened me in a sibling comment. Leaving the egg on my face for posterity below. --- Why do you want to change all the files? The license only says you have to change the names of files that you modify. It's a pretty weird term. If for some reason you were determined to change the names of all files then you ought to be able to create a plugin that walks the tree of classes and invokes the refactoring capabilities of the IDE to make the change. It's a strange use-case though so I'm not really surprised there isn't a ready tool for it.
- thangalin 4y ago> Why do you want to change all the files? Ever pull on a thread to unravel an entire sweater? Imagine wanting to add an SVG typesetter. To do this, the interface implemented by the DVI typesetter needs to be extracted and generalized so that it works for both SVG and DVI (to maintain existing behaviour). The `Typesetter` interface is used by, for example, `BaseNode`, so any changes to that interface could touch `BaseNode`. Changes to `BaseNode` can affect all `*Node` classes, which then cascade over to `*Noad` and `*Prim` classes, and from there the rest of the source base.