How can I include line numbers in automatically generated ASTs?

Fondement Frederic

Tree parsers are often used in type checkers. But useful error messages need the offending line number. So I have written:

import antlr.CommonAST;
import antlr.Token;
public class CommonASTWithLines extends CommonAST {
     private int line = 0;
     public void initialize(Token tok) {
     public int getLine(){
          return line;

initialize is automatically called when an AST is created from a Token object, which has its own line variable.