001    /*
002     * The JastAdd Extensible Java Compiler (http://jastadd.org) is covered
003     * by the modified BSD License. You should have received a copy of the
004     * modified BSD license with this compiler.
005     * 
006     * Copyright (c) 2005-2008, Torbjorn Ekman
007     * All rights reserved.
008     */
009    
010    aspect PrettyPrint {
011      // Default output
012      
013      public String ASTNode.toString() {
014        StringBuffer s = new StringBuffer();
015        toString(s);
016        return s.toString().trim();
017      }
018      
019      public void ASTNode.toString(StringBuffer s) {
020        throw new Error("Operation toString(StringBuffer s) not implemented for " + getClass().getName());
021      }
022    
023      public void Program.toString(StringBuffer s) {
024        for(Iterator iter = compilationUnitIterator(); iter.hasNext(); ) {
025          CompilationUnit cu = (CompilationUnit)iter.next();
026          if(cu.fromSource()) { 
027            cu.toString(s);
028          }
029        }
030      }
031            
032      public void CompilationUnit.toString(StringBuffer s) {
033        try {
034          if(!getPackageDecl().equals("")) {
035            s.append("package " + getPackageDecl() + ";\n");
036          }
037          for(int i = 0; i < getNumImportDecl(); i++) {
038            getImportDecl(i).toString(s);
039          }
040          for(int i = 0; i < getNumTypeDecl(); i++) {
041            getTypeDecl(i).toString(s);
042            s.append("\n");
043          }
044        } catch (NullPointerException e) {
045          System.out.print("Error in compilation unit hosting " + getTypeDecl(0).typeName());
046          throw e;
047        }
048      }
049    
050      public void SingleTypeImportDecl.toString(StringBuffer s) {
051        s.append("import ");
052        getAccess().toString(s);
053        s.append(";\n");
054      }
055    
056      public void TypeImportOnDemandDecl.toString(StringBuffer s) {
057        s.append("import ");
058        getAccess().toString(s);
059        s.append(".*;\n");
060      }
061    
062      protected void TypeDecl.ppBodyDecls(StringBuffer s) {
063        s.append(" {");
064        for(int i=0; i < getNumBodyDecl(); i++) {
065          getBodyDecl(i).toString(s);
066        }
067        s.append(indent() + "}");
068      } 
069        
070      public void ClassDecl.toString(StringBuffer s) {
071        s.append(indent());
072        getModifiers().toString(s);
073        s.append("class " + name());
074        if(hasSuperClassAccess()) {
075          s.append(" extends ");
076          getSuperClassAccess().toString(s);
077        }
078        if(getNumImplements() > 0) {
079          s.append(" implements ");
080          getImplements(0).toString(s);
081          for(int i = 1; i < getNumImplements(); i++) {
082            s.append(", ");
083            getImplements(i).toString(s);
084          }
085        }
086        ppBodyDecls(s);
087      }
088      
089      public void InterfaceDecl.toString(StringBuffer s) {
090        s.append(indent());
091        getModifiers().toString(s);
092        s.append("interface " + name());
093        if(getNumSuperInterfaceId() > 0) {
094          s.append(" extends ");
095          getSuperInterfaceId(0).toString(s);
096          for(int i = 1; i < getNumSuperInterfaceId(); i++) {
097            s.append(", ");
098            getSuperInterfaceId(i).toString(s);
099          }
100        }
101        ppBodyDecls(s);
102      }
103    
104      // Type body decl
105    
106      public void InstanceInitializer.toString(StringBuffer s) {
107        if(getBlock().getNumStmt() == 0) return;
108        s.append(indent());
109        getBlock().toString(s);
110      }
111    
112      public void StaticInitializer.toString(StringBuffer s) {
113        if(getBlock().getNumStmt() == 0) return;
114        s.append(indent());
115        s.append("static ");
116        getBlock().toString(s);
117      }
118      
119      public void ConstructorDecl.toString(StringBuffer s) {
120        if(isDefaultConstructor()) return;
121        s.append(indent());
122        getModifiers().toString(s);
123        s.append(name() + "(");
124        if(getNumParameter() > 0) {
125          getParameter(0).toString(s);
126          for(int i = 1; i < getNumParameter(); i++) {
127            s.append(", ");
128            getParameter(i).toString(s);
129          }
130        }
131        s.append(")");
132        if(getNumException() > 0) {
133          s.append(" throws ");
134          getException(0).toString(s);
135          for(int i = 1; i < getNumException(); i++) {
136            s.append(", ");
137            getException(i).toString(s);
138          }
139        }
140        
141        s.append(" {");
142        if(hasConstructorInvocation()) {
143          getConstructorInvocation().toString(s);
144        }
145        for(int i = 0; i < getBlock().getNumStmt(); i++) {
146          getBlock().getStmt(i).toString(s);
147        }
148        s.append(indent());
149        s.append("}");
150      }
151    
152      public void FieldDeclaration.toString(StringBuffer s) {
153        s.append(indent());
154        getModifiers().toString(s);
155        getTypeAccess().toString(s);
156        s.append(" " + name());
157        if(hasInit()) {
158          s.append(" = ");
159          getInit().toString(s);
160        }
161        s.append(";");
162      }
163    
164      public void VariableDeclaration.toString(StringBuffer s) {
165        s.append(indent());
166        getModifiers().toString(s);
167        getTypeAccess().toString(s);
168        s.append(" " + name());
169        if(hasInit()) {
170          s.append(" = ");
171          getInit().toString(s);
172        }
173        s.append(";");
174      }
175    
176      public void MethodDecl.toString(StringBuffer s) {
177        s.append(indent());
178        getModifiers().toString(s);
179        getTypeAccess().toString(s);
180        s.append(" " + name() + "(");
181        if(getNumParameter() > 0) {
182          getParameter(0).toString(s);
183          for(int i = 1; i < getNumParameter(); i++) {
184            s.append(", ");
185            getParameter(i).toString(s);
186          }
187        }
188        s.append(")");
189        if(getNumException() > 0) {
190          s.append(" throws ");
191          getException(0).toString(s);
192          for(int i = 1; i < getNumException(); i++) {
193            s.append(", ");
194            getException(i).toString(s);
195          }
196        }
197        if(hasBlock()) {
198          s.append(" ");
199          getBlock().toString(s);
200        }
201        else {
202          s.append(";");
203        }
204      }
205    
206      public void MemberClassDecl.toString(StringBuffer s) {
207        s.append(indent());
208        getClassDecl().toString(s);
209      }
210    
211      public void MemberInterfaceDecl.toString(StringBuffer s) {
212        s.append(indent());
213        getInterfaceDecl().toString(s);
214      }
215    
216      public void EmptyType.toString(StringBuffer s) {
217        s.append(indent());
218        s.append(";");
219      }
220    
221      public void ArrayInit.toString(StringBuffer s) {
222        s.append("{ ");
223        if(getNumInit() > 0) {
224          getInit(0).toString(s);
225          for(int i = 1; i < getNumInit(); i++) {
226            s.append(", ");
227            getInit(i).toString(s);
228          }
229        }
230        s.append(" } ");
231      }
232    
233      public void ParameterDeclaration.toString(StringBuffer s) {
234        getModifiers().toString(s);
235        getTypeAccess().toString(s);
236        s.append(" " + name());
237      }
238    
239      // Assign Expression
240    
241      public void AssignExpr.toString(StringBuffer s) {
242        getDest().toString(s);
243        s.append(printOp());
244        getSource().toString(s);
245      }
246    
247      syn String AssignExpr.printOp() = " = ";
248      eq AssignSimpleExpr.printOp() = " = ";
249      eq AssignMulExpr.printOp() = " *= ";
250      eq AssignDivExpr.printOp() = " /= ";
251      eq AssignModExpr.printOp() = " %= ";
252      eq AssignPlusExpr.printOp() = " += ";
253      eq AssignMinusExpr.printOp() = " -= ";
254      eq AssignLShiftExpr.printOp() = " <<= ";
255      eq AssignRShiftExpr.printOp() = " >>= ";
256      eq AssignURShiftExpr.printOp() = " >>>= ";
257      eq AssignAndExpr.printOp() = " &= ";
258      eq AssignXorExpr.printOp() = " ^= ";
259      eq AssignOrExpr.printOp()  = " |= ";
260    
261      // Literals
262        
263      public void Literal.toString(StringBuffer s) {
264        s.append(getLITERAL());
265      }
266      
267      public void StringLiteral.toString(StringBuffer s) {
268        s.append("\"" + escape(getLITERAL()) + "\"");
269      }
270      
271      public void CharacterLiteral.toString(StringBuffer s) {
272        s.append("'" + escape(getLITERAL()) + "'");
273      }
274    
275      public void LongLiteral.toString(StringBuffer s) {
276        s.append(getLITERAL());
277        s.append("L");
278      }
279    
280      public void FloatingPointLiteral.toString(StringBuffer s) {
281        s.append(getLITERAL());
282        s.append("F");
283      }
284    
285      public void DoubleLiteral.toString(StringBuffer s) {
286        s.append(getLITERAL());
287        s.append("D");
288      }
289    
290      protected static String Literal.escape(String s) {
291        StringBuffer result = new StringBuffer();
292        for (int i=0; i < s.length(); i++) {
293          switch(s.charAt(i)) {
294            case '\b' : result.append("\\b"); break;
295            case '\t' : result.append("\\t"); break;
296            case '\n' : result.append("\\n"); break;
297            case '\f' : result.append("\\f"); break;
298            case '\r' : result.append("\\r"); break;
299            case '\"' : result.append("\\\""); break;
300            case '\'' : result.append("\\\'"); break;
301            case '\\' : result.append("\\\\"); break;
302            default:
303              int value = (int)s.charAt(i);
304              if(value < 0x20 || (value > 0x7e))
305                result.append(asEscape(value));
306              else
307                result.append(s.charAt(i));
308          }
309        }
310        return result.toString();
311      }
312      protected static String Literal.asEscape(int value) {
313        StringBuffer s = new StringBuffer("\\u");
314        String hex = Integer.toHexString(value);
315        for(int i = 0; i < 4-hex.length(); i++)
316          s.append("0");
317        s.append(hex);
318        return s.toString();
319      }
320    
321      public void ParExpr.toString(StringBuffer s) {
322        s.append("(");
323        getExpr().toString(s);
324        s.append(")");
325      }
326    
327      public void ClassInstanceExpr.toString(StringBuffer s) {
328        s.append("new ");
329        getAccess().toString(s);
330        s.append("(");
331        if(getNumArg() > 0) {
332          getArg(0).toString(s);
333          for(int i = 1; i < getNumArg(); i++) {
334            s.append(", ");
335            getArg(i).toString(s);
336          }
337        }
338        s.append(")");
339    
340        if(hasTypeDecl()) {
341          TypeDecl decl = getTypeDecl();
342          s.append(" {");
343          for(int i = 0; i < decl.getNumBodyDecl(); i++) {
344            if(!(decl.getBodyDecl(i) instanceof ConstructorDecl))
345              decl.getBodyDecl(i).toString(s);
346          }
347          s.append(typeDeclIndent());
348          s.append("}");
349        }
350      }
351      inh String ClassInstanceExpr.typeDeclIndent();
352      eq Stmt.getChild().typeDeclIndent() = indent();
353      eq BodyDecl.getChild().typeDeclIndent() = indent();
354      eq Program.getChild().typeDeclIndent() = "";
355    
356      public void ArrayCreationExpr.toString(StringBuffer s) {
357        s.append("new ");
358        getTypeAccess().toString(s);
359        if(hasArrayInit()) {
360          getArrayInit().toString(s);
361        }
362      }
363    
364      // Pre and post operations for unary expression
365      
366      public void Unary.toString(StringBuffer s) {
367        s.append(printPreOp());
368        getOperand().toString(s);
369        s.append(printPostOp());
370      }
371    
372      syn String Unary.printPostOp() = "";
373      eq PostIncExpr.printPostOp() = "++";
374      eq PostDecExpr.printPostOp() = "--";
375    
376      syn String Unary.printPreOp() = "";
377      eq PreIncExpr.printPreOp() = "++";
378      eq PreDecExpr.printPreOp() = "--";
379      eq MinusExpr.printPreOp() = "-";
380      eq PlusExpr.printPreOp() = "+";
381      eq BitNotExpr.printPreOp() = "~";
382      eq LogNotExpr.printPreOp() = "!";
383      
384    
385      public void CastExpr.toString(StringBuffer s) {
386        s.append("(");
387        getTypeAccess().toString(s);
388        s.append(")");
389        getExpr().toString(s);
390      }
391    
392      // Binary Expr
393    
394      public void Binary.toString(StringBuffer s) {
395        getLeftOperand().toString(s);
396        s.append(printOp());
397        getRightOperand().toString(s);
398      }
399    
400      syn String Binary.printOp();
401      eq MulExpr.printOp() = " * ";
402      eq DivExpr.printOp() = " / ";
403      eq ModExpr.printOp() = " % ";
404      eq AddExpr.printOp() = " + ";
405      eq SubExpr.printOp() = " - ";
406      eq LShiftExpr.printOp() = " << ";
407      eq RShiftExpr.printOp() = " >> ";
408      eq URShiftExpr.printOp() = " >>> ";
409      eq AndBitwiseExpr.printOp() = " & ";
410      eq OrBitwiseExpr.printOp() = " | ";
411      eq XorBitwiseExpr.printOp() = " ^ ";
412      eq AndLogicalExpr.printOp() = " && ";
413      eq OrLogicalExpr.printOp() = " || ";
414      eq LTExpr.printOp() = " < ";
415      eq GTExpr.printOp() = " > ";
416      eq LEExpr.printOp() = " <= ";
417      eq GEExpr.printOp() = " >= ";
418      eq EQExpr.printOp() = " == ";
419      eq NEExpr.printOp() = " != ";
420    
421      public void InstanceOfExpr.toString(StringBuffer s) {
422        getExpr().toString(s);
423        s.append(" instanceof ");
424        getTypeAccess().toString(s);
425      }
426    
427      public void ConditionalExpr.toString(StringBuffer s) {
428        getCondition().toString(s);
429        s.append(" ? ");
430        getTrueExpr().toString(s);
431        s.append(" : ");
432        getFalseExpr().toString(s);
433      }
434    
435      public void Modifiers.toString(StringBuffer s) {
436        for(int i = 0; i < getNumModifier(); i++) {
437          getModifier(i).toString(s);
438          s.append(" ");
439        }
440      }
441         
442      public void Modifier.toString(StringBuffer s) {
443        s.append(getID());
444      }
445    
446      public void AbstractDot.toString(StringBuffer s) {
447        getLeft().toString(s);
448        if(!nextAccess().isArrayAccess())
449          s.append(".");
450        getRight().toString(s);
451      }
452    
453      public void VarAccess.toString(StringBuffer s) {
454        s.append(name());
455      }
456    
457      public void MethodAccess.toString(StringBuffer s) {
458        s.append(name());
459        s.append("(");
460        if(getNumArg() > 0) {
461          getArg(0).toString(s);
462          for(int i = 1; i < getNumArg(); i++) {
463            s.append(", ");
464            getArg(i).toString(s);
465          }
466        }
467        s.append(")");
468      }
469    
470      public void ConstructorAccess.toString(StringBuffer s) {
471        s.append(name());
472        s.append("(");
473        if(getNumArg() > 0) {
474          getArg(0).toString(s);
475          for(int i = 1; i < getNumArg(); i++) {
476            s.append(", ");
477            getArg(i).toString(s);
478          }
479        }
480        s.append(")");
481      }
482      
483      public void TypeAccess.toString(StringBuffer s) {
484        if(decl().isReferenceType())
485          s.append(nameWithPackage());
486        else
487          s.append(decl().name());
488      }
489      
490      public void ArrayTypeAccess.toString(StringBuffer s) {
491        getAccess().toString(s);
492        s.append("[]");
493      }
494    
495      public void ArrayTypeWithSizeAccess.toString(StringBuffer s) {
496        getAccess().toString(s);
497        s.append("[");
498        getExpr().toString(s);
499        s.append("]");
500      }
501    
502      public void ThisAccess.toString(StringBuffer s) {
503        s.append("this");
504      }
505      
506      public void SuperAccess.toString(StringBuffer s) {
507        s.append("super");
508      }
509    
510      public void PackageAccess.toString(StringBuffer s) {
511        s.append(getPackage());
512      }
513    
514      public void ArrayAccess.toString(StringBuffer s) {
515        s.append("[");
516        getExpr().toString(s);
517        s.append("]");
518      }
519    
520      public void ClassAccess.toString(StringBuffer s) {
521        s.append("class");
522      }
523    
524      // Stmts
525    
526      public void Block.toString(StringBuffer s) {
527        String indent = indent();
528        s.append(shouldHaveIndent() ? indent : "");
529        s.append("{");
530        for(int i = 0; i < getNumStmt(); i++) {
531          getStmt(i).toString(s);
532        }
533        s.append(shouldHaveIndent() ? indent : indent.substring(0, indent.length()-2));
534        s.append("}");
535      }
536    
537      public void EmptyStmt.toString(StringBuffer s) {
538        s.append(indent());
539        s.append(";");
540      }
541    
542      public void LabeledStmt.toString(StringBuffer s) {
543        s.append(indent());
544        s.append(getLabel() + ":");
545        getStmt().toString(s);
546      }
547    
548      public void ExprStmt.toString(StringBuffer s) {
549        s.append(indent());
550        getExpr().toString(s);
551        s.append(";");
552      }
553    
554      public void SwitchStmt.toString(StringBuffer s) {
555        s.append(indent());
556        s.append("switch (");
557        getExpr().toString(s);
558        s.append(")");
559        getBlock().toString(s);
560      }
561    
562      public void ConstCase.toString(StringBuffer s) {
563        s.append(indent());
564        s.append("case ");
565        getValue().toString(s);
566        s.append(":");
567      }
568    
569      public void DefaultCase.toString(StringBuffer s) {
570        s.append(indent());
571        s.append("default:");
572      }
573    
574      public void IfStmt.toString(StringBuffer s) {
575        s.append(indent());
576        s.append("if(");
577        getCondition().toString(s);
578        s.append(") ");
579        getThen().toString(s);
580        if(hasElse()) {
581          s.append(indent());
582          s.append("else ");
583          getElse().toString(s);
584        }
585      }
586    
587      public void WhileStmt.toString(StringBuffer s) {
588        s.append(indent());
589        s.append("while(");
590        getCondition().toString(s);
591        s.append(")");
592        getStmt().toString(s);
593      }
594    
595      public void DoStmt.toString(StringBuffer s) {
596        s.append(indent());
597        s.append("do ");
598        getStmt().toString(s);
599        s.append("while(");
600        getCondition().toString(s);
601        s.append(");");
602      }
603    
604      public void ForStmt.toString(StringBuffer s) {
605        s.append(indent());
606        s.append("for(");
607        if(getNumInitStmt() > 0) {
608          if(getInitStmt(0) instanceof VariableDeclaration) {
609            int minDimension = Integer.MAX_VALUE;
610            for(int i = 0; i < getNumInitStmt(); i++) {
611              VariableDeclaration v = (VariableDeclaration)getInitStmt(i);
612              minDimension = Math.min(minDimension, v.type().dimension());
613            }
614            VariableDeclaration v = (VariableDeclaration)getInitStmt(0);
615            v.getModifiers().toString(s);
616            s.append(v.type().elementType().typeName());
617            for(int i = minDimension; i > 0; i--)
618              s.append("[]");
619    
620            for(int i = 0; i < getNumInitStmt(); i++) {
621              if(i != 0)
622                s.append(",");
623              v = (VariableDeclaration)getInitStmt(i);
624              s.append(" " + v.name());
625              for(int j = v.type().dimension() - minDimension; j > 0; j--)
626                s.append("[]");
627              if(v.hasInit()) {
628                s.append(" = ");
629                v.getInit().toString(s);
630              }
631            }
632          }
633          else if(getInitStmt(0) instanceof ExprStmt) {
634            ExprStmt stmt = (ExprStmt)getInitStmt(0);
635            stmt.getExpr().toString(s);
636            for(int i = 1; i < getNumInitStmt(); i++) {
637              s.append(", ");
638              stmt = (ExprStmt)getInitStmt(i);
639              stmt.getExpr().toString(s);
640            }
641          }
642          else {
643            throw new Error("Unexpected initializer in for loop: " + getInitStmt(0));
644          }
645        }
646        
647        s.append("; ");
648        if(hasCondition()) {
649          getCondition().toString(s);
650        }
651        s.append("; ");
652    
653        if(getNumUpdateStmt() > 0) {
654          ExprStmt stmt = (ExprStmt)getUpdateStmt(0);
655          stmt.getExpr().toString(s);
656          for(int i = 1; i < getNumUpdateStmt(); i++) {
657            s.append(", ");
658            stmt = (ExprStmt)getUpdateStmt(i);
659            stmt.getExpr().toString(s);
660          }
661        }
662        
663        s.append(") ");
664        getStmt().toString(s);
665      }
666    
667      public void BreakStmt.toString(StringBuffer s) {
668        s.append(indent());
669        s.append("break ");
670        if(hasLabel())
671          s.append(getLabel());
672        s.append(";");
673      }
674    
675      public void ContinueStmt.toString(StringBuffer s) {
676        s.append(indent());
677        s.append("continue ");
678        if(hasLabel())
679          s.append(getLabel());
680        s.append(";");
681      }
682    
683      public void ReturnStmt.toString(StringBuffer s) {
684        s.append(indent());
685        s.append("return ");
686        if(hasResult()) {
687          getResult().toString(s);
688        }
689        s.append(";");
690      }
691    
692      public void ThrowStmt.toString(StringBuffer s) {
693        s.append(indent());
694        s.append("throw ");
695        getExpr().toString(s);
696        s.append(";");
697      }
698    
699      public void SynchronizedStmt.toString(StringBuffer s) {
700        s.append(indent());
701        s.append("synchronized(");
702        getExpr().toString(s);
703        s.append(") ");
704        getBlock().toString(s);
705      }
706    
707      public void TryStmt.toString(StringBuffer s) {
708        s.append(indent());
709        s.append("try ");
710        getBlock().toString(s);
711        for(int i = 0; i < getNumCatchClause(); i++) {
712          s.append(indent());
713          getCatchClause(i).toString(s);
714        }
715        if(hasFinally()) {
716          s.append(indent());
717          s.append("finally ");
718          getFinally().toString(s);
719        }
720      }
721    
722      public void BasicCatch.toString(StringBuffer s) {
723        s.append("catch (");
724        getParameter().toString(s);
725        s.append(") ");
726        getBlock().toString(s);
727      }
728    
729      public void AssertStmt.toString(StringBuffer s) {
730        s.append(indent());
731        s.append("assert ");
732        getfirst().toString(s);
733        if(hasExpr()) {
734          s.append(" : ");
735          getExpr().toString(s);
736        }
737        s.append(";");
738      }
739      
740      public void LocalClassDeclStmt.toString(StringBuffer s) {
741        getClassDecl().toString(s);
742      }
743    
744      syn String ASTNode.indent() {
745        String indent = extractIndent();
746        return indent.startsWith("\n") ? indent : ("\n" + indent);
747      }
748    
749      syn String ASTNode.extractIndent() {
750        if(getParent() == null)
751          return "";
752        String indent = getParent().extractIndent();
753        if(getParent().addsIndentationLevel())
754          indent += "  ";
755        return indent;
756      }
757    
758      syn boolean ASTNode.addsIndentationLevel() = false;
759      eq TypeDecl.addsIndentationLevel() = true;
760      eq BodyDecl.addsIndentationLevel() = true;
761      eq MemberTypeDecl.addsIndentationLevel() = false;
762      eq Stmt.addsIndentationLevel() = true;
763      eq Block.addsIndentationLevel() = shouldHaveIndent();
764    
765      syn boolean Block.shouldHaveIndent() = 
766        getParent() instanceof List && getParent().getParent() instanceof Block;
767    
768      // dump the AST to standard output
769    
770      public String ASTNode.dumpTree() {
771        StringBuffer s = new StringBuffer();
772        dumpTree(s, 0);
773        return s.toString();
774      }
775    
776      public void ASTNode.dumpTree(StringBuffer s, int j) {
777        for(int i = 0; i < j; i++) {
778          s.append("  ");
779        }
780        s.append(dumpString() + "\n");
781        for(int i = 0; i < getNumChild(); i++)
782          getChild(i).dumpTree(s, j + 1);
783      }
784    
785      public String ASTNode.dumpTreeNoRewrite() {
786        StringBuffer s = new StringBuffer();
787        dumpTreeNoRewrite(s, 0);
788        return s.toString();
789      }
790      protected void ASTNode.dumpTreeNoRewrite(StringBuffer s, int indent) {
791        for(int i = 0; i < indent; i++)
792          s.append("  ");
793        s.append(dumpString());
794        s.append("\n");
795        for(int i = 0; i < getNumChildNoTransform(); i++) {
796          getChildNoTransform(i).dumpTreeNoRewrite(s, indent+1);
797        }
798      }
799    
800      syn String ASTNode.dumpString() = getClass().getName();
801      eq CompilationUnit.dumpString() = getClass().getName() + " [" + getPackageDecl() + "]";
802      eq VarAccess.dumpString() = getClass().getName() + " [" + getID() + "]";
803      eq MethodAccess.dumpString() = getClass().getName() + " [" + getID() + "]";
804      eq TypeAccess.dumpString() = getClass().getName() + " [" + getPackage() + ", " + getID() + "]";
805      eq PrimitiveTypeAccess.dumpString() = getClass().getName() + " [" + getName() + "]";
806      eq ArrayTypeAccess.dumpString() = getClass().getName();
807      eq PackageAccess.dumpString() = getClass().getName() + " [" + getPackage() + "]";
808      eq ParseName.dumpString() = getClass().getName() + " [" + getID() + "]";
809      eq PackageOrTypeAccess.dumpString() = getClass().getName() + " [" + getID() + "]";
810      eq AmbiguousAccess.dumpString() = getClass().getName() + " [" + getID() + "]";
811      eq TypeDecl.dumpString() = getClass().getName() + " [" + getID() + "]";
812      eq FieldDeclaration.dumpString() = getClass().getName() + " [" + getID() + "]";
813      eq VariableDeclaration.dumpString() = getClass().getName() + " [" + getID() + "]";
814      eq ParameterDeclaration.dumpString() = getClass().getName() + " [" + getID() + "]";
815      eq MethodDecl.dumpString() = getClass().getName() + " [" + getID() + "]";
816      eq Modifier.dumpString() = getClass().getName() + " [" + getID() + "]";
817      eq Literal.dumpString() = getClass().getName() + " [" + getLITERAL() + "]";
818    
819      eq BoundTypeAccess.dumpString() = getClass().getName() + " [" + getTypeDecl().fullName() + "]";
820    
821      public String Program.dumpTree() {
822        StringBuffer s = new StringBuffer();
823        for(Iterator iter = compilationUnitIterator(); iter.hasNext(); ) {
824          CompilationUnit cu = (CompilationUnit)iter.next();
825          if(cu.fromSource()) { 
826            s.append(cu.dumpTree());
827          }
828        }
829        return s.toString();
830      }
831    
832       public void BooleanType.toString(StringBuffer s) {
833               s.append("boolean");
834       }
835       public void ByteType.toString(StringBuffer s) {
836               s.append("byte");
837       }
838       public void ShortType.toString(StringBuffer s) {
839               s.append("short");
840       }
841       public void IntType.toString(StringBuffer s) {
842               s.append("int");
843       }
844       public void LongType.toString(StringBuffer s) {
845               s.append("long");
846       }
847       public void CharType.toString(StringBuffer s) {
848               s.append("char");
849       }
850       public void FloatType.toString(StringBuffer s) {
851               s.append("float");
852       }
853       public void DoubleType.toString(StringBuffer s) {
854               s.append("double");
855       }
856       public void NullType.toString(StringBuffer s) {
857               s.append("null");
858       }
859       public void VoidType.toString(StringBuffer s) {
860               s.append("void");
861       }
862       
863    
864    }
865