1 /*******************************************************************************
2 * Copyright (c) 2000, 2008 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
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core.dom;
13 import java.util.Iterator;
14 import java.util.List;
16 import net.sourceforge.phpdt.core.dom.AST;
17 import net.sourceforge.phpdt.core.dom.ASTNode;
18 import net.sourceforge.phpdt.core.dom.ASTVisitor;
19 import net.sourceforge.phpdt.core.dom.AbstractTypeDeclaration;
20 import net.sourceforge.phpdt.core.dom.Annotation;
21 import net.sourceforge.phpdt.core.dom.AnnotationTypeDeclaration;
22 import net.sourceforge.phpdt.core.dom.AnnotationTypeMemberDeclaration;
23 import net.sourceforge.phpdt.core.dom.AnonymousClassDeclaration;
24 import net.sourceforge.phpdt.core.dom.ArrayAccess;
25 import net.sourceforge.phpdt.core.dom.ArrayCreation;
26 import net.sourceforge.phpdt.core.dom.ArrayInitializer;
27 import net.sourceforge.phpdt.core.dom.ArrayType;
28 import net.sourceforge.phpdt.core.dom.AssertStatement;
29 import net.sourceforge.phpdt.core.dom.Assignment;
30 import net.sourceforge.phpdt.core.dom.Block;
31 import net.sourceforge.phpdt.core.dom.BlockComment;
32 import net.sourceforge.phpdt.core.dom.BodyDeclaration;
33 import net.sourceforge.phpdt.core.dom.BooleanLiteral;
34 import net.sourceforge.phpdt.core.dom.BreakStatement;
35 import net.sourceforge.phpdt.core.dom.CastExpression;
36 import net.sourceforge.phpdt.core.dom.CatchClause;
37 import net.sourceforge.phpdt.core.dom.CharacterLiteral;
38 import net.sourceforge.phpdt.core.dom.ClassInstanceCreation;
39 import net.sourceforge.phpdt.core.dom.CompilationUnit;
40 import net.sourceforge.phpdt.core.dom.ConditionalExpression;
41 import net.sourceforge.phpdt.core.dom.ConstructorInvocation;
42 import net.sourceforge.phpdt.core.dom.ContinueStatement;
43 import net.sourceforge.phpdt.core.dom.DoStatement;
44 import net.sourceforge.phpdt.core.dom.EmptyStatement;
45 import net.sourceforge.phpdt.core.dom.EnhancedForStatement;
46 import net.sourceforge.phpdt.core.dom.EnumConstantDeclaration;
47 import net.sourceforge.phpdt.core.dom.EnumDeclaration;
48 import net.sourceforge.phpdt.core.dom.Expression;
49 import net.sourceforge.phpdt.core.dom.ExpressionStatement;
50 import net.sourceforge.phpdt.core.dom.FieldAccess;
51 import net.sourceforge.phpdt.core.dom.FieldDeclaration;
52 import net.sourceforge.phpdt.core.dom.ForStatement;
53 import net.sourceforge.phpdt.core.dom.IfStatement;
54 import net.sourceforge.phpdt.core.dom.ImportDeclaration;
55 import net.sourceforge.phpdt.core.dom.InfixExpression;
56 import net.sourceforge.phpdt.core.dom.Initializer;
57 import net.sourceforge.phpdt.core.dom.InstanceofExpression;
58 import net.sourceforge.phpdt.core.dom.Javadoc;
59 import net.sourceforge.phpdt.core.dom.LabeledStatement;
60 import net.sourceforge.phpdt.core.dom.LineComment;
61 import net.sourceforge.phpdt.core.dom.MarkerAnnotation;
62 import net.sourceforge.phpdt.core.dom.MemberRef;
63 import net.sourceforge.phpdt.core.dom.MemberValuePair;
64 import net.sourceforge.phpdt.core.dom.MethodDeclaration;
65 import net.sourceforge.phpdt.core.dom.MethodInvocation;
66 import net.sourceforge.phpdt.core.dom.MethodRef;
67 import net.sourceforge.phpdt.core.dom.MethodRefParameter;
68 import net.sourceforge.phpdt.core.dom.Modifier;
69 import net.sourceforge.phpdt.core.dom.Name;
70 import net.sourceforge.phpdt.core.dom.NormalAnnotation;
71 import net.sourceforge.phpdt.core.dom.NullLiteral;
72 import net.sourceforge.phpdt.core.dom.NumberLiteral;
73 import net.sourceforge.phpdt.core.dom.PackageDeclaration;
74 import net.sourceforge.phpdt.core.dom.ParameterizedType;
75 import net.sourceforge.phpdt.core.dom.ParenthesizedExpression;
76 import net.sourceforge.phpdt.core.dom.PostfixExpression;
77 import net.sourceforge.phpdt.core.dom.PrefixExpression;
78 import net.sourceforge.phpdt.core.dom.PrimitiveType;
79 import net.sourceforge.phpdt.core.dom.QualifiedName;
80 import net.sourceforge.phpdt.core.dom.QualifiedType;
81 import net.sourceforge.phpdt.core.dom.ReturnStatement;
82 import net.sourceforge.phpdt.core.dom.SimpleName;
83 import net.sourceforge.phpdt.core.dom.SimpleType;
84 import net.sourceforge.phpdt.core.dom.SingleMemberAnnotation;
85 import net.sourceforge.phpdt.core.dom.SingleVariableDeclaration;
86 import net.sourceforge.phpdt.core.dom.Statement;
87 import net.sourceforge.phpdt.core.dom.StringLiteral;
88 import net.sourceforge.phpdt.core.dom.SuperConstructorInvocation;
89 import net.sourceforge.phpdt.core.dom.SuperFieldAccess;
90 import net.sourceforge.phpdt.core.dom.SuperMethodInvocation;
91 import net.sourceforge.phpdt.core.dom.SwitchCase;
92 import net.sourceforge.phpdt.core.dom.SwitchStatement;
93 import net.sourceforge.phpdt.core.dom.SynchronizedStatement;
94 import net.sourceforge.phpdt.core.dom.TagElement;
95 import net.sourceforge.phpdt.core.dom.TextElement;
96 import net.sourceforge.phpdt.core.dom.ThisExpression;
97 import net.sourceforge.phpdt.core.dom.ThrowStatement;
98 import net.sourceforge.phpdt.core.dom.TryStatement;
99 import net.sourceforge.phpdt.core.dom.Type;
100 import net.sourceforge.phpdt.core.dom.TypeDeclaration;
101 import net.sourceforge.phpdt.core.dom.TypeDeclarationStatement;
102 import net.sourceforge.phpdt.core.dom.TypeLiteral;
103 import net.sourceforge.phpdt.core.dom.TypeParameter;
104 import net.sourceforge.phpdt.core.dom.VariableDeclarationExpression;
105 import net.sourceforge.phpdt.core.dom.VariableDeclarationFragment;
106 import net.sourceforge.phpdt.core.dom.VariableDeclarationStatement;
107 import net.sourceforge.phpdt.core.dom.WhileStatement;
108 import net.sourceforge.phpdt.core.dom.WildcardType;
111 * Internal AST visitor for serializing an AST in a quick and dirty fashion.
112 * For various reasons the resulting string is not necessarily legal
113 * Java code; and even if it is legal Java code, it is not necessarily the string
114 * that corresponds to the given AST. Although useless for most purposes, it's
115 * fine for generating debug print strings.
120 * NaiveASTFlattener p = new NaiveASTFlattener();
122 * String result = p.getResult();
125 * Call the <code>reset</code> method to clear the previous result before reusing an
131 public class NaiveASTFlattener extends ASTVisitor {
133 * Internal synonym for {@link AST#JLS2}. Use to alleviate
134 * deprecation warnings.
138 private static final int JLS2 = AST.JLS2;
141 * The string buffer into which the serialized representation of the AST is
144 protected StringBuffer buffer;
146 private int indent = 0;
149 * Creates a new AST printer.
151 public NaiveASTFlattener() {
152 this.buffer = new StringBuffer();
156 * Internal synonym for {@link ClassInstanceCreation#getName()}. Use to alleviate
157 * deprecation warnings.
161 private Name getName(ClassInstanceCreation node) {
162 return node.getName();
166 * Returns the string accumulated in the visit.
168 * @return the serialized
170 public String getResult() {
171 return this.buffer.toString();
175 * Internal synonym for {@link MethodDeclaration#getReturnType()}. Use to alleviate
176 * deprecation warnings.
180 private Type getReturnType(MethodDeclaration node) {
181 return node.getReturnType();
185 * Internal synonym for {@link TypeDeclaration#getSuperclass()}. Use to alleviate
186 * deprecation warnings.
190 private Name getSuperclass(TypeDeclaration node) {
191 return node.getSuperclass();
195 * Internal synonym for {@link TypeDeclarationStatement#getTypeDeclaration()}. Use to alleviate
196 * deprecation warnings.
200 private TypeDeclaration getTypeDeclaration(TypeDeclarationStatement node) {
201 return node.getTypeDeclaration();
205 for (int i = 0; i < this.indent; i++)
206 this.buffer.append(" "); //$NON-NLS-1$
210 * Appends the text representation of the given modifier flags, followed by a single space.
211 * Used for JLS2 modifiers.
213 * @param modifiers the modifier flags
215 void printModifiers(int modifiers) {
216 if (Modifier.isPublic(modifiers)) {
217 this.buffer.append("public ");//$NON-NLS-1$
219 if (Modifier.isProtected(modifiers)) {
220 this.buffer.append("protected ");//$NON-NLS-1$
222 if (Modifier.isPrivate(modifiers)) {
223 this.buffer.append("private ");//$NON-NLS-1$
225 if (Modifier.isStatic(modifiers)) {
226 this.buffer.append("static ");//$NON-NLS-1$
228 if (Modifier.isAbstract(modifiers)) {
229 this.buffer.append("abstract ");//$NON-NLS-1$
231 if (Modifier.isFinal(modifiers)) {
232 this.buffer.append("final ");//$NON-NLS-1$
234 if (Modifier.isSynchronized(modifiers)) {
235 this.buffer.append("synchronized ");//$NON-NLS-1$
237 if (Modifier.isVolatile(modifiers)) {
238 this.buffer.append("volatile ");//$NON-NLS-1$
240 if (Modifier.isNative(modifiers)) {
241 this.buffer.append("native ");//$NON-NLS-1$
243 if (Modifier.isStrictfp(modifiers)) {
244 this.buffer.append("strictfp ");//$NON-NLS-1$
246 if (Modifier.isTransient(modifiers)) {
247 this.buffer.append("transient ");//$NON-NLS-1$
252 * Appends the text representation of the given modifier flags, followed by a single space.
253 * Used for 3.0 modifiers and annotations.
255 * @param ext the list of modifier and annotation nodes
256 * (element type: <code>IExtendedModifiers</code>)
258 void printModifiers(List ext) {
259 for (Iterator it = ext.iterator(); it.hasNext(); ) {
260 ASTNode p = (ASTNode) it.next();
262 this.buffer.append(" ");//$NON-NLS-1$
267 * Resets this printer so that it can be used again.
269 public void reset() {
270 this.buffer.setLength(0);
274 * Internal synonym for {@link TypeDeclaration#superInterfaces()}. Use to alleviate
275 * deprecation warnings.
279 private List superInterfaces(TypeDeclaration node) {
280 return node.superInterfaces();
284 * @see ASTVisitor#visit(AnnotationTypeDeclaration)
287 public boolean visit(AnnotationTypeDeclaration node) {
288 if (node.getJavadoc() != null) {
289 node.getJavadoc().accept(this);
292 printModifiers(node.modifiers());
293 this.buffer.append("@interface ");//$NON-NLS-1$
294 node.getName().accept(this);
295 this.buffer.append(" {");//$NON-NLS-1$
296 for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
297 BodyDeclaration d = (BodyDeclaration) it.next();
300 this.buffer.append("}\n");//$NON-NLS-1$
305 * @see ASTVisitor#visit(AnnotationTypeMemberDeclaration)
308 public boolean visit(AnnotationTypeMemberDeclaration node) {
309 if (node.getJavadoc() != null) {
310 node.getJavadoc().accept(this);
313 printModifiers(node.modifiers());
314 node.getType().accept(this);
315 this.buffer.append(" ");//$NON-NLS-1$
316 node.getName().accept(this);
317 this.buffer.append("()");//$NON-NLS-1$
318 if (node.getDefault() != null) {
319 this.buffer.append(" default ");//$NON-NLS-1$
320 node.getDefault().accept(this);
322 this.buffer.append(";\n");//$NON-NLS-1$
327 * @see ASTVisitor#visit(AnonymousClassDeclaration)
329 public boolean visit(AnonymousClassDeclaration node) {
330 this.buffer.append("{\n");//$NON-NLS-1$
332 for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
333 BodyDeclaration b = (BodyDeclaration) it.next();
338 this.buffer.append("}\n");//$NON-NLS-1$
343 * @see ASTVisitor#visit(ArrayAccess)
345 public boolean visit(ArrayAccess node) {
346 node.getArray().accept(this);
347 this.buffer.append("[");//$NON-NLS-1$
348 node.getIndex().accept(this);
349 this.buffer.append("]");//$NON-NLS-1$
354 * @see ASTVisitor#visit(ArrayCreation)
356 public boolean visit(ArrayCreation node) {
357 this.buffer.append("new ");//$NON-NLS-1$
358 ArrayType at = node.getType();
359 int dims = at.getDimensions();
360 Type elementType = at.getElementType();
361 elementType.accept(this);
362 for (Iterator it = node.dimensions().iterator(); it.hasNext(); ) {
363 this.buffer.append("[");//$NON-NLS-1$
364 Expression e = (Expression) it.next();
366 this.buffer.append("]");//$NON-NLS-1$
369 // add empty "[]" for each extra array dimension
370 for (int i= 0; i < dims; i++) {
371 this.buffer.append("[]");//$NON-NLS-1$
373 if (node.getInitializer() != null) {
374 node.getInitializer().accept(this);
380 * @see ASTVisitor#visit(ArrayInitializer)
382 public boolean visit(ArrayInitializer node) {
383 this.buffer.append("{");//$NON-NLS-1$
384 for (Iterator it = node.expressions().iterator(); it.hasNext(); ) {
385 Expression e = (Expression) it.next();
388 this.buffer.append(",");//$NON-NLS-1$
391 this.buffer.append("}");//$NON-NLS-1$
396 * @see ASTVisitor#visit(ArrayType)
398 public boolean visit(ArrayType node) {
399 node.getComponentType().accept(this);
400 this.buffer.append("[]");//$NON-NLS-1$
405 * @see ASTVisitor#visit(AssertStatement)
407 public boolean visit(AssertStatement node) {
409 this.buffer.append("assert ");//$NON-NLS-1$
410 node.getExpression().accept(this);
411 if (node.getMessage() != null) {
412 this.buffer.append(" : ");//$NON-NLS-1$
413 node.getMessage().accept(this);
415 this.buffer.append(";\n");//$NON-NLS-1$
420 * @see ASTVisitor#visit(Assignment)
422 public boolean visit(Assignment node) {
423 node.getLeftHandSide().accept(this);
424 this.buffer.append(node.getOperator().toString());
425 node.getRightHandSide().accept(this);
430 * @see ASTVisitor#visit(Block)
432 public boolean visit(Block node) {
433 this.buffer.append("{\n");//$NON-NLS-1$
435 for (Iterator it = node.statements().iterator(); it.hasNext(); ) {
436 Statement s = (Statement) it.next();
441 this.buffer.append("}\n");//$NON-NLS-1$
446 * @see ASTVisitor#visit(BlockComment)
449 public boolean visit(BlockComment node) {
451 this.buffer.append("/* */");//$NON-NLS-1$
456 * @see ASTVisitor#visit(BooleanLiteral)
458 public boolean visit(BooleanLiteral node) {
459 if (node.booleanValue() == true) {
460 this.buffer.append("true");//$NON-NLS-1$
462 this.buffer.append("false");//$NON-NLS-1$
468 * @see ASTVisitor#visit(BreakStatement)
470 public boolean visit(BreakStatement node) {
472 this.buffer.append("break");//$NON-NLS-1$
473 if (node.getLabel() != null) {
474 this.buffer.append(" ");//$NON-NLS-1$
475 node.getLabel().accept(this);
477 this.buffer.append(";\n");//$NON-NLS-1$
482 * @see ASTVisitor#visit(CastExpression)
484 public boolean visit(CastExpression node) {
485 this.buffer.append("(");//$NON-NLS-1$
486 node.getType().accept(this);
487 this.buffer.append(")");//$NON-NLS-1$
488 node.getExpression().accept(this);
493 * @see ASTVisitor#visit(CatchClause)
495 public boolean visit(CatchClause node) {
496 this.buffer.append("catch (");//$NON-NLS-1$
497 node.getException().accept(this);
498 this.buffer.append(") ");//$NON-NLS-1$
499 node.getBody().accept(this);
504 * @see ASTVisitor#visit(CharacterLiteral)
506 public boolean visit(CharacterLiteral node) {
507 this.buffer.append(node.getEscapedValue());
512 * @see ASTVisitor#visit(ClassInstanceCreation)
514 public boolean visit(ClassInstanceCreation node) {
515 if (node.getExpression() != null) {
516 node.getExpression().accept(this);
517 this.buffer.append(".");//$NON-NLS-1$
519 this.buffer.append("new ");//$NON-NLS-1$
520 if (node.getAST().apiLevel() == JLS2) {
521 this.getName(node).accept(this);
523 if (node.getAST().apiLevel() >= AST.JLS3) {
524 if (!node.typeArguments().isEmpty()) {
525 this.buffer.append("<");//$NON-NLS-1$
526 for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) {
527 Type t = (Type) it.next();
530 this.buffer.append(",");//$NON-NLS-1$
533 this.buffer.append(">");//$NON-NLS-1$
535 node.getType().accept(this);
537 this.buffer.append("(");//$NON-NLS-1$
538 for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
539 Expression e = (Expression) it.next();
542 this.buffer.append(",");//$NON-NLS-1$
545 this.buffer.append(")");//$NON-NLS-1$
546 if (node.getAnonymousClassDeclaration() != null) {
547 node.getAnonymousClassDeclaration().accept(this);
553 * @see ASTVisitor#visit(CompilationUnit)
555 public boolean visit(CompilationUnit node) {
556 if (node.getPackage() != null) {
557 node.getPackage().accept(this);
559 for (Iterator it = node.imports().iterator(); it.hasNext(); ) {
560 ImportDeclaration d = (ImportDeclaration) it.next();
563 for (Iterator it = node.types().iterator(); it.hasNext(); ) {
564 AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next();
571 * @see ASTVisitor#visit(ConditionalExpression)
573 public boolean visit(ConditionalExpression node) {
574 node.getExpression().accept(this);
575 this.buffer.append(" ? ");//$NON-NLS-1$
576 node.getThenExpression().accept(this);
577 this.buffer.append(" : ");//$NON-NLS-1$
578 node.getElseExpression().accept(this);
583 * @see ASTVisitor#visit(ConstructorInvocation)
585 public boolean visit(ConstructorInvocation node) {
587 if (node.getAST().apiLevel() >= AST.JLS3) {
588 if (!node.typeArguments().isEmpty()) {
589 this.buffer.append("<");//$NON-NLS-1$
590 for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) {
591 Type t = (Type) it.next();
594 this.buffer.append(",");//$NON-NLS-1$
597 this.buffer.append(">");//$NON-NLS-1$
600 this.buffer.append("this(");//$NON-NLS-1$
601 for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
602 Expression e = (Expression) it.next();
605 this.buffer.append(",");//$NON-NLS-1$
608 this.buffer.append(");\n");//$NON-NLS-1$
613 * @see ASTVisitor#visit(ContinueStatement)
615 public boolean visit(ContinueStatement node) {
617 this.buffer.append("continue");//$NON-NLS-1$
618 if (node.getLabel() != null) {
619 this.buffer.append(" ");//$NON-NLS-1$
620 node.getLabel().accept(this);
622 this.buffer.append(";\n");//$NON-NLS-1$
627 * @see ASTVisitor#visit(DoStatement)
629 public boolean visit(DoStatement node) {
631 this.buffer.append("do ");//$NON-NLS-1$
632 node.getBody().accept(this);
633 this.buffer.append(" while (");//$NON-NLS-1$
634 node.getExpression().accept(this);
635 this.buffer.append(");\n");//$NON-NLS-1$
640 * @see ASTVisitor#visit(EmptyStatement)
642 public boolean visit(EmptyStatement node) {
644 this.buffer.append(";\n");//$NON-NLS-1$
649 * @see ASTVisitor#visit(EnhancedForStatement)
652 public boolean visit(EnhancedForStatement node) {
654 this.buffer.append("for (");//$NON-NLS-1$
655 node.getParameter().accept(this);
656 this.buffer.append(" : ");//$NON-NLS-1$
657 node.getExpression().accept(this);
658 this.buffer.append(") ");//$NON-NLS-1$
659 node.getBody().accept(this);
664 * @see ASTVisitor#visit(EnumConstantDeclaration)
667 public boolean visit(EnumConstantDeclaration node) {
668 if (node.getJavadoc() != null) {
669 node.getJavadoc().accept(this);
672 printModifiers(node.modifiers());
673 node.getName().accept(this);
674 if (!node.arguments().isEmpty()) {
675 this.buffer.append("(");//$NON-NLS-1$
676 for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
677 Expression e = (Expression) it.next();
680 this.buffer.append(",");//$NON-NLS-1$
683 this.buffer.append(")");//$NON-NLS-1$
685 if (node.getAnonymousClassDeclaration() != null) {
686 node.getAnonymousClassDeclaration().accept(this);
692 * @see ASTVisitor#visit(EnumDeclaration)
695 public boolean visit(EnumDeclaration node) {
696 if (node.getJavadoc() != null) {
697 node.getJavadoc().accept(this);
700 printModifiers(node.modifiers());
701 this.buffer.append("enum ");//$NON-NLS-1$
702 node.getName().accept(this);
703 this.buffer.append(" ");//$NON-NLS-1$
704 if (!node.superInterfaceTypes().isEmpty()) {
705 this.buffer.append("implements ");//$NON-NLS-1$
706 for (Iterator it = node.superInterfaceTypes().iterator(); it.hasNext(); ) {
707 Type t = (Type) it.next();
710 this.buffer.append(", ");//$NON-NLS-1$
713 this.buffer.append(" ");//$NON-NLS-1$
715 this.buffer.append("{");//$NON-NLS-1$
716 for (Iterator it = node.enumConstants().iterator(); it.hasNext(); ) {
717 EnumConstantDeclaration d = (EnumConstantDeclaration) it.next();
719 // enum constant declarations do not include punctuation
721 // enum constant declarations are separated by commas
722 this.buffer.append(", ");//$NON-NLS-1$
725 if (!node.bodyDeclarations().isEmpty()) {
726 this.buffer.append("; ");//$NON-NLS-1$
727 for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
728 BodyDeclaration d = (BodyDeclaration) it.next();
730 // other body declarations include trailing punctuation
733 this.buffer.append("}\n");//$NON-NLS-1$
738 * @see ASTVisitor#visit(ExpressionStatement)
740 public boolean visit(ExpressionStatement node) {
742 node.getExpression().accept(this);
743 this.buffer.append(";\n");//$NON-NLS-1$
748 * @see ASTVisitor#visit(FieldAccess)
750 public boolean visit(FieldAccess node) {
751 node.getExpression().accept(this);
752 this.buffer.append(".");//$NON-NLS-1$
753 node.getName().accept(this);
758 * @see ASTVisitor#visit(FieldDeclaration)
760 public boolean visit(FieldDeclaration node) {
761 if (node.getJavadoc() != null) {
762 node.getJavadoc().accept(this);
765 if (node.getAST().apiLevel() == JLS2) {
766 printModifiers(node.getModifiers());
768 if (node.getAST().apiLevel() >= AST.JLS3) {
769 printModifiers(node.modifiers());
771 node.getType().accept(this);
772 this.buffer.append(" ");//$NON-NLS-1$
773 for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
774 VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
777 this.buffer.append(", ");//$NON-NLS-1$
780 this.buffer.append(";\n");//$NON-NLS-1$
785 * @see ASTVisitor#visit(ForStatement)
787 public boolean visit(ForStatement node) {
789 this.buffer.append("for (");//$NON-NLS-1$
790 for (Iterator it = node.initializers().iterator(); it.hasNext(); ) {
791 Expression e = (Expression) it.next();
793 if (it.hasNext()) buffer.append(", ");//$NON-NLS-1$
795 this.buffer.append("; ");//$NON-NLS-1$
796 if (node.getExpression() != null) {
797 node.getExpression().accept(this);
799 this.buffer.append("; ");//$NON-NLS-1$
800 for (Iterator it = node.updaters().iterator(); it.hasNext(); ) {
801 Expression e = (Expression) it.next();
803 if (it.hasNext()) buffer.append(", ");//$NON-NLS-1$
805 this.buffer.append(") ");//$NON-NLS-1$
806 node.getBody().accept(this);
811 * @see ASTVisitor#visit(IfStatement)
813 public boolean visit(IfStatement node) {
815 this.buffer.append("if (");//$NON-NLS-1$
816 node.getExpression().accept(this);
817 this.buffer.append(") ");//$NON-NLS-1$
818 node.getThenStatement().accept(this);
819 if (node.getElseStatement() != null) {
820 this.buffer.append(" else ");//$NON-NLS-1$
821 node.getElseStatement().accept(this);
827 * @see ASTVisitor#visit(ImportDeclaration)
829 public boolean visit(ImportDeclaration node) {
831 this.buffer.append("import ");//$NON-NLS-1$
832 if (node.getAST().apiLevel() >= AST.JLS3) {
833 if (node.isStatic()) {
834 this.buffer.append("static ");//$NON-NLS-1$
837 node.getName().accept(this);
838 if (node.isOnDemand()) {
839 this.buffer.append(".*");//$NON-NLS-1$
841 this.buffer.append(";\n");//$NON-NLS-1$
846 * @see ASTVisitor#visit(InfixExpression)
848 public boolean visit(InfixExpression node) {
849 node.getLeftOperand().accept(this);
850 this.buffer.append(' '); // for cases like x= i - -1; or x= i++ + ++i;
851 this.buffer.append(node.getOperator().toString());
852 this.buffer.append(' ');
853 node.getRightOperand().accept(this);
854 final List extendedOperands = node.extendedOperands();
855 if (extendedOperands.size() != 0) {
856 this.buffer.append(' ');
857 for (Iterator it = extendedOperands.iterator(); it.hasNext(); ) {
858 this.buffer.append(node.getOperator().toString()).append(' ');
859 Expression e = (Expression) it.next();
867 * @see ASTVisitor#visit(Initializer)
869 public boolean visit(Initializer node) {
870 if (node.getJavadoc() != null) {
871 node.getJavadoc().accept(this);
873 if (node.getAST().apiLevel() == JLS2) {
874 printModifiers(node.getModifiers());
876 if (node.getAST().apiLevel() >= AST.JLS3) {
877 printModifiers(node.modifiers());
879 node.getBody().accept(this);
884 * @see ASTVisitor#visit(InstanceofExpression)
886 public boolean visit(InstanceofExpression node) {
887 node.getLeftOperand().accept(this);
888 this.buffer.append(" instanceof ");//$NON-NLS-1$
889 node.getRightOperand().accept(this);
894 * @see ASTVisitor#visit(Javadoc)
896 public boolean visit(Javadoc node) {
898 this.buffer.append("/** ");//$NON-NLS-1$
899 for (Iterator it = node.tags().iterator(); it.hasNext(); ) {
900 ASTNode e = (ASTNode) it.next();
903 this.buffer.append("\n */\n");//$NON-NLS-1$
908 * @see ASTVisitor#visit(LabeledStatement)
910 public boolean visit(LabeledStatement node) {
912 node.getLabel().accept(this);
913 this.buffer.append(": ");//$NON-NLS-1$
914 node.getBody().accept(this);
919 * @see ASTVisitor#visit(LineComment)
922 public boolean visit(LineComment node) {
923 this.buffer.append("//\n");//$NON-NLS-1$
928 * @see ASTVisitor#visit(MarkerAnnotation)
931 public boolean visit(MarkerAnnotation node) {
932 this.buffer.append("@");//$NON-NLS-1$
933 node.getTypeName().accept(this);
938 * @see ASTVisitor#visit(MemberRef)
941 public boolean visit(MemberRef node) {
942 if (node.getQualifier() != null) {
943 node.getQualifier().accept(this);
945 this.buffer.append("#");//$NON-NLS-1$
946 node.getName().accept(this);
951 * @see ASTVisitor#visit(MemberValuePair)
954 public boolean visit(MemberValuePair node) {
955 node.getName().accept(this);
956 this.buffer.append("=");//$NON-NLS-1$
957 node.getValue().accept(this);
962 * @see ASTVisitor#visit(MethodDeclaration)
964 public boolean visit(MethodDeclaration node) {
965 if (node.getJavadoc() != null) {
966 node.getJavadoc().accept(this);
969 if (node.getAST().apiLevel() == JLS2) {
970 printModifiers(node.getModifiers());
972 if (node.getAST().apiLevel() >= AST.JLS3) {
973 printModifiers(node.modifiers());
974 if (!node.typeParameters().isEmpty()) {
975 this.buffer.append("<");//$NON-NLS-1$
976 for (Iterator it = node.typeParameters().iterator(); it.hasNext(); ) {
977 TypeParameter t = (TypeParameter) it.next();
980 this.buffer.append(",");//$NON-NLS-1$
983 this.buffer.append(">");//$NON-NLS-1$
986 if (!node.isConstructor()) {
987 if (node.getAST().apiLevel() == JLS2) {
988 this.getReturnType(node).accept(this);
990 if (node.getReturnType2() != null) {
991 node.getReturnType2().accept(this);
993 // methods really ought to have a return type
994 this.buffer.append("void");//$NON-NLS-1$
997 this.buffer.append(" ");//$NON-NLS-1$
999 node.getName().accept(this);
1000 this.buffer.append("(");//$NON-NLS-1$
1001 for (Iterator it = node.parameters().iterator(); it.hasNext(); ) {
1002 SingleVariableDeclaration v = (SingleVariableDeclaration) it.next();
1005 this.buffer.append(",");//$NON-NLS-1$
1008 this.buffer.append(")");//$NON-NLS-1$
1009 for (int i = 0; i < node.getExtraDimensions(); i++) {
1010 this.buffer.append("[]"); //$NON-NLS-1$
1012 if (!node.thrownExceptions().isEmpty()) {
1013 this.buffer.append(" throws ");//$NON-NLS-1$
1014 for (Iterator it = node.thrownExceptions().iterator(); it.hasNext(); ) {
1015 Name n = (Name) it.next();
1018 this.buffer.append(", ");//$NON-NLS-1$
1021 this.buffer.append(" ");//$NON-NLS-1$
1023 if (node.getBody() == null) {
1024 this.buffer.append(";\n");//$NON-NLS-1$
1026 node.getBody().accept(this);
1032 * @see ASTVisitor#visit(MethodInvocation)
1034 public boolean visit(MethodInvocation node) {
1035 if (node.getExpression() != null) {
1036 node.getExpression().accept(this);
1037 this.buffer.append(".");//$NON-NLS-1$
1039 if (node.getAST().apiLevel() >= AST.JLS3) {
1040 if (!node.typeArguments().isEmpty()) {
1041 this.buffer.append("<");//$NON-NLS-1$
1042 for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) {
1043 Type t = (Type) it.next();
1046 this.buffer.append(",");//$NON-NLS-1$
1049 this.buffer.append(">");//$NON-NLS-1$
1052 node.getName().accept(this);
1053 this.buffer.append("(");//$NON-NLS-1$
1054 for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
1055 Expression e = (Expression) it.next();
1058 this.buffer.append(",");//$NON-NLS-1$
1061 this.buffer.append(")");//$NON-NLS-1$
1066 * @see ASTVisitor#visit(MethodRef)
1069 public boolean visit(MethodRef node) {
1070 if (node.getQualifier() != null) {
1071 node.getQualifier().accept(this);
1073 this.buffer.append("#");//$NON-NLS-1$
1074 node.getName().accept(this);
1075 this.buffer.append("(");//$NON-NLS-1$
1076 for (Iterator it = node.parameters().iterator(); it.hasNext(); ) {
1077 MethodRefParameter e = (MethodRefParameter) it.next();
1080 this.buffer.append(",");//$NON-NLS-1$
1083 this.buffer.append(")");//$NON-NLS-1$
1088 * @see ASTVisitor#visit(MethodRefParameter)
1091 public boolean visit(MethodRefParameter node) {
1092 node.getType().accept(this);
1093 if (node.getAST().apiLevel() >= AST.JLS3) {
1094 if (node.isVarargs()) {
1095 this.buffer.append("...");//$NON-NLS-1$
1098 if (node.getName() != null) {
1099 this.buffer.append(" ");//$NON-NLS-1$
1100 node.getName().accept(this);
1106 * @see ASTVisitor#visit(Modifier)
1109 public boolean visit(Modifier node) {
1110 this.buffer.append(node.getKeyword().toString());
1115 * @see ASTVisitor#visit(NormalAnnotation)
1118 public boolean visit(NormalAnnotation node) {
1119 this.buffer.append("@");//$NON-NLS-1$
1120 node.getTypeName().accept(this);
1121 this.buffer.append("(");//$NON-NLS-1$
1122 for (Iterator it = node.values().iterator(); it.hasNext(); ) {
1123 MemberValuePair p = (MemberValuePair) it.next();
1126 this.buffer.append(",");//$NON-NLS-1$
1129 this.buffer.append(")");//$NON-NLS-1$
1134 * @see ASTVisitor#visit(NullLiteral)
1136 public boolean visit(NullLiteral node) {
1137 this.buffer.append("null");//$NON-NLS-1$
1142 * @see ASTVisitor#visit(NumberLiteral)
1144 public boolean visit(NumberLiteral node) {
1145 this.buffer.append(node.getToken());
1150 * @see ASTVisitor#visit(PackageDeclaration)
1152 public boolean visit(PackageDeclaration node) {
1153 if (node.getAST().apiLevel() >= AST.JLS3) {
1154 if (node.getJavadoc() != null) {
1155 node.getJavadoc().accept(this);
1157 for (Iterator it = node.annotations().iterator(); it.hasNext(); ) {
1158 Annotation p = (Annotation) it.next();
1160 this.buffer.append(" ");//$NON-NLS-1$
1164 this.buffer.append("package ");//$NON-NLS-1$
1165 node.getName().accept(this);
1166 this.buffer.append(";\n");//$NON-NLS-1$
1171 * @see ASTVisitor#visit(ParameterizedType)
1174 public boolean visit(ParameterizedType node) {
1175 node.getType().accept(this);
1176 this.buffer.append("<");//$NON-NLS-1$
1177 for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) {
1178 Type t = (Type) it.next();
1181 this.buffer.append(",");//$NON-NLS-1$
1184 this.buffer.append(">");//$NON-NLS-1$
1189 * @see ASTVisitor#visit(ParenthesizedExpression)
1191 public boolean visit(ParenthesizedExpression node) {
1192 this.buffer.append("(");//$NON-NLS-1$
1193 node.getExpression().accept(this);
1194 this.buffer.append(")");//$NON-NLS-1$
1199 * @see ASTVisitor#visit(PostfixExpression)
1201 public boolean visit(PostfixExpression node) {
1202 node.getOperand().accept(this);
1203 this.buffer.append(node.getOperator().toString());
1208 * @see ASTVisitor#visit(PrefixExpression)
1210 public boolean visit(PrefixExpression node) {
1211 this.buffer.append(node.getOperator().toString());
1212 node.getOperand().accept(this);
1217 * @see ASTVisitor#visit(PrimitiveType)
1219 public boolean visit(PrimitiveType node) {
1220 this.buffer.append(node.getPrimitiveTypeCode().toString());
1225 * @see ASTVisitor#visit(QualifiedName)
1227 public boolean visit(QualifiedName node) {
1228 node.getQualifier().accept(this);
1229 this.buffer.append(".");//$NON-NLS-1$
1230 node.getName().accept(this);
1235 * @see ASTVisitor#visit(QualifiedType)
1238 public boolean visit(QualifiedType node) {
1239 node.getQualifier().accept(this);
1240 this.buffer.append(".");//$NON-NLS-1$
1241 node.getName().accept(this);
1246 * @see ASTVisitor#visit(ReturnStatement)
1248 public boolean visit(ReturnStatement node) {
1250 this.buffer.append("return");//$NON-NLS-1$
1251 if (node.getExpression() != null) {
1252 this.buffer.append(" ");//$NON-NLS-1$
1253 node.getExpression().accept(this);
1255 this.buffer.append(";\n");//$NON-NLS-1$
1260 * @see ASTVisitor#visit(SimpleName)
1262 public boolean visit(SimpleName node) {
1263 this.buffer.append(node.getIdentifier());
1268 * @see ASTVisitor#visit(SimpleType)
1270 public boolean visit(SimpleType node) {
1275 * @see ASTVisitor#visit(SingleMemberAnnotation)
1278 public boolean visit(SingleMemberAnnotation node) {
1279 this.buffer.append("@");//$NON-NLS-1$
1280 node.getTypeName().accept(this);
1281 this.buffer.append("(");//$NON-NLS-1$
1282 node.getValue().accept(this);
1283 this.buffer.append(")");//$NON-NLS-1$
1288 * @see ASTVisitor#visit(SingleVariableDeclaration)
1290 public boolean visit(SingleVariableDeclaration node) {
1292 if (node.getAST().apiLevel() == JLS2) {
1293 printModifiers(node.getModifiers());
1295 if (node.getAST().apiLevel() >= AST.JLS3) {
1296 printModifiers(node.modifiers());
1298 node.getType().accept(this);
1299 if (node.getAST().apiLevel() >= AST.JLS3) {
1300 if (node.isVarargs()) {
1301 this.buffer.append("...");//$NON-NLS-1$
1304 this.buffer.append(" ");//$NON-NLS-1$
1305 node.getName().accept(this);
1306 for (int i = 0; i < node.getExtraDimensions(); i++) {
1307 this.buffer.append("[]"); //$NON-NLS-1$
1309 if (node.getInitializer() != null) {
1310 this.buffer.append("=");//$NON-NLS-1$
1311 node.getInitializer().accept(this);
1317 * @see ASTVisitor#visit(StringLiteral)
1319 public boolean visit(StringLiteral node) {
1320 this.buffer.append(node.getEscapedValue());
1325 * @see ASTVisitor#visit(SuperConstructorInvocation)
1327 public boolean visit(SuperConstructorInvocation node) {
1329 if (node.getExpression() != null) {
1330 node.getExpression().accept(this);
1331 this.buffer.append(".");//$NON-NLS-1$
1333 if (node.getAST().apiLevel() >= AST.JLS3) {
1334 if (!node.typeArguments().isEmpty()) {
1335 this.buffer.append("<");//$NON-NLS-1$
1336 for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) {
1337 Type t = (Type) it.next();
1340 this.buffer.append(",");//$NON-NLS-1$
1343 this.buffer.append(">");//$NON-NLS-1$
1346 this.buffer.append("super(");//$NON-NLS-1$
1347 for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
1348 Expression e = (Expression) it.next();
1351 this.buffer.append(",");//$NON-NLS-1$
1354 this.buffer.append(");\n");//$NON-NLS-1$
1359 * @see ASTVisitor#visit(SuperFieldAccess)
1361 public boolean visit(SuperFieldAccess node) {
1362 if (node.getQualifier() != null) {
1363 node.getQualifier().accept(this);
1364 this.buffer.append(".");//$NON-NLS-1$
1366 this.buffer.append("super.");//$NON-NLS-1$
1367 node.getName().accept(this);
1372 * @see ASTVisitor#visit(SuperMethodInvocation)
1374 public boolean visit(SuperMethodInvocation node) {
1375 if (node.getQualifier() != null) {
1376 node.getQualifier().accept(this);
1377 this.buffer.append(".");//$NON-NLS-1$
1379 this.buffer.append("super.");//$NON-NLS-1$
1380 if (node.getAST().apiLevel() >= AST.JLS3) {
1381 if (!node.typeArguments().isEmpty()) {
1382 this.buffer.append("<");//$NON-NLS-1$
1383 for (Iterator it = node.typeArguments().iterator(); it.hasNext(); ) {
1384 Type t = (Type) it.next();
1387 this.buffer.append(",");//$NON-NLS-1$
1390 this.buffer.append(">");//$NON-NLS-1$
1393 node.getName().accept(this);
1394 this.buffer.append("(");//$NON-NLS-1$
1395 for (Iterator it = node.arguments().iterator(); it.hasNext(); ) {
1396 Expression e = (Expression) it.next();
1399 this.buffer.append(",");//$NON-NLS-1$
1402 this.buffer.append(")");//$NON-NLS-1$
1407 * @see ASTVisitor#visit(SwitchCase)
1409 public boolean visit(SwitchCase node) {
1410 if (node.isDefault()) {
1411 this.buffer.append("default :\n");//$NON-NLS-1$
1413 this.buffer.append("case ");//$NON-NLS-1$
1414 node.getExpression().accept(this);
1415 this.buffer.append(":\n");//$NON-NLS-1$
1417 this.indent++; //decremented in visit(SwitchStatement)
1422 * @see ASTVisitor#visit(SwitchStatement)
1424 public boolean visit(SwitchStatement node) {
1425 this.buffer.append("switch (");//$NON-NLS-1$
1426 node.getExpression().accept(this);
1427 this.buffer.append(") ");//$NON-NLS-1$
1428 this.buffer.append("{\n");//$NON-NLS-1$
1430 for (Iterator it = node.statements().iterator(); it.hasNext(); ) {
1431 Statement s = (Statement) it.next();
1433 this.indent--; // incremented in visit(SwitchCase)
1437 this.buffer.append("}\n");//$NON-NLS-1$
1442 * @see ASTVisitor#visit(SynchronizedStatement)
1444 public boolean visit(SynchronizedStatement node) {
1445 this.buffer.append("synchronized (");//$NON-NLS-1$
1446 node.getExpression().accept(this);
1447 this.buffer.append(") ");//$NON-NLS-1$
1448 node.getBody().accept(this);
1453 * @see ASTVisitor#visit(TagElement)
1456 public boolean visit(TagElement node) {
1457 if (node.isNested()) {
1458 // nested tags are always enclosed in braces
1459 this.buffer.append("{");//$NON-NLS-1$
1461 // top-level tags always begin on a new line
1462 this.buffer.append("\n * ");//$NON-NLS-1$
1464 boolean previousRequiresWhiteSpace = false;
1465 if (node.getTagName() != null) {
1466 this.buffer.append(node.getTagName());
1467 previousRequiresWhiteSpace = true;
1469 boolean previousRequiresNewLine = false;
1470 for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
1471 ASTNode e = (ASTNode) it.next();
1472 // assume text elements include necessary leading and trailing whitespace
1473 // but Name, MemberRef, MethodRef, and nested TagElement do not include white space
1474 boolean currentIncludesWhiteSpace = (e instanceof TextElement);
1475 if (previousRequiresNewLine && currentIncludesWhiteSpace) {
1476 this.buffer.append("\n * ");//$NON-NLS-1$
1478 previousRequiresNewLine = currentIncludesWhiteSpace;
1479 // add space if required to separate
1480 if (previousRequiresWhiteSpace && !currentIncludesWhiteSpace) {
1481 this.buffer.append(" "); //$NON-NLS-1$
1484 previousRequiresWhiteSpace = !currentIncludesWhiteSpace && !(e instanceof TagElement);
1486 if (node.isNested()) {
1487 this.buffer.append("}");//$NON-NLS-1$
1493 * @see ASTVisitor#visit(TextElement)
1496 public boolean visit(TextElement node) {
1497 this.buffer.append(node.getText());
1502 * @see ASTVisitor#visit(ThisExpression)
1504 public boolean visit(ThisExpression node) {
1505 if (node.getQualifier() != null) {
1506 node.getQualifier().accept(this);
1507 this.buffer.append(".");//$NON-NLS-1$
1509 this.buffer.append("this");//$NON-NLS-1$
1514 * @see ASTVisitor#visit(ThrowStatement)
1516 public boolean visit(ThrowStatement node) {
1518 this.buffer.append("throw ");//$NON-NLS-1$
1519 node.getExpression().accept(this);
1520 this.buffer.append(";\n");//$NON-NLS-1$
1525 * @see ASTVisitor#visit(TryStatement)
1527 public boolean visit(TryStatement node) {
1529 this.buffer.append("try ");//$NON-NLS-1$
1530 node.getBody().accept(this);
1531 this.buffer.append(" ");//$NON-NLS-1$
1532 for (Iterator it = node.catchClauses().iterator(); it.hasNext(); ) {
1533 CatchClause cc = (CatchClause) it.next();
1536 if (node.getFinally() != null) {
1537 this.buffer.append(" finally ");//$NON-NLS-1$
1538 node.getFinally().accept(this);
1544 * @see ASTVisitor#visit(TypeDeclaration)
1546 public boolean visit(TypeDeclaration node) {
1547 if (node.getJavadoc() != null) {
1548 node.getJavadoc().accept(this);
1550 if (node.getAST().apiLevel() == JLS2) {
1551 printModifiers(node.getModifiers());
1553 if (node.getAST().apiLevel() >= AST.JLS3) {
1554 printModifiers(node.modifiers());
1556 this.buffer.append(node.isInterface() ? "interface " : "class ");//$NON-NLS-2$//$NON-NLS-1$
1557 node.getName().accept(this);
1558 if (node.getAST().apiLevel() >= AST.JLS3) {
1559 if (!node.typeParameters().isEmpty()) {
1560 this.buffer.append("<");//$NON-NLS-1$
1561 for (Iterator it = node.typeParameters().iterator(); it.hasNext(); ) {
1562 TypeParameter t = (TypeParameter) it.next();
1565 this.buffer.append(",");//$NON-NLS-1$
1568 this.buffer.append(">");//$NON-NLS-1$
1571 this.buffer.append(" ");//$NON-NLS-1$
1572 if (node.getAST().apiLevel() == JLS2) {
1573 if (this.getSuperclass(node) != null) {
1574 this.buffer.append("extends ");//$NON-NLS-1$
1575 this.getSuperclass(node).accept(this);
1576 this.buffer.append(" ");//$NON-NLS-1$
1578 if (!this.superInterfaces(node).isEmpty()) {
1579 this.buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
1580 for (Iterator it = this.superInterfaces(node).iterator(); it.hasNext(); ) {
1581 Name n = (Name) it.next();
1584 this.buffer.append(", ");//$NON-NLS-1$
1587 this.buffer.append(" ");//$NON-NLS-1$
1590 if (node.getAST().apiLevel() >= AST.JLS3) {
1591 if (node.getSuperclassType() != null) {
1592 this.buffer.append("extends ");//$NON-NLS-1$
1593 node.getSuperclassType().accept(this);
1594 this.buffer.append(" ");//$NON-NLS-1$
1596 if (!node.superInterfaceTypes().isEmpty()) {
1597 this.buffer.append(node.isInterface() ? "extends " : "implements ");//$NON-NLS-2$//$NON-NLS-1$
1598 for (Iterator it = node.superInterfaceTypes().iterator(); it.hasNext(); ) {
1599 Type t = (Type) it.next();
1602 this.buffer.append(", ");//$NON-NLS-1$
1605 this.buffer.append(" ");//$NON-NLS-1$
1608 this.buffer.append("{\n");//$NON-NLS-1$
1610 for (Iterator it = node.bodyDeclarations().iterator(); it.hasNext(); ) {
1611 BodyDeclaration d = (BodyDeclaration) it.next();
1616 this.buffer.append("}\n");//$NON-NLS-1$
1621 * @see ASTVisitor#visit(TypeDeclarationStatement)
1623 public boolean visit(TypeDeclarationStatement node) {
1624 if (node.getAST().apiLevel() == JLS2) {
1625 this.getTypeDeclaration(node).accept(this);
1627 if (node.getAST().apiLevel() >= AST.JLS3) {
1628 node.getDeclaration().accept(this);
1634 * @see ASTVisitor#visit(TypeLiteral)
1636 public boolean visit(TypeLiteral node) {
1637 node.getType().accept(this);
1638 this.buffer.append(".class");//$NON-NLS-1$
1643 * @see ASTVisitor#visit(TypeParameter)
1646 public boolean visit(TypeParameter node) {
1647 node.getName().accept(this);
1648 if (!node.typeBounds().isEmpty()) {
1649 this.buffer.append(" extends ");//$NON-NLS-1$
1650 for (Iterator it = node.typeBounds().iterator(); it.hasNext(); ) {
1651 Type t = (Type) it.next();
1654 this.buffer.append(" & ");//$NON-NLS-1$
1662 * @see ASTVisitor#visit(VariableDeclarationExpression)
1664 public boolean visit(VariableDeclarationExpression node) {
1665 if (node.getAST().apiLevel() == JLS2) {
1666 printModifiers(node.getModifiers());
1668 if (node.getAST().apiLevel() >= AST.JLS3) {
1669 printModifiers(node.modifiers());
1671 node.getType().accept(this);
1672 this.buffer.append(" ");//$NON-NLS-1$
1673 for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
1674 VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
1677 this.buffer.append(", ");//$NON-NLS-1$
1684 * @see ASTVisitor#visit(VariableDeclarationFragment)
1686 public boolean visit(VariableDeclarationFragment node) {
1687 node.getName().accept(this);
1688 for (int i = 0; i < node.getExtraDimensions(); i++) {
1689 this.buffer.append("[]");//$NON-NLS-1$
1691 if (node.getInitializer() != null) {
1692 this.buffer.append("=");//$NON-NLS-1$
1693 node.getInitializer().accept(this);
1699 * @see ASTVisitor#visit(VariableDeclarationStatement)
1701 public boolean visit(VariableDeclarationStatement node) {
1703 if (node.getAST().apiLevel() == JLS2) {
1704 printModifiers(node.getModifiers());
1706 if (node.getAST().apiLevel() >= AST.JLS3) {
1707 printModifiers(node.modifiers());
1709 node.getType().accept(this);
1710 this.buffer.append(" ");//$NON-NLS-1$
1711 for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
1712 VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
1715 this.buffer.append(", ");//$NON-NLS-1$
1718 this.buffer.append(";\n");//$NON-NLS-1$
1723 * @see ASTVisitor#visit(WhileStatement)
1725 public boolean visit(WhileStatement node) {
1727 this.buffer.append("while (");//$NON-NLS-1$
1728 node.getExpression().accept(this);
1729 this.buffer.append(") ");//$NON-NLS-1$
1730 node.getBody().accept(this);
1735 * @see ASTVisitor#visit(WildcardType)
1738 public boolean visit(WildcardType node) {
1739 this.buffer.append("?");//$NON-NLS-1$
1740 Type bound = node.getBound();
1741 if (bound != null) {
1742 if (node.isUpperBound()) {
1743 this.buffer.append(" extends ");//$NON-NLS-1$
1745 this.buffer.append(" super ");//$NON-NLS-1$