01: package org.acm.seguin.refactor.method;
02:
03: import java.util.Iterator;
04: import java.util.LinkedList;
05: import org.acm.seguin.summary.*;
06:
07: /**
08: * This class contains a static method to determine if the method in question
09: * makes any references to the local object
10: *
11: *@author Chris Seguin
12: */
13: class ObjectReference {
14: /**
15: * Determines if this object is referenced
16: *
17: *@param methodSummary the method summary
18: *@return true if the object is referenced
19: */
20: public static boolean isReferenced(MethodSummary methodSummary) {
21: LinkedList locals = new LinkedList();
22: Iterator iter = methodSummary.getDependencies();
23: if (iter != null) {
24: while (iter.hasNext()) {
25: Summary next = (Summary) iter.next();
26: if (next instanceof LocalVariableSummary) {
27: locals.add(next.getName());
28: } else if (next instanceof FieldAccessSummary) {
29: FieldAccessSummary fas = (FieldAccessSummary) next;
30: if ((fas.getPackageName() == null)
31: && (fas.getObjectName() == null)
32: && (!locals.contains(fas.getFieldName()))) {
33: return true;
34: }
35: } else if (next instanceof MessageSendSummary) {
36: MessageSendSummary mss = (MessageSendSummary) next;
37: if ((mss.getPackageName() == null)
38: && ((mss.getObjectName() == null) || (mss
39: .getObjectName().equals("this")))) {
40: return true;
41: }
42: }
43: }
44: }
45: return false;
46: }
47: }
|