001package gudusoft.gsqlparser.nodes;
002
003import java.util.ArrayList;
004
005/**
006 * An object access expression specifies attribute reference and method invocation.
007 * <p> Syntax:
008 * objectExpr.[attribute|method()]+
009 * <br>
010 * objectExpr can be a qualified name or function call or expression or subquery:
011 * <ul>
012 *     </li>qualified name: column</li>
013 *     </li>qualified name: table.column</li>
014 *     </li>function call: function()</li>
015 *     </li>subquery: (subquery)</li>
016 *</ul>
017 *
018 * If the objectExpr is in the following format, then it the raw format from the parser and need to be converted to
019 * the format which is syntax compliant. (TODO: need to provide the conversion method)
020 *<ul>
021 *     </li>qualified name: column1.method(), method() need to be moved to {@link #attributeOrMethods}</li>
022 *     </li>qualified name: part1.part2.method(), if part1 is a table, then part2 is a column. Otherwise, if part1 is a column, then part2 is an attribute</li>
023 *     </li>qualified name: part1.part2.part3.method(), if part1 is a table, then part2 is a column, part3 is an attribute. Otherwise, if part1 is a column, then part2, part3 are attributes</li>
024 *     </li>qualified name: part1.part2.[part3]+.method(), if part1 is a table, then part2 is a column, part3 is an attribute. Otherwise, if part1 is a column, then part2, part3 are attributes</li>
025 *</ul>
026 */
027
028public class TObjectAccess extends TParseTreeNode {
029
030    private TExpression objectExpr;
031    /**
032     * @deprecated since v3.0.1.6, use {@link #attributeOrMethods} instead.
033     */
034    private TFunctionCall method;
035
036    /**
037     * @deprecated since v3.0.1.6, use {@link #attributeOrMethods} instead.
038     */
039    private TObjectNameList attributes;
040
041    private ArrayList<TAttributeOrMethod> attributeOrMethods = null;
042
043    public TObjectNameList getAttributes() {
044        return attributes;
045    }
046
047    public TFunctionCall getMethod() {
048        return method;
049    }
050
051    public TExpression getObjectExpr() {
052        return objectExpr;
053    }
054
055
056    public ArrayList<TAttributeOrMethod> getAttributeOrMethods() {
057        return attributeOrMethods;
058    }
059
060    public void init(Object arg1, Object arg2){
061        objectExpr = (TExpression)arg1;
062        attributeOrMethods = (ArrayList<TAttributeOrMethod>)arg2;
063    }
064
065    public void init(Object arg1,Object arg2, Object arg3){
066        objectExpr = (TExpression)arg1;
067        attributes = (TObjectNameList)arg2;
068        method = (TFunctionCall)arg3;
069    }
070
071    public void setObjectExpr(TExpression objectExpr) {
072        this.objectExpr = objectExpr;
073    }
074
075    public void setMethod(TFunctionCall method) {
076        this.method = method;
077    }
078
079    public void setAttributes(TObjectNameList attributes) {
080        this.attributes = attributes;
081    }
082
083    public void accept(TParseTreeVisitor v){
084        v.preVisit(this);
085        v.postVisit(this);
086    }
087    public void acceptChildren(TParseTreeVisitor v){
088        v.preVisit(this);
089        v.postVisit(this);
090    }
091}