Adding Roo to a project using pull-out refactoring

The pull-out refactoring is the reverse of push-in refactoring. In push-out refactoring you extract methods and attributes from the Java source file and move it to an AspectJ ITD file. This feature is particularly useful in the following situations:

  • If you had earlier performed push-in refactoring on your Roo project, and now you want to develop your project once again using Spring Roo
  • If you have partially developed a project and now you want to use Spring Roo in its development
  • In this recipe we'll look at how to pull-out the toString method from the Flight.java file to Flight_To_String.aj file.

Getting ready

Follow the instructions specified in the Removing Roo with push-in refactoring recipe to push the toString method defined in the Flight_To_String.aj file to Flight.java file.

How to do it...

Follow these steps to move the code from Java source file to an AspectJ ITD file:

  1. Create a Flight_To_String.aj file in the sample.roo.flightapp.domain package, as shown here:
    package sample.roo.flightapp.domain;
    
    public aspect Flight_To_String { }

    This an empty aspect into which we want to pull-out fields, contructors, methods, and so on, from Java source file.

  2. Open the Flight.java file in Eclipse IDE.
  3. Right-click the toString method from the Outline view and select Refactor | Pull Out ITD, as shown in the following screenshot:
    How to do it...
  4. Selecting the Pull Out ITD option shows the following dialog box to let you specify the AspectJ ITD file into which the selected toString method should be added:
    How to do it...

    In the preceding screenshot enter sample.roo.flightapp.domain.Flight_To_String as the name of the Target Aspect and make sure that you check the Make the Aspect Privileged option.

  5. Click OK to pull-out the toString method to the Flight_To_String.aj file.

There's more...

IIf you want to use Spring Roo for an existing project, then you need to move the methods, attributes or constructors from Java source files to AspectJ ITD files. These ITD files are then managed by Spring Roo. You need to make sure that you only move those Java elements to AspectJ ITD files that can be managed by Roo. The naming convention followed by these AspectJ ITD files should follow the naming convention expected by Roo. You'll also have to add necessary Roo-related dependencies in your pom.xml file.

See also

  • Refer to the Removing Roo with push-in refactoring recipe for removing Roo from your project
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.122.244