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 org.acm.seguin.refactor.ComplexTransform;
012: import org.acm.seguin.summary.MethodSummary;
013: import org.acm.seguin.summary.PackageSummary;
014: import org.acm.seguin.summary.Summary;
015: import org.acm.seguin.summary.TypeSummary;
016: import org.acm.seguin.summary.query.Ancestor;
017:
018: /**
019: * Object used to store the state of the rename method visitor
020: *
021: * @author Mike Atkinson
022: * @since 2.9.11
023: */
024: class RenameMethodData {
025: private String oldName;
026: private String newName;
027: private boolean this Required;
028: private Summary current;
029: private boolean mustInsertThis;
030: private TypeSummary typeSummary;
031: private boolean canBeFirst;
032: private boolean canBeThis;
033: private MethodSummary oldMethod;
034: private ComplexTransform transform;
035: private String fullName;
036: private String importedName;
037:
038: /**
039: * Constructor for the RenameFieldData object
040: *
041: *@param newName the new field name
042: *@param oldField Description of Parameter
043: */
044: public RenameMethodData(MethodSummary oldMethod, String newName) {
045: this .oldName = oldMethod.getName();
046: this .newName = newName;
047: this .oldMethod = oldMethod;
048: this Required = false;
049: canBeFirst = false;
050: canBeThis = false;
051: mustInsertThis = false;
052: current = null;
053: typeSummary = (TypeSummary) oldMethod.getParent();
054: initNames(oldMethod);
055: }
056:
057: /**
058: * Constructor for the RenameFieldData object
059: *
060: *@param newName the new field name
061: *@param oldField Description of Parameter
062: *@param transform Description of Parameter
063: */
064: public RenameMethodData(MethodSummary oldMethod, String newName,
065: ComplexTransform transform) {
066: this .newName = newName;
067: this .oldMethod = oldMethod;
068: this .transform = transform;
069: oldName = oldMethod.getName();
070: typeSummary = (TypeSummary) oldMethod.getParent();
071: }
072:
073: /**
074: * Sets the ThisRequired attribute of the RenameFieldData object
075: *
076: *@param way The new ThisRequired value
077: */
078: public void setThisRequired(boolean way) {
079: this Required = way;
080: }
081:
082: /**
083: * Sets the CurrentSummary attribute of the RenameFieldData object
084: *
085: *@param value The new CurrentSummary value
086: */
087: public void setCurrentSummary(Summary value) {
088: current = value;
089: if (current instanceof TypeSummary) {
090: check((TypeSummary) current);
091: }
092: }
093:
094: /**
095: * Sets the MustInsertThis attribute of the RenameFieldData object
096: *
097: *@param value The new MustInsertThis value
098: */
099: public void setMustInsertThis(boolean value) {
100: mustInsertThis = value;
101: }
102:
103: /**
104: * Gets the OldName attribute of the RenameFieldData object
105: *
106: *@return The OldName value
107: */
108: public String getOldName() {
109: return oldName;
110: }
111:
112: /**
113: * Gets the NewName attribute of the RenameFieldData object
114: *
115: *@return The NewName value
116: */
117: public String getNewName() {
118: return newName;
119: }
120:
121: /**
122: * Gets the ThisRequired attribute of the RenameFieldData object
123: *
124: *@return The ThisRequired value
125: */
126: public boolean isThisRequired() {
127: return this Required;
128: }
129:
130: /**
131: * Gets the CurrentSummary attribute of the RenameFieldData object
132: *
133: *@return The CurrentSummary value
134: */
135: public Summary getCurrentSummary() {
136: return current;
137: }
138:
139: /**
140: * Gets the MustInsertThis attribute of the RenameFieldData object
141: *
142: *@return The MustInsertThis value
143: */
144: public boolean isMustInsertThis() {
145: return mustInsertThis;
146: }
147:
148: /**
149: * Returns the type summary where the field is changing
150: *
151: *@return The TypeSummary value
152: */
153: public TypeSummary getTypeSummary() {
154: return typeSummary;
155: }
156:
157: /**
158: * Gets the AllowedToChangeFirst attribute of the RenameFieldData object
159: *
160: *@return The AllowedToChangeFirst value
161: */
162: public boolean isAllowedToChangeFirst() {
163: return canBeFirst;
164: }
165:
166: /**
167: * Gets the AllowedToChangeThis attribute of the RenameFieldData object
168: *
169: *@return The AllowedToChangeThis value
170: */
171: public boolean isAllowedToChangeThis() {
172: return canBeThis;
173: }
174:
175: /**
176: * Gets the OldField attribute of the RenameFieldData object
177: *
178: *@return The OldField value
179: */
180: public MethodSummary getOldMethod() {
181: return oldMethod;
182: }
183:
184: /**
185: * Gets the ComplexTransform attribute of the RenameFieldData object
186: *
187: *@return The ComplexTransform value
188: */
189: public ComplexTransform getComplexTransform() {
190: return transform;
191: }
192:
193: /**
194: * Gets the FullName attribute of the RenameFieldData object
195: *
196: *@return The FullName value
197: */
198: public String getFullName() {
199: return fullName;
200: }
201:
202: /**
203: * Gets the ImportedName attribute of the RenameFieldData object
204: *
205: *@return The ImportedName value
206: */
207: public String getImportedName() {
208: return importedName;
209: }
210:
211: /**
212: * Returns true if the system can change the first name in an array
213: *
214: *@param current the type summary in question
215: */
216: private void check(TypeSummary current) {
217: if ((current == typeSummary)
218: || Ancestor.query(current, typeSummary)) {
219: canBeFirst = true;
220: canBeThis = true;
221: return;
222: }
223:
224: Summary cs = current;
225: while (cs != null) {
226: if (cs == typeSummary) {
227: canBeThis = false;
228: canBeFirst = true;
229: return;
230: }
231:
232: cs = cs.getParent();
233: }
234:
235: canBeThis = false;
236: canBeFirst = false;
237: }
238:
239: /**
240: * Initialize the names
241: *
242: *@param field the field summary
243: */
244: private void initNames(MethodSummary method) {
245: StringBuffer buffer = new StringBuffer(method.getName());
246:
247: Summary current = method;
248: while (current != null) {
249: if (current instanceof TypeSummary) {
250: buffer.insert(0, ".");
251: buffer.insert(0, current.getName());
252: }
253:
254: if (current instanceof PackageSummary) {
255: importedName = buffer.toString();
256: buffer.insert(0, ".");
257: buffer.insert(0, current.getName());
258: fullName = buffer.toString();
259: return;
260: }
261:
262: current = current.getParent();
263: }
264:
265: // We should never get here
266: importedName = buffer.toString();
267: fullName = buffer.toString();
268: }
269: }
|