Wednesday, May 27, 2009

Push in refactoring for AJDT

I just finished implementing the new Push In refactoring for the AJDT plugin, available in the latest dev build.

Essentially, the refactoring pushes intertype declarations into their target types. So, when a push in refactoring is applied to the following aspect and class:

aspect Foo {
int Bar.x;
declare parents : Bar implements I;
declare @type : Bar : @Baz;

class Bar { }

the result is:

class Bar implements I {
int x;

The Foo aspect is deleted because it is empty.

It is simple to use. Select the ITDs or set of ITDs that you want to push in. You can select an entire project, source folder, or package to push all of its ITDs into the target types:

And then follow the wizard:


The result is that all ITDs have been successfully pushed in and all aspects that are made empty because of this refactoring have been deleted.

And undo works, too:

It is also possible to execute the refactoring from an editor. Just select all or part of the ITD you want to push in. However, the command itself is in a different sub-menu:

Please try it out and let me know if it works for you. We are working on adding more refactorings to AJDT. Next on the list is the analogous refactoring pull-out.


  1. Great,
    I wanted to use roo for the point of "go-ahead with your project now", but then I wanted POJOs.
    Roo with this push-in will help

  2. I imported a roo project into eclipse, but I could not get the ajdt to provide the push-in option, can you provide a walk tru from creating a web app from roo and then using the push-in to remove aspects and have a complete pojo

  3. When you right click in an editor (any Java or AJ editor), do you see the menu item "AspectJ Refactorings"?

    If not, then AJDT does not seem to be installed properly.

    Are you seeing any relevant exceptions in your error log? If so, can you post them here?

  4. Thanks for responding,
    in the file when I right click I do get the AspectJ Refactoring/Push-in,
    However I get the following message box 'No Innertype declarations selected'

  5. Here is source for the file:

    import javax.persistence.Entity;
    import org.springframework.roo.addon.javabean.RooJavaBean;
    import org.springframework.roo.addon.tostring.RooToString;
    import org.springframework.roo.addon.entity.RooEntity;

    public class Rsvp {

  6. That's the correct behavior. is not an aspect, so it has no intertype declarations. You must explicitly select the intertype declarations from the aspects that you want to push in (either in the text or in the package explorer).

  7. Here is the content of the Rsvp_Roo_Entity.aj file,
    How can I push all of it into file

    privileged aspect Rsvp_Roo_Entity {

    transient EntityManager Rsvp.entityManager;

    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long;

    @Column(name = "version")
    private Integer Rsvp.version;

    public Long Rsvp.getId() {

    public void Rsvp.setId(Long id) { = id;

  8. In the package explorer, right click on Rsvp_Roo_Entity.aj. Select Refactoring -> Push In... This should bring up the correct refactoring dialog.

  9. Thanks for taking time,
    I get the message:
    'Rebuild Project. No crosscutting model available'
    I did rebuild the project several times.

  10. Hmmmm...this is starting to sound like a bug.

    Can you try a few things first, though:

    1. What happens when you click on one of the gutter markers for the ITDs? Are you able to navigate to their declaration?
    2. Are there any relevant exceptions in the error log view?
    3. Are you able to run your program correctly?

    If all this leads to nothing, can you please raise a bugzilla report for this? And attach the full project that you are using.

  11. A big thank you,
    The issue is with M2_REPO variable not configured properly.
    You guidence was helpfull in reaching the goal.

  12. Hello friends,
    I have the same problem when wanting to make the push in. I want to know what the problem is your variable M2_REPO

  13. Not sure if RHLeone still has this problem, but I was having the same issue and was able to right-click the project, select Maven and "Update Dependencies". After that, the push-in refactoring seemed ready to work again.

  14. Hello, I have got trouble with push in. I used it in a roo project. For some reason roo produces tests with errors for an entity. The wrong tests are in ITDs. I chose push in in order to change them but after the re factoring the methods with errors disappeared and they didn't move to the class. Is it because the methods have got error? Does the push in not work when the methods contain errors?
    Thanks for your help.

  15. That's correct. Push in will only work on code with no compile errors. What you are describing sounds like a bug with Roo. I'd recommend writing a post on the roo forum. Include the code snippet that is giving you problems.

    Here's the forum: