Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing a new refactoring plugin for Eclipse?

Is there any good documentation on implementing new refactorings in Eclipse? Specifically, I'd like to access the AST for a Java class, make some non-trivial changes, and save the result back to the source file.

So far, the only documentation I've found is (1) the source code for the existing refactorings and (2) a few articles on the LTK and Java AST:

Are there any other articles or tutorials that I should read?

like image 937
emk Avatar asked Aug 21 '09 21:08

emk


People also ask

How do you refactor in Eclipse?

Refactoring using Eclipse Right clicking on a Java element in the Package Explorer view and selecting Refactor menu item. Right clicking on a Java element in the Java editor and selecting Refactor menu item. Selecting a Java element in either the Package Explorer view or Java Editor and clicking Shift + Alt + T.

Does Eclipse support refactoring?

Compositional Refactoring This Eclipse bundle provides new Quick Assist actions to support refactorings in a compositional paradigm. In the compositional paradigm, the tool automates small, predictable steps of a refactorin...

How do I change all references in Eclipse?

Eclipse makes this absurdly easy to do. Right-click on almost anything and choose Refactor > Rename. Type in a new name for whatever it is, and make sure that the Update References checkbox is checked. This will ensure that all references in all of your code will be updated.


2 Answers

I found the eclipse.org article the most helpful to get me started. To be honest you're probably best off debugging some of the Eclipse refactorings to get a real feel for how they work.

A good place to get started debugging the code is to set breakpoints on org.eclipse.jdt.core.dom.rewrite.ASTRewrite, particularly the rewriteAST() method, then trigger some refactorings.

Here are a few you might find useful. Are you looking for anything in particular or a general sense of how to process the AST?

  • http://www.ibm.com/developerworks/opensource/library/os-ast/
  • http://blog.sahits.ch/?p=228
  • http://www.vogella.de/articles/EclipseJDT/article.html
like image 60
Rich Seller Avatar answered Oct 01 '22 08:10

Rich Seller


You can take a look at Lombok Project. It seems they have Eclipse plugin.

It does some AST manipulations - e.q. getters/setters. Could be helpful for you too.

like image 29
daoway Avatar answered Oct 01 '22 06:10

daoway