jrefactory

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » UML » jrefactory 
jrefactory
License:
URL:http://sourceforge.net/projects/jrefactory/
Description:A refactoring tool for the Java programming language, it includes the JavaStyle pretty printer, a UML java class diagram viewer, a coding standards checker and computes program metrics.
Package NameComment
com.aravox.ShunWizard
com.dbnet.common.view.report
field
field.pullup
imp
imp.inh
method
method.param
msn.messages.commands
net.sourceforge.jrefactory.action
net.sourceforge.jrefactory.ast
net.sourceforge.jrefactory.build Responsible for building up structures that can be used by a number of different classes. The first instance builds an expression based on some input criteria.
net.sourceforge.jrefactory.factory
net.sourceforge.jrefactory.io
net.sourceforge.jrefactory.parser
net.sourceforge.jrefactory.query
net.sourceforge.jrefactory.uml
net.sourceforge.jrefactory.uml.line Contains the basic components for drawing UML diagrams. These are the lines that connect classes, the labels for methods and fields, and the panels that hold the classes themselves. Software is provided to zoom in and out on the class diagrams.
net.sourceforge.jrefactory.uml.loader Contains code to reload the class diagrams. Essentially this is an interface which specifies how to reload the source code and a singleton object that contains the object responsible for reloading the source code.
net.sourceforge.jrefactory.uml.print Contains code to print the class diagrams.
net.sourceforge.jrefactory.uml.render Contains code to generate .JPG files from the class diagrams.
org
org.acm
org.acm.seguin Contains junit test composite pattern that runs unit tests in subpackages.
org.acm.seguin.ant
org.acm.seguin.awt This package abstracts the creation of GUI components. The components in this package prompt the user with a yes/no question and prints an exception in a dialog box.
org.acm.seguin.completer
org.acm.seguin.completer.info
org.acm.seguin.completer.popup
org.acm.seguin.findbugs
org.acm.seguin.ide.cafe Responsible for creating a plugin for Visual Cafe. The classes in this package provide the functionality of the pretty printer and the refactory inside WebGain's Visual Cafe.
org.acm.seguin.ide.command Responsible for command line refactoring. The objects in this package isolate the portions of the system that are used when the Refactory tool is run from the command line.
org.acm.seguin.ide.common Classes common to all IDEs. In creating the refactory tool and plugging it into a number of different IDEs, it became clear that there were some objects that were not directly related to any specific refactoring functionality, but were useful as abstract classes or shared components. This package holds those classes.
org.acm.seguin.ide.common.action
org.acm.seguin.ide.common.options
org.acm.seguin.ide.elixir Holds those classes which allow the pretty printer and the refactory tool to plug into the Elixir IDE.
org.acm.seguin.ide.elixir.version Adds a Source Safe plugin for the Elixir IDE.
org.acm.seguin.ide.jbuilder Responsible for creating a plugin for the JBuilder. The code here creates a pretty printer that works with the file in the editor, and also provides the UML class diagrams and other refactoring features.
org.acm.seguin.ide.jbuilder.refactor
org.acm.seguin.ide.jdeveloper Responsible for creating a plugin for jDeveloper9i. The classes in this package provide the functionality of the pretty printer inside Oracle jDeveloper 9i.
org.acm.seguin.ide.jedit
org.acm.seguin.ide.jedit.action

Creating custom actions.

ProjectViewer allows other plugin developers too interact with the file trees by creating custom actions to be executed on the nodes. Actions can be added to the tree's context menu or to the viewer's toolbar. It's recommended to extend the context menu, since there's only so much useful space in the toolbar for new actions.

