Automated and programmed refactoring in Java

I am facing the challenge of internationalizing a project that includes code (now 80% of the variable names are in Italian, which needs to be changed to English). Some of the translation is fine, but how to find a way to refactor the code is to drive me crazy. Almost every IDE on the market has such a refactoring feature, but none of them work automatically or programmatically.

My question is, do they just use a regex to scan all the files in the project and then reorganize them, or do they follow some tricky rules?

+3


source to share


2 answers


I used a combination of JavaParser and another tool I forgot, whose name allowed me to track the use of all variables in classes from the compiled .class / .jar file.



JavaParser is definitely a tool that could get the job done. Tomorrow I'll see what the other component is. Maybe a class dependency analyzer .

+3


source


The OP seems to want to do a bulk rename.

Until you can find the tool, you can use our Java obfuscator to achieve this. This solution does rename in bulk, ignoring scopes, but I suspect it works great.

Many original obfuscators take IDs and cross them sequentially. This means that somewhere in the obfuscator, there is a map from obfuscated identifiers to obfuscated identifiers, for example, "foo" → "bar", which means "replace" foo "with" bar ".

Our obfuscator reads such a map before launching it (and this is the key to the solution). This map was supposedly formed by the previous stage of obfuscation; reading and reusing such a map will ensure that any incremental / additional obfuscation is performed just like the original.

If you execute our obfuscator on a set of source files, you get a complete map of each ID and what it was mapped to (randomly) in a text file that looks like (as above):

 foo -> i3718234
 fas -> h823478
 ...

      

If you run the obfuscator again and feed it the same bags and this map file, it (by design) matches the IDs in the same way, producing the same result the first time.

To complete the OPs task, you can run our obfuscator on its code to get:

  italianID1 -> i23432
  italianID2 -> g232343
  ...

      



Using a text editor, he can modify this file:

  italianID1 -> englishID1
  italianID2 -> englishID2
  ...

      

The names he doesn't want to touch are edited (obviously) in this form:

   foo -> foo
   bar -> bar

      

(The shorthand for this is to just leave the "-> id" part. "Foo" itself is interpreted as "foo → foo").

Now running obfuscator will rename all Italian IDs to English IDs.

Check out my bio for the link. Its a commercial tool, but its probably less expensive than OP's day and I think it solves his problem, waaaaay is easier than making your own refactoring tool.

Disadvantage: I think he will be forced to reformat his code. This is normal, the obfuscator includes a transducer.

+3


source







All Articles