KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > dom > NaiveASTFlattener


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.core.dom;
12
13 import java.util.Iterator JavaDoc;
14 import java.util.List JavaDoc;
15
16 /**
17  * Internal AST visitor for serializing an AST in a quick and dirty fashion.
18  * For various reasons the resulting string is not necessarily legal
19  * Java code; and even if it is legal Java code, it is not necessarily the string
20  * that corresponds to the given AST. Although useless for most purposes, it's
21  * fine for generating debug print strings.
22  * <p>
23  * Example usage:
24  * <code>
25  * <pre>
26  * NaiveASTFlattener p = new NaiveASTFlattener();
27  * node.accept(p);
28  * String result = p.getResult();
29  * </pre>
30  * </code>
31  * Call the <code>reset</code> method to clear the previous result before reusing an
32  * existing instance.
33  * </p>
34  *
35  * @since 2.0
36  */

37 class NaiveASTFlattener extends ASTVisitor {
38     
39     /**
40      * The string buffer into which the serialized representation of the AST is
41      * written.
42      */

43     private StringBuffer JavaDoc buffer;
44     
45     private int indent = 0;
46     
47     /**
48      * Creates a new AST printer.
49      */

50     NaiveASTFlattener() {
51         this.buffer = new StringBuffer JavaDoc();
52     }
53     
54     /**
55      * Returns the string accumulated in the visit.
56      *
57      * @return the serialized
58      */

59     public String JavaDoc getResult() {
60         return this.buffer.toString();
61     }
62     
63     /**
64      * Resets this printer so that it can be used again.
65      */

66     public void reset() {
67         this.buffer.setLength(0);
68     }
69     
70     void printIndent() {
71         for (int i = 0; i < this.indent; i++)
72             this.buffer.append(" "); //$NON-NLS-1$
73
}
74     
75     /**
76      * Appends the text representation of the given modifier flags, followed by a single space.
77      * Used for 3.0 modifiers and annotations.
78      *
79      * @param ext the list of modifier and annotation nodes
80      * (element type: <code>IExtendedModifiers</code>)
81      */

82     void printModifiers(List JavaDoc ext) {
83         for (Iterator JavaDoc it = ext.iterator(); it.hasNext(); ) {
84             ASTNode p = (ASTNode) it.next();
85             p.accept(this);
86             this.buffer.append(" ");//$NON-NLS-1$
87
}
88     }
89     
90     /**
91      * Appends the text representation of the given modifier flags, followed by a single space.
92      * Used for JLS2 modifiers.
93      *
94      * @param modifiers the modifier flags
95      */

96     void printModifiers(int modifiers) {
97         if (Modifier.isPublic(modifiers)) {
98             this.buffer.append("public ");//$NON-NLS-1$
99
}
100         if (Modifier.isProtected(modifiers)) {
101             this.buffer.append("protected ");//$NON-NLS-1$
102
}
103         if (Modifier.isPrivate(modifiers)) {
104             this.buffer.append("private ");//$NON-NLS-1$
105
}
106         if (Modifier.isStatic(modifiers)) {
107             this.buffer.append("static ");//$NON-NLS-1$
108
}
109         if (Modifier.isAbstract(modifiers)) {
110             this.buffer.append("abstract ");//$NON-NLS-1$
111
}
112         if (Modifier.isFinal(modifiers)) {
113             this.buffer.append("final ");//$NON-NLS-1$
114
}
115         if (Modifier.isSynchronized(modifiers)) {
116             this.buffer.append("synchronized ");//$NON-NLS-1$
117
}
118         if (Modifier.isVolatile(modifiers)) {
119             this.buffer.append("volatile ");//$NON-NLS-1$
120
}
121         if (Modifier.isNative(modifiers)) {
122             this.buffer.append("native ");//$NON-NLS-1$
123
}
124         if (Modifier.isStrictfp(modifiers)) {
125             this.buffer.append("strictfp ");//$NON-NLS-1$
126
}
127         if (Modifier.isTransient(modifiers)) {
128             this.buffer.append("transient ");//$NON-NLS-1$
129
}
130     }
131     
132     /*
133      * @see ASTVisitor#visit(AnnotationTypeDeclaration)
134      * @since 3.1
135      */

136     public boolean visit(AnnotationTypeDeclaration node) {
137         if (node.getJavadoc() != null) {
138             node.getJavadoc().accept(this);
139         }
140         printIndent();
141         printModifiers(node.modifiers());
142         this.buffer.append("@interface ");//$NON-NLS-1$
143
node.getName().accept(this);
144         this.buffer.append(" {");//$NON-NLS-1$
145
for (Iterator JavaDoc it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
146             BodyDeclaration d = (BodyDeclaration) it.next();
147             d.accept(this);
148         }
149         this.buffer.append("}\n");//$NON-NLS-1$
150
return false;
151     }
152     
153     /*
154      * @see ASTVisitor#visit(AnnotationTypeMemberDeclaration)
155      * @since 3.1
156      */

157     public boolean visit(AnnotationTypeMemberDeclaration node) {
158         if (node.getJavadoc() != null) {
159             node.getJavadoc().accept(this);
160         }
161         printIndent();
162         printModifiers(node.modifiers());
163         node.getType().accept(this);
164         this.buffer.append(" ");//$NON-NLS-1$
165
node.getName().accept(this);
166         this.buffer.append("()");//$NON-NLS-1$
167
if (node.getDefault() != null) {
168             this.buffer.append(" default ");//$NON-NLS-1$
169
node.getDefault().accept(this);
170         }
171         this.buffer.append(";\n");//$NON-NLS-1$
172
return false;
173     }
174     
175     /*
176      * @see ASTVisitor#visit(AnonymousClassDeclaration)
177      */

178     public boolean visit(AnonymousClassDeclaration node) {
179         this.buffer.append("{\n");//$NON-NLS-1$
180
this.indent++;
181         for (Iterator JavaDoc it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
182             BodyDeclaration b = (BodyDeclaration) it.next();
183             b.accept(this);
184         }
185         this.indent--;
186         printIndent();
187         this.buffer.append("}\n");//$NON-NLS-1$
188
return false;
189     }
190
191     /*
192      * @see ASTVisitor#visit(ArrayAccess)
193      */

194     public boolean visit(ArrayAccess node) {
195         node.getArray().accept(this);
196         this.buffer.append("[");//$NON-NLS-1$
197
node.getIndex().accept(this);
198         this.buffer.append("]");//$NON-NLS-1$
199
return false;
200     }
201
202     /*
203      * @see ASTVisitor#visit(ArrayCreation)
204      */

205     public boolean visit(ArrayCreation node) {
206         this.buffer.append("new ");//$NON-NLS-1$
207
ArrayType at = node.getType();
208         int dims = at.getDimensions();
209         Type elementType = at.getElementType();
210         elementType.accept(this);
211         for (Iterator JavaDoc it = node.dimensions().iterator(); it.hasNext(); ) {
212             this.buffer.append("[");//$NON-NLS-1$
213
Expression e = (Expression) it.next();
214             e.accept(this);
215             this.buffer.append("]");//$NON-NLS-1$
216
dims--;
217         }
218         // add empty "[]" for each extra array dimension
219
for (int i= 0; i < dims; i++) {
220             this.buffer.append("[]");//$NON-NLS-1$
221
}
222         if (node.getInitializer() != null) {
223             node.getInitializer().accept(this);
224         }
225         return false;
226     }
227
228     /*
229      * @see ASTVisitor#visit(ArrayInitializer)
230      */

231     public boolean visit(ArrayInitializer node) {
232         this.buffer.append("{");//$NON-NLS-1$
233
for (Iterator JavaDoc it = node.expressions().iterator(); it.hasNext(); ) {
234             Expression e = (Expression) it.next();
235             e.accept(this);
236             if (it.hasNext()) {
237                 this.buffer.append(",");//$NON-NLS-1$
238
}
239         }
240         this.buffer.append("}");//$NON-NLS-1$
241
return false;
242     }
243
244     /*
245      * @see ASTVisitor#visit(ArrayType)
246      */

247     public boolean visit(ArrayType node) {
248         node.getComponentType().accept(this);
249         this.buffer.append("[]");//$NON-NLS-1$
250
return false;
251     }
252
253     /*
254      * @see ASTVisitor#visit(AssertStatement)
255      */

256     public boolean visit(AssertStatement node) {
257         printIndent();
258         this.buffer.append("assert ");//$NON-NLS-1$
259
node.getExpression().accept(this);
260         if (node.getMessage() != null) {
261             this.buffer.append(" : ");//$NON-NLS-1$
262
node.getMessage().accept(this);
263         }
264         this.buffer.append(";\n");//$NON-NLS-1$
265
return false;
266     }
267
268     /*
269      * @see ASTVisitor#visit(Assignment)
270      */

271     public boolean visit(Assignment node) {
272         node.getLeftHandSide().accept(this);
273         this.buffer.append(node.getOperator().toString());
274         node.getRightHandSide().accept(this);
275         return false;
276     }
277
278     /*
279      * @see ASTVisitor#visit(Block)
280      */

281     public boolean visit(Block node) {
282         this.buffer.append("{\n");//$NON-NLS-1$
283
this.indent++;
284         for (Iterator JavaDoc it = node.statements().iterator(); it.hasNext(); ) {
285             Statement s = (Statement) it.next();
286             s.accept(this);
287         }
288         this.indent--;
289         printIndent();
290         this.buffer.append("}\n");//$NON-NLS-1$
291
return false;
292     }
293
294     /*
295      * @see ASTVisitor#visit(BlockComment)
296      * @since 3.0
297      */

298     public boolean visit(BlockComment node) {
299         printIndent();
300         this.buffer.append("/* */");//$NON-NLS-1$
301
return false;
302     }
303
304     /*
305      * @see ASTVisitor#visit(BooleanLiteral)
306      */

307     public boolean visit(BooleanLiteral node) {
308         if (node.booleanValue() == true) {
309             this.buffer.append("true");//$NON-NLS-1$
310
} else {
311             this.buffer.append("false");//$NON-NLS-1$
312
}
313         return false;
314     }
315
316     /*
317      * @see ASTVisitor#visit(BreakStatement)
318      */

319     public boolean visit(BreakStatement node) {
320         printIndent();
321         this.buffer.append("break");//$NON-NLS-1$
322
if (node.getLabel() != null) {
323             this.buffer.append(" ");//$NON-NLS-1$
324
node.getLabel().accept(this);
325         }
326         this.buffer.append(";\n");//$NON-NLS-1$
327
return false;
328     }
329
330     /*
331      * @see ASTVisitor#visit(CastExpression)
332      */

333     public boolean visit(CastExpression node) {
334         this.buffer.append("(");//$NON-NLS-1$
335
node.getType().accept(this);
336         this.buffer.append(")");//$NON-NLS-1$
337
node.getExpression().accept(this);
338         return false;
339     }
340
341     /*
342      * @see ASTVisitor#visit(CatchClause)
343      */

344     public boolean visit(CatchClause node) {
345         this.buffer.append("catch (");//$NON-NLS-1$
346
node.getException().accept(this);
347         this.buffer.append(") ");//$NON-NLS-1$
348
node.getBody().accept(this);
349         return false;
350     }
351
352     /*
353      * @see ASTVisitor#visit(CharacterLiteral)
354      */

355     public boolean visit(CharacterLiteral node) {
356         this.buffer.append(node.getEscapedValue());
357         return false;
358     }
359
360     /*
361      * @see ASTVisitor#visit(ClassInstanceCreation)
362      */

363     public boolean visit(ClassInstanceCreation node) {
364         if (node.getExpression() != null) {
365             node.getExpression().accept(this);
366             this.buffer.append(".");//$NON-NLS-1$
367
}
368         this.buffer.append("new ");//$NON-NLS-1$
369
if (node.getAST().apiLevel() == AST.JLS2_INTERNAL) {
370             node.internalGetName().accept(this);
371         }
372         if (node.getAST().apiLevel() >= AST.JLS3) {
373             if (!node.typeArguments().isEmpty()) {
374                 this.buffer.append("<");//$NON-NLS-1$
375
for (Iterator JavaDoc it = node.typeArguments().iterator(); it.hasNext(); ) {
376                     Type t = (Type) it.next();
377                     t.accept(this);
378                     if (it.hasNext()) {
379                         this.buffer.append(",");//$NON-NLS-1$
380
}
381                 }
382                 this.buffer.append(">");//$NON-NLS-1$
383
}
384             node.getType().accept(this);
385         }
386         this.buffer.append("(");//$NON-NLS-1$
387
for (Iterator JavaDoc it = node.arguments().iterator(); it.hasNext(); ) {
388             Expression e = (Expression) it.next();
389             e.accept(this);
390             if (it.hasNext()) {
391                 this.buffer.append(",");//$NON-NLS-1$
392
}
393         }
394         this.buffer.append(")");//$NON-NLS-1$
395
if (node.getAnonymousClassDeclaration() != null) {
396             node.getAnonymousClassDeclaration().accept(this);
397         }
398         return false;
399     }
400
401     /*
402      * @see ASTVisitor#visit(CompilationUnit)
403      */

404     public boolean visit(CompilationUnit node) {
405         if (node.getPackage() != null) {
406             node.getPackage().accept(this);
407         }
408         for (Iterator JavaDoc it = node.imports().iterator(); it.hasNext(); ) {
409             ImportDeclaration d = (ImportDeclaration) it.next();
410             d.accept(this);
411         }
412         for (Iterator JavaDoc it = node.types().iterator(); it.hasNext(); ) {
413             AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next();
414             d.accept(this);
415         }
416         return false;
417     }
418
419     /*
420      * @see ASTVisitor#visit(ConditionalExpression)
421      */

422     public boolean visit(ConditionalExpression node) {
423         node.getExpression().accept(this);
424         this.buffer.append(" ? ");//$NON-NLS-1$
425
node.getThenExpression().accept(this);
426         this.buffer.append(" : ");//$NON-NLS-1$
427
node.getElseExpression().accept(this);
428         return false;
429     }
430
431     /*
432      * @see ASTVisitor#visit(ConstructorInvocation)
433      */

434     public boolean visit(ConstructorInvocation node) {
435         printIndent();
436         if (node.getAST().apiLevel() >= AST.JLS3) {
437             if (!node.typeArguments().isEmpty()) {
438                 this.buffer.append("<");//$NON-NLS-1$
439
for (Iterator JavaDoc it = node.typeArguments().iterator(); it.hasNext(); ) {
440                     Type t = (Type) it.next();
441                     t.accept(this);
442                     if (it.hasNext()) {
443                         this.buffer.append(",");//$NON-NLS-1$
444
}
445                 }
446                 this.buffer.append(">");//$NON-NLS-1$
447
}
448         }
449         this.buffer.append("this(");//$NON-NLS-1$
450
for (Iterator JavaDoc it = node.arguments().iterator(); it.hasNext(); ) {
451             Expression e = (Expression) it.next();
452             e.accept(this);
453             if (it.hasNext()) {
454                 this.buffer.append(",");//$NON-NLS-1$
455
}
456         }
457         this.buffer.append(");\n");//$NON-NLS-1$
458
return false;
459     }
460
461     /*
462      * @see ASTVisitor#visit(ContinueStatement)
463      */

464     public boolean visit(ContinueStatement node) {
465         printIndent();
466         this.buffer.append("continue");//$NON-NLS-1$
467
if (node.getLabel() != null) {
468             this.buffer.append(" ");//$NON-NLS-1$
469
node.getLabel().accept(this);
470         }
471         this.buffer.append(";\n");//$NON-NLS-1$
472
return false;
473     }
474
475     /*
476      * @see ASTVisitor#visit(DoStatement)
477      */

478     public boolean visit(DoStatement node) {
479         printIndent();
480         this.buffer.append("do ");//$NON-NLS-1$
481
node.getBody().accept(this);
482         this.buffer.append(" while (");//$NON-NLS-1$
483
node.getExpression().accept(this);
484         this.buffer.append(");\n");//$NON-NLS-1$
485
return false;
486     }
487
488     /*
489      * @see ASTVisitor#visit(EmptyStatement)
490      */

491     public boolean visit(EmptyStatement node) {
492         printIndent();
493         this.buffer.append(";\n");//$NON-NLS-1$
494
return false;
495     }
496
497     /*
498      * @see ASTVisitor#visit(EnhancedForStatement)
499      * @since 3.1
500      */

501     public boolean visit(EnhancedForStatement node) {
502         printIndent();
503         this.buffer.append("for (");//$NON-NLS-1$
504
node.getParameter().accept(this);
505         this.buffer.append(" : ");//$NON-NLS-1$
506
node.getExpression().accept(this);
507         this.buffer.append(") ");//$NON-NLS-1$
508
node.getBody().accept(this);
509         return false;
510     }
511
512     /*
513      * @see ASTVisitor#visit(EnumConstantDeclaration)
514      * @since 3.1
515      */

516     public boolean visit(EnumConstantDeclaration node) {
517         if (node.getJavadoc() != null) {
518             node.getJavadoc().accept(this);
519         }
520         printIndent();
521         printModifiers(node.modifiers());
522         node.getName().accept(this);
523         if (!node.arguments().isEmpty()) {
524             this.buffer.append("(");//$NON-NLS-1$
525
for (Iterator JavaDoc it = node.arguments().iterator(); it.hasNext(); ) {
526                 Expression e = (Expression) it.next();
527                 e.accept(this);
528                 if (it.hasNext()) {
529                     this.buffer.append(",");//$NON-NLS-1$
530
}
531             }
532             this.buffer.append(")");//$NON-NLS-1$
533
}
534         if (node.getAnonymousClassDeclaration() != null) {
535             node.getAnonymousClassDeclaration().accept(this);
536         }
537         return false;
538     }
539
540     /*
541      * @see ASTVisitor#visit(EnumDeclaration)
542      * @since 3.1
543      */

544     public boolean visit(EnumDeclaration node) {
545         if (node.getJavadoc() != null) {
546             node.getJavadoc().accept(this);
547         }
548         printIndent();
549         printModifiers(node.modifiers());
550         this.buffer.append("enum ");//$NON-NLS-1$
551
node.getName().accept(this);
552         this.buffer.append(" ");//$NON-NLS-1$
553
if (!node.superInterfaceTypes().isEmpty()) {
554             this.buffer.append("implements ");//$NON-NLS-1$
555
for (Iterator JavaDoc it = node.superInterfaceTypes().iterator(); it.hasNext(); ) {
556                 Type t = (Type) it.next();
557                 t.accept(this);
558                 if (it.hasNext()) {
559                     this.buffer.append(", ");//$NON-NLS-1$
560
}
561             }
562             this.buffer.append(" ");//$NON-NLS-1$
563
}
564         this.buffer.append("{");//$NON-NLS-1$
565
for (Iterator JavaDoc it = node.enumConstants().iterator(); it.hasNext(); ) {
566             EnumConstantDeclaration d = (EnumConstantDeclaration) it.next();
567             d.accept(this);
568             // enum constant declarations do not include punctuation
569
if (it.hasNext()) {
570                 // enum constant declarations are separated by commas
571
this.buffer.append(", ");//$NON-NLS-1$
572
}
573         }
574         if (!node.bodyDeclarations().isEmpty()) {
575             this.buffer.append("; ");//$NON-NLS-1$
576
for (Iterator JavaDoc it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
577                 BodyDeclaration d = (BodyDeclaration) it.next();
578                 d.accept(this);
579                 // other body declarations include trailing punctuation
580
}
581         }
582         this.buffer.append("}\n");//$NON-NLS-1$
583
return false;
584     }
585
586     /*
587      * @see ASTVisitor#visit(ExpressionStatement)
588      */

589     public boolean visit(ExpressionStatement node) {
590         printIndent();
591         node.getExpression().accept(this);
592         this.buffer.append(";\n");//$NON-NLS-1$
593
return false;
594     }
595
596     /*
597      * @see ASTVisitor#visit(FieldAccess)
598      */

599     public boolean visit(FieldAccess node) {
600         node.getExpression().accept(this);
601         this.buffer.append(".");//$NON-NLS-1$
602
node.getName().accept(this);
603         return false;
604     }
605
606     /*
607      * @see ASTVisitor#visit(FieldDeclaration)
608      */

609     public boolean visit(FieldDeclaration node) {
610         if (node.getJavadoc() != null) {
611             node.getJavadoc().accept(this);
612         }
613         printIndent();
614         if (node.getAST().apiLevel() == AST.JLS2_INTERNAL) {
615             printModifiers(node.getModifiers());
616         }
617         if (node.getAST().apiLevel() >= AST.JLS3) {
618             printModifiers(node.modifiers());
619         }
620         node.getType().accept(this);
621         this.buffer.append(" ");//$NON-NLS-1$
622
for (Iterator JavaDoc it = node.fragments().iterator(); it.hasNext(); ) {
623             VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
624             f.accept(this);
625             if (it.hasNext()) {
626                 this.buffer.append(", ");//$NON-NLS-1$
627
}
628         }
629         this.buffer.append(";\n");//$NON-NLS-1$
630
return false;
631     }
632
633     /*
634      * @see ASTVisitor#visit(ForStatement)
635      */

636     public boolean visit(ForStatement node) {
637         printIndent();
638         this.buffer.append("for (");//$NON-NLS-1$
639
for (Iterator JavaDoc it = node.initializers().iterator(); it.hasNext(); ) {
640             Expression e = (Expression) it.next();
641             e.accept(this);
642             if (it.hasNext()) buffer.append(", ");//$NON-NLS-1$
643
}
644         this.buffer.append("; ");//$NON-NLS-1$
645
if (node.getExpression() != null) {
646             node.getExpression().accept(this);
647         }
648         this.buffer.append("; ");//$NON-NLS-1$
649
for (Iterator JavaDoc it = node.updaters().iterator(); it.hasNext(); ) {
650             Expression e = (Expression) it.next();
651             e.accept(this);
652             if (it.hasNext()) buffer.append(", ");//$NON-NLS-1$
653
}
654         this.buffer.append(") ");//$NON-NLS-1$
655
node.getBody().accept(this);
656         return false;
657     }
658
659     /*
660      * @see ASTVisitor#visit(IfStatement)
661      */

662     public boolean visit(IfStatement node) {
663         printIndent();
664         this.buffer.append("if (");//$NON-NLS-1$
665
node.getExpression().accept(this);
666         this.buffer.append(") ");//$NON-NLS-1$
667
node.getThenStatement().accept(this);
668         if (node.getElseStatement() != null) {
669             this.buffer.append(" else ");//$NON-NLS-1$
670
node.getElseStatement().accept(this);
671         }
672         return false;
673     }
674
675     /*
676      * @see ASTVisitor#visit(ImportDeclaration)
677      */

678     public boolean visit(ImportDeclaration node) {
679         printIndent();
680         this.buffer.append("import ");//$NON-NLS-1$
681
if (node.getAST().apiLevel() >= AST.JLS3) {
682             if (node.isStatic()) {
683                 this.buffer.append("static ");//$NON-NLS-1$
684
}
685         }
686         node.getName().accept(this);
687         if (node.isOnDemand()) {
688             this.buffer.append(".*");//$NON-NLS-1$
689
}
690         this.buffer.append(";\n");//$NON-NLS-1$
691
return false;
692     }
693
694     /*
695      * @see ASTVisitor#visit(InfixExpression)
696      */

697     public boolean visit(InfixExpression node) {
698         node.getLeftOperand().accept(this);
699         this.buffer.append(' '); // for cases like x= i - -1; or x= i++ + ++i;
700
this.buffer.append(node.getOperator().toString());
701         this.buffer.append(' ');
702         node.getRightOperand().accept(this);
703         final List JavaDoc extendedOperands = node.extendedOperands();
704         if (extendedOperands.size() != 0) {
705             this.buffer.append(' ');
706             for (Iterator JavaDoc it = extendedOperands.iterator(); it.hasNext(); ) {
707                 this.buffer.append(node.getOperator().toString()).append(' ');
708                 Expression e = (Expression) it.next();
709                 e.accept(this);
710             }
711         }
712         return false;
713     }
714
715     /*
716      * @see ASTVisitor#visit(InstanceofExpression)
717      */

718     public boolean visit(InstanceofExpression node) {
719         node.getLeftOperand().accept(this);
720         this.buffer.append(" instanceof ");//$NON-NLS-1$
721
node.getRightOperand().accept(this);
722         return false;
723     }
724
725     /*
726      * @see ASTVisitor#visit(Initializer)
727      */

728     public boolean visit(Initializer node) {
729         if (node.getJavadoc() != null) {
730             node.getJavadoc().accept(this);
731         }
732         if (node.getAST().apiLevel() == AST.JLS2_INTERNAL) {
733             printModifiers(node.getModifiers());
734         }
735         if (node.getAST().apiLevel() >= AST.JLS3) {
736             printModifiers(node.modifiers());
737         }
738         node.getBody().accept(this);
739         return false;
740     }
741
742     /*
743      * @see ASTVisitor#visit(Javadoc)
744      */

745     public boolean visit(Javadoc node) {
746         printIndent();
747         this.buffer.append("/** ");//$NON-NLS-1$
748
for (Iterator JavaDoc it = node.tags().iterator(); it.hasNext(); ) {
749             ASTNode e = (ASTNode) it.next();
750             e.accept(this);
751         }
752         this.buffer.append("\n */\n");//$NON-NLS-1$
753
return false;
754     }
755
756     /*
757      * @see ASTVisitor#visit(LabeledStatement)
758      */

759     public boolean visit(LabeledStatement node) {
760         printIndent();
761         node.getLabel().accept(this);
762         this.buffer.append(": ");//$NON-NLS-1$
763
node.getBody().accept(this);
764         return false;
765     }
766
767     /*
768      * @see ASTVisitor#visit(LineComment)
769      * @since 3.0
770      */

771     public boolean visit(LineComment node) {
772         this.buffer.append("//\n");//$NON-NLS-1$
773
return false;
774     }
775
776     /*
777      * @see ASTVisitor#visit(MarkerAnnotation)
778      * @since 3.1
779      */

780     public boolean visit(MarkerAnnotation node) {
781         this.buffer.append("@");//$NON-NLS-1$
782
node.getTypeName().accept(this);
783         return false;
784     }
785     
786     /*
787      * @see ASTVisitor#visit(MemberRef)
788      * @since 3.0
789      */

790     public boolean visit(MemberRef node) {
791         if (node.getQualifier() != null) {
792             node.getQualifier().accept(this);
793         }
794         this.buffer.append("#");//$NON-NLS-1$
795
node.getName().accept(this);
796         return false;
797     }
798     
799     /*
800      * @see ASTVisitor#visit(MemberValuePair)
801      * @since 3.1
802      */

803     public boolean visit(MemberValuePair node) {
804         node.getName().accept(this);
805         this.buffer.append("=");//$NON-NLS-1$
806
node.getValue().accept(this);
807         return false;
808     }
809     
810     /*
811      * @see ASTVisitor#visit(MethodRef)
812      * @since 3.0
813      */

814     public boolean visit(MethodRef node) {
815         if (node.getQualifier() != null) {
816             node.getQualifier().accept(this);
817         }
818         this.buffer.append("#");//$NON-NLS-1$
819
node.getName().accept(this);
820         this.buffer.append("(");//$NON-NLS-1$
821
for (Iterator JavaDoc it = node.parameters().iterator(); it.hasNext(); ) {
822             MethodRefParameter e = (MethodRefParameter) it.next();
823             e.accept(this);
824             if (it.hasNext()) {
825                 this.buffer.append(",");//$NON-NLS-1$
826
}
827         }
828         this.buffer.append(")");//$NON-NLS-1$
829
return false;
830     }
831     
832     /*
833      * @see ASTVisitor#visit(MethodRefParameter)
834      * @since 3.0
835      */

836     public boolean visit(MethodRefParameter node) {
837         node.getType().accept(this);
838         if (node.getAST().apiLevel() >= AST.JLS3) {
839             if (node.isVarargs()) {
840                 this.buffer.append("...");//$NON-NLS-1$
841
}
842         }
843         if (node.getName() != null) {
844             this.buffer.append(" ");//$NON-NLS-1$
845
node.getName().accept(this);
846         }
847         return false;
848     }
849     
850     /*
851      * @see ASTVisitor#visit(MethodDeclaration)
852      */

853     public boolean visit(MethodDeclaration node) {
854         if (node.getJavadoc() != null) {
855             node.getJavadoc().accept(this);
856         }
857         printIndent();
858         if (node.getAST().apiLevel() == AST.JLS2_INTERNAL) {
859             printModifiers(node.getModifiers());
860         }
861         if (node.getAST().apiLevel() >= AST.JLS3) {
862             printModifiers(node.modifiers());
863             if (!node.typeParameters().isEmpty()) {
864                 this.buffer.append("<");//$NON-NLS-1$
865
for (Iterator JavaDoc it = node.typeParameters().iterator(); it.hasNext(); ) {
866                     TypeParameter t = (TypeParameter) it.next();
867                     t.accept(this);
868                     if (it.hasNext()) {
869                         this.buffer.append(",");//$NON-NLS-1$
870
}
871                 }
872                 this.buffer.append(">");//$NON-NLS-1$
873
}
874         }
875         if (!node.isConstructor()) {
876             if (node.getAST().apiLevel() == AST.JLS2_INTERNAL) {
877                 node.internalGetReturnType().accept(this);
878             } else {
879                 if (node.getReturnType2() != null) {
880                     node.getReturnType2().accept(this);
881                 } else {
882                     // methods really ought to have a return type
883
this.buffer.append("void");//$NON-NLS-1$
884
}
885             }
886             this.buffer.append(" ");//$NON-NLS-1$
887
}
888         node.getName().accept(this);
889         this.buffer.append("(");//$NON-NLS-1$
890
for (Iterator JavaDoc it = node.parameters().iterator(); it.hasNext(); ) {
891             SingleVariableDeclaration v = (SingleVariableDeclaration) it.next();
892             v.accept(this);
893             if (it.hasNext()) {
894                 this.buffer.append(",");//$NON-NLS-1$
895
}
896         }
897         this.buffer.append(")");//$NON-NLS-1$
898
for (int i = 0; i < node.getExtraDimensions(); i++) {
899             this.buffer.append("[]"); //$NON-NLS-1$
900
}
901         if (!node.thrownExceptions().isEmpty()) {
902             this.buffer.append(" throws ");//$NON-NLS-1$
903
for (Iterator JavaDoc it = node.thrownExceptions().iterator(); it.hasNext(); ) {
904                 Name n = (Name) it.next();
905                 n.accept(this);
906                 if (it.hasNext()) {
907                     this.buffer.append(", ");//$NON-NLS-1$
908
}
909             }
910             this.buffer.append(" ");//$NON-NLS-1$
911
}
912         if (node.getBody() == null) {
913             this.buffer.append(";\n");//$NON-NLS-1$
914
} else {
915             node.getBody().accept(this);
916         }
917         return false;
918     }
919
920     /*
921      * @see ASTVisitor#visit(MethodInvocation)
922      */

923     public boolean visit(MethodInvocation node) {
924         if (node.getExpression() != null) {
925             node.getExpression().accept(this);
926             this.buffer.append(".");//$NON-NLS-1$
927
}
928         if (node.getAST().apiLevel() >= AST.JLS3) {
929             if (!node.typeArguments().isEmpty()) {
930                 this.buffer.append("<");//$NON-NLS-1$
931
for (Iterator JavaDoc it = node.typeArguments().iterator(); it.hasNext(); ) {
932                     Type t = (Type) it.next();
933                     t.accept(this);
934                     if (it.hasNext()) {
935                         this.buffer.append(",");//$NON-NLS-1$
936
}
937                 }
938                 this.buffer.append(">");//$NON-NLS-1$
939
}
940         }
941         node.getName().accept(this);
942         this.buffer.append("(");//$NON-NLS-1$
943
for (Iterator JavaDoc it = node.arguments().iterator(); it.hasNext(); ) {
944             Expression e = (Expression) it.next();
945             e.accept(this);
946             if (it.hasNext()) {
947                 this.buffer.append(",");//$NON-NLS-1$
948
}
949         }
950         this.buffer.append(")");//$NON-NLS-1$
951
return false;
952     }
953
954     /*
955      * @see ASTVisitor#visit(Modifier)
956      * @since 3.1
957      */

958     public boolean visit(Modifier node) {
959         this.buffer.append(node.getKeyword().toString());
960         return false;
961     }
962     
963     /*
964      * @see ASTVisitor#visit(NormalAnnotation)
965      * @since 3.1
966      */

967     public boolean visit(NormalAnnotation node) {
968         this.buffer.append("@");//$NON-NLS-1$
969
node.getTypeName().accept(this);
970         this.buffer.append("(");//$NON-NLS-1$
971
for (Iterator JavaDoc it = node.values().iterator(); it.hasNext(); ) {
972             MemberValuePair p = (MemberValuePair) it.next();
973             p.accept(this);
974             if (it.hasNext()) {
975                 this.buffer.append(",");//$NON-NLS-1$
976
}
977         }
978         this.buffer.append(")");//$NON-NLS-1$
979
return false;
980     }
981     
982     /*
983      * @see ASTVisitor#visit(NullLiteral)
984      */

985     public boolean visit(NullLiteral node) {
986         this.buffer.append("null");//$NON-NLS-1$
987
return false;
988     }
989
990     /*
991      * @see ASTVisitor#visit(NumberLiteral)
992      */

993     public boolean visit(NumberLiteral node) {
994         this.buffer.append(node.getToken());
995         return false;
996     }
997
998     /*
999      * @see ASTVisitor#visit(PackageDeclaration)
1000     */

1001    public boolean visit(PackageDeclaration node) {
1002        if (node.getAST().apiLevel() >= AST.JLS3) {
1003            if (node.getJavadoc() != null) {
1004                node.getJavadoc().accept(this);
1005            }
1006            for (Iterator JavaDoc it = node.annotations().iterator(); it.hasNext(); ) {
1007                Annotation p = (Annotation) it.next();
1008                p.accept(this);
1009                this.buffer.append(" ");//$NON-NLS-1$
1010
}
1011        }
1012        printIndent();
1013        this.buffer.append("package ");//$NON-NLS-1$
1014
node.getName().accept(this);
1015        this.buffer.append(";\n");//$NON-NLS-1$
1016
return false;
1017    }
1018
1019    /*
1020     * @see ASTVisitor#visit(ParameterizedType)
1021     * @since 3.1
1022     */

1023    public boolean visit(ParameterizedType node) {
1024        node.getType().accept(this);
1025        this.buffer.append("<");//$NON-NLS-1$
1026
for (Iterator JavaDoc it = node.typeArguments().iterator(); it.hasNext(); ) {
1027            Type t = (Type) it.next();
1028            t.accept(this);
1029            if (it.hasNext()) {
1030                this.buffer.append(",");//$NON-NLS-1$
1031
}
1032        }
1033        this.buffer.append(">");//$NON-NLS-1$
1034
return false;
1035    }
1036
1037    /*
1038     * @see ASTVisitor#visit(ParenthesizedExpression)
1039     */

1040    public boolean visit(ParenthesizedExpression node) {
1041        this.buffer.append("(");//$NON-NLS-1$
1042
node.getExpression().accept(this);
1043        this.buffer.append(")");//$NON-NLS-1$
1044
return false;
1045    }
1046
1047    /*
1048     * @see ASTVisitor#visit(PostfixExpression)
1049     */

1050    public boolean visit(PostfixExpression node) {
1051        node.getOperand().accept(this);
1052        this.buffer.append(node.getOperator().toString());
1053        return false;
1054    }
1055
1056    /*
1057     * @see ASTVisitor#visit(PrefixExpression)
1058     */

1059    public boolean visit(PrefixExpression node) {
1060        this.buffer.append(node.getOperator().toString());
1061        node.getOperand().accept(this);
1062        return false;
1063    }
1064
1065    /*
1066     * @see ASTVisitor#visit(PrimitiveType)
1067     */

1068    public boolean visit(PrimitiveType node) {
1069        this.buffer.append(node.getPrimitiveTypeCode().toString());
1070        return false;
1071    }
1072
1073    /*
1074     * @see ASTVisitor#visit(QualifiedName)
1075     */

1076    public boolean visit(QualifiedName node) {
1077        node.getQualifier().accept(this);
1078        this.buffer.append(".");//$NON-NLS-1$
1079
node.getName().accept(this);
1080        return false;
1081    }
1082
1083    /*
1084     * @see ASTVisitor#visit(QualifiedType)
1085     * @since 3.1
1086     */

1087    public boolean visit(QualifiedType node) {
1088        node.getQualifier().accept(this);
1089        this.buffer.append(".");//$NON-NLS-1$
1090
node.getName().accept(this);
1091        return false;
1092    }
1093
1094    /*
1095     * @see ASTVisitor#visit(ReturnStatement)
1096     */

1097    public boolean visit(ReturnStatement node) {
1098        printIndent();
1099        this.buffer.append("return");//$NON-NLS-1$
1100
if (node.getExpression() != null) {
1101            this.buffer.append(" ");//$NON-NLS-1$
1102
node.getExpression().accept(this);
1103        }
1104        this.buffer.append(";\n");//$NON-NLS-1$
1105
return false;
1106    }
1107
1108    /*
1109     * @see ASTVisitor#visit(SimpleName)
1110     */

1111    public boolean visit(SimpleName node) {
1112        this.buffer.append(node.getIdentifier());
1113        return false;
1114    }
1115
1116    /*
1117     * @see ASTVisitor#visit(SimpleType)
1118     */

1119    public boolean visit(SimpleType node) {
1120        return true;
1121    }
1122
1123    /*
1124     * @see ASTVisitor#visit(SingleMemberAnnotation)
1125     * @since 3.1
1126     */

1127    public boolean visit(SingleMemberAnnotation node) {
1128        this.buffer.append("@");//$NON-NLS-1$
1129
node.getTypeName().accept(this);
1130        this.buffer.append("(");//$NON-NLS-1$
1131
node.getValue().accept(this);
1132        this.buffer.append(")");//$NON-NLS-1$
1133
return false;
1134    }
1135    
1136    /*
1137     * @see ASTVisitor#visit(SingleVariableDeclaration)
1138     */

1139    public boolean visit(SingleVariableDeclaration node) {
1140        printIndent();
1141        if (node.getAST().apiLevel() == AST.JLS2_INTERNAL) {
1142            printModifiers(node.getModifiers());
1143        }
1144        if (node.getAST().apiLevel() >= AST.JLS3) {
1145            printModifiers(node.modifiers());
1146        }
1147        node.getType().accept(this);
1148        if (node.getAST().apiLevel() >= AST.JLS3) {
1149            if (node.isVarargs()) {
1150                this.buffer.append("...");//$NON-NLS-1$
1151
}
1152        }
1153        this.buffer.append(" ");//$NON-NLS-1$
1154
node.getName().accept(this);
1155        for (int i = 0; i < node.getExtraDimensions(); i++) {
1156            this.buffer.append("[]"); //$NON-NLS-1$
1157
}
1158        if (node.getInitializer() != null) {
1159            this.buffer.append("=");//$NON-NLS-1$
1160
node.getInitializer().accept(this);
1161        }
1162        return false;
1163    }
1164
1165    /*
1166     * @see ASTVisitor#visit(StringLiteral)
1167     */

1168    public boolean visit(StringLiteral node) {
1169        this.buffer.append(node.getEscapedValue());
1170        return false;
1171    }
1172
1173    /*
1174     * @see ASTVisitor#visit(SuperConstructorInvocation)
1175     */

1176    public boolean visit(SuperConstructorInvocation node) {
1177        printIndent();
1178        if (node.getExpression() != null) {
1179            node.getExpression().accept(this);
1180            this.buffer.append(".");//$NON-NLS-1$
1181
}
1182        if (node.getAST().apiLevel() >= AST.JLS3) {
1183            if (!node.typeArguments().isEmpty()) {
1184                this.buffer.append("<");//$NON-NLS-1$
1185
for (Iterator JavaDoc it = node.typeArguments().iterator(); it.hasNext(); ) {
1186                    Type t = (Type) it.next();
1187                    t.accept(this);
1188                    if (it.hasNext()) {
1189                        this.buffer.append(",");//$NON-NLS-1$
1190
}
1191                }
1192                this.buffer.append(">");//$NON-NLS-1$
1193
}
1194        }
1195        this.buffer.append("super(");//$NON-NLS-1$
1196
for (Iterator JavaDoc it = node.arguments().iterator(); it.hasNext(); ) {
1197            Expression e = (Expression) it.next();
1198            e.accept(this);
1199            if (it.hasNext()) {
1200                this.buffer.append(",");//$NON-NLS-1$
1201
}
1202        }
1203        this.buffer.append(");\n");//$NON-NLS-1$
1204
return false;
1205    }
1206
1207    /*
1208     * @see ASTVisitor#visit(SuperFieldAccess)
1209     */

1210    public boolean visit(SuperFieldAccess node) {
1211        if (node.getQualifier() != null) {
1212            node.getQualifier().accept(this);
1213            this.buffer.append(".");//$NON-NLS-1$
1214
}
1215        this.buffer.append("super.");//$NON-NLS-1$
1216
node.getName().accept(this);
1217        return false;
1218    }
1219
1220    /*
1221     * @see ASTVisitor#visit(SuperMethodInvocation)
1222     */

1223    public boolean visit(SuperMethodInvocation node) {
1224        if (node.getQualifier() != null) {
1225            node.getQualifier().accept(this);
1226            this.buffer.append(".");//$NON-NLS-1$
1227
}
1228        this.buffer.append("super.");//$NON-NLS-1$
1229
if (node.getAST().apiLevel() >= AST.JLS3) {
1230            if (!node.typeArguments().isEmpty()) {
1231                this.buffer.append("<");//$NON-NLS-1$
1232
for (Iterator JavaDoc it = node.typeArguments().iterator(); it.hasNext(); ) {
1233                    Type t = (Type) it.next();
1234                    t.accept(this);
1235                    if (it.hasNext()) {
1236                        this.buffer.append(",");//$NON-NLS-1$
1237
}
1238                }
1239                this.buffer.append(">");//$NON-NLS-1$
1240
}
1241        }
1242        node.getName().accept(this);
1243        this.buffer.append("(");//$NON-NLS-1$
1244
for (Iterator JavaDoc it = node.arguments().iterator(); it.hasNext(); ) {
1245            Expression e = (Expression) it.next();
1246            e.accept(this);
1247            if (it.hasNext()) {
1248                this.buffer.append(",");//$NON-NLS-1$
1249
}
1250        }
1251        this.buffer.append(")");//$NON-NLS-1$
1252
return false;
1253    }
1254
1255    /*
1256     * @see ASTVisitor#visit(SwitchCase)
1257     */

1258    public boolean visit(SwitchCase node) {
1259        if (node.isDefault()) {
1260            this.buffer.append("default :\n");//$NON-NLS-1$
1261
} else {
1262            this.buffer.append("case ");//$NON-NLS-1$
1263
node.getExpression().accept(this);
1264            this.buffer.append(":\n");//$NON-NLS-1$
1265
}
1266        this.indent++; //decremented in visit(SwitchStatement)
1267
return false;
1268    }
1269
1270    /*
1271     * @see ASTVisitor#visit(SwitchStatement)
1272     */

1273    public boolean visit(SwitchStatement node) {
1274        this.buffer.append("switch (");//$NON-NLS-1$
1275
node.getExpression().accept(this);
1276        this.buffer.append(") ");//$NON-NLS-1$
1277
this.buffer.append("{\n");//$NON-NLS-1$
1278
this.indent++;
1279        for (Iterator JavaDoc it = node.statements().iterator(); it.hasNext(); ) {
1280            Statement s = (Statement) it.next();
1281            s.accept(this);
1282            this.indent--; // incremented in visit(SwitchCase)
1283
}
1284        this.indent--;
1285        printIndent();
1286        this.buffer.append("}\n");//$NON-NLS-1$
1287
return false;
1288    }
1289
1290    /*
1291     * @see ASTVisitor#visit(SynchronizedStatement)
1292     */

1293    public boolean visit(SynchronizedStatement node) {
1294        this.buffer.append("synchronized (");//$NON-NLS-1$
1295
node.getExpression().accept(this);
1296        this.buffer.append(") ");//$NON-NLS-1$
1297
node.getBody().accept(this);
1298        return false;
1299    }
1300
1301    /*
1302     * @see ASTVisitor#visit(TagElement)
1303     * @since 3.0
1304     */

1305    public boolean visit(TagElement node) {
1306        if (node.isNested()) {
1307            // nested tags are always enclosed in braces
1308
this.buffer.append("{");//$NON-NLS-1$
1309
} else {
1310            // top-level tags always begin on a new line
1311
this.buffer.append("\n * ");//$NON-NLS-1$
1312
}
1313        boolean previousRequiresWhiteSpace = false;
1314        if (node.getTagName() != null) {
1315            this.buffer.append(node.getTagName());
1316            previousRequiresWhiteSpace = true;
1317        }
1318        boolean previousRequiresNewLine = false;
1319        for (Iterator JavaDoc it = node.fragments().iterator(); it.hasNext(); ) {
1320            ASTNode e = (ASTNode) it.next();
1321            // assume text elements include necessary leading and trailing whitespace
1322
// but Name, MemberRef, MethodRef, and nested TagElement do not include white space
1323
boolean currentIncludesWhiteSpace = (e instanceof TextElement);
1324            if (previousRequiresNewLine && currentIncludesWhiteSpace) {
1325                this.buffer.append("\n * ");//$NON-NLS-1$
1326
}
1327            previousRequiresNewLine = currentIncludesWhiteSpace;
1328            // add space if required to separate
1329
if (previousRequiresWhiteSpace && !currentIncludesWhiteSpace) {
1330                this.buffer.append(" "); //$NON-NLS-1$
1331
}
1332            e.accept(this);
1333            previousRequiresWhiteSpace = !currentIncludesWhiteSpace && !(e instanceof TagElement);
1334        }
1335        if (node.isNested()) {
1336            this.buffer.append("}");//$NON-NLS-1$
1337
}
1338        return false;
1339    }
1340    
1341    /*
1342     * @see ASTVisitor#visit(TextElement)
1343     * @since 3.0
1344     */

1345    public boolean visit(TextElement node) {
1346        this.buffer.append(node.getText());
1347        return false;
1348    }
1349    
1350    /*
1351     * @see ASTVisitor#visit(ThisExpression)
1352     */

1353    public boolean visit(ThisExpression node) {
1354        if (node.getQualifier() != null) {
1355            node.getQualifier().accept(this);
1356            this.buffer.append(".");//$NON-NLS-1$
1357
}
1358        this.buffer.append("this");//$NON-NLS-1$
1359
return false;
1360    }
1361
1362    /*
1363     * @see ASTVisitor#visit(ThrowStatement)
1364     */

1365    public boolean visit(ThrowStatement node) {
1366        printIndent();
1367        this.buffer.append("throw ");//$NON-NLS-1$
1368
node.getExpression().accept(this);
1369        this.buffer.append(";\n");//$NON-NLS-1$
1370
return false;
1371    }
1372
1373    /*
1374     * @see ASTVisitor#visit(TryStatement)
1375     */

1376    public boolean visit(TryStatement node) {
1377        printIndent();
1378        this.buffer.append("try ");//$NON-NLS-1$
1379
node.getBody().accept(this);
1380        this.buffer.append(" ");//$NON-NLS-1$
1381
for (Iterator JavaDoc it = node.catchClauses().iterator(); it.hasNext(); ) {
1382            CatchClause cc = (CatchClause) it.next();
1383            cc.accept(this);
1384        }
1385        if (node.getFinally() != null) {
1386            this.buffer.append(" finally ");//$NON-NLS-1$
1387
node.getFinally().accept(this);
1388        }
1389        return false;
1390    }
1391
1392    /*
1393     * @see ASTVisitor#visit(TypeDeclaration)
1394     */

1395    public boolean visit(TypeDeclaration node) {
1396        if (node.getJavadoc() != null) {
1397            node.getJavadoc().accept(this);
1398        }
1399        if (node.getAST().apiLevel() == AST.JLS2_INTERNAL) {
1400            printModifiers(node.getModifiers());
1401        }
1402        if (node.getAST().apiLevel() >= AST.JLS3) {
1403            printModifiers(node.modifiers());
1404        }
1405        this.buffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$
1406
node.getName().accept(this);
1407        if (node.getAST().apiLevel() >= AST.JLS3) {
1408            if (!node.typeParameters().isEmpty()) {
1409                this.buffer.append("<");//$NON-NLS-1$
1410
for (Iterator JavaDoc it = node.typeParameters().iterator(); it.hasNext(); ) {
1411                    TypeParameter t = (TypeParameter) it.next();
1412                    t.accept(this);
1413                    if (it.hasNext()) {
1414                        this.buffer.append(",");//$NON-NLS-1$
1415
}
1416                }
1417                this.buffer.append(">");//$NON-NLS-1$
1418
}
1419        }
1420        this.buffer.append(" ");//$NON-NLS-1$
1421
if (node.getAST().apiLevel() == AST.JLS2_INTERNAL) {
1422            if (node.internalGetSuperclass() != null) {
1423                this.buffer.append("extends ");//$NON-NLS-1$
1424
node.internalGetSuperclass().accept(this);
1425                this.buffer.append(" ");//$NON-NLS-1$
1426
}
1427            if (!node.internalSuperInterfaces().isEmpty()) {
1428                this.buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
1429
for (Iterator JavaDoc it = node.internalSuperInterfaces().iterator(); it.hasNext(); ) {
1430                    Name n = (Name) it.next();
1431                    n.accept(this);
1432                    if (it.hasNext()) {
1433                        this.buffer.append(", ");//$NON-NLS-1$
1434
}
1435                }
1436                this.buffer.append(" ");//$NON-NLS-1$
1437
}
1438        }
1439        if (node.getAST().apiLevel() >= AST.JLS3) {
1440            if (node.getSuperclassType() != null) {
1441                this.buffer.append("extends ");//$NON-NLS-1$
1442
node.getSuperclassType().accept(this);
1443                this.buffer.append(" ");//$NON-NLS-1$
1444
}
1445            if (!node.superInterfaceTypes().isEmpty()) {
1446                this.buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
1447
for (Iterator JavaDoc it = node.superInterfaceTypes().iterator(); it.hasNext(); ) {
1448                    Type t = (Type) it.next();
1449                    t.accept(this);
1450                    if (it.hasNext()) {
1451                        this.buffer.append(", ");//$NON-NLS-1$
1452
}
1453                }
1454                this.buffer.append(" ");//$NON-NLS-1$
1455
}
1456        }
1457        this.buffer.append("{\n");//$NON-NLS-1$
1458
this.indent++;
1459        for (Iterator JavaDoc it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
1460            BodyDeclaration d = (BodyDeclaration) it.next();
1461            d.accept(this);
1462        }
1463        this.indent--;
1464        printIndent();
1465        this.buffer.append("}\n");//$NON-NLS-1$
1466
return false;
1467    }
1468
1469    /*
1470     * @see ASTVisitor#visit(TypeDeclarationStatement)
1471     */

1472    public boolean visit(TypeDeclarationStatement node) {
1473        if (node.getAST().apiLevel() == AST.JLS2_INTERNAL) {
1474            node.internalGetTypeDeclaration().accept(this);
1475        }
1476        if (node.getAST().apiLevel() >= AST.JLS3) {
1477            node.getDeclaration().accept(this);
1478        }
1479        return false;
1480    }
1481
1482    /*
1483     * @see ASTVisitor#visit(TypeLiteral)
1484     */

1485    public boolean visit(TypeLiteral node) {
1486        node.getType().accept(this);
1487        this.buffer.append(".class");//$NON-NLS-1$
1488
return false;
1489    }
1490
1491    /*
1492     * @see ASTVisitor#visit(TypeParameter)
1493     * @since 3.1
1494     */

1495    public boolean visit(TypeParameter node) {
1496        node.getName().accept(this);
1497        if (!node.typeBounds().isEmpty()) {
1498            this.buffer.append(" extends ");//$NON-NLS-1$
1499
for (Iterator JavaDoc it = node.typeBounds().iterator(); it.hasNext(); ) {
1500                Type t = (Type) it.next();
1501                t.accept(this);
1502                if (it.hasNext()) {
1503                    this.buffer.append(" & ");//$NON-NLS-1$
1504
}
1505            }
1506        }
1507        return false;
1508    }
1509
1510    /*
1511     * @see ASTVisitor#visit(VariableDeclarationExpression)
1512     */

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

1535    public boolean visit(VariableDeclarationFragment node) {
1536        node.getName().accept(this);
1537        for (int i = 0; i < node.getExtraDimensions(); i++) {
1538            this.buffer.append("[]");//$NON-NLS-1$
1539
}
1540        if (node.getInitializer() != null) {
1541            this.buffer.append("=");//$NON-NLS-1$
1542
node.getInitializer().accept(this);
1543        }
1544        return false;
1545    }
1546
1547    /*
1548     * @see ASTVisitor#visit(VariableDeclarationStatement)
1549     */

1550    public boolean visit(VariableDeclarationStatement node) {
1551        printIndent();
1552        if (node.getAST().apiLevel() == AST.JLS2_INTERNAL) {
1553            printModifiers(node.getModifiers());
1554        }
1555        if (node.getAST().apiLevel() >= AST.JLS3) {
1556            printModifiers(node.modifiers());
1557        }
1558        node.getType().accept(this);
1559        this.buffer.append(" ");//$NON-NLS-1$
1560
for (Iterator JavaDoc it = node.fragments().iterator(); it.hasNext(); ) {
1561            VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
1562            f.accept(this);
1563            if (it.hasNext()) {
1564                this.buffer.append(", ");//$NON-NLS-1$
1565
}
1566        }
1567        this.buffer.append(";\n");//$NON-NLS-1$
1568
return false;
1569    }
1570
1571    /*
1572     * @see ASTVisitor#visit(WildcardType)
1573     * @since 3.1
1574     */

1575    public boolean visit(WildcardType node) {
1576        this.buffer.append("?");//$NON-NLS-1$
1577
Type bound = node.getBound();
1578        if (bound != null) {
1579            if (node.isUpperBound()) {
1580                this.buffer.append(" extends ");//$NON-NLS-1$
1581
} else {
1582                this.buffer.append(" super ");//$NON-NLS-1$
1583
}
1584            bound.accept(this);
1585        }
1586        return false;
1587    }
1588
1589    /*
1590     * @see ASTVisitor#visit(WhileStatement)
1591     */

1592    public boolean visit(WhileStatement node) {
1593        printIndent();
1594        this.buffer.append("while (");//$NON-NLS-1$
1595
node.getExpression().accept(this);
1596        this.buffer.append(") ");//$NON-NLS-1$
1597
node.getBody().accept(this);
1598        return false;
1599    }
1600
1601}
1602
Popular Tags