Creating a new action is very simple:

  • Create a new class that extends {@link projectviewer.action.Action Action}.
  • Implement the {@link projectviewer.action.Action#actionPerformed(ActionEvent) actionPerformed()} method to execute the desired operations.
  • Register the action in the context menu ({@link projectviewer.vpt.VPTContextMenu#registerAction(Action) registerAction()}) or in the toolbar ({@link projectviewer.ProjectViewer#registerAction(Action) registerAction()}) by calling the appropriate method.

The menu item show in the context menu is provided by the {@link projectviewer.action.Action#getMenuItem() getMenuItem()} of the Action class. Subclasses are welcome to override this method to provide other kinds of menu items (a sub-menu, for example). For the toolbar button, the {@link projectviewer.action.Action#getButton() getButton()} method is used.

Before showing the menu item in the context menu, ProjectViewer will call the {@link projectviewer.action.Action#prepareForNode(VPTNode) prepareForNode()} method in all actions registered in the context menu. This allows each action to decide if it should be shown for the given node and what message to show, for example. For the toolbar buttons, this method is never called, so the toolbar buttons should be able to be executed regardless of the current tree selection. If your action depends on a certain kind of node, add it to the context menu, and not to the toolbar. If you want to add it to the toolbar, check for the node type in your actionPerformed() implementation.

Another important thing to notice in the prepareForNode() method is that the actions should check is the node is of a certain type, and not if the node is not of a certain type. For example, use "node.isFile()" and not "!node.isDirectory()". This ensures that the action will not do anything wrong if a different node type is added in the future to PV, or if another plugin adds a new node type to PV.

It's important to notice that the instance given to the registerAction methods is not the instance used by the viewer instances. Those instances are used as prototypes, and the viewers use {@link projectviewer.action.Action#clone() clone()} to get instances for the specific viewer. After the cloning, the {@link projectviewer.action.Action#setViewer(ProjectViewer) setViewer()} method is called, so the actions have a reference to the viewers where they are being used. This also means that you should not use the constructor of your Action implementation to instantiate GUI components. Instantiations of GUI components should be done lazily in the getMenuItem() or getButton() methods. The default implementation already does this, so you should only worry about this if you are overriding one of these methods.

org.acm.seguin.ide.jedit.event
org.acm.seguin.ide.kawa
org.acm.seguin.ide.netbeans
org.acm.seguin.ide.standalone
org.acm.seguin.io Contains a number of classes that are responsible for dealing with input and output streams and directories of files. This package is where I place the classes that extend objects in java.io.
org.acm.seguin.junit
org.acm.seguin.metrics Contains code to gather metrics about the source code. The first step in determining whether a refactoring should be done is gathering information about the source code. The metrics presented here are relatively simple and based on a book on object oriented metrics.
org.acm.seguin.pmd
org.acm.seguin.pmd.ant
org.acm.seguin.pmd.cpd
org.acm.seguin.pmd.cpd.cppast
org.acm.seguin.pmd.jaxen
org.acm.seguin.pmd.renderers
org.acm.seguin.pmd.rules
org.acm.seguin.pmd.rules.design
org.acm.seguin.pmd.rules.junit
org.acm.seguin.pmd.rules.strictexception
org.acm.seguin.pmd.stat
org.acm.seguin.pmd.swingui
org.acm.seguin.pmd.swingui.event
org.acm.seguin.pmd.symboltable
org.acm.seguin.pmd.util
org.acm.seguin.pretty
org.acm.seguin.pretty.ai
org.acm.seguin.pretty.jdi
org.acm.seguin.pretty.line
org.acm.seguin.pretty.sort
org.acm.seguin.print
org.acm.seguin.print.text
org.acm.seguin.print.xml
org.acm.seguin.project
org.acm.seguin.refactor Responsible for storing the software that performs the refactorings. This package contains the base classes for the refactorings. It also has a number of classes that are used by several types of refactorings. This page briefly describes these types, then moves on to describe how to create a new refactoring.

  • Refactoring is the base class for refactoring.
  • TransformAST is the base class for making a transformation on a syntax tree.
  • ComplexTransform combines a number of TransformASTs together to update a single file.
  • RefactoringException is thrown when the requested refactoring cannot be performed.
  • AddImportTransform is a TransformAST that adds an import statement to the file
  • RemoveImportTransform is a TransformAST that removes an import statement from a file

How to create a new refactoring

This portion of the document describes how to create a new refactoring, or at least the methodology that was used to create the existing refactorings.

The first step is to create a set of source files to test on. This file contains the "clean" version of the file before the refactoring was applied. Then I hand edited the file so that it was the correct result. Then applied the pretty printer to the edited file. (If more than one file is updated by a refactoring, this process is repeated for each file.)

The second step is to create a unit test. To do this, I extended org.acm.seguin.junit.DirSourceTestCase. This takes all the features of the TestCase from junit and adds in the specific directories. Root is the working directory, clean contains the unmodified files, and check contains the correct files. The unit test:

  1. Copies the files from the clean directory to the working directory
  2. Applies the refactoring
  3. Compares the file in the working directory to the correct file
  4. Deletes the file in the working directory

To get the unit test to compile, I create a refactoring class. I call the refactoring class XXXRefactoring, and it extends org.acm.seguin.refactor.Refactoring. The refactoring goes into the appropriate package. At the moment, the kinds of refactoring are:

  • org.acm.seguin.refactor.type - renaming and moving classes, adding child or parent classes, removing classes
  • org.acm.seguin.refactor.field - renaming and moving fields
  • org.acm.seguin.refactor.method - renaming and moving methods

I quickly create the empty methods so that the refactoring is not abstract, and then everything should compile. I compile, and run the unit tests to see that the junit test fails because the files do not match. (Other types of failures are caused by the unit test being incorrect - so now that is debugged.)

Next I create a number of TransformASTs that perform some unit transformation on the parse tree. I've used these to add or remove a node in the parse tree or replace a name everywhere it occurs in the source tree.

Sometimes a TransformAST hands it's work off to a Visitor object. The org.acm.seguin.parser.ChildrenVisitor is a good one to choose as a base class for this visitor. It already provides the ability to traverse the entire tree. Then all I have to do is overload the specific visit methods for the nodes I'm concerned about.

To learn more about what exactly the source tree looks like, look at the java1_1.jjt file that is included in the code.jar file.

Now we have a bunch of TransformAST objects which might call visitors to do their work. How do these get combined together to update a single file? I would then create a ComplexTransform and add to it each TransformAST object that is necessary to update that file. Create an instance of the ComplexTransform with the getComplexTransform() method of the Refactoring object. (This is done to support undoing the refactoring.)

If the effect of a refactoring requires that perhaps a large number of files be modified, then I use a SummaryVisitor to traverse all the source files that are loaded into memory. A good visitor to extend is the org.acm.seguin.summary.TraversalVisitor. It traverses the summary file.

To learn more about the Summary objects, look at the org.acm.seguin.summary package. The Summary objects store the metadata for all the source files that are loaded. One thing to note about the FileSummary objects is that if they have a file that is equal to null, then the FileSummary and associated types are from the JDK or a 3rd party library. These types cannot be updated by the refactoring tool.

By this point we have a Refactoring object. It applies a ComplexTransform to a single file or uses a TraversalVisitor to apply the ComplexTransform to a series of files. The ComplexTransform applies a number of TransformAST objects to update a single parse tree.

Once the unit test passes, you are done!

org.acm.seguin.refactor.field Contains refactorings that apply to fields. The classes here are either the refactorings that move fields around or are the TransformAST objects and visitors that update the individual syntax trees.

org.acm.seguin.refactor.method Responsible for method refactorings. This package contains classes that are method based refactorings, such as Move Method or Push Method. It also contains the visitors and TransformAST objects that perform the units of operation on the syntax trees.

org.acm.seguin.refactor.type Contains the type refactorings. The refactorings in this package are type based refactorings, for instance move a class to a different package or rename a class.

This package also contains a number of different visitors that traverse the entire tree of source files, since type based operations have the possibility of changing all the source files in the system.

Beneath that are TransformAST objects which perform a single unit operation such as renaming a type. The actual work isusually done by the associated visitor object.

org.acm.seguin.refactor.undo The undo package is responsible for being able to undo the refactoring operations. This package currently consists of two objects. One is the stack that maintains a list of all the undo actions. The second is the specific action that can be undone.

There is no support yet for redoing actions.

Undoing a particular change to a specific file are stored by renaming the current file with an extension, .java.# where # is the number of times the file has been changed by the refactoring tool. Let's call this method of storing the previous incarnations of a file an indexed file.

An undo action then has a number of indexed files associated with them. It also has a description of the refactoring so that a user interface component can display a list of refactorings to undo.

The undo stack then holds all the undo action objects. It uses a singleton pattern to insure that only a single instance of the undo stack is present in the editor at a time.

org.acm.seguin.summary Stores the metadata for the source code. This package is responsible for storing the summaries of all the java source files. The parser contained in the org.acm.seguin.parser package loads individual files. These files are then scanned for types, methods, fields, and the details of these values. They are stored in a tree.

This package stores summaries as well as the loaders for these structures.

Subpackages store procedures that search the summary tree or find specific information about the tree.

org.acm.seguin.summary.load
org.acm.seguin.summary.query
org.acm.seguin.test
org.acm.seguin.test.io
org.acm.seguin.tools
org.acm.seguin.tools.build Tools to help me create the jar files necessary to release the refactory tool.
org.acm.seguin.tools.builder
org.acm.seguin.tools.install
org.acm.seguin.tools.international Contains code to help internationalize software. The first object in this class is one that searches through the directory structure of the software, and creates a list of strings.
org.acm.seguin.tools.stub
org.acm.seguin.uml Responsible for drawing the UML class diagrams. This package contains all the various components to draw the UML class diagram. The main pieces are the UMLPackage, which serves as a background. UMLClass holds a particular class, and UMLField, UMLMethod, and UMLNestedClass are each lines in the UMLClass.

To add more items to the menu that pops up on the class diagrams, edit UMLPopupMenu. This menu has been broken into a number of methods each generating a particular submenu. The ActionListener that is invoked are stored either in org.acm.seguin.uml.refactor if it is a refactoring, or org.acm.seguin.ide.common.

The reason to place it in ide.common is that we want to isolate changes that are specific to a particular release of an editor. This makes it easier to add the feature to other editors.

org.acm.seguin.uml.jpg Contains code to generate .JPG files from the class diagrams.
org.acm.seguin.uml.line Contains the basic components for drawing UML diagrams. These are the lines that connect classes, the labels for methods and fields, and the panels that hold the classes themselves. Software is provided to zoom in and out on the class diagrams.
org.acm.seguin.uml.loader Contains code to reload the class diagrams. Essentially this is an interface which specifies how to reload the source code and a singleton object that contains the object responsible for reloading the source code.
org.acm.seguin.uml.print Contains code to print the class diagrams.
org.acm.seguin.uml.refactor Contains the user interface compontents, controllers and dialog boxes, that allow a programmer to specify parameters for the refactorings. These components prompt the user for the names of the package or the class and other information.
org.acm.seguin.util Contains classes that either match what is contained in java.util or otherwise miscellaneous classes. The most important software here is the settings files which are my replacement for property files. This software is responsible for loading specific values and complaining when it is not there.
org.acm.seguin.version Contains code to interact with a version control system. This one is primarly used to direct the user to check a read-only file out from the version control system.
org.apache.tools.ant.taskdefs.optional.javastyle
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.