001: /*
002: * Author: Chris Seguin
003: *
004: * This software has been developed under the copyleft
005: * rules of the GNU General Public License. Please
006: * consult the GNU General Public License for more
007: * details about use and distribution of this software.
008: */
009: package org.acm.seguin.refactor;
010:
011: import org.acm.seguin.refactor.field.FieldRefactoringFactory;
012: import org.acm.seguin.refactor.field.PushDownFieldRefactoring;
013: import org.acm.seguin.refactor.field.PushUpFieldRefactoring;
014: import org.acm.seguin.refactor.field.RenameFieldRefactoring;
015: import org.acm.seguin.refactor.method.ExtractMethodRefactoring;
016: import org.acm.seguin.refactor.method.MethodRefactoringFactory;
017: import org.acm.seguin.refactor.method.MoveMethodRefactoring;
018: import org.acm.seguin.refactor.method.RenameMethodRefactoring;
019: import org.acm.seguin.refactor.method.PushDownMethodRefactoring;
020: import org.acm.seguin.refactor.method.PushUpAbstractMethodRefactoring;
021: import org.acm.seguin.refactor.method.PushUpMethodRefactoring;
022: import org.acm.seguin.refactor.method.RenameParameterRefactoring;
023: import org.acm.seguin.refactor.type.AddAbstractParent;
024: import org.acm.seguin.refactor.type.AddChildRefactoring;
025: import org.acm.seguin.refactor.type.ExtractInterfaceRefactoring;
026: import org.acm.seguin.refactor.type.MoveClass;
027: import org.acm.seguin.refactor.type.RemoveEmptyClassRefactoring;
028: import org.acm.seguin.refactor.type.RenameClassRefactoring;
029: import org.acm.seguin.refactor.type.TypeRefactoringFactory;
030:
031: /**
032: * Factory for all refactorings
033: *
034: *@author Chris Seguin
035: */
036: public class RefactoringFactory {
037: /**
038: * Generates the type refactorings
039: */
040: private TypeRefactoringFactory typeFactory;
041:
042: /**
043: * Generates the field refactorings
044: */
045: private FieldRefactoringFactory fieldFactory;
046:
047: /**
048: * Generates the method refactorings
049: */
050: private MethodRefactoringFactory methodFactory;
051:
052: /**
053: * Stores the singleton
054: */
055: private static RefactoringFactory singleton;
056:
057: /**
058: * Constructor for the RefactoringFactory object
059: */
060: protected RefactoringFactory() {
061: typeFactory = new TypeRefactoringFactory();
062: fieldFactory = new FieldRefactoringFactory();
063: methodFactory = new MethodRefactoringFactory();
064: }
065:
066: /**
067: * Adds a feature to the Child attribute of the TypeRefactoringFactory
068: * object
069: *
070: *@return Description of the Returned Value
071: */
072: public AddChildRefactoring addChild() {
073: prepare();
074: return typeFactory.addChild();
075: }
076:
077: /**
078: * Adds a feature to the Parent attribute of the TypeRefactoringFactory
079: * object
080: *
081: *@return Description of the Returned Value
082: */
083: public AddAbstractParent addParent() {
084: prepare();
085: return typeFactory.addParent();
086: }
087:
088: /**
089: * Creates a move class refactoring object
090: *
091: *@return the move class refactoring object
092: */
093: public MoveClass moveClass() {
094: prepare();
095: return typeFactory.moveClass();
096: }
097:
098: /**
099: * Description of the Method
100: *
101: *@return Description of the Returned Value
102: */
103: public RenameClassRefactoring renameClass() {
104: prepare();
105: return typeFactory.renameClass();
106: }
107:
108: /**
109: * Description of the Method
110: *
111: *@return Description of the Returned Value
112: */
113: public RemoveEmptyClassRefactoring removeEmptyClass() {
114: prepare();
115: return typeFactory.removeEmptyClass();
116: }
117:
118: /**
119: * Extracts the interface of a class into a new interface object
120: *
121: *@return Description of the Returned Value
122: */
123: public ExtractInterfaceRefactoring extractInterface() {
124: prepare();
125: return typeFactory.extractInterface();
126: }
127:
128: /**
129: * Moves the field into the parent class
130: *
131: *@return Description of the Returned Value
132: */
133: public PushDownFieldRefactoring pushDownField() {
134: prepare();
135: return fieldFactory.pushDownField();
136: }
137:
138: /**
139: * Renames a field
140: *
141: *@return The refactoring
142: */
143: public RenameFieldRefactoring renameField() {
144: prepare();
145: return fieldFactory.renameField();
146: }
147:
148: /**
149: * Moves the field into the child class
150: *
151: *@return Description of the Returned Value
152: */
153: public PushUpFieldRefactoring pushUpField() {
154: prepare();
155: return fieldFactory.pushUpField();
156: }
157:
158: /**
159: * Moves the method into the parent class
160: *
161: *@return Description of the Returned Value
162: */
163: public PushUpMethodRefactoring pushUpMethod() {
164: prepare();
165: return methodFactory.pushUpMethod();
166: }
167:
168: /**
169: * Moves the method signature into the parent class
170: *
171: *@return Description of the Returned Value
172: */
173: public PushUpAbstractMethodRefactoring pushUpAbstractMethod() {
174: prepare();
175: return methodFactory.pushUpAbstractMethod();
176: }
177:
178: /**
179: * Moves the method into a child class
180: *
181: *@return Description of the Returned Value
182: */
183: public PushDownMethodRefactoring pushDownMethod() {
184: prepare();
185: return methodFactory.pushDownMethod();
186: }
187:
188: /**
189: * Moves the method into another class
190: *
191: *@return Description of the Returned Value
192: */
193: public MoveMethodRefactoring moveMethod() {
194: prepare();
195: return methodFactory.moveMethod();
196: }
197:
198: /**
199: * Moves the method into another class
200: *
201: *@return Description of the Returned Value
202: */
203: public RenameMethodRefactoring renameMethod() {
204: prepare();
205: return methodFactory.renameMethod();
206: }
207:
208: /**
209: * Renames a parameter
210: *
211: *@return Description of the Returned Value
212: */
213: public RenameParameterRefactoring renameParameter() {
214: prepare();
215: return methodFactory.renameParameter();
216: }
217:
218: /**
219: * Extracts code from one method to create a new method
220: *
221: *@return Description of the Returned Value
222: */
223: public ExtractMethodRefactoring extractMethod() {
224: return methodFactory.extractMethod();
225: }
226:
227: /**
228: * Prepare to create a refactoring that operates on files on the disk. This
229: * is an IDE's last opportunity to save files before the refactoring is
230: * performed. This is not used for ExtractMethod which works on code that is
231: * in memory (rather than on the disk)
232: */
233: protected void prepare() {
234: }
235:
236: /**
237: * This allows someone to replace this factory
238: *
239: *@param value The new Singleton value
240: */
241: public static void setSingleton(RefactoringFactory value) {
242: singleton = value;
243: }
244:
245: /**
246: * A standard method to get the factory
247: *
248: *@return Description of the Returned Value
249: */
250: public static RefactoringFactory get() {
251: if (singleton == null) {
252: init();
253: }
254: return singleton;
255: }
256:
257: /**
258: * Initializes the singleton
259: */
260: private static synchronized void init() {
261: if (singleton == null) {
262: singleton = new RefactoringFactory();
263: }
264: }
265: }
|