01: /*
02: * Author: Chris Seguin
03: *
04: * This software has been developed under the copyleft
05: * rules of the GNU General Public License. Please
06: * consult the GNU General Public License for more
07: * details about use and distribution of this software.
08: */
09: package org.acm.seguin.refactor.method;
10:
11: import net.sourceforge.jrefactory.ast.ModifierHolder;
12: import org.acm.seguin.refactor.ComplexTransform;
13: import org.acm.seguin.summary.FileSummary;
14: import org.acm.seguin.summary.TypeDeclSummary;
15: import org.acm.seguin.summary.TypeSummary;
16: import org.acm.seguin.summary.query.GetTypeSummary;
17:
18: /**
19: * Pushes up the signature of an abstract method into the parent class
20: *
21: *@author Chris Seguin
22: */
23: public class PushUpAbstractMethodRefactoring extends
24: PushUpMethodRefactoring {
25: /**
26: * Constructor for the PushUpAbstractMethodRefactoring object
27: */
28: protected PushUpAbstractMethodRefactoring() {
29: }
30:
31: /**
32: * Gets the ID attribute of the PushUpAbstractMethodRefactoring object
33: *
34: *@return The ID value
35: */
36: public int getID() {
37: return PUSH_UP_ABSTRACT_METHOD;
38: }
39:
40: /**
41: * Moves the method to the parent class
42: */
43: protected void transform() {
44: ComplexTransform transform = getComplexTransform();
45: FileSummary fileSummary;
46: TypeSummary typeSummary = (TypeSummary) methodSummary
47: .getParent();
48:
49: //ModifierHolder holder = methodSummary.getModifiers();
50: if (!(methodSummary.isPublic() || methodSummary.isProtected())) {
51: transform.add(new ChangeMethodScopeTransform(methodSummary,
52: ChangeMethodScopeVisitor.PROTECTED));
53: fileSummary = (FileSummary) typeSummary.getParent();
54: transform.apply(fileSummary.getFile(), fileSummary
55: .getFile());
56: transform.clear();
57: }
58:
59: TypeDeclSummary parentDecl = typeSummary.getParentClass();
60: TypeSummary parentSummary = GetTypeSummary.query(parentDecl);
61: transform.add(new AddAbstractMethod(methodSummary));
62:
63: AddMethodTypeVisitor visitor = new AddMethodTypeVisitor(false);
64: methodSummary.accept(visitor, transform);
65:
66: fileSummary = (FileSummary) parentSummary.getParent();
67: transform.apply(fileSummary.getFile(), fileSummary.getFile());
68: }
69: }
|