001: /* ====================================================================
002: * The JRefactory License, Version 1.0
003: *
004: * Copyright (c) 2001 JRefactory. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution,
019: * if any, must include the following acknowledgment:
020: * "This product includes software developed by the
021: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022: * Alternately, this acknowledgment may appear in the software itself,
023: * if and wherever such third-party acknowledgments normally appear.
024: *
025: * 4. The names "JRefactory" must not be used to endorse or promote
026: * products derived from this software without prior written
027: * permission. For written permission, please contact seguin@acm.org.
028: *
029: * 5. Products derived from this software may not be called "JRefactory",
030: * nor may "JRefactory" appear in their name, without prior written
031: * permission of Chris Seguin.
032: *
033: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
037: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044: * SUCH DAMAGE.
045: * ====================================================================
046: *
047: * This software consists of voluntary contributions made by many
048: * individuals on behalf of JRefactory. For more information on
049: * JRefactory, please see
050: * <http://www.sourceforge.org/projects/jrefactory>.
051: */
052: package org.acm.seguin.summary;
053:
054: import java.util.Iterator;
055:
056: /**
057: * Print all the summaries
058: *
059: *@author Chris Seguin
060: *@created May 15, 1999
061: */
062: public class PrintVisitor extends TraversalVisitor {
063: /**
064: * Visit a summary node. This is the default method.
065: *
066: *@param node the summary that we are visiting
067: *@param data the data that was passed in
068: *@return the result
069: */
070: public Object visit(Summary node, Object data) {
071: // Shouldn't have to do anything about one of these nodes
072: return data;
073: }
074:
075: /**
076: * Visit a package summary.
077: *
078: *@param node the summary that we are visiting
079: *@param data the data that was passed in
080: *@return the result
081: */
082: public Object visit(PackageSummary node, Object data) {
083: // Print the message
084: String indent = (String) data;
085: System.out.println(indent + "Package: " + node.getName());
086:
087: // Traverse the children
088: super .visit(node, indent + " ");
089:
090: // Doesn't change
091: return data;
092: }
093:
094: /**
095: * Visit a file summary.
096: *
097: *@param node the summary that we are visiting
098: *@param data the data that was passed in
099: *@return the result
100: */
101: public Object visit(FileSummary node, Object data) {
102: if (node.getFile() == null) {
103: return data;
104: }
105:
106: // Print the message
107: String indent = (String) data;
108: System.out.println(indent + "File: " + node.getName());
109:
110: // Traverse the children
111: super .visit(node, indent + " ");
112:
113: // Doesn't change
114: return data;
115: }
116:
117: /**
118: * Visit a import summary.
119: *
120: *@param node the summary that we are visiting
121: *@param data the data that was passed in
122: *@return the result
123: */
124: public Object visit(ImportSummary node, Object data) {
125: // Print the message
126: String indent = (String) data;
127: String type = node.getType();
128:
129: // Print what we have loaded
130: System.out.print(indent + "Import: "
131: + node.getPackage().getName());
132: if (type == null) {
133: System.out.println(" *");
134: } else {
135: System.out.println(" " + type);
136: }
137:
138: // Doesn't change
139: return data;
140: }
141:
142: /**
143: * Visit a type summary.
144: *
145: *@param node the summary that we are visiting
146: *@param data the data that was passed in
147: *@return the result
148: */
149: public Object visit(TypeSummary node, Object data) {
150: // Local Variables
151: String prefix;
152:
153: // Print the message
154: String indent = (String) data;
155: if (node.isInterface()) {
156: System.out
157: .println(indent + "Interface: " + node.getName());
158: prefix = indent + " Extends: ";
159: } else {
160: System.out.println(indent + "Class: " + node.getName());
161: Summary parentClass = node.getParentClass();
162: if (parentClass != null) {
163: System.out.println(indent + " Extends: "
164: + parentClass.toString());
165: }
166: prefix = indent + " Implements: ";
167: }
168:
169: // The iterator over interfaces
170: Iterator iter = node.getImplementedInterfaces();
171: if (iter != null) {
172: while (iter.hasNext()) {
173: TypeDeclSummary next = (TypeDeclSummary) iter.next();
174: System.out.println(prefix + next.toString());
175: }
176: }
177:
178: // Traverse the children
179: super .visit(node, indent + " ");
180:
181: // Doesn't change
182: return data;
183: }
184:
185: /**
186: * Visit a method summary.
187: *
188: *@param node the summary that we are visiting
189: *@param data the data that was passed in
190: *@return the result
191: */
192: public Object visit(MethodSummary node, Object data) {
193: // Local Variables
194: String prefix;
195:
196: // Print the message
197: String indent = (String) data;
198: System.out.println(indent + "Method: " + node.getName());
199: prefix = indent + " Depends: ";
200:
201: // The iterator over dependencies
202: Iterator iter = node.getDependencies();
203: if (iter != null) {
204: while (iter.hasNext()) {
205: Summary next = (Summary) iter.next();
206: System.out.println(prefix + next.toString());
207: }
208: }
209:
210: // Doesn't change
211: return data;
212: }
213:
214: /**
215: * Visit a field summary.
216: *
217: *@param node the summary that we are visiting
218: *@param data the data that was passed in
219: *@return the result
220: */
221: public Object visit(FieldSummary node, Object data) {
222: // Print the message
223: String indent = (String) data;
224: System.out.println(indent + "Field: " + node.getName());
225:
226: // Doesn't change
227: return data;
228: }
229:
230: /**
231: * Visit a parameter summary.
232: *
233: *@param node the summary that we are visiting
234: *@param data the data that was passed in
235: *@return the result
236: */
237: public Object visit(ParameterSummary node, Object data) {
238: return data;
239: }
240:
241: /**
242: * Visit a local variable summary.
243: *
244: *@param node the summary that we are visiting
245: *@param data the data that was passed in
246: *@return the result
247: */
248: public Object visit(LocalVariableSummary node, Object data) {
249: return data;
250: }
251:
252: /**
253: * Visit a variable summary.
254: *
255: *@param node the summary that we are visiting
256: *@param data the data that was passed in
257: *@return the result
258: */
259: public Object visit(VariableSummary node, Object data) {
260: return data;
261: }
262:
263: /**
264: * Visit a type declaration summary.
265: *
266: *@param node the summary that we are visiting
267: *@param data the data that was passed in
268: *@return the result
269: */
270: public Object visit(TypeDeclSummary node, Object data) {
271: return data;
272: }
273:
274: /**
275: * Visit a message send summary.
276: *
277: *@param node the summary that we are visiting
278: *@param data the data that was passed in
279: *@return the result
280: */
281: public Object visit(MessageSendSummary node, Object data) {
282: return data;
283: }
284:
285: /**
286: * Visit a field access summary.
287: *
288: *@param node the summary that we are visiting
289: *@param data the data that was passed in
290: *@return the result
291: */
292: public Object visit(FieldAccessSummary node, Object data) {
293: return data;
294: }
295: }
|