001package gudusoft.gsqlparser.nodes; 002 003import gudusoft.gsqlparser.TSourceToken; 004 005/** 006 * TColumnReference represents column, variable, function/procedure parameter 007 */ 008public class TColumnReference extends TParseTreeNode { 009 010 public TObjectName objectname; 011 public TSourceToken sourcetoken; 012 013 /** 014 * where this column was used in query. 015 * can be referenced in multiplace such as select clause, where clause and etc. 016 */ 017 018 private int location; 019 020 public TSourceToken getObjectToken(){ 021 TSourceToken retVal = null; 022 if (objectname == null) return null; 023 retVal = objectname.getObjectToken(); 024 return retVal; 025 } 026 027 public TColumnReference (){ 028 029 } 030 031 public TColumnReference (TObjectName obj){ 032 objectname = obj; 033 } 034 035 public void init(Object arg1) 036 { 037 if (arg1 instanceof TObjectName){ 038 objectname = (TObjectName)arg1; 039 }else if (arg1 instanceof TSourceToken){ 040 sourcetoken = (TSourceToken)arg1; 041 } 042 } 043 044 045 public String getColumnNameOnly(){ 046 if (objectname != null) {return objectname.getPartToken().toString();} 047 else if (sourcetoken != null) { return sourcetoken.toString();} 048 else return null; 049 } 050 051 public long getColumns() { 052 // return columns; 053 if (objectname != null) {return objectname.getColumnNo();} 054 else if (sourcetoken != null) { return sourcetoken.columnNo;} 055 else return -1; 056 } 057 058 public long getLines() { 059 // return lines; 060 if (objectname != null) {return objectname.getLineNo();} 061 else if (sourcetoken != null) { return sourcetoken.lineNo;} 062 else return -1; 063 } 064 065 public void setObjectname(TObjectName objectname) { 066 this.objectname = objectname; 067 } 068 069 public void setLocation(int location) { 070 this.location = location; 071 } 072}