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.method;
010:
011: import net.sourceforge.jrefactory.ast.ASTMethodDeclaration;
012: import net.sourceforge.jrefactory.ast.ASTNestedClassDeclaration;
013: import net.sourceforge.jrefactory.ast.ASTNestedInterfaceDeclaration;
014: import net.sourceforge.jrefactory.ast.ModifierHolder;
015: import org.acm.seguin.summary.MethodSummary;
016:
017: /**
018: * Changes the scope of the method (from private to protected, etc.)
019: *
020: *@author Chris Seguin
021: */
022: class ChangeMethodScopeVisitor extends IdentifyMethodVisitor {
023: private int changeTo;
024:
025: final static int PRIVATE = 1;
026: final static int PACKAGE = 2;
027: final static int PROTECTED = 3;
028: final static int PUBLIC = 4;
029:
030: /**
031: * Constructor for the ChangeMethodScopeVisitor object
032: *
033: *@param init Description of Parameter
034: *@param newScope Description of Parameter
035: */
036: public ChangeMethodScopeVisitor(MethodSummary init, int newScope) {
037: super (init);
038: changeTo = newScope;
039: }
040:
041: /**
042: * Visit a class body
043: *
044: *@param node the class body node
045: *@param data the data for the visitor
046: *@return the method if it is found
047: */
048: public Object visit(ASTMethodDeclaration node, Object data) {
049: if (isFound(node)) {
050: changeScope(node);
051: }
052: return null;
053: }
054:
055: /**
056: * Skip nested classes
057: *
058: *@param node the nested class
059: *@param data the data for the visitor
060: *@return the method if it is found
061: */
062: public Object visit(ASTNestedClassDeclaration node, Object data) {
063: return null;
064: }
065:
066: /**
067: * Skip nested interfaces
068: *
069: *@param node the nested interface
070: *@param data the data for the visitor
071: *@return the method if it is found
072: */
073: public Object visit(ASTNestedInterfaceDeclaration node, Object data) {
074: return null;
075: }
076:
077: /**
078: * Changes the scope on a method declaration
079: *
080: *@param decl the declaration to change scope on
081: */
082: private void changeScope(ASTMethodDeclaration decl) {
083: //ModifierHolder holder = decl.getModifiers();
084:
085: switch (changeTo) {
086: case PUBLIC:
087: decl.setPrivate(false);
088: decl.setProtected(false);
089: decl.setPublic(true);
090: break;
091: case PROTECTED:
092: decl.setPrivate(false);
093: decl.setProtected(true);
094: decl.setPublic(false);
095: break;
096: case PACKAGE:
097: decl.setPrivate(false);
098: decl.setProtected(false);
099: decl.setPublic(false);
100: break;
101: case PRIVATE:
102: decl.setPrivate(true);
103: decl.setProtected(false);
104: decl.setPublic(false);
105: break;
106: }
107: }
108: }
|