KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > dom > rewrite > ASTRewriteFlattener


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

11 package org.eclipse.jdt.internal.core.dom.rewrite;
12
13 import java.util.List JavaDoc;
14
15 import org.eclipse.jdt.core.dom.*;
16 import org.eclipse.jdt.internal.compiler.util.Util;
17
18 public class ASTRewriteFlattener extends ASTVisitor {
19     
20     /**
21      * Internal synonynm for deprecated constant AST.JSL2
22      * to alleviate deprecation warnings.
23      * @deprecated
24      */

25     /*package*/ static final int JLS2_INTERNAL = AST.JLS2;
26     
27     public static String JavaDoc asString(ASTNode node, RewriteEventStore store) {
28         ASTRewriteFlattener flattener= new ASTRewriteFlattener(store);
29         node.accept(flattener);
30         return flattener.getResult();
31     }
32
33     protected StringBuffer JavaDoc result;
34     private RewriteEventStore store;
35
36     public ASTRewriteFlattener(RewriteEventStore store) {
37         this.store= store;
38         this.result= new StringBuffer JavaDoc();
39     }
40     
41     /**
42      * Returns the string accumulated in the visit.
43      *
44      * @return the serialized
45      */

46     public String JavaDoc getResult() {
47         // convert to a string, but lose any extra space in the string buffer by copying
48
return new String JavaDoc(this.result.toString());
49     }
50     
51     /**
52      * Resets this printer so that it can be used again.
53      */

54     public void reset() {
55         this.result.setLength(0);
56     }
57     
58     /**
59      * Appends the text representation of the given modifier flags, followed by a single space.
60      *
61      * @param modifiers the modifiers
62      * @param buf The <code>StringBuffer</code> to write the result to.
63      */

64     public static void printModifiers(int modifiers, StringBuffer JavaDoc buf) {
65         if (Modifier.isPublic(modifiers)) {
66             buf.append("public "); //$NON-NLS-1$
67
}
68         if (Modifier.isProtected(modifiers)) {
69             buf.append("protected "); //$NON-NLS-1$
70
}
71         if (Modifier.isPrivate(modifiers)) {
72             buf.append("private "); //$NON-NLS-1$
73
}
74         if (Modifier.isStatic(modifiers)) {
75             buf.append("static "); //$NON-NLS-1$
76
}
77         if (Modifier.isAbstract(modifiers)) {
78             buf.append("abstract "); //$NON-NLS-1$
79
}
80         if (Modifier.isFinal(modifiers)) {
81             buf.append("final "); //$NON-NLS-1$
82
}
83         if (Modifier.isSynchronized(modifiers)) {
84             buf.append("synchronized "); //$NON-NLS-1$
85
}
86         if (Modifier.isVolatile(modifiers)) {
87             buf.append("volatile "); //$NON-NLS-1$
88
}
89         if (Modifier.isNative(modifiers)) {
90             buf.append("native "); //$NON-NLS-1$
91
}
92         if (Modifier.isStrictfp(modifiers)) {
93             buf.append("strictfp "); //$NON-NLS-1$
94
}
95         if (Modifier.isTransient(modifiers)) {
96             buf.append("transient "); //$NON-NLS-1$
97
}
98     }
99         
100     protected List JavaDoc getChildList(ASTNode parent, StructuralPropertyDescriptor childProperty) {
101         return (List JavaDoc) getAttribute(parent, childProperty);
102     }
103     
104     protected ASTNode getChildNode(ASTNode parent, StructuralPropertyDescriptor childProperty) {
105         return (ASTNode) getAttribute(parent, childProperty);
106     }
107     
108     protected int getIntAttribute(ASTNode parent, StructuralPropertyDescriptor childProperty) {
109         return ((Integer JavaDoc) getAttribute(parent, childProperty)).intValue();
110     }
111     
112     protected boolean getBooleanAttribute(ASTNode parent, StructuralPropertyDescriptor childProperty) {
113         return ((Boolean JavaDoc) getAttribute(parent, childProperty)).booleanValue();
114     }
115     
116     protected Object JavaDoc getAttribute(ASTNode parent, StructuralPropertyDescriptor childProperty) {
117         return this.store.getNewValue(parent, childProperty);
118     }
119     
120     protected void visitList(ASTNode parent, StructuralPropertyDescriptor childProperty, String JavaDoc separator) {
121         List JavaDoc list= getChildList(parent, childProperty);
122         for (int i= 0; i < list.size(); i++) {
123             if (separator != null && i > 0) {
124                 this.result.append(separator);
125             }
126             ((ASTNode) list.get(i)).accept(this);
127         }
128     }
129     
130     protected void visitList(ASTNode parent, StructuralPropertyDescriptor childProperty, String JavaDoc separator, String JavaDoc lead, String JavaDoc post) {
131         List JavaDoc list= getChildList(parent, childProperty);
132         if (!list.isEmpty()) {
133             this.result.append(lead);
134             for (int i= 0; i < list.size(); i++) {
135                 if (separator != null && i > 0) {
136                     this.result.append(separator);
137                 }
138                 ((ASTNode) list.get(i)).accept(this);
139             }
140             this.result.append(post);
141         }
142     }
143     
144     
145     /*
146      * @see ASTVisitor#visit(AnonymousClassDeclaration)
147      */

148     public boolean visit(AnonymousClassDeclaration node) {
149         this.result.append('{');
150         visitList(node, AnonymousClassDeclaration.BODY_DECLARATIONS_PROPERTY, null);
151         this.result.append('}');
152         return false;
153     }
154
155     /*
156      * @see ASTVisitor#visit(ArrayAccess)
157      */

158     public boolean visit(ArrayAccess node) {
159         getChildNode(node, ArrayAccess.ARRAY_PROPERTY).accept(this);
160         this.result.append('[');
161         getChildNode(node, ArrayAccess.INDEX_PROPERTY).accept(this);
162         this.result.append(']');
163         return false;
164     }
165
166     /*
167      * @see ASTVisitor#visit(ArrayCreation)
168      */

169     public boolean visit(ArrayCreation node) {
170         this.result.append("new "); //$NON-NLS-1$
171
ArrayType arrayType= (ArrayType) getChildNode(node, ArrayCreation.TYPE_PROPERTY);
172         
173         // get the element type and count dimensions
174
Type elementType= (Type) getChildNode(arrayType, ArrayType.COMPONENT_TYPE_PROPERTY);
175         int dimensions= 1; // always include this array type
176
while (elementType.isArrayType()) {
177             dimensions++;
178             elementType = (Type) getChildNode(elementType, ArrayType.COMPONENT_TYPE_PROPERTY);
179         }
180         
181         elementType.accept(this);
182         
183         List JavaDoc list= getChildList(node, ArrayCreation.DIMENSIONS_PROPERTY);
184         for (int i= 0; i < list.size(); i++) {
185             this.result.append('[');
186             ((ASTNode) list.get(i)).accept(this);
187             this.result.append(']');
188             dimensions--;
189         }
190         
191         // add empty "[]" for each extra array dimension
192
for (int i= 0; i < dimensions; i++) {
193             this.result.append("[]"); //$NON-NLS-1$
194
}
195         ASTNode initializer= getChildNode(node, ArrayCreation.INITIALIZER_PROPERTY);
196         if (initializer != null) {
197             getChildNode(node, ArrayCreation.INITIALIZER_PROPERTY).accept(this);
198         }
199         return false;
200     }
201     
202     /*
203      * @see ASTVisitor#visit(ArrayInitializer)
204      */

205     public boolean visit(ArrayInitializer node) {
206         this.result.append('{');
207         visitList(node, ArrayInitializer.EXPRESSIONS_PROPERTY, String.valueOf(','));
208         this.result.append('}');
209         return false;
210     }
211
212     /*
213      * @see ASTVisitor#visit(ArrayType)
214      */

215     public boolean visit(ArrayType node) {
216         getChildNode(node, ArrayType.COMPONENT_TYPE_PROPERTY).accept(this);
217         this.result.append("[]"); //$NON-NLS-1$
218
return false;
219     }
220
221     /*
222      * @see ASTVisitor#visit(AssertStatement)
223      */

224     public boolean visit(AssertStatement node) {
225         this.result.append("assert "); //$NON-NLS-1$
226
getChildNode(node, AssertStatement.EXPRESSION_PROPERTY).accept(this);
227         
228         ASTNode message= getChildNode(node, AssertStatement.MESSAGE_PROPERTY);
229         if (message != null) {
230             this.result.append(':');
231             message.accept(this);
232         }
233         this.result.append(';');
234         return false;
235     }
236
237     /*
238      * @see ASTVisitor#visit(Assignment)
239      */

240     public boolean visit(Assignment node) {
241         getChildNode(node, Assignment.LEFT_HAND_SIDE_PROPERTY).accept(this);
242         this.result.append(getAttribute(node, Assignment.OPERATOR_PROPERTY).toString());
243         getChildNode(node, Assignment.RIGHT_HAND_SIDE_PROPERTY).accept(this);
244         return false;
245     }
246
247
248
249     /*
250      * @see ASTVisitor#visit(Block)
251      */

252     public boolean visit(Block node) {
253         this.result.append('{');
254         visitList(node, Block.STATEMENTS_PROPERTY, null);
255         this.result.append('}');
256         return false;
257     }
258
259     /*
260      * @see ASTVisitor#visit(BooleanLiteral)
261      */

262     public boolean visit(BooleanLiteral node) {
263         if (node.booleanValue() == true) {
264             this.result.append("true"); //$NON-NLS-1$
265
} else {
266             this.result.append("false"); //$NON-NLS-1$
267
}
268         return false;
269     }
270
271     /*
272      * @see ASTVisitor#visit(BreakStatement)
273      */

274     public boolean visit(BreakStatement node) {
275         this.result.append("break"); //$NON-NLS-1$
276
ASTNode label= getChildNode(node, BreakStatement.LABEL_PROPERTY);
277         if (label != null) {
278             this.result.append(' ');
279             label.accept(this);
280         }
281         this.result.append(';');
282         return false;
283     }
284
285     /*
286      * @see ASTVisitor#visit(CastExpression)
287      */

288     public boolean visit(CastExpression node) {
289         this.result.append('(');
290         getChildNode(node, CastExpression.TYPE_PROPERTY).accept(this);
291         this.result.append(')');
292         getChildNode(node, CastExpression.EXPRESSION_PROPERTY).accept(this);
293         return false;
294     }
295
296     /*
297      * @see ASTVisitor#visit(CatchClause)
298      */

299     public boolean visit(CatchClause node) {
300         this.result.append("catch ("); //$NON-NLS-1$
301
getChildNode(node, CatchClause.EXCEPTION_PROPERTY).accept(this);
302         this.result.append(')');
303         getChildNode(node, CatchClause.BODY_PROPERTY).accept(this);
304         return false;
305     }
306
307     /*
308      * @see ASTVisitor#visit(CharacterLiteral)
309      */

310     public boolean visit(CharacterLiteral node) {
311         this.result.append(getAttribute(node, CharacterLiteral.ESCAPED_VALUE_PROPERTY));
312         return false;
313     }
314
315     /*
316      * @see ASTVisitor#visit(ClassInstanceCreation)
317      */

318     public boolean visit(ClassInstanceCreation node) {
319         ASTNode expression= getChildNode(node, ClassInstanceCreation.EXPRESSION_PROPERTY);
320         if (expression != null) {
321             expression.accept(this);
322             this.result.append('.');
323         }
324         this.result.append("new ");//$NON-NLS-1$
325
if (node.getAST().apiLevel() == JLS2_INTERNAL) {
326             getChildNode(node, ClassInstanceCreation.NAME_PROPERTY).accept(this);
327         } else {
328             visitList(node, ClassInstanceCreation.TYPE_ARGUMENTS_PROPERTY, String.valueOf(','), String.valueOf('<'), String.valueOf('>'));
329             getChildNode(node, ClassInstanceCreation.TYPE_PROPERTY).accept(this);
330         }
331
332         this.result.append('(');
333         visitList(node, ClassInstanceCreation.ARGUMENTS_PROPERTY, String.valueOf(','));
334         this.result.append(')');
335         ASTNode decl= getChildNode(node, ClassInstanceCreation.ANONYMOUS_CLASS_DECLARATION_PROPERTY);
336         if (decl != null) {
337             decl.accept(this);
338         }
339         return false;
340     }
341
342     /*
343      * @see ASTVisitor#visit(CompilationUnit)
344      */

345     public boolean visit(CompilationUnit node) {
346         ASTNode pack= getChildNode(node, CompilationUnit.PACKAGE_PROPERTY);
347         if (pack != null) {
348             pack.accept(this);
349         }
350         visitList(node, CompilationUnit.IMPORTS_PROPERTY, null);
351         visitList(node, CompilationUnit.TYPES_PROPERTY, null);
352         return false;
353     }
354
355     /*
356      * @see ASTVisitor#visit(ConditionalExpression)
357      */

358     public boolean visit(ConditionalExpression node) {
359         getChildNode(node, ConditionalExpression.EXPRESSION_PROPERTY).accept(this);
360         this.result.append('?');
361         getChildNode(node, ConditionalExpression.THEN_EXPRESSION_PROPERTY).accept(this);
362         this.result.append(':');
363         getChildNode(node, ConditionalExpression.ELSE_EXPRESSION_PROPERTY).accept(this);
364         return false;
365     }
366
367     /*
368      * @see ASTVisitor#visit(ConstructorInvocation)
369      */

370     public boolean visit(ConstructorInvocation node) {
371         if (node.getAST().apiLevel() >= AST.JLS3) {
372             visitList(node, ConstructorInvocation.TYPE_ARGUMENTS_PROPERTY, String.valueOf(','), String.valueOf('<'), String.valueOf('>'));
373         }
374         this.result.append("this("); //$NON-NLS-1$
375
visitList(node, ConstructorInvocation.ARGUMENTS_PROPERTY, String.valueOf(','));
376         this.result.append(");"); //$NON-NLS-1$
377
return false;
378     }
379
380     /*
381      * @see ASTVisitor#visit(ContinueStatement)
382      */

383     public boolean visit(ContinueStatement node) {
384         this.result.append("continue"); //$NON-NLS-1$
385
ASTNode label= getChildNode(node, ContinueStatement.LABEL_PROPERTY);
386         if (label != null) {
387             this.result.append(' ');
388             label.accept(this);
389         }
390         this.result.append(';');
391         return false;
392     }
393
394     /*
395      * @see ASTVisitor#visit(DoStatement)
396      */

397     public boolean visit(DoStatement node) {
398         this.result.append("do "); //$NON-NLS-1$
399
getChildNode(node, DoStatement.BODY_PROPERTY).accept(this);
400         this.result.append(" while ("); //$NON-NLS-1$
401
getChildNode(node, DoStatement.EXPRESSION_PROPERTY).accept(this);
402         this.result.append(");"); //$NON-NLS-1$
403
return false;
404     }
405
406     /*
407      * @see ASTVisitor#visit(EmptyStatement)
408      */

409     public boolean visit(EmptyStatement node) {
410         this.result.append(';');
411         return false;
412     }
413
414     /*
415      * @see ASTVisitor#visit(ExpressionStatement)
416      */

417     public boolean visit(ExpressionStatement node) {
418         getChildNode(node, ExpressionStatement.EXPRESSION_PROPERTY).accept(this);
419         this.result.append(';');
420         return false;
421     }
422
423     /*
424      * @see ASTVisitor#visit(FieldAccess)
425      */

426     public boolean visit(FieldAccess node) {
427         getChildNode(node, FieldAccess.EXPRESSION_PROPERTY).accept(this);
428         this.result.append('.');
429         getChildNode(node, FieldAccess.NAME_PROPERTY).accept(this);
430         return false;
431     }
432
433     /*
434      * @see ASTVisitor#visit(FieldDeclaration)
435      */

436     public boolean visit(FieldDeclaration node) {
437         ASTNode javadoc= getChildNode(node, FieldDeclaration.JAVADOC_PROPERTY);
438         if (javadoc != null) {
439             javadoc.accept(this);
440         }
441         if (node.getAST().apiLevel() == JLS2_INTERNAL) {
442             printModifiers(getIntAttribute(node, FieldDeclaration.MODIFIERS_PROPERTY), this.result);
443         } else {
444             visitList(node, FieldDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
445         }
446         getChildNode(node, FieldDeclaration.TYPE_PROPERTY).accept(this);
447         this.result.append(' ');
448         visitList(node, FieldDeclaration.FRAGMENTS_PROPERTY, String.valueOf(','));
449         this.result.append(';');
450         return false;
451     }
452
453     /*
454      * @see ASTVisitor#visit(ForStatement)
455      */

456     public boolean visit(ForStatement node) {
457         this.result.append("for ("); //$NON-NLS-1$
458
visitList(node, ForStatement.INITIALIZERS_PROPERTY, String.valueOf(','));
459         this.result.append(';');
460         ASTNode expression= getChildNode(node, ForStatement.EXPRESSION_PROPERTY);
461         if (expression != null) {
462             expression.accept(this);
463         }
464         this.result.append(';');
465         visitList(node, ForStatement.UPDATERS_PROPERTY, String.valueOf(','));
466         this.result.append(')');
467         getChildNode(node, ForStatement.BODY_PROPERTY).accept(this);
468         return false;
469     }
470
471     /*
472      * @see ASTVisitor#visit(IfStatement)
473      */

474     public boolean visit(IfStatement node) {
475         this.result.append("if ("); //$NON-NLS-1$
476
getChildNode(node, IfStatement.EXPRESSION_PROPERTY).accept(this);
477         this.result.append(')');
478         getChildNode(node, IfStatement.THEN_STATEMENT_PROPERTY).accept(this);
479         ASTNode elseStatement= getChildNode(node, IfStatement.ELSE_STATEMENT_PROPERTY);
480         if (elseStatement != null) {
481             this.result.append(" else "); //$NON-NLS-1$
482
elseStatement.accept(this);
483         }
484         return false;
485     }
486
487     /*
488      * @see ASTVisitor#visit(ImportDeclaration)
489      */

490     public boolean visit(ImportDeclaration node) {
491         this.result.append("import "); //$NON-NLS-1$
492
if (node.getAST().apiLevel() >= AST.JLS3) {
493             if (getBooleanAttribute(node, ImportDeclaration.STATIC_PROPERTY)) {
494                 this.result.append("static ");//$NON-NLS-1$
495
}
496         }
497         getChildNode(node, ImportDeclaration.NAME_PROPERTY).accept(this);
498         if (getBooleanAttribute(node, ImportDeclaration.ON_DEMAND_PROPERTY)) {
499             this.result.append(".*"); //$NON-NLS-1$
500
}
501         this.result.append(';');
502         return false;
503     }
504
505
506
507     /*
508      * @see ASTVisitor#visit(InfixExpression)
509      */

510     public boolean visit(InfixExpression node) {
511         getChildNode(node, InfixExpression.LEFT_OPERAND_PROPERTY).accept(this);
512         this.result.append(' ');
513         String JavaDoc operator= getAttribute(node, InfixExpression.OPERATOR_PROPERTY).toString();
514         
515         this.result.append(operator);
516         this.result.append(' ');
517         getChildNode(node, InfixExpression.RIGHT_OPERAND_PROPERTY).accept(this);
518         
519         List JavaDoc list= getChildList(node, InfixExpression.EXTENDED_OPERANDS_PROPERTY);
520         for (int i= 0; i < list.size(); i++) {
521             this.result.append(operator);
522             ((ASTNode) list.get(i)).accept(this);
523         }
524         return false;
525     }
526
527     /*
528      * @see ASTVisitor#visit(InstanceofExpression)
529      */

530     public boolean visit(InstanceofExpression node) {
531         getChildNode(node, InstanceofExpression.LEFT_OPERAND_PROPERTY).accept(this);
532         this.result.append(" instanceof "); //$NON-NLS-1$
533
getChildNode(node, InstanceofExpression.RIGHT_OPERAND_PROPERTY).accept(this);
534         return false;
535     }
536
537     /*
538      * @see ASTVisitor#visit(Initializer)
539      */

540     public boolean visit(Initializer node) {
541         ASTNode javadoc= getChildNode(node, Initializer.JAVADOC_PROPERTY);
542         if (javadoc != null) {
543             javadoc.accept(this);
544         }
545         if (node.getAST().apiLevel() == JLS2_INTERNAL) {
546             printModifiers(getIntAttribute(node, Initializer.MODIFIERS_PROPERTY), this.result);
547         } else {
548             visitList(node, Initializer.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
549         }
550         getChildNode(node, Initializer.BODY_PROPERTY).accept(this);
551         return false;
552     }
553
554     /*
555      * @see ASTVisitor#visit(Javadoc)
556      */

557     public boolean visit(Javadoc node) {
558         this.result.append("/**"); //$NON-NLS-1$
559
List JavaDoc list= getChildList(node, Javadoc.TAGS_PROPERTY);
560         for (int i= 0; i < list.size(); i++) {
561             this.result.append("\n * "); //$NON-NLS-1$
562
((ASTNode) list.get(i)).accept(this);
563         }
564         this.result.append("\n */"); //$NON-NLS-1$
565
return false;
566     }
567
568     /*
569      * @see ASTVisitor#visit(LabeledStatement)
570      */

571     public boolean visit(LabeledStatement node) {
572         getChildNode(node, LabeledStatement.LABEL_PROPERTY).accept(this);
573         this.result.append(": "); //$NON-NLS-1$
574
getChildNode(node, LabeledStatement.BODY_PROPERTY).accept(this);
575         return false;
576     }
577
578     /*
579      * @see ASTVisitor#visit(MethodDeclaration)
580      */

581     public boolean visit(MethodDeclaration node) {
582         ASTNode javadoc= getChildNode(node, MethodDeclaration.JAVADOC_PROPERTY);
583         if (javadoc != null) {
584             javadoc.accept(this);
585         }
586         if (node.getAST().apiLevel() == JLS2_INTERNAL) {
587             printModifiers(getIntAttribute(node, MethodDeclaration.MODIFIERS_PROPERTY), this.result);
588         } else {
589             visitList(node, MethodDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
590             visitList(node, MethodDeclaration.TYPE_PARAMETERS_PROPERTY, String.valueOf(','), String.valueOf('<'), String.valueOf('>'));
591         }
592                 
593         if (!getBooleanAttribute(node, MethodDeclaration.CONSTRUCTOR_PROPERTY)) {
594             if (node.getAST().apiLevel() == JLS2_INTERNAL) {
595                 getChildNode(node, MethodDeclaration.RETURN_TYPE_PROPERTY).accept(this);
596             } else {
597                 ASTNode returnType = getChildNode(node, MethodDeclaration.RETURN_TYPE2_PROPERTY);
598                 if (returnType != null) {
599                     returnType.accept(this);
600                 } else {
601                     // methods really ought to have a return type
602
this.result.append("void");//$NON-NLS-1$
603
}
604             }
605             this.result.append(' ');
606         }
607         getChildNode(node, MethodDeclaration.NAME_PROPERTY).accept(this);
608         this.result.append('(');
609         visitList(node, MethodDeclaration.PARAMETERS_PROPERTY, String.valueOf(','));
610         this.result.append(')');
611         int extraDims= getIntAttribute(node, MethodDeclaration.EXTRA_DIMENSIONS_PROPERTY);
612         for (int i = 0; i < extraDims; i++) {
613             this.result.append("[]"); //$NON-NLS-1$
614
}
615         visitList(node, MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY, String.valueOf(','), " throws ", Util.EMPTY_STRING); //$NON-NLS-1$
616
ASTNode body= getChildNode(node, MethodDeclaration.BODY_PROPERTY);
617         if (body == null) {
618             this.result.append(';');
619         } else {
620             body.accept(this);
621         }
622         return false;
623     }
624
625     /*
626      * @see ASTVisitor#visit(MethodInvocation)
627      */

628     public boolean visit(MethodInvocation node) {
629         ASTNode expression= getChildNode(node, MethodInvocation.EXPRESSION_PROPERTY);
630         if (expression != null) {
631             expression.accept(this);
632             this.result.append('.');
633         }
634         if (node.getAST().apiLevel() >= AST.JLS3) {
635             visitList(node, MethodInvocation.TYPE_ARGUMENTS_PROPERTY, String.valueOf(','), String.valueOf('<'), String.valueOf('>'));
636         }
637
638         getChildNode(node, MethodInvocation.NAME_PROPERTY).accept(this);
639         this.result.append('(');
640         visitList(node, MethodInvocation.ARGUMENTS_PROPERTY, String.valueOf(','));
641         this.result.append(')');
642         return false;
643     }
644
645     /*
646      * @see ASTVisitor#visit(NullLiteral)
647      */

648     public boolean visit(NullLiteral node) {
649         this.result.append("null"); //$NON-NLS-1$
650
return false;
651     }
652
653     /*
654      * @see ASTVisitor#visit(NumberLiteral)
655      */

656     public boolean visit(NumberLiteral node) {
657         this.result.append(getAttribute(node, NumberLiteral.TOKEN_PROPERTY).toString());
658         return false;
659     }
660
661     /*
662      * @see ASTVisitor#visit(PackageDeclaration)
663      */

664     public boolean visit(PackageDeclaration node) {
665         if (node.getAST().apiLevel() >= AST.JLS3) {
666             ASTNode javadoc = getChildNode(node, PackageDeclaration.JAVADOC_PROPERTY);
667             if (javadoc != null) {
668                 javadoc.accept(this);
669             }
670             visitList(node, PackageDeclaration.ANNOTATIONS_PROPERTY, String.valueOf(' '));
671         }
672         this.result.append("package "); //$NON-NLS-1$
673
getChildNode(node, PackageDeclaration.NAME_PROPERTY).accept(this);
674         this.result.append(';');
675         return false;
676     }
677
678     /*
679      * @see ASTVisitor#visit(ParenthesizedExpression)
680      */

681     public boolean visit(ParenthesizedExpression node) {
682         this.result.append('(');
683         getChildNode(node, ParenthesizedExpression.EXPRESSION_PROPERTY).accept(this);
684         this.result.append(')');
685         return false;
686     }
687
688     /*
689      * @see ASTVisitor#visit(PostfixExpression)
690      */

691     public boolean visit(PostfixExpression node) {
692         getChildNode(node, PostfixExpression.OPERAND_PROPERTY).accept(this);
693         this.result.append(getAttribute(node, PostfixExpression.OPERATOR_PROPERTY).toString());
694         return false;
695     }
696
697     /*
698      * @see ASTVisitor#visit(PrefixExpression)
699      */

700     public boolean visit(PrefixExpression node) {
701         this.result.append(getAttribute(node, PrefixExpression.OPERATOR_PROPERTY).toString());
702         getChildNode(node, PrefixExpression.OPERAND_PROPERTY).accept(this);
703         return false;
704     }
705
706     /*
707      * @see ASTVisitor#visit(PrimitiveType)
708      */

709     public boolean visit(PrimitiveType node) {
710         this.result.append(getAttribute(node, PrimitiveType.PRIMITIVE_TYPE_CODE_PROPERTY).toString());
711         return false;
712     }
713
714     /*
715      * @see ASTVisitor#visit(QualifiedName)
716      */

717     public boolean visit(QualifiedName node) {
718         getChildNode(node, QualifiedName.QUALIFIER_PROPERTY).accept(this);
719         this.result.append('.');
720         getChildNode(node, QualifiedName.NAME_PROPERTY).accept(this);
721         return false;
722     }
723
724     /*
725      * @see ASTVisitor#visit(ReturnStatement)
726      */

727     public boolean visit(ReturnStatement node) {
728         this.result.append("return"); //$NON-NLS-1$
729
ASTNode expression= getChildNode(node, ReturnStatement.EXPRESSION_PROPERTY);
730         if (expression != null) {
731             this.result.append(' ');
732             expression.accept(this);
733         }
734         this.result.append(';');
735         return false;
736     }
737
738     /*
739      * @see ASTVisitor#visit(SimpleName)
740      */

741     public boolean visit(SimpleName node) {
742         this.result.append(getAttribute(node, SimpleName.IDENTIFIER_PROPERTY));
743         return false;
744     }
745
746     /*
747      * @see ASTVisitor#visit(SimpleType)
748      */

749     public boolean visit(SimpleType node) {
750         return true;
751     }
752
753     /*
754      * @see ASTVisitor#visit(SingleVariableDeclaration)
755      */

756     public boolean visit(SingleVariableDeclaration node) {
757         if (node.getAST().apiLevel() == JLS2_INTERNAL) {
758             printModifiers(getIntAttribute(node, SingleVariableDeclaration.MODIFIERS_PROPERTY), this.result);
759         } else {
760             visitList(node, SingleVariableDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
761         }
762         getChildNode(node, SingleVariableDeclaration.TYPE_PROPERTY).accept(this);
763         if (node.getAST().apiLevel() >= AST.JLS3) {
764             if (getBooleanAttribute(node, SingleVariableDeclaration.VARARGS_PROPERTY)) {
765                 this.result.append("...");//$NON-NLS-1$
766
}
767         }
768         this.result.append(' ');
769         getChildNode(node, SingleVariableDeclaration.NAME_PROPERTY).accept(this);
770         int extraDimensions= getIntAttribute(node, SingleVariableDeclaration.EXTRA_DIMENSIONS_PROPERTY);
771         for (int i = 0; i < extraDimensions; i++) {
772             this.result.append("[]"); //$NON-NLS-1$
773
}
774         ASTNode initializer= getChildNode(node, SingleVariableDeclaration.INITIALIZER_PROPERTY);
775         if (initializer != null) {
776             this.result.append('=');
777             initializer.accept(this);
778         }
779         return false;
780     }
781
782     /*
783      * @see ASTVisitor#visit(StringLiteral)
784      */

785     public boolean visit(StringLiteral node) {
786         this.result.append(getAttribute(node, StringLiteral.ESCAPED_VALUE_PROPERTY));
787         return false;
788     }
789
790     /*
791      * @see ASTVisitor#visit(SuperConstructorInvocation)
792      */

793     public boolean visit(SuperConstructorInvocation node) {
794         ASTNode expression= getChildNode(node, SuperConstructorInvocation.EXPRESSION_PROPERTY);
795         if (expression != null) {
796             expression.accept(this);
797             this.result.append('.');
798         }
799         if (node.getAST().apiLevel() >= AST.JLS3) {
800             visitList(node, SuperConstructorInvocation.TYPE_ARGUMENTS_PROPERTY, String.valueOf(','), String.valueOf('<'), String.valueOf('>'));
801         }
802         this.result.append("super("); //$NON-NLS-1$
803
visitList(node, SuperConstructorInvocation.ARGUMENTS_PROPERTY, String.valueOf(','));
804         this.result.append(");"); //$NON-NLS-1$
805
return false;
806     }
807
808     /*
809      * @see ASTVisitor#visit(SuperFieldAccess)
810      */

811     public boolean visit(SuperFieldAccess node) {
812         ASTNode qualifier= getChildNode(node, SuperFieldAccess.QUALIFIER_PROPERTY);
813         if (qualifier != null) {
814             qualifier.accept(this);
815             this.result.append('.');
816         }
817         this.result.append("super."); //$NON-NLS-1$
818
getChildNode(node, SuperFieldAccess.NAME_PROPERTY).accept(this);
819         return false;
820     }
821
822     /*
823      * @see ASTVisitor#visit(SuperMethodInvocation)
824      */

825     public boolean visit(SuperMethodInvocation node) {
826         ASTNode qualifier= getChildNode(node, SuperMethodInvocation.QUALIFIER_PROPERTY);
827         if (qualifier != null) {
828             qualifier.accept(this);
829             this.result.append('.');
830         }
831         this.result.append("super."); //$NON-NLS-1$
832
if (node.getAST().apiLevel() >= AST.JLS3) {
833             visitList(node, SuperMethodInvocation.TYPE_ARGUMENTS_PROPERTY, String.valueOf(','), String.valueOf('<'), String.valueOf('>'));
834         }
835         getChildNode(node, SuperMethodInvocation.NAME_PROPERTY).accept(this);
836         this.result.append('(');
837         visitList(node, SuperMethodInvocation.ARGUMENTS_PROPERTY, String.valueOf(','));
838         this.result.append(')');
839         return false;
840     }
841
842     /*
843      * @see ASTVisitor#visit(SwitchCase)
844      */

845     public boolean visit(SwitchCase node) {
846         ASTNode expression= getChildNode(node, SwitchCase.EXPRESSION_PROPERTY);
847         if (expression == null) {
848             this.result.append("default"); //$NON-NLS-1$
849
} else {
850             this.result.append("case "); //$NON-NLS-1$
851
expression.accept(this);
852         }
853         this.result.append(':');
854         return false;
855     }
856
857     /*
858      * @see ASTVisitor#visit(SwitchStatement)
859      */

860     public boolean visit(SwitchStatement node) {
861         this.result.append("switch ("); //$NON-NLS-1$
862
getChildNode(node, SwitchStatement.EXPRESSION_PROPERTY).accept(this);
863         this.result.append(')');
864         this.result.append('{');
865         visitList(node, SwitchStatement.STATEMENTS_PROPERTY, null);
866         this.result.append('}');
867         return false;
868     }
869
870     /*
871      * @see ASTVisitor#visit(SynchronizedStatement)
872      */

873     public boolean visit(SynchronizedStatement node) {
874         this.result.append("synchronized ("); //$NON-NLS-1$
875
getChildNode(node, SynchronizedStatement.EXPRESSION_PROPERTY).accept(this);
876         this.result.append(')');
877         getChildNode(node, SynchronizedStatement.BODY_PROPERTY).accept(this);
878         return false;
879     }
880
881     /*
882      * @see ASTVisitor#visit(ThisExpression)
883      */

884     public boolean visit(ThisExpression node) {
885         ASTNode qualifier= getChildNode(node, ThisExpression.QUALIFIER_PROPERTY);
886         if (qualifier != null) {
887             qualifier.accept(this);
888             this.result.append('.');
889         }
890         this.result.append("this"); //$NON-NLS-1$
891
return false;
892     }
893
894     /*
895      * @see ASTVisitor#visit(ThrowStatement)
896      */

897     public boolean visit(ThrowStatement node) {
898         this.result.append("throw "); //$NON-NLS-1$
899
getChildNode(node, ThrowStatement.EXPRESSION_PROPERTY).accept(this);
900         this.result.append(';');
901         return false;
902     }
903
904     /*
905      * @see ASTVisitor#visit(TryStatement)
906      */

907     public boolean visit(TryStatement node) {
908         this.result.append("try "); //$NON-NLS-1$
909
getChildNode(node, TryStatement.BODY_PROPERTY).accept(this);
910         this.result.append(' ');
911         visitList(node, TryStatement.CATCH_CLAUSES_PROPERTY, null);
912         ASTNode finallyClause= getChildNode(node, TryStatement.FINALLY_PROPERTY);
913         if (finallyClause != null) {
914             this.result.append(" finally "); //$NON-NLS-1$
915
finallyClause.accept(this);
916         }
917         return false;
918     }
919
920     /*
921      * @see ASTVisitor#visit(TypeDeclaration)
922      */

923     public boolean visit(TypeDeclaration node) {
924         int apiLevel= node.getAST().apiLevel();
925         
926         ASTNode javadoc= getChildNode(node, TypeDeclaration.JAVADOC_PROPERTY);
927         if (javadoc != null) {
928             javadoc.accept(this);
929         }
930
931         if (apiLevel == JLS2_INTERNAL) {
932             printModifiers(getIntAttribute(node, TypeDeclaration.MODIFIERS_PROPERTY), this.result);
933         } else {
934             visitList(node, TypeDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
935         }
936     
937         boolean isInterface= getBooleanAttribute(node, TypeDeclaration.INTERFACE_PROPERTY);
938         this.result.append(isInterface ? "interface " : "class "); //$NON-NLS-1$ //$NON-NLS-2$
939
getChildNode(node, TypeDeclaration.NAME_PROPERTY).accept(this);
940         if (apiLevel >= AST.JLS3) {
941             visitList(node, TypeDeclaration.TYPE_PARAMETERS_PROPERTY, String.valueOf(','), String.valueOf('<'), String.valueOf('>'));
942         }
943
944         this.result.append(' ');
945         
946         ChildPropertyDescriptor superClassProperty= (apiLevel == JLS2_INTERNAL) ? TypeDeclaration.SUPERCLASS_PROPERTY : TypeDeclaration.SUPERCLASS_TYPE_PROPERTY;
947         ASTNode superclass= getChildNode(node, superClassProperty);
948         if (superclass != null) {
949             this.result.append("extends "); //$NON-NLS-1$
950
superclass.accept(this);
951             this.result.append(' ');
952         }
953         
954         ChildListPropertyDescriptor superInterfaceProperty= (apiLevel == JLS2_INTERNAL) ? TypeDeclaration.SUPER_INTERFACES_PROPERTY : TypeDeclaration.SUPER_INTERFACE_TYPES_PROPERTY;
955         String JavaDoc lead= isInterface ? "extends " : "implements "; //$NON-NLS-1$//$NON-NLS-2$
956
visitList(node, superInterfaceProperty, String.valueOf(','), lead, Util.EMPTY_STRING);
957         this.result.append('{');
958         visitList(node, TypeDeclaration.BODY_DECLARATIONS_PROPERTY, null);
959         this.result.append('}');
960         return false;
961     }
962
963     /*
964      * @see ASTVisitor#visit(TypeDeclarationStatement)
965      */

966     public boolean visit(TypeDeclarationStatement node) {
967         if (node.getAST().apiLevel() == JLS2_INTERNAL) {
968             getChildNode(node, TypeDeclarationStatement.TYPE_DECLARATION_PROPERTY).accept(this);
969         } else {
970             getChildNode(node, TypeDeclarationStatement.DECLARATION_PROPERTY).accept(this);
971         }
972         return false;
973     }
974
975     /*
976      * @see ASTVisitor#visit(TypeLiteral)
977      */

978     public boolean visit(TypeLiteral node) {
979         getChildNode(node, TypeLiteral.TYPE_PROPERTY).accept(this);
980         this.result.append(".class"); //$NON-NLS-1$
981
return false;
982     }
983
984     /*
985      * @see ASTVisitor#visit(VariableDeclarationExpression)
986      */

987     public boolean visit(VariableDeclarationExpression node) {
988         if (node.getAST().apiLevel() == JLS2_INTERNAL) {
989             printModifiers(getIntAttribute(node, VariableDeclarationExpression.MODIFIERS_PROPERTY), this.result);
990         } else {
991             visitList(node, VariableDeclarationExpression.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
992         }
993         getChildNode(node, VariableDeclarationExpression.TYPE_PROPERTY).accept(this);
994         this.result.append(' ');
995         visitList(node, VariableDeclarationExpression.FRAGMENTS_PROPERTY, String.valueOf(','));
996         return false;
997     }
998
999     /*
1000     * @see ASTVisitor#visit(VariableDeclarationFragment)
1001     */

1002    public boolean visit(VariableDeclarationFragment node) {
1003        getChildNode(node, VariableDeclarationFragment.NAME_PROPERTY).accept(this);
1004        int extraDimensions= getIntAttribute(node, VariableDeclarationFragment.EXTRA_DIMENSIONS_PROPERTY);
1005        for (int i = 0; i < extraDimensions; i++) {
1006            this.result.append("[]"); //$NON-NLS-1$
1007
}
1008        ASTNode initializer= getChildNode(node, VariableDeclarationFragment.INITIALIZER_PROPERTY);
1009        if (initializer != null) {
1010            this.result.append('=');
1011            initializer.accept(this);
1012        }
1013        return false;
1014    }
1015
1016    /*
1017     * @see ASTVisitor#visit(VariableDeclarationStatement)
1018     */

1019    public boolean visit(VariableDeclarationStatement node) {
1020        if (node.getAST().apiLevel() == JLS2_INTERNAL) {
1021            printModifiers(getIntAttribute(node, VariableDeclarationStatement.MODIFIERS_PROPERTY), this.result);
1022        } else {
1023            visitList(node, VariableDeclarationStatement.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
1024        }
1025        getChildNode(node, VariableDeclarationStatement.TYPE_PROPERTY).accept(this);
1026        this.result.append(' ');
1027        visitList(node, VariableDeclarationStatement.FRAGMENTS_PROPERTY, String.valueOf(','));
1028        this.result.append(';');
1029        return false;
1030    }
1031
1032    /*
1033     * @see ASTVisitor#visit(WhileStatement)
1034     */

1035    public boolean visit(WhileStatement node) {
1036        this.result.append("while ("); //$NON-NLS-1$
1037
getChildNode(node, WhileStatement.EXPRESSION_PROPERTY).accept(this);
1038        this.result.append(')');
1039        getChildNode(node, WhileStatement.BODY_PROPERTY).accept(this);
1040        return false;
1041    }
1042    
1043    
1044    /* (non-Javadoc)
1045     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.BlockComment)
1046     */

1047    public boolean visit(BlockComment node) {
1048        return false; // cant flatten, needs source
1049
}
1050    /* (non-Javadoc)
1051     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.LineComment)
1052     */

1053    public boolean visit(LineComment node) {
1054        return false; // cant flatten, needs source
1055
}
1056    /* (non-Javadoc)
1057     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MemberRef)
1058     */

1059    public boolean visit(MemberRef node) {
1060        ASTNode qualifier= getChildNode(node, MemberRef.QUALIFIER_PROPERTY);
1061        if (qualifier != null) {
1062            qualifier.accept(this);
1063        }
1064        this.result.append('#');
1065        getChildNode(node, MemberRef.NAME_PROPERTY).accept(this);
1066        return false;
1067    }
1068    /* (non-Javadoc)
1069     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodRef)
1070     */

1071    public boolean visit(MethodRef node) {
1072        ASTNode qualifier= getChildNode(node, MethodRef.QUALIFIER_PROPERTY);
1073        if (qualifier != null) {
1074            qualifier.accept(this);
1075        }
1076        this.result.append('#');
1077        getChildNode(node, MethodRef.NAME_PROPERTY).accept(this);
1078        this.result.append('(');
1079        visitList(node, MethodRef.PARAMETERS_PROPERTY, ","); //$NON-NLS-1$
1080
this.result.append(')');
1081        return false;
1082    }
1083    /* (non-Javadoc)
1084     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.MethodRefParameter)
1085     */

1086    public boolean visit(MethodRefParameter node) {
1087        getChildNode(node, MethodRefParameter.TYPE_PROPERTY).accept(this);
1088        if (node.getAST().apiLevel() >= AST.JLS3) {
1089            if (getBooleanAttribute(node, MethodRefParameter.VARARGS_PROPERTY)) {
1090                this.result.append("..."); //$NON-NLS-1$
1091
}
1092        }
1093        ASTNode name= getChildNode(node, MethodRefParameter.NAME_PROPERTY);
1094        if (name != null) {
1095            this.result.append(' ');
1096            name.accept(this);
1097        }
1098        return false;
1099    }
1100    /* (non-Javadoc)
1101     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TagElement)
1102     */

1103    public boolean visit(TagElement node) {
1104        Object JavaDoc tagName= getAttribute(node, TagElement.TAG_NAME_PROPERTY);
1105        if (tagName != null) {
1106            this.result.append((String JavaDoc) tagName);
1107        }
1108        List JavaDoc list= getChildList(node, TagElement.FRAGMENTS_PROPERTY);
1109        for (int i= 0; i < list.size(); i++) {
1110            if (i > 0 || tagName != null) {
1111                this.result.append(' ');
1112            }
1113            ASTNode curr= (ASTNode) list.get(i);
1114            if (curr instanceof TagElement) {
1115                this.result.append('{');
1116                curr.accept(this);
1117                this.result.append('}');
1118            } else {
1119                curr.accept(this);
1120            }
1121        }
1122        return false;
1123    }
1124    /* (non-Javadoc)
1125     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TextElement)
1126     */

1127    public boolean visit(TextElement node) {
1128        this.result.append(getAttribute(node, TextElement.TEXT_PROPERTY));
1129        return false;
1130    }
1131    /*
1132     * @see ASTVisitor#visit(AnnotationTypeDeclaration)
1133     * @since 3.0
1134     */

1135    public boolean visit(AnnotationTypeDeclaration node) {
1136        ASTNode javadoc= getChildNode(node, AnnotationTypeDeclaration.JAVADOC_PROPERTY);
1137        if (javadoc != null) {
1138            javadoc.accept(this);
1139        }
1140        visitList(node, AnnotationTypeDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
1141        this.result.append("@interface ");//$NON-NLS-1$
1142
getChildNode(node, AnnotationTypeDeclaration.NAME_PROPERTY).accept(this);
1143        this.result.append('{');
1144        visitList(node, AnnotationTypeDeclaration.BODY_DECLARATIONS_PROPERTY, Util.EMPTY_STRING);
1145        this.result.append('}');
1146        return false;
1147    }
1148    
1149    /*
1150     * @see ASTVisitor#visit(AnnotationTypeMemberDeclaration)
1151     * @since 3.0
1152     */

1153    public boolean visit(AnnotationTypeMemberDeclaration node) {
1154        ASTNode javadoc= getChildNode(node, AnnotationTypeMemberDeclaration.JAVADOC_PROPERTY);
1155        if (javadoc != null) {
1156            javadoc.accept(this);
1157        }
1158        visitList(node, AnnotationTypeMemberDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
1159        getChildNode(node, AnnotationTypeMemberDeclaration.TYPE_PROPERTY).accept(this);
1160        this.result.append(' ');
1161        getChildNode(node, AnnotationTypeMemberDeclaration.NAME_PROPERTY).accept(this);
1162        this.result.append("()");//$NON-NLS-1$
1163
ASTNode def= getChildNode(node, AnnotationTypeMemberDeclaration.DEFAULT_PROPERTY);
1164        if (def != null) {
1165            this.result.append(" default ");//$NON-NLS-1$
1166
def.accept(this);
1167        }
1168        this.result.append(';');
1169        return false;
1170    }
1171
1172    /*
1173     * @see ASTVisitor#visit(EnhancedForStatement)
1174     * @since 3.0
1175     */

1176    public boolean visit(EnhancedForStatement node) {
1177        this.result.append("for (");//$NON-NLS-1$
1178
getChildNode(node, EnhancedForStatement.PARAMETER_PROPERTY).accept(this);
1179        this.result.append(':');
1180        getChildNode(node, EnhancedForStatement.EXPRESSION_PROPERTY).accept(this);
1181        this.result.append(')');
1182        getChildNode(node, EnhancedForStatement.BODY_PROPERTY).accept(this);
1183        return false;
1184    }
1185
1186    /*
1187     * @see ASTVisitor#visit(EnumConstantDeclaration)
1188     * @since 3.0
1189     */

1190    public boolean visit(EnumConstantDeclaration node) {
1191        ASTNode javadoc= getChildNode(node, EnumConstantDeclaration.JAVADOC_PROPERTY);
1192        if (javadoc != null) {
1193            javadoc.accept(this);
1194        }
1195        visitList(node, EnumConstantDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
1196        getChildNode(node, EnumConstantDeclaration.NAME_PROPERTY).accept(this);
1197        visitList(node, EnumConstantDeclaration.ARGUMENTS_PROPERTY, String.valueOf(','), String.valueOf('('), String.valueOf(')'));
1198        ASTNode classDecl= getChildNode(node, EnumConstantDeclaration.ANONYMOUS_CLASS_DECLARATION_PROPERTY);
1199        if (classDecl != null) {
1200            classDecl.accept(this);
1201        }
1202        return false;
1203    }
1204
1205    /*
1206     * @see ASTVisitor#visit(EnumDeclaration)
1207     * @since 3.0
1208     */

1209    public boolean visit(EnumDeclaration node) {
1210        ASTNode javadoc= getChildNode(node, EnumDeclaration.JAVADOC_PROPERTY);
1211        if (javadoc != null) {
1212            javadoc.accept(this);
1213        }
1214        visitList(node, EnumDeclaration.MODIFIERS2_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
1215        this.result.append("enum ");//$NON-NLS-1$
1216
getChildNode(node, EnumDeclaration.NAME_PROPERTY).accept(this);
1217        this.result.append(' ');
1218        visitList(node, EnumDeclaration.SUPER_INTERFACE_TYPES_PROPERTY, String.valueOf(','), "implements ", Util.EMPTY_STRING); //$NON-NLS-1$
1219

1220        this.result.append('{');
1221        visitList(node, EnumDeclaration.ENUM_CONSTANTS_PROPERTY, String.valueOf(','), Util.EMPTY_STRING, Util.EMPTY_STRING);
1222        visitList(node, EnumDeclaration.BODY_DECLARATIONS_PROPERTY, Util.EMPTY_STRING, String.valueOf(';'), Util.EMPTY_STRING);
1223        this.result.append('}');
1224        return false;
1225    }
1226    /*
1227     * @see ASTVisitor#visit(MarkerAnnotation)
1228     * @since 3.0
1229     */

1230    public boolean visit(MarkerAnnotation node) {
1231        this.result.append('@');
1232        getChildNode(node, MarkerAnnotation.TYPE_NAME_PROPERTY).accept(this);
1233        return false;
1234    }
1235    
1236    /*
1237     * @see ASTVisitor#visit(MemberValuePair)
1238     * @since 3.0
1239     */

1240    public boolean visit(MemberValuePair node) {
1241        getChildNode(node, MemberValuePair.NAME_PROPERTY).accept(this);
1242        this.result.append('=');
1243        getChildNode(node, MemberValuePair.VALUE_PROPERTY).accept(this);
1244        return false;
1245    }
1246    /*
1247     * @see ASTVisitor#visit(Modifier)
1248     * @since 3.0
1249     */

1250    public boolean visit(Modifier node) {
1251        this.result.append(getAttribute(node, Modifier.KEYWORD_PROPERTY).toString());
1252        return false;
1253    }
1254    
1255    /*
1256     * @see ASTVisitor#visit(NormalAnnotation)
1257     * @since 3.0
1258     */

1259    public boolean visit(NormalAnnotation node) {
1260        this.result.append('@');
1261        getChildNode(node, NormalAnnotation.TYPE_NAME_PROPERTY).accept(this);
1262        this.result.append('(');
1263        visitList(node, NormalAnnotation.VALUES_PROPERTY, ", "); //$NON-NLS-1$
1264
this.result.append(')');
1265        return false;
1266    }
1267    /*
1268     * @see ASTVisitor#visit(ParameterizedType)
1269     * @since 3.0
1270     */

1271    public boolean visit(ParameterizedType node) {
1272        getChildNode(node, ParameterizedType.TYPE_PROPERTY).accept(this);
1273        this.result.append('<');
1274        visitList(node, ParameterizedType.TYPE_ARGUMENTS_PROPERTY, ", "); //$NON-NLS-1$
1275
this.result.append('>');
1276        return false;
1277    }
1278
1279    /*
1280     * @see ASTVisitor#visit(QualifiedType)
1281     * @since 3.0
1282     */

1283    public boolean visit(QualifiedType node) {
1284        getChildNode(node, QualifiedType.QUALIFIER_PROPERTY).accept(this);
1285        this.result.append('.');
1286        getChildNode(node, QualifiedType.NAME_PROPERTY).accept(this);
1287        return false;
1288    }
1289
1290    /* (non-Javadoc)
1291     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SingleMemberAnnotation)
1292     */

1293    public boolean visit(SingleMemberAnnotation node) {
1294        this.result.append('@');
1295        getChildNode(node, SingleMemberAnnotation.TYPE_NAME_PROPERTY).accept(this);
1296        this.result.append('(');
1297        getChildNode(node, SingleMemberAnnotation.VALUE_PROPERTY).accept(this);
1298        this.result.append(')');
1299        return false;
1300    }
1301
1302    /* (non-Javadoc)
1303     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.TypeParameter)
1304     */

1305    public boolean visit(TypeParameter node) {
1306        getChildNode(node, TypeParameter.NAME_PROPERTY).accept(this);
1307        visitList(node, TypeParameter.TYPE_BOUNDS_PROPERTY, " & ", " extends ", Util.EMPTY_STRING); //$NON-NLS-1$ //$NON-NLS-2$
1308
return false;
1309    }
1310    
1311    /* (non-Javadoc)
1312     * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.WildcardType)
1313     */

1314    public boolean visit(WildcardType node) {
1315        this.result.append('?');
1316        ASTNode bound = getChildNode(node, WildcardType.BOUND_PROPERTY);
1317        if (bound != null) {
1318            if (getBooleanAttribute(node, WildcardType.UPPER_BOUND_PROPERTY)) {
1319                this.result.append(" extends ");//$NON-NLS-1$
1320
} else {
1321                this.result.append(" super ");//$NON-NLS-1$
1322
}
1323            bound.accept(this);
1324        }
1325        return false;
1326    }
1327}
1328
Popular Tags