Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   /*
    * Copyright 2003-2007 the original author or authors.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    *     http://www.apache.org/licenses/LICENSE-2.0
    *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.codehaus.groovy.antlr.treewalker;
  
  import java.util.Stack;
  
An antlr AST visitor that prints groovy source code for each visited node to the supplied PrintStream.

Author(s):
Jeremy Rayner
Version:
$Revision: 7922 $
  
  
  public class SourcePrinter extends VisitorAdapter {
      private final String[] tokenNames;
      private int tabLevel;
      private int lastLinePrinted;
      private final boolean newLines;
      protected final PrintStream out;
      private String className;
      private final Stack stack;
      private int stringConstructorCounter;

    
A visitor that prints groovy source code for each node visited.

Parameters:
out where to print the source code to
tokenNames an array of token names from antlr
  
      public SourcePrinter(PrintStream out,String[] tokenNames) {
          this(out,tokenNames,true);
      }

    
A visitor that prints groovy source code for each node visited.

Parameters:
out where to print the source code to
tokenNames an array of token names from antlr
newLines output newline character
  
      public SourcePrinter(PrintStream out,String[] tokenNamesboolean newLines) {
          this. = tokenNames;
           = 0;
           = 0;
          this. = out;
          this. = newLines;
          this. = new Stack();
      }
      
  
  	public void visitAbstract(GroovySourceAST tint visit) {
  		print(t,visit,"abstract ",null,null);
  	}
  
  	public void visitAnnotation(GroovySourceAST tint visit) {
  		if (visit == ) {
  			print(t,visit,"@");
  		}
  		if (visit == ) {
  			print(t,visit,"(");
  		}
  		if (visit == ) {
  			print(t,visit,", ");
  		}
  		if (visit == ) {
  			if (t.getNumberOfChildren() > 1) {
  				print(t,visit,") ");
  			} else {
  				print(t,visit," ");
  			}
  		}
  
      }
  
      public void visitAnnotations(GroovySourceAST tint visit) {
      	// do nothing
      }
  
      public void visitAnnotationDef(GroovySourceAST t,int visit) {
          print(t,visit,"@interface ",null,null);
      }
  
  	public void visitAnnotationFieldDef(GroovySourceAST tint visit) {
     	print(t,visit,"() ","default ",null);
 	}
 
 	public void visitAnnotationMemberValuePair(GroovySourceAST tint visit) {
 		print(t,visit," = ",null,null);
 	}
 
 	public void visitArrayDeclarator(GroovySourceAST tint visit) {
 		//<ARRAY_DECLARATOR>int</ARRAY_DECLARATOR> primes = new int(<ARRAY_DECLARATOR>5</ARRAY_DECLARATOR>)
 				getParentNode().getType() == .) { // ugly hack
 			// type defintion, i.e.   int[] x;
 			print(t,visit,null,null,"[]");
 		} else {
 			// usually in new, i.e.   def y = new int[5];
 			print(t,visit,"[",null,"]");
 		}
 	}
 
 	public void visitAssign(GroovySourceAST t,int visit) {
         print(t,visit," = ",null,null);
     }
 	
     // visitAt() ...
     //   token type 'AT' should never be visited, as annotation definitions and usage, and
     //   direct field access should have all moved this token out of the way. No test needed.
 
 	//   one of the BAND tokens is actually replaced by TYPE_UPPER_BOUNDS (e.g. class Foo<T extends C & I> {T t} )
     public void visitBand(GroovySourceAST tint visit) {
         print(t,visit," & ",null,null);
     }
 
 	public void visitBandAssign(GroovySourceAST t,int visit) {
         print(t,visit," &= ",null,null);
     }
 	
     // visitBigSuffix() ...
 	//   token type BIG_SUFFIX never created/visited, NUM_BIG_INT, NUM_BIG_DECIMAL instead...    
     
 	// visitBlock() ...
 	//   token type BLOCK never created/visited, see CLOSABLE_BLOCK etc...
 	
 	public void visitBnot(GroovySourceAST tint visit) {
 		print(t,visit,"~",null,null);
 	}
 	
 	// Note: old closure syntax using BOR is deprecated, and also never creates/visits a BOR node
     public void visitBor(GroovySourceAST tint visit) {
         print(t,visit," | ",null,null);
     }
 	
 	public void visitBorAssign(GroovySourceAST t,int visit) {
         print(t,visit," |= ",null,null);
     }
 	
     public void visitBsr(GroovySourceAST tint visit) {
         print(t,visit," >>> ",null,null);
     }
 	
 	public void visitBsrAssign(GroovySourceAST t,int visit) {
         print(t,visit," >>>= ",null,null);
     }
 	
     public void visitBxor(GroovySourceAST tint visit) {
         print(t,visit," ^ ",null,null);
     }
 	
 	public void visitBxorAssign(GroovySourceAST t,int visit) {
         print(t,visit," ^= ",null,null);
     }
 	
     public void visitCaseGroup(GroovySourceAST tint visit) {
         if (visit == ) {
             ++;
         }
         if (visit == ) {
             --;
         }
     }
 
     public void visitClassDef(GroovySourceAST t,int visit) {
         print(t,visit,"class ",null,null);
 
         if (visit == ) {
             // store name of class away for use in constructor ident
              = t.childOfType(.).getText();
         }
     }
 
     public void visitClosedBlock(GroovySourceAST tint visit) {
         printUpdatingTabLevel(t,visit,"{","-> ","}");
     }
     
     public void visitClosureList(GroovySourceAST tint visit) {
     	print(t,visit,"(","; ",")");
     }
     // visitClosureOp ...
 	//   token type CLOSABLE_BLOCK_OP never created/visited, see CLOSABLE_BLOCK...
 	
 
     // visitColon ...
     //   token type COLON never created/visited, see LABELED_STAT, FOR_IN_ITERABLE, 
     //   ASSERT, CASE, QUESTION, MAP_CONSTRUCTOR, LABELED_ARG, SPREAD_MAP_ARG
 
     // visitComma ...
     //   token type COMMA never created/visited,
     //   see TYPE_ARGUMENTS, ANNOTATION, many others ...
     
     public void visitCompareTo(GroovySourceAST t,int visit) {
         print(t,visit," <=> ",null,null);
     }
 
     public void visitCtorCall(GroovySourceAST t,int visit) {
         printUpdatingTabLevel(t,visit,"this("," ",")");
     }
 
     public void visitCtorIdent(GroovySourceAST tint visit) {
         // use name of class for constructor from the class definition
         print(t,visit,,null,null);
     }
 
     public void visitDec(GroovySourceAST tint visit) {
     	print(t,visit,"--",null,null);
     }
     
     // visitDigit ...
     //    never created/visited
     
     public void visitDiv(GroovySourceAST tint visit) {
         print(t,visit," / ",null,null);
     }
 
 	public void visitDivAssign(GroovySourceAST t,int visit) {
         print(t,visit," /= ",null,null);
     }
 	
     // visitDollar ...
     //   token type DOLLAR never created/visited, see SCOPE_ESCAPE instead
     
     public void visitDot(GroovySourceAST t,int visit) {
         print(t,visit,".",null,null);
     }
     
     public void visitDynamicMember(GroovySourceAST tint visit) {
     	if (t.childOfType(.) == null) {
     		printUpdatingTabLevel(t,visit,"(",null,")");
     	}
     }
     
     public void visitElist(GroovySourceAST t,int visit) {
     		print(t,visit,"(",", ",")");
     	} else {
     		print(t,visit,null,", ",null);
     	}
     }
 
     // visitEmptyStat ...
     //   token type EMPTY_STAT obsolete and should be removed, never visited/created
     
     public void visitEnumConstantDef(GroovySourceAST t,int visit) {
     	GroovySourceAST sibling = (GroovySourceAST)t.getNextSibling();
     	if (sibling != null && sibling.getType() == .) {
     		print(t,visit,null,null,", ");
     	}
     }
 
     public void visitEnumDef(GroovySourceAST t,int visit) {
         print(t,visit,"enum ",null,null);
     }
 
     // visitEof ...
     //   token type EOF never visited/created
 
     public void visitEqual(GroovySourceAST t,int visit) {
         print(t,visit," == ",null,null);
     }
 
     // visitExponent ...
     //   token type EXPONENT only used by lexer, never visited/created
     
     public void visitExpr(GroovySourceAST t,int visit) {
     	// do nothing
     }
 
     public void visitExtendsClause(GroovySourceAST t,int visit) {
         if (visit == ) {
             if (t.getNumberOfChildren() != 0) {
                 print(t,visit," extends ");
             }
         }
     }
     
 	public void visitFinal(GroovySourceAST tint visit) {
         print(t,visit,"final ",null,null);
 	}
 
 	// visitFloatSuffix ... never visited/created see NUM_DOUBLE or NUM_FLOAT instead
 	
 	public void visitForCondition(GroovySourceAST tint visit) {
     	print(t,visit," ; ",null,null);
     }
 	
 	// visitForEachClause ... 
 	//   FOR_EACH_CLAUSE obsolete and should be removed, never visited/created
 
     public void visitForInit(GroovySourceAST tint visit) {
     	print(t,visit,"(",null,null);
     }
     
     public void visitForInIterable(GroovySourceAST tint visit) {
         printUpdatingTabLevel(t,visit,"("," in ",") ");
     }
 
     public void visitForIterator(GroovySourceAST tint visit) {
     	print(t,visit," ; ",null,")");
     }
     
     public void visitGe(GroovySourceAST tint visit) {
     	print(t,visit," >= ",null,null);
     }
     
     public void visitGt(GroovySourceAST tint visit) {
         print(t,visit," > ",null,null);
     }
 
     public void visitIdent(GroovySourceAST t,int visit) {
         print(t,visit,t.getText(),null,null);
     }
     public void visitImplementsClause(GroovySourceAST t,int visit) {
         if (visit == ) {
             if (t.getNumberOfChildren() != 0) {
                 print(t,visit," implements ");
             }
         }
         if (visit == ) {
             //space between classdef and objblock
             print(t,visit," ");
         }
     }
 
     public void visitImplicitParameters(GroovySourceAST tint visit) {
     	// do nothing
     }
 
     public void visitImport(GroovySourceAST t,int visit) {
         print(t,visit,"import ",null,null);
     }
 
     public void visitInc(GroovySourceAST tint visit) {
     	print(t,visit,"++",null,null);
     }
 
     public void visitIndexOp(GroovySourceAST tint visit) {
         printUpdatingTabLevel(t,visit,"[",null,"]");
     }
 
     public void visitInterfaceDef(GroovySourceAST t,int visit) {
         print(t,visit,"interface ",null,null);
     }
 
     public void visitInstanceInit(GroovySourceAST tint visit) {
     	// do nothing
 	}
 
 	public void visitLabeledArg(GroovySourceAST tint visit) {
         print(t,visit,":",null,null);
     }
 
 	public void visitLabeledStat(GroovySourceAST tint visit) {
         print(t,visit,":",null,null);
     }
 
     public void visitLand(GroovySourceAST tint visit) {
         print(t,visit," && ",null,null);
     }
 
     // visit lbrack()
     //   token type LBRACK only used inside parser, never visited/created
 
     // visit lcurly()
     //   token type LCURLY only used inside parser, never visited/created
     
     public void visitLe(GroovySourceAST tint visit) {
     	print(t,visit," <= ",null,null);
     }
 
     // visitLetter ...
     //   token type LETTER only used by lexer, never visited/created
 
     public void visitListConstructor(GroovySourceAST tint visit) {
         printUpdatingTabLevel(t,visit,"[",null,"]");
     }
 
     public void visitLiteralAs(GroovySourceAST t,int visit) {
         print(t,visit," as ",null,null);
     }
 
     public void visitLiteralAssert(GroovySourceAST t,int visit) {
     	if (t.getNumberOfChildren() > 1) {
     		print(t,visit,"assert ",null," : ");
     	} else {
     		print(t,visit,"assert ",null,null);
     	}
     }
 
     public void visitLiteralBoolean(GroovySourceAST tint visit) {
         print(t,visit,"boolean",null,null);
     }
 
     public void visitLiteralBreak(GroovySourceAST tint visit) {
         print(t,visit,"break ",null,null);
     }
 
     public void visitLiteralByte(GroovySourceAST tint visit) {
         print(t,visit,"byte",null,null);
     }
 
     public void visitLiteralCase(GroovySourceAST tint visit) {
         print(t,visit,"case ",null,":");
     }
 
     public void visitLiteralCatch(GroovySourceAST t,int visit) {
         printUpdatingTabLevel(t,visit," catch (",null,") ");
     }
 
     public void visitLiteralChar(GroovySourceAST tint visit) {
         print(t,visit,"char",null,null);
     }
 
     // visitLiteralClass ...
     //   token type "class" only used by parser, never visited/created directly
 
     public void visitLiteralContinue(GroovySourceAST tint visit) {
         print(t,visit,"continue ",null,null);
     }
 
     // visitLiteralDef ...
     //   token type "def" only used by parser, never visited/created directly
 
     public void visitLiteralDefault(GroovySourceAST t,int visit) {
         print(t,visit,"default",null,":");
     }
 
     public void visitLiteralDouble(GroovySourceAST tint visit) {
         print(t,visit,"double",null,null);
     }
 
     // visitLiteralElse ...
     //   token type "else" only used by parser, never visited/created directly
 
     // visitLiteralEnum ...
     //   token type "enum" only used by parser, never visited/created directly
 
     // visitLiteralExtends
     //   token type "extends" only used by parser, never visited/created directly
     
     public void visitLiteralFalse(GroovySourceAST t,int visit) {
         print(t,visit,"false",null,null);
     }
 
     public void visitLiteralFinally(GroovySourceAST t,int visit) {
         print(t,visit,"finally ",null,null);
     }
     public void visitLiteralFloat(GroovySourceAST t,int visit) {
         print(t,visit,"float",null,null);
     }
 
     public void visitLiteralFor(GroovySourceAST t,int visit) {
         print(t,visit,"for ",null,null);
     }
     
     public void visitLiteralIf(GroovySourceAST t,int visit) {
         // slightly strange as subsequent visit is done after closing visit
         printUpdatingTabLevel(t,visit,"if ("," else ",") ");
     }
 
     // visitLiteralImplements
     //   token type "implements" only used by parser, never visited/created directly
 
     // visitLiteralImport
     //   token type "import" only used by parser, never visited/created directly
 
     public void visitLiteralIn(GroovySourceAST tint visit) {
         print(t,visit," in ",null,null);
     }
 
     public void visitLiteralInstanceof(GroovySourceAST tint visit) {
         print(t,visit," instanceof ",null,null);
     }
 
     public void visitLiteralInt(GroovySourceAST t,int visit) {
         print(t,visit,"int",null,null);
     }
 
     // visitLiteralInterface
     //   token type "interface" only used by parser, never visited/created directly
 
     public void visitLiteralLong(GroovySourceAST t,int visit) {
         print(t,visit,"long",null,null);
     }
 
     public void visitLiteralNative(GroovySourceAST t,int visit) {
         print(t,visit,"native ",null,null);
     }
     public void visitLiteralNew(GroovySourceAST t,int visit) {
     	if (t.childOfType(.) == null) {
     		// only print parenthesis if is not of form def x = new int[5]
     		print(t,visit,"new ","(",")");
     	} else {
     		print(t,visit,"new ",null,null);
     	}
     }
 
     public void visitLiteralNull(GroovySourceAST tint visit) {
         print(t,visit,"null",null,null);
     }
 
     // visitLiteralPackage
     //   token type "package" only used by parser, never visited/created directly
 
     public void visitLiteralPrivate(GroovySourceAST t,int visit) {
         print(t,visit,"private ",null,null);
     }
 
     public void visitLiteralProtected(GroovySourceAST t,int visit) {
         print(t,visit,"protected ",null,null);
     }
 
     public void visitLiteralPublic(GroovySourceAST t,int visit) {
         print(t,visit,"public ",null,null);
     }
 
     public void visitLiteralReturn(GroovySourceAST tint visit) {
         print(t,visit,"return ",null,null);
     }
 
     public void visitLiteralShort(GroovySourceAST t,int visit) {
         print(t,visit,"short",null,null);
     }
 
     public void visitLiteralStatic(GroovySourceAST tint visit) {
         print(t,visit,"static ",null,null);
     }
 
     public void visitLiteralSuper(GroovySourceAST tint visit) {
     	// only visited when calling super() without parentheses, i.e. "super 99" is equivalent to "super(99)"
     	print(t,visit,"super",null,null);
     }
 
     public void visitLiteralSwitch(GroovySourceAST tint visit) {
         if (visit == ) {
             print(t,visit,"switch (");
             ++;
         }
         if (visit == ) {
             print(t,visit,") {");
         }
         if (visit == ) {
             --;
             print(t,visit,"}");
         }
     }
 
     public void visitLiteralSynchronized(GroovySourceAST t,int visit) {
     	if (t.getNumberOfChildren() > 0) {
     		print(t,visit,"synchronized (",null,") ");
     	} else {
     		print(t,visit,"synchronized ",null,null);    		
     	}
 	}
 
     public void visitLiteralThis(GroovySourceAST tint visit) {
         print(t,visit,"this",null,null);
     }
 
     public void visitLiteralThreadsafe(GroovySourceAST t,int visit) {
         print(t,visit,"threadsafe ",null,null);
     }
 
     public void visitLiteralThrow(GroovySourceAST tint visit) {
         print(t,visit,"throw ",null,null);
     }
 
     public void visitLiteralThrows(GroovySourceAST tint visit) {
         print(t,visit,"throws ",null,null);
     }
 
     public void visitLiteralTransient(GroovySourceAST t,int visit) {
         print(t,visit,"transient ",null,null);
     }
 
     public void visitLiteralTrue(GroovySourceAST t,int visit) {
         print(t,visit,"true",null,null);
     }
     public void visitLiteralTry(GroovySourceAST t,int visit) {
         print(t,visit,"try ",null,null);
     }
     public void visitLiteralVoid(GroovySourceAST t,int visit) {
         print(t,visit,"void",null,null);
     }
     public void visitLiteralVolatile(GroovySourceAST t,int visit) {
         print(t,visit,"volatile ",null,null);
     }
     public void visitLiteralWhile(GroovySourceAST t,int visit) {
         printUpdatingTabLevel(t,visit,"while (",null,") ");
     }
 
 //deprecated
 //  public void visitLiteralWith(GroovySourceAST t,int visit) {
 //        printUpdatingTabLevel(t,visit,"with (",null,") ");
 //    }
     
     public void visitLnot(GroovySourceAST tint visit) {
         print(t,visit,"!",null,null);
     }
 
 	// Note: old closure syntax using LOR is deprecated, and also never creates/visits a LOR node
     public void visitLor(GroovySourceAST tint visit) {
         print(t,visit," || ",null,null);
     }
 
     public void visitLt(GroovySourceAST tint visit) {
         print(t,visit," < ",null,null);
     }
 
     public void visitMapConstructor(GroovySourceAST tint visit) {
         if (t.getNumberOfChildren() == 0) {
             print(t,visit,"[:]",null,null);
         } else {
             printUpdatingTabLevel(t,visit,"[",null,"]");
         }
     }
 
     public void visitMemberPointer(GroovySourceAST tint visit) {
         print(t,visit,".&",null,null);
     }
 
     public void visitMethodCall(GroovySourceAST t,int visit) {
     	if ("<command>".equals(t.getText())) {
     		printUpdatingTabLevel(t,visit," "," ",null);
     	} else {
     		printUpdatingTabLevel(t,visit,"("," ",")");
     	}
     }
     public void visitMethodDef(GroovySourceAST t,int visit) {
         //do nothing
     }
     public void visitMinus(GroovySourceAST t,int visit) {
         print(t,visit," - ",null,null);
     }
     public void visitMinusAssign(GroovySourceAST tint visit) {
         print(t,visit," -= ",null,null);
     }
 
     // visitMlComment
     //   multi-line comments are not created on the AST currently.
 
     public void visitMod(GroovySourceAST tint visit) {
         print(t,visit," % ",null,null);
     }
 
     public void visitModifiers(GroovySourceAST t,int visit) {
         //do nothing
     }
     public void visitModAssign(GroovySourceAST tint visit) {
         print(t,visit," %= ",null,null);
     }
 
     // visitNls
     //   new lines are used by parser, but are not created on the AST,
     //   they can be implied by the source code line/column information
 
     // visitNullTreeLookahead
     //   not used explicitly by parser.
     
     
     public void visitNotEqual(GroovySourceAST tint visit) {
         print(t,visit," != ",null,null);
     }
 
     public void visitNumBigDecimal(GroovySourceAST t,int visit) {
         print(t,visit,t.getText(),null,null);
     }
     public void visitNumBigInt(GroovySourceAST t,int visit) {
         print(t,visit,t.getText(),null,null);
     }
     public void visitNumDouble(GroovySourceAST t,int visit) {
         print(t,visit,t.getText(),null,null);
     }
     public void visitNumInt(GroovySourceAST t,int visit) {
         print(t,visit,t.getText(),null,null);
     }
     public void visitNumFloat(GroovySourceAST t,int visit) {
         print(t,visit,t.getText(),null,null);
     }
     public void visitNumLong(GroovySourceAST t,int visit) {
         print(t,visit,t.getText(),null,null);
     }
     public void visitObjblock(GroovySourceAST t,int visit) {
         if (visit == ) {
             ++;
             print(t,visit,"{");
         } else {
             --;
             print(t,visit,"}");
         }
     }
 
     // visitOneNl
     //   new lines are used by parser, but are not created on the AST,
     //   they can be implied by the source code line/column information
 
     public void visitOptionalDot(GroovySourceAST t,int visit) {
         print(t,visit,"?.",null,null);
     }
     
     public void visitPackageDef(GroovySourceAST tint visit) {
         print(t,visit,"package ",null,null);
     }
 
     public void visitParameterDef(GroovySourceAST t,int visit) {
         //do nothing
     }
 
     public void visitParameters(GroovySourceAST t,int visit) {
     		printUpdatingTabLevel(t,visit,null,","," ");
     	} else {
     		printUpdatingTabLevel(t,visit,"(",", ",") ");
     	}
     }
 
     public void visitPlus(GroovySourceAST tint visit) {
         print(t,visit," + ",null,null);
     }
     
     public void visitPlusAssign(GroovySourceAST tint visit) {
         print(t,visit," += ",null,null);
     }
     public void visitPostDec(GroovySourceAST tint visit) {
     	print(t,visit,null,null,"--");
     }
 
     public void visitPostInc(GroovySourceAST tint visit) {
     	print(t,visit,null,null,"++");
     }
 
     public void visitQuestion(GroovySourceAST tint visit) {
         // ternary operator
         print(t,visit,"?",":",null);
     }
 
     public void visitRangeExclusive(GroovySourceAST tint visit) {
         print(t,visit,"..<",null,null);
     }
 
     public void visitRangeInclusive(GroovySourceAST tint visit) {
         print(t,visit,"..",null,null);
     }
 
     // visit rbrack()
     //   token type RBRACK only used inside parser, never visited/created
 
     // visit rcurly()
     //   token type RCURLY only used inside parser, never visited/created
 
     // visit RegexpCtorEnd
     // visit RegexpLiteral
     // visit RegexpSymbol
     //    token types REGEXP_CTOR_END, REGEXP_LITERAL, REGEXP_SYMBOL only used inside lexer
     
     public void visitRegexFind(GroovySourceAST tint visit) {
     	print(t,visit," =~ ",null,null);
     }
     public void visitRegexMatch(GroovySourceAST tint visit) {
     	print(t,visit," ==~ ",null,null);
     }
     // visit rparen()
     //   token type RPAREN only used inside parser, never visited/created
 
     public void visitSelectSlot(GroovySourceAST tint visit) {
     	print(t,visit,"@",null,null);
     }
     
     // visit semi()
     //  SEMI only used inside parser, never visited/created (see visitForCondition(), visitForIterator())
     
     // visit ShComment()
     //  never visited/created by parser
     
     public void visitSl(GroovySourceAST tint visit) {
     	print(t,visit," << ",null,null);
     }
     public void visitSlAssign(GroovySourceAST tint visit) {
     	print(t,visit," <<= ",null,null);
     }
     public void visitSlist(GroovySourceAST t,int visit) {
         if (visit == ) {
             ++;
             print(t,visit,"{");
         } else {
             --;
             print(t,visit,"}");
         }
     }
 
     // visit SlComment()
     //   never visited/created by parser
     
     public void visitSpreadArg(GroovySourceAST t,int visit) {
     	print(t,visit,"*",null,null);
     }
 
     public void visitSpreadDot(GroovySourceAST t,int visit) {
 	print(t,visit,"*.",null,null);
     }
 
     public void visitSpreadMapArg(GroovySourceAST t,int visit) {
     	print(t,visit,"*:",null,null);
     }
     
     public void visitSr(GroovySourceAST tint visit) {
     	print(t,visit," >> ",null,null);
     }
     public void visitSrAssign(GroovySourceAST tint visit) {
     	print(t,visit," >>= ",null,null);
     }
 
     public void visitStar(GroovySourceAST t,int visit) {
         print(t,visit,"*",null,null);
     }
     public void visitStarAssign(GroovySourceAST tint visit) {
     	print(t,visit," *= ",null,null);
     }
     public void visitStarStar(GroovySourceAST t,int visit) {
         print(t,visit,"**",null,null);
     }
     public void visitStarStarAssign(GroovySourceAST tint visit) {
     	print(t,visit," **= ",null,null);
     }
     
     public void visitStaticInit(GroovySourceAST tint visit) {
     	print(t,visit,"static ",null,null);
     }
     public void visitStaticImport(GroovySourceAST t,int visit) {
         print(t,visit,"import static ",null,null);
     }
     public void visitStrictfp(GroovySourceAST t,int visit) {
     	print(t,visit,"strictfp ",null,null);
     }
 
     // visitStringch
     //   String characters only used by lexer, never visited/created directly
 
 
     public void visitStringConstructor(GroovySourceAST t,int visit) {
         if (visit == ) {
              = 0;
             print(t,visit,"\"");
         }
         if (visit == ) {
             // every other subsequent visit use an escaping $
             if ( % 2 == 0) {
                print(t,visit,"$");
             }
             ++;
         }
         if (visit == ) {
             print(t,visit,"\"");
         }
     }
 
     public void visitStringLiteral(GroovySourceAST t,int visit) {
         if (visit == ) {
             String theString = escape(t.getText());
         if (getParentNode().getType() != . &&
             getParentNode().getType() != .) {
                 theString = "\"" + theString + "\"";
             }
             print(t,visit,theString);
         }
     }
 
     private String escape(String literal) {
         literal = literal.replaceAll("\n","\\\\<<REMOVE>>n"); // can't seem to do \n in one go with Java regex
         literal = literal.replaceAll("<<REMOVE>>","");
         return literal;
     }
 
     public void visitSuperCtorCall(GroovySourceAST t,int visit) {
 		printUpdatingTabLevel(t,visit,"super("," ",")");
     }
     
     // visit TripleDot, not used in the AST
     
     public void visitType(GroovySourceAST t,int visit) {
         GroovySourceAST parent = getParentNode();
         GroovySourceAST modifiers = parent.childOfType(.);
 
         // No need to print 'def' if we already have some modifiers
         if (modifiers == null || modifiers.getNumberOfChildren() == 0) {
 
             if (visit == ) {
                 if (t.getNumberOfChildren() == 0 && 
                 		parent.getType() != .) { // no need for 'def' if in a parameter list
                     print(t,visit,"def");
                 }
             } 
             if (visit == ) {
                 if (  parent.getType() == .         ||
                       parent.getType() == .           ||
                       parent.getType() == . ||
                      (parent.getType() == . && t.getNumberOfChildren()!=0))             
                 {
                     print(t,visit," ");
                 }
             }
             
         	/*if (visit == CLOSING_VISIT) {
         		print(t,visit," ");
             }*/
         } else {