001/* 002 * Copyright (c) 2012-2018 Institut National des Sciences Appliquées de Lyon (INSA Lyon) and others 003 * 004 * This program and the accompanying materials are made available under the 005 * terms of the Eclipse Public License 2.0 which is available at 006 * http://www.eclipse.org/legal/epl-2.0. 007 * 008 * SPDX-License-Identifier: EPL-2.0 009 */ 010 011package org.eclipse.golo.compiler.parser; 012 013import org.eclipse.golo.compiler.PositionInSourceCode; 014 015public class GoloASTNode extends SimpleNode { 016 017 private String documentation; 018 019 public GoloASTNode(int i) { 020 super(i); 021 } 022 023 public GoloASTNode(GoloParser p, int i) { 024 super(p, i); 025 } 026 027 public int getLineInSourceCode() { 028 return jjtGetFirstToken().beginLine; 029 } 030 031 public int getColumnInSourceCode() { 032 return jjtGetFirstToken().beginColumn; 033 } 034 035 public PositionInSourceCode getPositionInSourceCode() { 036 Token firstToken = this.jjtGetFirstToken(); 037 if (firstToken == null) { 038 return PositionInSourceCode.undefined(); 039 } 040 int startLine = firstToken.beginLine; 041 int startColumn = firstToken.beginColumn; 042 int endLine = firstToken.endLine; 043 int endColumn = firstToken.endColumn; 044 Token lastToken = this.jjtGetLastToken(); 045 if (lastToken != null) { 046 endLine = lastToken.endLine; 047 endColumn = lastToken.endColumn; 048 } 049 return PositionInSourceCode.of(startLine, startColumn, endLine, endColumn); 050 } 051 052 @Override 053 public Object jjtAccept(GoloParserVisitor visitor, Object data) { 054 return visitor.visit(this, data); 055 } 056 057 public String getDocumentation() { 058 return documentation; 059 } 060 061 public void setDocumentation(String documentation) { 062 this.documentation = documentation; 063 } 064}