KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > dom > ASTFlattener


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.corext.dom;
12
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.runtime.Assert;
17
18 import org.eclipse.jdt.core.dom.*;
19
20
21 public class ASTFlattener extends GenericVisitor {
22
23     /**
24      * The string buffer into which the serialized representation of the AST is
25      * written.
26      */

27     protected StringBuffer JavaDoc fBuffer;
28
29     /**
30      * Creates a new AST printer.
31      */

32     public ASTFlattener() {
33         this.fBuffer= new StringBuffer JavaDoc();
34     }
35
36     /**
37      * Returns the string accumulated in the visit.
38      *
39      * @return the serialized
40      */

41     public String JavaDoc getResult() {
42         return this.fBuffer.toString();
43     }
44
45     /**
46      * Resets this printer so that it can be used again.
47      */

48     public void reset() {
49         this.fBuffer.setLength(0);
50     }
51
52     public static String JavaDoc asString(ASTNode node) {
53         ASTFlattener flattener= new ASTFlattener();
54         node.accept(flattener);
55         return flattener.getResult();
56     }
57
58
59     protected boolean visitNode(ASTNode node) {
60         Assert.isTrue(false, "No implementation to flatten node: " + node.toString()); //$NON-NLS-1$
61
return false;
62     }
63     
64     /**
65      * Appends the text representation of the given modifier flags, followed by a single space.
66      * Used for 3.0 modifiers and annotations.
67      *
68      * @param ext the list of modifier and annotation nodes
69      * (element type: <code>IExtendedModifiers</code>)
70      */

71     private void printModifiers(List JavaDoc ext) {
72         for (Iterator JavaDoc it= ext.iterator(); it.hasNext();) {
73             ASTNode p= (ASTNode) it.next();
74             p.accept(this);
75             this.fBuffer.append(" ");//$NON-NLS-1$
76
}
77     }
78
79     /**
80      * Appends the text representation of the given modifier flags, followed by a single space.
81      * Used for JLS2 modifiers.
82      *
83      * @param modifiers the modifier flags
84      */

85     private void printModifiers(int modifiers) {
86         if (Modifier.isPublic(modifiers)) {
87             this.fBuffer.append("public ");//$NON-NLS-1$
88
}
89         if (Modifier.isProtected(modifiers)) {
90             this.fBuffer.append("protected ");//$NON-NLS-1$
91
}
92         if (Modifier.isPrivate(modifiers)) {
93             this.fBuffer.append("private ");//$NON-NLS-1$
94
}
95         if (Modifier.isStatic(modifiers)) {
96             this.fBuffer.append("static ");//$NON-NLS-1$
97
}
98         if (Modifier.isAbstract(modifiers)) {
99             this.fBuffer.append("abstract ");//$NON-NLS-1$
100
}
101         if (Modifier.isFinal(modifiers)) {
102             this.fBuffer.append("final ");//$NON-NLS-1$
103
}
104         if (Modifier.isSynchronized(modifiers)) {
105             this.fBuffer.append("synchronized ");//$NON-NLS-1$
106
}
107         if (Modifier.isVolatile(modifiers)) {
108             this.fBuffer.append("volatile ");//$NON-NLS-1$
109
}
110         if (Modifier.isNative(modifiers)) {
111             this.fBuffer.append("native ");//$NON-NLS-1$
112
}
113         if (Modifier.isStrictfp(modifiers)) {
114             this.fBuffer.append("strictfp ");//$NON-NLS-1$
115
}
116         if (Modifier.isTransient(modifiers)) {
117             this.fBuffer.append("transient ");//$NON-NLS-1$
118
}
119     }
120
121     /*
122      * @see ASTVisitor#visit(AnnotationTypeDeclaration)
123      * @since 3.0
124      */

125     public boolean visit(AnnotationTypeDeclaration node) {
126         if (node.getJavadoc() != null) {
127             node.getJavadoc().accept(this);
128         }
129         printModifiers(node.modifiers());
130         this.fBuffer.append("@interface ");//$NON-NLS-1$
131
node.getName().accept(this);
132         this.fBuffer.append(" {");//$NON-NLS-1$
133
for (Iterator JavaDoc it= node.bodyDeclarations().iterator(); it.hasNext();) {
134             BodyDeclaration d= (BodyDeclaration) it.next();
135             d.accept(this);
136         }
137         this.fBuffer.append("}");//$NON-NLS-1$
138
return false;
139     }
140
141     /*
142      * @see ASTVisitor#visit(AnnotationTypeMemberDeclaration)
143      * @since 3.0
144      */

145     public boolean visit(AnnotationTypeMemberDeclaration node) {
146         if (node.getJavadoc() != null) {
147             node.getJavadoc().accept(this);
148         }
149         printModifiers(node.modifiers());
150         node.getType().accept(this);
151         this.fBuffer.append(" ");//$NON-NLS-1$
152
node.getName().accept(this);
153         this.fBuffer.append("()");//$NON-NLS-1$
154
if (node.getDefault() != null) {
155             this.fBuffer.append(" default ");//$NON-NLS-1$
156
node.getDefault().accept(this);
157         }
158         this.fBuffer.append(";");//$NON-NLS-1$
159
return false;
160     }
161
162     /*
163      * @see ASTVisitor#visit(AnonymousClassDeclaration)
164      */

165     public boolean visit(AnonymousClassDeclaration node) {
166         this.fBuffer.append("{");//$NON-NLS-1$
167
for (Iterator JavaDoc it= node.bodyDeclarations().iterator(); it.hasNext();) {
168             BodyDeclaration b= (BodyDeclaration) it.next();
169             b.accept(this);
170         }
171         this.fBuffer.append("}");//$NON-NLS-1$
172
return false;
173     }
174
175     /*
176      * @see ASTVisitor#visit(ArrayAccess)
177      */

178     public boolean visit(ArrayAccess node) {
179         node.getArray().accept(this);
180         this.fBuffer.append("[");//$NON-NLS-1$
181
node.getIndex().accept(this);
182         this.fBuffer.append("]");//$NON-NLS-1$
183
return false;
184     }
185
186     /*
187      * @see ASTVisitor#visit(ArrayCreation)
188      */

189     public boolean visit(ArrayCreation node) {
190         this.fBuffer.append("new ");//$NON-NLS-1$
191
ArrayType at= node.getType();
192         int dims= at.getDimensions();
193         Type elementType= at.getElementType();
194         elementType.accept(this);
195         for (Iterator JavaDoc it= node.dimensions().iterator(); it.hasNext();) {
196             this.fBuffer.append("[");//$NON-NLS-1$
197
Expression e= (Expression) it.next();
198             e.accept(this);
199             this.fBuffer.append("]");//$NON-NLS-1$
200
dims--;
201         }
202         // add empty "[]" for each extra array dimension
203
for (int i= 0; i < dims; i++) {
204             this.fBuffer.append("[]");//$NON-NLS-1$
205
}
206         if (node.getInitializer() != null) {
207             node.getInitializer().accept(this);
208         }
209         return false;
210     }
211
212     /*
213      * @see ASTVisitor#visit(ArrayInitializer)
214      */

215     public boolean visit(ArrayInitializer node) {
216         this.fBuffer.append("{");//$NON-NLS-1$
217
for (Iterator JavaDoc it= node.expressions().iterator(); it.hasNext();) {
218             Expression e= (Expression) it.next();
219             e.accept(this);
220             if (it.hasNext()) {
221                 this.fBuffer.append(",");//$NON-NLS-1$
222
}
223         }
224         this.fBuffer.append("}");//$NON-NLS-1$
225
return false;
226     }
227
228     /*
229      * @see ASTVisitor#visit(ArrayType)
230      */

231     public boolean visit(ArrayType node) {
232         node.getComponentType().accept(this);
233         this.fBuffer.append("[]");//$NON-NLS-1$
234
return false;
235     }
236
237     /*
238      * @see ASTVisitor#visit(AssertStatement)
239      */

240     public boolean visit(AssertStatement node) {
241         this.fBuffer.append("assert ");//$NON-NLS-1$
242
node.getExpression().accept(this);
243         if (node.getMessage() != null) {
244             this.fBuffer.append(" : ");//$NON-NLS-1$
245
node.getMessage().accept(this);
246         }
247         this.fBuffer.append(";");//$NON-NLS-1$
248
return false;
249     }
250
251     /*
252      * @see ASTVisitor#visit(Assignment)
253      */

254     public boolean visit(Assignment node) {
255         node.getLeftHandSide().accept(this);
256         this.fBuffer.append(node.getOperator().toString());
257         node.getRightHandSide().accept(this);
258         return false;
259     }
260
261     /*
262      * @see ASTVisitor#visit(Block)
263      */

264     public boolean visit(Block node) {
265         this.fBuffer.append("{");//$NON-NLS-1$
266
for (Iterator JavaDoc it= node.statements().iterator(); it.hasNext();) {
267             Statement s= (Statement) it.next();
268             s.accept(this);
269         }
270         this.fBuffer.append("}");//$NON-NLS-1$
271
return false;
272     }
273
274     /*
275      * @see ASTVisitor#visit(BlockComment)
276      * @since 3.0
277      */

278     public boolean visit(BlockComment node) {
279         this.fBuffer.append("/* */");//$NON-NLS-1$
280
return false;
281     }
282
283     /*
284      * @see ASTVisitor#visit(BooleanLiteral)
285      */

286     public boolean visit(BooleanLiteral node) {
287         if (node.booleanValue() == true) {
288             this.fBuffer.append("true");//$NON-NLS-1$
289
} else {
290             this.fBuffer.append("false");//$NON-NLS-1$
291
}
292         return false;
293     }
294
295     /*
296      * @see ASTVisitor#visit(BreakStatement)
297      */

298     public boolean visit(BreakStatement node) {
299         this.fBuffer.append("break");//$NON-NLS-1$
300
if (node.getLabel() != null) {
301             this.fBuffer.append(" ");//$NON-NLS-1$
302
node.getLabel().accept(this);
303         }
304         this.fBuffer.append(";");//$NON-NLS-1$
305
return false;
306     }
307
308     /*
309      * @see ASTVisitor#visit(CastExpression)
310      */

311     public boolean visit(CastExpression node) {
312         this.fBuffer.append("(");//$NON-NLS-1$
313
node.getType().accept(this);
314         this.fBuffer.append(")");//$NON-NLS-1$
315
node.getExpression().accept(this);
316         return false;
317     }
318
319     /*
320      * @see ASTVisitor#visit(CatchClause)
321      */

322     public boolean visit(CatchClause node) {
323         this.fBuffer.append("catch (");//$NON-NLS-1$
324
node.getException().accept(this);
325         this.fBuffer.append(") ");//$NON-NLS-1$
326
node.getBody().accept(this);
327         return false;
328     }
329
330     /*
331      * @see ASTVisitor#visit(CharacterLiteral)
332      */

333     public boolean visit(CharacterLiteral node) {
334         this.fBuffer.append(node.getEscapedValue());
335         return false;
336     }
337
338     /*
339      * @see ASTVisitor#visit(ClassInstanceCreation)
340      */

341     public boolean visit(ClassInstanceCreation node) {
342         if (node.getExpression() != null) {
343             node.getExpression().accept(this);
344             this.fBuffer.append(".");//$NON-NLS-1$
345
}
346         this.fBuffer.append("new ");//$NON-NLS-1$
347
if (node.getAST().apiLevel() == AST.JLS2) {
348             node.getName().accept(this);
349         }
350         if (node.getAST().apiLevel() >= AST.JLS3) {
351             if (!node.typeArguments().isEmpty()) {
352                 this.fBuffer.append("<");//$NON-NLS-1$
353
for (Iterator JavaDoc it= node.typeArguments().iterator(); it.hasNext();) {
354                     Type t= (Type) it.next();
355                     t.accept(this);
356                     if (it.hasNext()) {
357                         this.fBuffer.append(",");//$NON-NLS-1$
358
}
359                 }
360                 this.fBuffer.append(">");//$NON-NLS-1$
361
}
362             node.getType().accept(this);
363         }
364         this.fBuffer.append("(");//$NON-NLS-1$
365
for (Iterator JavaDoc it= node.arguments().iterator(); it.hasNext();) {
366             Expression e= (Expression) it.next();
367             e.accept(this);
368             if (it.hasNext()) {
369                 this.fBuffer.append(",");//$NON-NLS-1$
370
}
371         }
372         this.fBuffer.append(")");//$NON-NLS-1$
373
if (node.getAnonymousClassDeclaration() != null) {
374             node.getAnonymousClassDeclaration().accept(this);
375         }
376         return false;
377     }
378
379     /*
380      * @see ASTVisitor#visit(CompilationUnit)
381      */

382     public boolean visit(CompilationUnit node) {
383         if (node.getPackage() != null) {
384             node.getPackage().accept(this);
385         }
386         for (Iterator JavaDoc it= node.imports().iterator(); it.hasNext();) {
387             ImportDeclaration d= (ImportDeclaration) it.next();
388             d.accept(this);
389         }
390         for (Iterator JavaDoc it= node.types().iterator(); it.hasNext();) {
391             AbstractTypeDeclaration d= (AbstractTypeDeclaration) it.next();
392             d.accept(this);
393         }
394         return false;
395     }
396
397     /*
398      * @see ASTVisitor#visit(ConditionalExpression)
399      */

400     public boolean visit(ConditionalExpression node) {
401         node.getExpression().accept(this);
402         this.fBuffer.append("?");//$NON-NLS-1$
403
node.getThenExpression().accept(this);
404         this.fBuffer.append(":");//$NON-NLS-1$
405
node.getElseExpression().accept(this);
406         return false;
407     }
408
409     /*
410      * @see ASTVisitor#visit(ConstructorInvocation)
411      */

412     public boolean visit(ConstructorInvocation node) {
413         if (node.getAST().apiLevel() >= AST.JLS3) {
414             if (!node.typeArguments().isEmpty()) {
415                 this.fBuffer.append("<");//$NON-NLS-1$
416
for (Iterator JavaDoc it= node.typeArguments().iterator(); it.hasNext();) {
417                     Type t= (Type) it.next();
418                     t.accept(this);
419                     if (it.hasNext()) {
420                         this.fBuffer.append(",");//$NON-NLS-1$
421
}
422                 }
423                 this.fBuffer.append(">");//$NON-NLS-1$
424
}
425         }
426         this.fBuffer.append("this(");//$NON-NLS-1$
427
for (Iterator JavaDoc it= node.arguments().iterator(); it.hasNext();) {
428             Expression e= (Expression) it.next();
429             e.accept(this);
430             if (it.hasNext()) {
431                 this.fBuffer.append(",");//$NON-NLS-1$
432
}
433         }
434         this.fBuffer.append(");");//$NON-NLS-1$
435
return false;
436     }
437
438     /*
439      * @see ASTVisitor#visit(ContinueStatement)
440      */

441     public boolean visit(ContinueStatement node) {
442         this.fBuffer.append("continue");//$NON-NLS-1$
443
if (node.getLabel() != null) {
444             this.fBuffer.append(" ");//$NON-NLS-1$
445
node.getLabel().accept(this);
446         }
447         this.fBuffer.append(";");//$NON-NLS-1$
448
return false;
449     }
450
451     /*
452      * @see ASTVisitor#visit(DoStatement)
453      */

454     public boolean visit(DoStatement node) {
455         this.fBuffer.append("do ");//$NON-NLS-1$
456
node.getBody().accept(this);
457         this.fBuffer.append(" while (");//$NON-NLS-1$
458
node.getExpression().accept(this);
459         this.fBuffer.append(");");//$NON-NLS-1$
460
return false;
461     }
462
463     /*
464      * @see ASTVisitor#visit(EmptyStatement)
465      */

466     public boolean visit(EmptyStatement node) {
467         this.fBuffer.append(";");//$NON-NLS-1$
468
return false;
469     }
470
471     /*
472      * @see ASTVisitor#visit(EnhancedForStatement)
473      * @since 3.0
474      */

475     public boolean visit(EnhancedForStatement node) {
476         this.fBuffer.append("for (");//$NON-NLS-1$
477
node.getParameter().accept(this);
478         this.fBuffer.append(" : ");//$NON-NLS-1$
479
node.getExpression().accept(this);
480         this.fBuffer.append(") ");//$NON-NLS-1$
481
node.getBody().accept(this);
482         return false;
483     }
484
485     /*
486      * @see ASTVisitor#visit(EnumConstantDeclaration)
487      * @since 3.0
488      */

489     public boolean visit(EnumConstantDeclaration node) {
490         if (node.getJavadoc() != null) {
491             node.getJavadoc().accept(this);
492         }
493         printModifiers(node.modifiers());
494         node.getName().accept(this);
495         if (!node.arguments().isEmpty()) {
496             this.fBuffer.append("(");//$NON-NLS-1$
497
for (Iterator JavaDoc it= node.arguments().iterator(); it.hasNext();) {
498                 Expression e= (Expression) it.next();
499                 e.accept(this);
500                 if (it.hasNext()) {
501                     this.fBuffer.append(",");//$NON-NLS-1$
502
}
503             }
504             this.fBuffer.append(")");//$NON-NLS-1$
505
}
506         if (node.getAnonymousClassDeclaration() != null) {
507             node.getAnonymousClassDeclaration().accept(this);
508         }
509         return false;
510     }
511
512     /*
513      * @see ASTVisitor#visit(EnumDeclaration)
514      * @since 3.0
515      */

516     public boolean visit(EnumDeclaration node) {
517         if (node.getJavadoc() != null) {
518             node.getJavadoc().accept(this);
519         }
520         printModifiers(node.modifiers());
521         this.fBuffer.append("enum ");//$NON-NLS-1$
522
node.getName().accept(this);
523         this.fBuffer.append(" ");//$NON-NLS-1$
524
if (!node.superInterfaceTypes().isEmpty()) {
525             this.fBuffer.append("implements ");//$NON-NLS-1$
526
for (Iterator JavaDoc it= node.superInterfaceTypes().iterator(); it.hasNext();) {
527                 Type t= (Type) it.next();
528                 t.accept(this);
529                 if (it.hasNext()) {
530                     this.fBuffer.append(", ");//$NON-NLS-1$
531
}
532             }
533             this.fBuffer.append(" ");//$NON-NLS-1$
534
}
535         this.fBuffer.append("{");//$NON-NLS-1$
536
for (Iterator JavaDoc it = node.enumConstants().iterator(); it.hasNext(); ) {
537             EnumConstantDeclaration d = (EnumConstantDeclaration) it.next();
538             d.accept(this);
539             // enum constant declarations do not include punctuation
540
if (it.hasNext()) {
541                 // enum constant declarations are separated by commas
542
this.fBuffer.append(", ");//$NON-NLS-1$
543
}
544         }
545         if (!node.bodyDeclarations().isEmpty()) {
546             this.fBuffer.append("; ");//$NON-NLS-1$
547
for (Iterator JavaDoc it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
548                 BodyDeclaration d = (BodyDeclaration) it.next();
549                 d.accept(this);
550                 // other body declarations include trailing punctuation
551
}
552         }
553         this.fBuffer.append("}");//$NON-NLS-1$
554
return false;
555     }
556
557     /*
558      * @see ASTVisitor#visit(ExpressionStatement)
559      */

560     public boolean visit(ExpressionStatement node) {
561         node.getExpression().accept(this);
562         this.fBuffer.append(";");//$NON-NLS-1$
563
return false;
564     }
565
566     /*
567      * @see ASTVisitor#visit(FieldAccess)
568      */

569     public boolean visit(FieldAccess node) {
570         node.getExpression().accept(this);
571         this.fBuffer.append(".");//$NON-NLS-1$
572
node.getName().accept(this);
573         return false;
574     }
575
576     /*
577      * @see ASTVisitor#visit(FieldDeclaration)
578      */

579     public boolean visit(FieldDeclaration node) {
580         if (node.getJavadoc() != null) {
581             node.getJavadoc().accept(this);
582         }
583         if (node.getAST().apiLevel() == AST.JLS2) {
584             printModifiers(node.getModifiers());
585         }
586         if (node.getAST().apiLevel() >= AST.JLS3) {
587             printModifiers(node.modifiers());
588         }
589         node.getType().accept(this);
590         this.fBuffer.append(" ");//$NON-NLS-1$
591
for (Iterator JavaDoc it= node.fragments().iterator(); it.hasNext();) {
592             VariableDeclarationFragment f= (VariableDeclarationFragment) it.next();
593             f.accept(this);
594             if (it.hasNext()) {
595                 this.fBuffer.append(", ");//$NON-NLS-1$
596
}
597         }
598         this.fBuffer.append(";");//$NON-NLS-1$
599
return false;
600     }
601
602     /*
603      * @see ASTVisitor#visit(ForStatement)
604      */

605     public boolean visit(ForStatement node) {
606         this.fBuffer.append("for (");//$NON-NLS-1$
607
for (Iterator JavaDoc it= node.initializers().iterator(); it.hasNext();) {
608             Expression e= (Expression) it.next();
609             e.accept(this);
610         }
611         this.fBuffer.append("; ");//$NON-NLS-1$
612
if (node.getExpression() != null) {
613             node.getExpression().accept(this);
614         }
615         this.fBuffer.append("; ");//$NON-NLS-1$
616
for (Iterator JavaDoc it= node.updaters().iterator(); it.hasNext();) {
617             Expression e= (Expression) it.next();
618             e.accept(this);
619         }
620         this.fBuffer.append(") ");//$NON-NLS-1$
621
node.getBody().accept(this);
622         return false;
623     }
624
625     /*
626      * @see ASTVisitor#visit(IfStatement)
627      */

628     public boolean visit(IfStatement node) {
629         this.fBuffer.append("if (");//$NON-NLS-1$
630
node.getExpression().accept(this);
631         this.fBuffer.append(") ");//$NON-NLS-1$
632
node.getThenStatement().accept(this);
633         if (node.getElseStatement() != null) {
634             this.fBuffer.append(" else ");//$NON-NLS-1$
635
node.getElseStatement().accept(this);
636         }
637         return false;
638     }
639
640     /*
641      * @see ASTVisitor#visit(ImportDeclaration)
642      */

643     public boolean visit(ImportDeclaration node) {
644         this.fBuffer.append("import ");//$NON-NLS-1$
645
if (node.getAST().apiLevel() >= AST.JLS3) {
646             if (node.isStatic()) {
647                 this.fBuffer.append("static ");//$NON-NLS-1$
648
}
649         }
650         node.getName().accept(this);
651         if (node.isOnDemand()) {
652             this.fBuffer.append(".*");//$NON-NLS-1$
653
}
654         this.fBuffer.append(";");//$NON-NLS-1$
655
return false;
656     }
657
658     /*
659      * @see ASTVisitor#visit(InfixExpression)
660      */

661     public boolean visit(InfixExpression node) {
662         node.getLeftOperand().accept(this);
663         this.fBuffer.append(' '); // for cases like x= i - -1; or x= i++ + ++i;
664
this.fBuffer.append(node.getOperator().toString());
665         this.fBuffer.append(' ');
666         node.getRightOperand().accept(this);
667         final List JavaDoc extendedOperands = node.extendedOperands();
668         if (extendedOperands.size() != 0) {
669             this.fBuffer.append(' ');
670             for (Iterator JavaDoc it = extendedOperands.iterator(); it.hasNext(); ) {
671                 this.fBuffer.append(node.getOperator().toString()).append(' ');
672                 Expression e = (Expression) it.next();
673                 e.accept(this);
674             }
675         }
676         return false;
677     }
678
679     /*
680      * @see ASTVisitor#visit(InstanceofExpression)
681      */

682     public boolean visit(InstanceofExpression node) {
683         node.getLeftOperand().accept(this);
684         this.fBuffer.append(" instanceof ");//$NON-NLS-1$
685
node.getRightOperand().accept(this);
686         return false;
687     }
688
689     /*
690      * @see ASTVisitor#visit(Initializer)
691      */

692     public boolean visit(Initializer node) {
693         if (node.getJavadoc() != null) {
694             node.getJavadoc().accept(this);
695         }
696         if (node.getAST().apiLevel() == AST.JLS2) {
697             printModifiers(node.getModifiers());
698         }
699         if (node.getAST().apiLevel() >= AST.JLS3) {
700             printModifiers(node.modifiers());
701         }
702         node.getBody().accept(this);
703         return false;
704     }
705
706     /*
707      * @see ASTVisitor#visit(Javadoc)
708      */

709     public boolean visit(Javadoc node) {
710         this.fBuffer.append("/** ");//$NON-NLS-1$
711
for (Iterator JavaDoc it= node.tags().iterator(); it.hasNext();) {
712             ASTNode e= (ASTNode) it.next();
713             e.accept(this);
714         }
715         this.fBuffer.append("\n */");//$NON-NLS-1$
716
return false;
717     }
718
719     /*
720      * @see ASTVisitor#visit(LabeledStatement)
721      */

722     public boolean visit(LabeledStatement node) {
723         node.getLabel().accept(this);
724         this.fBuffer.append(": ");//$NON-NLS-1$
725
node.getBody().accept(this);
726         return false;
727     }
728
729     /*
730      * @see ASTVisitor#visit(LineComment)
731      * @since 3.0
732      */

733     public boolean visit(LineComment node) {
734         this.fBuffer.append("//\n");//$NON-NLS-1$
735
return false;
736     }
737
738     /*
739      * @see ASTVisitor#visit(MarkerAnnotation)
740      * @since 3.0
741      */

742     public boolean visit(MarkerAnnotation node) {
743         this.fBuffer.append("@");//$NON-NLS-1$
744
node.getTypeName().accept(this);
745         return false;
746     }
747
748     /*
749      * @see ASTVisitor#visit(MemberRef)
750      * @since 3.0
751      */

752     public boolean visit(MemberRef node) {
753         if (node.getQualifier() != null) {
754             node.getQualifier().accept(this);
755         }
756         this.fBuffer.append("#");//$NON-NLS-1$
757
node.getName().accept(this);
758         return false;
759     }
760
761     /*
762      * @see ASTVisitor#visit(MemberValuePair)
763      * @since 3.0
764      */

765     public boolean visit(MemberValuePair node) {
766         node.getName().accept(this);
767         this.fBuffer.append("=");//$NON-NLS-1$
768
node.getValue().accept(this);
769         return false;
770     }
771
772     /*
773      * @see ASTVisitor#visit(MethodRef)
774      * @since 3.0
775      */

776     public boolean visit(MethodRef node) {
777         if (node.getQualifier() != null) {
778             node.getQualifier().accept(this);
779         }
780         this.fBuffer.append("#");//$NON-NLS-1$
781
node.getName().accept(this);
782         this.fBuffer.append("(");//$NON-NLS-1$
783
for (Iterator JavaDoc it= node.parameters().iterator(); it.hasNext();) {
784             MethodRefParameter e= (MethodRefParameter) it.next();
785             e.accept(this);
786             if (it.hasNext()) {
787                 this.fBuffer.append(",");//$NON-NLS-1$
788
}
789         }
790         this.fBuffer.append(")");//$NON-NLS-1$
791
return false;
792     }
793
794     /*
795      * @see ASTVisitor#visit(MethodRefParameter)
796      * @since 3.0
797      */

798     public boolean visit(MethodRefParameter node) {
799         node.getType().accept(this);
800         if (node.getAST().apiLevel() >= AST.JLS3) {
801             if (node.isVarargs()) {
802                 this.fBuffer.append("...");//$NON-NLS-1$
803
}
804         }
805         if (node.getName() != null) {
806             this.fBuffer.append(" ");//$NON-NLS-1$
807
node.getName().accept(this);
808         }
809         return false;
810     }
811
812     /*
813      * @see ASTVisitor#visit(MethodDeclaration)
814      */

815     public boolean visit(MethodDeclaration node) {
816         if (node.getJavadoc() != null) {
817             node.getJavadoc().accept(this);
818         }
819         if (node.getAST().apiLevel() == AST.JLS2) {
820             printModifiers(node.getModifiers());
821         }
822         if (node.getAST().apiLevel() >= AST.JLS3) {
823             printModifiers(node.modifiers());
824             if (!node.typeParameters().isEmpty()) {
825                 this.fBuffer.append("<");//$NON-NLS-1$
826
for (Iterator JavaDoc it= node.typeParameters().iterator(); it.hasNext();) {
827                     TypeParameter t= (TypeParameter) it.next();
828                     t.accept(this);
829                     if (it.hasNext()) {
830                         this.fBuffer.append(",");//$NON-NLS-1$
831
}
832                 }
833                 this.fBuffer.append("> ");//$NON-NLS-1$
834
}
835         }
836         if (!node.isConstructor()) {
837             if (node.getAST().apiLevel() == AST.JLS2) {
838                 node.getReturnType().accept(this);
839             } else {
840                 if (node.getReturnType2() != null) {
841                     node.getReturnType2().accept(this);
842                 } else {
843                     // methods really ought to have a return type
844
this.fBuffer.append("void");//$NON-NLS-1$
845
}
846             }
847             this.fBuffer.append(" ");//$NON-NLS-1$
848
}
849         node.getName().accept(this);
850         this.fBuffer.append("(");//$NON-NLS-1$
851
for (Iterator JavaDoc it= node.parameters().iterator(); it.hasNext();) {
852             SingleVariableDeclaration v= (SingleVariableDeclaration) it.next();
853             v.accept(this);
854             if (it.hasNext()) {
855                 this.fBuffer.append(",");//$NON-NLS-1$
856
}
857         }
858         this.fBuffer.append(")");//$NON-NLS-1$
859
for (int i= 0; i < node.getExtraDimensions(); i++) {
860             this.fBuffer.append("[]"); //$NON-NLS-1$
861
}
862         if (!node.thrownExceptions().isEmpty()) {
863             this.fBuffer.append(" throws ");//$NON-NLS-1$
864
for (Iterator JavaDoc it= node.thrownExceptions().iterator(); it.hasNext();) {
865                 Name n= (Name) it.next();
866                 n.accept(this);
867                 if (it.hasNext()) {
868                     this.fBuffer.append(", ");//$NON-NLS-1$
869
}
870             }
871             this.fBuffer.append(" ");//$NON-NLS-1$
872
}
873         if (node.getBody() == null) {
874             this.fBuffer.append(";");//$NON-NLS-1$
875
} else {
876             node.getBody().accept(this);
877         }
878         return false;
879     }
880
881     /*
882      * @see ASTVisitor#visit(MethodInvocation)
883      */

884     public boolean visit(MethodInvocation node) {
885         if (node.getExpression() != null) {
886             node.getExpression().accept(this);
887             this.fBuffer.append(".");//$NON-NLS-1$
888
}
889         if (node.getAST().apiLevel() >= AST.JLS3) {
890             if (!node.typeArguments().isEmpty()) {
891                 this.fBuffer.append("<");//$NON-NLS-1$
892
for (Iterator JavaDoc it= node.typeArguments().iterator(); it.hasNext();) {
893                     Type t= (Type) it.next();
894                     t.accept(this);
895                     if (it.hasNext()) {
896                         this.fBuffer.append(",");//$NON-NLS-1$
897
}
898                 }
899                 this.fBuffer.append(">");//$NON-NLS-1$
900
}
901         }
902         node.getName().accept(this);
903         this.fBuffer.append("(");//$NON-NLS-1$
904
for (Iterator JavaDoc it= node.arguments().iterator(); it.hasNext();) {
905             Expression e= (Expression) it.next();
906             e.accept(this);
907             if (it.hasNext()) {
908                 this.fBuffer.append(",");//$NON-NLS-1$
909
}
910         }
911         this.fBuffer.append(")");//$NON-NLS-1$
912
return false;
913     }
914
915     /*
916      * @see ASTVisitor#visit(Modifier)
917      * @since 3.0
918      */

919     public boolean visit(Modifier node) {
920         this.fBuffer.append(node.getKeyword().toString());
921         return false;
922     }
923
924     /*
925      * @see ASTVisitor#visit(NormalAnnotation)
926      * @since 3.0
927      */

928     public boolean visit(NormalAnnotation node) {
929         this.fBuffer.append("@");//$NON-NLS-1$
930
node.getTypeName().accept(this);
931         this.fBuffer.append("(");//$NON-NLS-1$
932
for (Iterator JavaDoc it= node.values().iterator(); it.hasNext();) {
933             MemberValuePair p= (MemberValuePair) it.next();
934             p.accept(this);
935             if (it.hasNext()) {
936                 this.fBuffer.append(",");//$NON-NLS-1$
937
}
938         }
939         this.fBuffer.append(")");//$NON-NLS-1$
940
return false;
941     }
942
943     /*
944      * @see ASTVisitor#visit(NullLiteral)
945      */

946     public boolean visit(NullLiteral node) {
947         this.fBuffer.append("null");//$NON-NLS-1$
948
return false;
949     }
950
951     /*
952      * @see ASTVisitor#visit(NumberLiteral)
953      */

954     public boolean visit(NumberLiteral node) {
955         this.fBuffer.append(node.getToken());
956         return false;
957     }
958
959     /*
960      * @see ASTVisitor#visit(PackageDeclaration)
961      */

962     public boolean visit(PackageDeclaration node) {
963         if (node.getAST().apiLevel() >= AST.JLS3) {
964             if (node.getJavadoc() != null) {
965                 node.getJavadoc().accept(this);
966             }
967             for (Iterator JavaDoc it= node.annotations().iterator(); it.hasNext();) {
968                 Annotation p= (Annotation) it.next();
969                 p.accept(this);
970                 this.fBuffer.append(" ");//$NON-NLS-1$
971
}
972         }
973         this.fBuffer.append("package ");//$NON-NLS-1$
974
node.getName().accept(this);
975         this.fBuffer.append(";");//$NON-NLS-1$
976
return false;
977     }
978
979     /*
980      * @see ASTVisitor#visit(ParameterizedType)
981      * @since 3.0
982      */

983     public boolean visit(ParameterizedType node) {
984         node.getType().accept(this);
985         this.fBuffer.append("<");//$NON-NLS-1$
986
for (Iterator JavaDoc it= node.typeArguments().iterator(); it.hasNext();) {
987             Type t= (Type) it.next();
988             t.accept(this);
989             if (it.hasNext()) {
990                 this.fBuffer.append(",");//$NON-NLS-1$
991
}
992         }
993         this.fBuffer.append(">");//$NON-NLS-1$
994
return false;
995     }
996
997     /*
998      * @see ASTVisitor#visit(ParenthesizedExpression)
999      */

1000    public boolean visit(ParenthesizedExpression node) {
1001        this.fBuffer.append("(");//$NON-NLS-1$
1002
node.getExpression().accept(this);
1003        this.fBuffer.append(")");//$NON-NLS-1$
1004
return false;
1005    }
1006
1007    /*
1008     * @see ASTVisitor#visit(PostfixExpression)
1009     */

1010    public boolean visit(PostfixExpression node) {
1011        node.getOperand().accept(this);
1012        this.fBuffer.append(node.getOperator().toString());
1013        return false;
1014    }
1015
1016    /*
1017     * @see ASTVisitor#visit(PrefixExpression)
1018     */

1019    public boolean visit(PrefixExpression node) {
1020        this.fBuffer.append(node.getOperator().toString());
1021        node.getOperand().accept(this);
1022        return false;
1023    }
1024
1025    /*
1026     * @see ASTVisitor#visit(PrimitiveType)
1027     */

1028    public boolean visit(PrimitiveType node) {
1029        this.fBuffer.append(node.getPrimitiveTypeCode().toString());
1030        return false;
1031    }
1032
1033    /*
1034     * @see ASTVisitor#visit(QualifiedName)
1035     */

1036    public boolean visit(QualifiedName node) {
1037        node.getQualifier().accept(this);
1038        this.fBuffer.append(".");//$NON-NLS-1$
1039
node.getName().accept(this);
1040        return false;
1041    }
1042
1043    /*
1044     * @see ASTVisitor#visit(QualifiedType)
1045     * @since 3.0
1046     */

1047    public boolean visit(QualifiedType node) {
1048        node.getQualifier().accept(this);
1049        this.fBuffer.append(".");//$NON-NLS-1$
1050
node.getName().accept(this);
1051        return false;
1052    }
1053
1054    /*
1055     * @see ASTVisitor#visit(ReturnStatement)
1056     */

1057    public boolean visit(ReturnStatement node) {
1058        this.fBuffer.append("return");//$NON-NLS-1$
1059
if (node.getExpression() != null) {
1060            this.fBuffer.append(" ");//$NON-NLS-1$
1061
node.getExpression().accept(this);
1062        }
1063        this.fBuffer.append(";");//$NON-NLS-1$
1064
return false;
1065    }
1066
1067    /*
1068     * @see ASTVisitor#visit(SimpleName)
1069     */

1070    public boolean visit(SimpleName node) {
1071        this.fBuffer.append(node.getIdentifier());
1072        return false;
1073    }
1074
1075    /*
1076     * @see ASTVisitor#visit(SimpleType)
1077     */

1078    public boolean visit(SimpleType node) {
1079        return true;
1080    }
1081
1082    /*
1083     * @see ASTVisitor#visit(SingleMemberAnnotation)
1084     * @since 3.0
1085     */

1086    public boolean visit(SingleMemberAnnotation node) {
1087        this.fBuffer.append("@");//$NON-NLS-1$
1088
node.getTypeName().accept(this);
1089        this.fBuffer.append("(");//$NON-NLS-1$
1090
node.getValue().accept(this);
1091        this.fBuffer.append(")");//$NON-NLS-1$
1092
return false;
1093    }
1094
1095    /*
1096     * @see ASTVisitor#visit(SingleVariableDeclaration)
1097     */

1098    public boolean visit(SingleVariableDeclaration node) {
1099        if (node.getAST().apiLevel() == AST.JLS2) {
1100            printModifiers(node.getModifiers());
1101        }
1102        if (node.getAST().apiLevel() >= AST.JLS3) {
1103            printModifiers(node.modifiers());
1104        }
1105        node.getType().accept(this);
1106        if (node.getAST().apiLevel() >= AST.JLS3) {
1107            if (node.isVarargs()) {
1108                this.fBuffer.append("...");//$NON-NLS-1$
1109
}
1110        }
1111        this.fBuffer.append(" ");//$NON-NLS-1$
1112
node.getName().accept(this);
1113        for (int i= 0; i < node.getExtraDimensions(); i++) {
1114            this.fBuffer.append("[]"); //$NON-NLS-1$
1115
}
1116        if (node.getInitializer() != null) {
1117            this.fBuffer.append("=");//$NON-NLS-1$
1118
node.getInitializer().accept(this);
1119        }
1120        return false;
1121    }
1122
1123    /*
1124     * @see ASTVisitor#visit(StringLiteral)
1125     */

1126    public boolean visit(StringLiteral node) {
1127        this.fBuffer.append(node.getEscapedValue());
1128        return false;
1129    }
1130
1131    /*
1132     * @see ASTVisitor#visit(SuperConstructorInvocation)
1133     */

1134    public boolean visit(SuperConstructorInvocation node) {
1135        if (node.getExpression() != null) {
1136            node.getExpression().accept(this);
1137            this.fBuffer.append(".");//$NON-NLS-1$
1138
}
1139        if (node.getAST().apiLevel() >= AST.JLS3) {
1140            if (!node.typeArguments().isEmpty()) {
1141                this.fBuffer.append("<");//$NON-NLS-1$
1142
for (Iterator JavaDoc it= node.typeArguments().iterator(); it.hasNext();) {
1143                    Type t= (Type) it.next();
1144                    t.accept(this);
1145                    if (it.hasNext()) {
1146                        this.fBuffer.append(",");//$NON-NLS-1$
1147
}
1148                }
1149                this.fBuffer.append(">");//$NON-NLS-1$
1150
}
1151        }
1152        this.fBuffer.append("super(");//$NON-NLS-1$
1153
for (Iterator JavaDoc it= node.arguments().iterator(); it.hasNext();) {
1154            Expression e= (Expression) it.next();
1155            e.accept(this);
1156            if (it.hasNext()) {
1157                this.fBuffer.append(",");//$NON-NLS-1$
1158
}
1159        }
1160        this.fBuffer.append(");");//$NON-NLS-1$
1161
return false;
1162    }
1163
1164    /*
1165     * @see ASTVisitor#visit(SuperFieldAccess)
1166     */

1167    public boolean visit(SuperFieldAccess node) {
1168        if (node.getQualifier() != null) {
1169            node.getQualifier().accept(this);
1170            this.fBuffer.append(".");//$NON-NLS-1$
1171
}
1172        this.fBuffer.append("super.");//$NON-NLS-1$
1173
node.getName().accept(this);
1174        return false;
1175    }
1176
1177    /*
1178     * @see ASTVisitor#visit(SuperMethodInvocation)
1179     */

1180    public boolean visit(SuperMethodInvocation node) {
1181        if (node.getQualifier() != null) {
1182            node.getQualifier().accept(this);
1183            this.fBuffer.append(".");//$NON-NLS-1$
1184
}
1185        this.fBuffer.append("super.");//$NON-NLS-1$
1186
if (node.getAST().apiLevel() >= AST.JLS3) {
1187            if (!node.typeArguments().isEmpty()) {
1188                this.fBuffer.append("<");//$NON-NLS-1$
1189
for (Iterator JavaDoc it= node.typeArguments().iterator(); it.hasNext();) {
1190                    Type t= (Type) it.next();
1191                    t.accept(this);
1192                    if (it.hasNext()) {
1193                        this.fBuffer.append(",");//$NON-NLS-1$
1194
}
1195                }
1196                this.fBuffer.append(">");//$NON-NLS-1$
1197
}
1198        }
1199        node.getName().accept(this);
1200        this.fBuffer.append("(");//$NON-NLS-1$
1201
for (Iterator JavaDoc it= node.arguments().iterator(); it.hasNext();) {
1202            Expression e= (Expression) it.next();
1203            e.accept(this);
1204            if (it.hasNext()) {
1205                this.fBuffer.append(",");//$NON-NLS-1$
1206
}
1207        }
1208        this.fBuffer.append(")");//$NON-NLS-1$
1209
return false;
1210    }
1211
1212    /*
1213     * @see ASTVisitor#visit(SwitchCase)
1214     */

1215    public boolean visit(SwitchCase node) {
1216        if (node.isDefault()) {
1217            this.fBuffer.append("default :");//$NON-NLS-1$
1218
} else {
1219            this.fBuffer.append("case ");//$NON-NLS-1$
1220
node.getExpression().accept(this);
1221            this.fBuffer.append(":");//$NON-NLS-1$
1222
}
1223        return false;
1224    }
1225
1226    /*
1227     * @see ASTVisitor#visit(SwitchStatement)
1228     */

1229    public boolean visit(SwitchStatement node) {
1230        this.fBuffer.append("switch (");//$NON-NLS-1$
1231
node.getExpression().accept(this);
1232        this.fBuffer.append(") ");//$NON-NLS-1$
1233
this.fBuffer.append("{");//$NON-NLS-1$
1234
for (Iterator JavaDoc it= node.statements().iterator(); it.hasNext();) {
1235            Statement s= (Statement) it.next();
1236            s.accept(this);
1237        }
1238        this.fBuffer.append("}");//$NON-NLS-1$
1239
return false;
1240    }
1241
1242    /*
1243     * @see ASTVisitor#visit(SynchronizedStatement)
1244     */

1245    public boolean visit(SynchronizedStatement node) {
1246        this.fBuffer.append("synchronized (");//$NON-NLS-1$
1247
node.getExpression().accept(this);
1248        this.fBuffer.append(") ");//$NON-NLS-1$
1249
node.getBody().accept(this);
1250        return false;
1251    }
1252
1253    /*
1254     * @see ASTVisitor#visit(TagElement)
1255     * @since 3.0
1256     */

1257    public boolean visit(TagElement node) {
1258        if (node.isNested()) {
1259            // nested tags are always enclosed in braces
1260
this.fBuffer.append("{");//$NON-NLS-1$
1261
} else {
1262            // top-level tags always begin on a new line
1263
this.fBuffer.append("\n * ");//$NON-NLS-1$
1264
}
1265        boolean previousRequiresWhiteSpace= false;
1266        if (node.getTagName() != null) {
1267            this.fBuffer.append(node.getTagName());
1268            previousRequiresWhiteSpace= true;
1269        }
1270        boolean previousRequiresNewLine= false;
1271        for (Iterator JavaDoc it= node.fragments().iterator(); it.hasNext();) {
1272            ASTNode e= (ASTNode) it.next();
1273            // assume text elements include necessary leading and trailing whitespace
1274
// but Name, MemberRef, MethodRef, and nested TagElement do not include white space
1275
boolean currentIncludesWhiteSpace= (e instanceof TextElement);
1276            if (previousRequiresNewLine && currentIncludesWhiteSpace) {
1277                this.fBuffer.append("\n * ");//$NON-NLS-1$
1278
}
1279            previousRequiresNewLine= currentIncludesWhiteSpace;
1280            // add space if required to separate
1281
if (previousRequiresWhiteSpace && !currentIncludesWhiteSpace) {
1282                this.fBuffer.append(" "); //$NON-NLS-1$
1283
}
1284            e.accept(this);
1285            previousRequiresWhiteSpace= !currentIncludesWhiteSpace && !(e instanceof TagElement);
1286        }
1287        if (node.isNested()) {
1288            this.fBuffer.append("}");//$NON-NLS-1$
1289
}
1290        return false;
1291    }
1292
1293    /*
1294     * @see ASTVisitor#visit(TextElement)
1295     * @since 3.0
1296     */

1297    public boolean visit(TextElement node) {
1298        this.fBuffer.append(node.getText());
1299        return false;
1300    }
1301
1302    /*
1303     * @see ASTVisitor#visit(ThisExpression)
1304     */

1305    public boolean visit(ThisExpression node) {
1306        if (node.getQualifier() != null) {
1307            node.getQualifier().accept(this);
1308            this.fBuffer.append(".");//$NON-NLS-1$
1309
}
1310        this.fBuffer.append("this");//$NON-NLS-1$
1311
return false;
1312    }
1313
1314    /*
1315     * @see ASTVisitor#visit(ThrowStatement)
1316     */

1317    public boolean visit(ThrowStatement node) {
1318        this.fBuffer.append("throw ");//$NON-NLS-1$
1319
node.getExpression().accept(this);
1320        this.fBuffer.append(";");//$NON-NLS-1$
1321
return false;
1322    }
1323
1324    /*
1325     * @see ASTVisitor#visit(TryStatement)
1326     */

1327    public boolean visit(TryStatement node) {
1328        this.fBuffer.append("try ");//$NON-NLS-1$
1329
node.getBody().accept(this);
1330        this.fBuffer.append(" ");//$NON-NLS-1$
1331
for (Iterator JavaDoc it= node.catchClauses().iterator(); it.hasNext();) {
1332            CatchClause cc= (CatchClause) it.next();
1333            cc.accept(this);
1334        }
1335        if (node.getFinally() != null) {
1336            this.fBuffer.append("finally ");//$NON-NLS-1$
1337
node.getFinally().accept(this);
1338        }
1339        return false;
1340    }
1341
1342    /*
1343     * @see ASTVisitor#visit(TypeDeclaration)
1344     */

1345    public boolean visit(TypeDeclaration node) {
1346        if (node.getJavadoc() != null) {
1347            node.getJavadoc().accept(this);
1348        }
1349        if (node.getAST().apiLevel() == AST.JLS2) {
1350            printModifiers(node.getModifiers());
1351        }
1352        if (node.getAST().apiLevel() >= AST.JLS3) {
1353            printModifiers(node.modifiers());
1354        }
1355        this.fBuffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$
1356
node.getName().accept(this);
1357        if (node.getAST().apiLevel() >= AST.JLS3) {
1358            if (!node.typeParameters().isEmpty()) {
1359                this.fBuffer.append("<");//$NON-NLS-1$
1360
for (Iterator JavaDoc it= node.typeParameters().iterator(); it.hasNext();) {
1361                    TypeParameter t= (TypeParameter) it.next();
1362                    t.accept(this);
1363                    if (it.hasNext()) {
1364                        this.fBuffer.append(",");//$NON-NLS-1$
1365
}
1366                }
1367                this.fBuffer.append(">");//$NON-NLS-1$
1368
}
1369        }
1370        this.fBuffer.append(" ");//$NON-NLS-1$
1371
if (node.getAST().apiLevel() == AST.JLS2) {
1372            if (node.getSuperclass() != null) {
1373                this.fBuffer.append("extends ");//$NON-NLS-1$
1374
node.getSuperclass().accept(this);
1375                this.fBuffer.append(" ");//$NON-NLS-1$
1376
}
1377            if (!node.superInterfaces().isEmpty()) {
1378                this.fBuffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
1379
for (Iterator JavaDoc it= node.superInterfaces().iterator(); it.hasNext();) {
1380                    Name n= (Name) it.next();
1381                    n.accept(this);
1382                    if (it.hasNext()) {
1383                        this.fBuffer.append(", ");//$NON-NLS-1$
1384
}
1385                }
1386                this.fBuffer.append(" ");//$NON-NLS-1$
1387
}
1388        }
1389        if (node.getAST().apiLevel() >= AST.JLS3) {
1390            if (node.getSuperclassType() != null) {
1391                this.fBuffer.append("extends ");//$NON-NLS-1$
1392
node.getSuperclassType().accept(this);
1393                this.fBuffer.append(" ");//$NON-NLS-1$
1394
}
1395            if (!node.superInterfaceTypes().isEmpty()) {
1396                this.fBuffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
1397
for (Iterator JavaDoc it= node.superInterfaceTypes().iterator(); it.hasNext();) {
1398                    Type t= (Type) it.next();
1399                    t.accept(this);
1400                    if (it.hasNext()) {
1401                        this.fBuffer.append(", ");//$NON-NLS-1$
1402
}
1403                }
1404                this.fBuffer.append(" ");//$NON-NLS-1$
1405
}
1406        }
1407        this.fBuffer.append("{");//$NON-NLS-1$
1408
BodyDeclaration prev= null;
1409        for (Iterator JavaDoc it= node.bodyDeclarations().iterator(); it.hasNext();) {
1410            BodyDeclaration d= (BodyDeclaration) it.next();
1411            if (prev instanceof EnumConstantDeclaration) {
1412                // enum constant declarations do not include punctuation
1413
if (d instanceof EnumConstantDeclaration) {
1414                    // enum constant declarations are separated by commas
1415
this.fBuffer.append(", ");//$NON-NLS-1$
1416
} else {
1417                    // semicolon separates last enum constant declaration from
1418
// first class body declarations
1419
this.fBuffer.append("; ");//$NON-NLS-1$
1420
}
1421            }
1422            d.accept(this);
1423        }
1424        this.fBuffer.append("}");//$NON-NLS-1$
1425
return false;
1426    }
1427
1428    /*
1429     * @see ASTVisitor#visit(TypeDeclarationStatement)
1430     */

1431    public boolean visit(TypeDeclarationStatement node) {
1432        if (node.getAST().apiLevel() == AST.JLS2) {
1433            node.getTypeDeclaration().accept(this);
1434        }
1435        if (node.getAST().apiLevel() >= AST.JLS3) {
1436            node.getDeclaration().accept(this);
1437        }
1438        return false;
1439    }
1440
1441    /*
1442     * @see ASTVisitor#visit(TypeLiteral)
1443     */

1444    public boolean visit(TypeLiteral node) {
1445        node.getType().accept(this);
1446        this.fBuffer.append(".class");//$NON-NLS-1$
1447
return false;
1448    }
1449
1450    /*
1451     * @see ASTVisitor#visit(TypeParameter)
1452     * @since 3.0
1453     */

1454    public boolean visit(TypeParameter node) {
1455        node.getName().accept(this);
1456        if (!node.typeBounds().isEmpty()) {
1457            this.fBuffer.append(" extends ");//$NON-NLS-1$
1458
for (Iterator JavaDoc it= node.typeBounds().iterator(); it.hasNext();) {
1459                Type t= (Type) it.next();
1460                t.accept(this);
1461                if (it.hasNext()) {
1462                    this.fBuffer.append(" & ");//$NON-NLS-1$
1463
}
1464            }
1465        }
1466        return false;
1467    }
1468
1469    /*
1470     * @see ASTVisitor#visit(VariableDeclarationExpression)
1471     */

1472    public boolean visit(VariableDeclarationExpression node) {
1473        if (node.getAST().apiLevel() == AST.JLS2) {
1474            printModifiers(node.getModifiers());
1475        }
1476        if (node.getAST().apiLevel() >= AST.JLS3) {
1477            printModifiers(node.modifiers());
1478        }
1479        node.getType().accept(this);
1480        this.fBuffer.append(" ");//$NON-NLS-1$
1481
for (Iterator JavaDoc it= node.fragments().iterator(); it.hasNext();) {
1482            VariableDeclarationFragment f= (VariableDeclarationFragment) it.next();
1483            f.accept(this);
1484            if (it.hasNext()) {
1485                this.fBuffer.append(", ");//$NON-NLS-1$
1486
}
1487        }
1488        return false;
1489    }
1490
1491    /*
1492     * @see ASTVisitor#visit(VariableDeclarationFragment)
1493     */

1494    public boolean visit(VariableDeclarationFragment node) {
1495        node.getName().accept(this);
1496        for (int i= 0; i < node.getExtraDimensions(); i++) {
1497            this.fBuffer.append("[]");//$NON-NLS-1$
1498
}
1499        if (node.getInitializer() != null) {
1500            this.fBuffer.append("=");//$NON-NLS-1$
1501
node.getInitializer().accept(this);
1502        }
1503        return false;
1504    }
1505
1506    /*
1507     * @see ASTVisitor#visit(VariableDeclarationStatement)
1508     */

1509    public boolean visit(VariableDeclarationStatement node) {
1510        if (node.getAST().apiLevel() == AST.JLS2) {
1511            printModifiers(node.getModifiers());
1512        }
1513        if (node.getAST().apiLevel() >= AST.JLS3) {
1514            printModifiers(node.modifiers());
1515        }
1516        node.getType().accept(this);
1517        this.fBuffer.append(" ");//$NON-NLS-1$
1518
for (Iterator JavaDoc it= node.fragments().iterator(); it.hasNext();) {
1519            VariableDeclarationFragment f= (VariableDeclarationFragment) it.next();
1520            f.accept(this);
1521            if (it.hasNext()) {
1522                this.fBuffer.append(", ");//$NON-NLS-1$
1523
}
1524        }
1525        this.fBuffer.append(";");//$NON-NLS-1$
1526
return false;
1527    }
1528
1529    /*
1530     * @see ASTVisitor#visit(WildcardType)
1531     * @since 3.0
1532     */

1533    public boolean visit(WildcardType node) {
1534        this.fBuffer.append("?");//$NON-NLS-1$
1535
Type bound= node.getBound();
1536        if (bound != null) {
1537            if (node.isUpperBound()) {
1538                this.fBuffer.append(" extends ");//$NON-NLS-1$
1539
} else {
1540                this.fBuffer.append(" super ");//$NON-NLS-1$
1541
}
1542            bound.accept(this);
1543        }
1544        return false;
1545    }
1546
1547    /*
1548     * @see ASTVisitor#visit(WhileStatement)
1549     */

1550    public boolean visit(WhileStatement node) {
1551        this.fBuffer.append("while (");//$NON-NLS-1$
1552
node.getExpression().accept(this);
1553        this.fBuffer.append(") ");//$NON-NLS-1$
1554
node.getBody().accept(this);
1555        return false;
1556    }
1557
1558}
1559
Popular Tags