001: package org.acm.seguin.refactor.method;
002:
003: import org.acm.seguin.refactor.Refactoring;
004: import org.acm.seguin.summary.MethodSummary;
005: import org.acm.seguin.summary.TypeSummary;
006: import org.acm.seguin.refactor.RefactoringException;
007: import net.sourceforge.jrefactory.ast.ModifierHolder;
008: import org.acm.seguin.refactor.RefactoringException;
009: import org.acm.seguin.summary.query.SameMethod;
010: import net.sourceforge.jrefactory.ast.ASTMethodDeclaration;
011: import net.sourceforge.jrefactory.ast.SimpleNode;
012: import net.sourceforge.jrefactory.ast.ASTMethodDeclaration;
013: import org.acm.seguin.refactor.ComplexTransform;
014: import org.acm.seguin.summary.FileSummary;
015:
016: /**
017: * Moves a method between levels in the inheretence hierarchy
018: *
019: *@author Chris Seguin
020: */
021: abstract class InheretenceMethodRefactoring extends MethodRefactoring {
022: /**
023: * the method that is being moved around
024: */
025: protected MethodSummary methodSummary = null;
026:
027: /**
028: * Sets the Method attribute of the PushUpMethodRefactoring object
029: *
030: *@param value The new Method value
031: */
032: public void setMethod(MethodSummary value) {
033: methodSummary = value;
034: }
035:
036: /**
037: * Description of the Method
038: *
039: *@param dest Description of Parameter
040: *@exception RefactoringException Description of Exception
041: */
042: protected void checkDestination(TypeSummary dest)
043: throws RefactoringException {
044: MethodSummary alternate = SameMethod.find(dest, methodSummary);
045: if (alternate != null) {
046: //ModifierHolder holder = alternate.getModifiers();
047: if (!alternate.isAbstract()) {
048: throw new RefactoringException(
049: "A method with the same signature (name and parameter types) already exists in the "
050: + dest.getName() + " class");
051: }
052: } else if (SameMethod.findConflict(dest, methodSummary) != null) {
053: throw new RefactoringException(
054: "A method with the conflicting signature (name and parameter types) already exists in the "
055: + dest.getName() + " class");
056: }
057: }
058:
059: /**
060: * Description of the Method
061: *
062: *@param methodDecl Description of Parameter
063: *@return Description of the Returned Value
064: */
065: protected ASTMethodDeclaration updateMethod(SimpleNode methodDecl) {
066: ASTMethodDeclaration decl = (ASTMethodDeclaration) methodDecl
067: .jjtGetFirstChild();
068: //ModifierHolder holder = decl.getModifiers();
069: if (!decl.isPublic()) {
070: decl.setPrivate(false);
071: decl.setProtected(true);
072: }
073: return decl;
074: }
075:
076: /**
077: * Adds the method to the destination class
078: *
079: *@param transform The feature to be added to the MethodToDest attribute
080: *@param rft The feature to be added to the MethodToDest attribute
081: *@param methodDecl The feature to be added to the MethodToDest attribute
082: *@param dest The feature to be added to the MethodToDest attribute
083: */
084: protected void addMethodToDest(ComplexTransform transform,
085: RemoveMethodTransform rft, SimpleNode methodDecl,
086: TypeSummary dest) {
087: transform.clear();
088: transform.add(rft);
089: AddMethodTransform aft = new AddMethodTransform(methodDecl);
090: transform.add(aft);
091:
092: AddMethodTypeVisitor visitor = new AddMethodTypeVisitor();
093: methodSummary.accept(visitor, transform);
094:
095: // Add appropriate import statements - to be determined later
096: FileSummary parentFileSummary = (FileSummary) dest.getParent();
097: transform.apply(parentFileSummary.getFile(), parentFileSummary
098: .getFile());
099: }
100: }
|