001package gudusoft.gsqlparser;
002
003
004import gudusoft.gsqlparser.nodes.TObjectName;
005
006/**
007 * Detailed information about syntax error.
008 */
009
010public class TSyntaxError {
011//    public TSyntaxError(TSourceToken sourceToken,String hint, EErrorType errortype, int errorno, TCustomSqlStatement sql){
012//        this.tokentext = sourceToken.toString();
013//        this.lineNo = sourceToken.lineNo;
014//        this.columnNo = sourceToken.columnNo;
015//        this.posInList  = sourceToken.posinlist;
016//
017//        this.hint = hint;
018//        this.errortype = errortype;
019//        this.errorno = errorno;
020//        this.sqlStatement = sql;
021//        this.tokencode = sourceToken.tokencode;
022//
023//    }
024
025    public TSyntaxError(TSourceToken pSt, String hint, EErrorType errortype, int errorno, TCustomSqlStatement sql){
026        TSourceToken st = pSt;
027        if ((pSt.tokencode == 0) && (pSt.container != null)){
028            st = pSt.container.get(pSt.container.size()-1);
029        }
030
031        this.tokentext = st.getAstext();
032        this.lineNo = st.lineNo;
033        this.columnNo = st.columnNo;
034        this.posInList  = st.posinlist;
035
036        this.hint = hint;
037        this.errortype = errortype;
038        this.errorno = errorno;
039        this.sqlStatement = sql;
040    }
041
042    public TSyntaxError(String tokentext,long lines,long columns,String hint, EErrorType errortype, int errorno, TCustomSqlStatement sql, int posInList){
043        this.tokentext = tokentext;
044        this.lineNo = lines;
045        this.columnNo = columns;
046        this.posInList  = posInList;
047
048        this.hint = hint;
049        this.errortype = errortype;
050        this.errorno = errorno;
051        this.sqlStatement = sql;
052    }
053
054    public TSyntaxError(String tokentext,long lines,long columns,String hint, EErrorType errortype, int errorno, TCustomSqlStatement sql, int posInList,TObjectName objectName){
055        this.tokentext = tokentext;
056        this.lineNo = lines;
057        this.columnNo = columns;
058        this.posInList  = posInList;
059
060        this.hint = hint;
061        this.errortype = errortype;
062        this.errorno = errorno;
063        this.sqlStatement = sql;
064        this.objectName  = objectName;
065    }
066
067    public TSyntaxError(TSyntaxError n){
068        this.tokentext = n.tokentext;
069        this.lineNo = n.lineNo;
070        this.columnNo = n.columnNo;
071        this.hint = n.hint;
072        this.errortype = n.errortype;
073        this.errorno = n.errorno;
074        this.sqlStatement = n.sqlStatement;
075        this.posInList = n.posInList;
076        this.tokencode = n.tokencode;
077    }
078
079    /**
080     * Text of token where syntax error occurs.
081     */
082    public String tokentext;
083    /**
084     * the line number of the first character for error token.
085     */
086    public long lineNo;
087    /**
088     * the column number of the first character for error token.
089     */
090    public long columnNo;
091    public String hint;
092    public EErrorType errortype;
093    public int errorno;
094    public TCustomSqlStatement sqlStatement;
095    public int posInList;
096    public int tokencode;
097
098    public TObjectName objectName;
099
100    public long getLineNo() {
101        return lineNo;
102    }
103
104    public long getColumnNo() {
105        return columnNo;
106    }
107
108    public String getErrorMessage(){
109        return "Error: " + tokentext + " at line " + lineNo + ", column " + columnNo + ".";
110    }
111}