Java Refactoring / Restructuring Tool

I have a large monolithic web application that I want to split into smaller modules. As a first step, I would like to change the package hierarchy, which currently looks like this:

- com.companyname.project - dao - bean - booking // possibly containing more sub packages - core ... etc etc (there are a bunch of others as well) - service - booking // possibly containing more sub packages - core ... etc etc - logic - bean - booking // possibly containing more sub packages - core ... etc etc - service - booking - core ... etc etc - web - bean // same substructure as above... - service // same substructure as above... - taglib // same substructure as above... - util 

I would like the package structure used for the booking example as the package name below com.companyname.project

Now I am wondering if there is a tool that could, for example, use a simple regular expression to do the restructuring for me.

eg.
com.companyname.project.dao.bean.booking
will become:
com.companyname.project.booking.dao.bean

and

com.companyname.project.dao.service.booking
will become:
com.companyname.project.booking.dao.service

I could use Eclipse and drag and drop packages, but I'm looking for something that can do this with a minimal amount of my participation, as it will be very repetitive.

+4
source share
2 answers

You can use any Java IDE with refactoring compatibility:

  • IntelliJ IDEA (best refactoring support). It has an open source community version and a limited version released.
  • Eclipse (open source)
  • NetBeans (open source)

I do not recommend using regexp search / replace as it is error prone.

+1
source

Why not use Java yourself? I believe in your current scenario, you can easily write a small Java program to do the exact refactoring you are talking about, and ensure that you don’t miss out on this path.

You can write a method that accepts the parameters "pre" (i.e., "com.companyname.project.dao.bean.booking") and "post" (i.e., "com.companyname.project.booking.dao. bean ") and accordingly copies the" pre "structure to the" post "structure.

In this program, I will introduce the main method and the convertPackage (pre, post) method. Then you can have an array of your "pre" and "post" structures, and you can convert them to a new one. It would be best to do this copying to some temporary directory, and not using the original as an additional security measure.

Perhaps my thinking is too simple in this matter, but I saw a program created for this refactoring, one and a half times a day or less.

You will get an additional advantage, knowing exactly what is changing, and not the uncertainty that comes with these automatic tools that can do it right for you or cannot ...

-one
source

Source: https://habr.com/ru/post/1399168/


All Articles