Package org.apache.imperius.spl.parser.compiler

Source Code of org.apache.imperius.spl.parser.compiler.ASTWithLineNumber

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you 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.apache.imperius.spl.parser.compiler;



import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import antlr.CommonAST;
import antlr.Token;
import antlr.collections.AST;
import antlr.debug.misc.ASTFrame;

/**
* CommonAST(default) from Antlr does not store line information.
* So we extend it, so use setASTNodeClass() to set it up in parser.
*/
public class ASTWithLineNumber extends CommonAST {

  private static final long serialVersionUID = 1L;
  private int line_ = 0;

  public void initialize(Token tok) {
    super.initialize(tok);
    line_ = tok.getLine();
  }

  public void initialize (AST ast) {
    super.initialize(ast);
    if (ast instanceof ASTWithLineNumber){
      line_ = ((ASTWithLineNumber)ast).getLine();
    }
  }

  public int getLine() {
    return line_;
  }
 
  public void displayTree(AST r){
    final ASTFrame frame = new ASTFrame("Java AST", r);
    frame.setVisible(true);
    frame.addWindowListener(
      new WindowAdapter() {
               public void windowClosing (WindowEvent e) {
                   frame.setVisible(true); // hide the Frame
                   frame.dispose();
                   System.exit(0);
               }
          }
    );
  }
}
TOP

Related Classes of org.apache.imperius.spl.parser.compiler.ASTWithLineNumber

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.