001/* ASTPtMethodCallNode represents method calls on other Tokens and functional
002 if-then else (?:) constructs.
003
004 Copyright (c) 1998-2014 The Regents of the University of California and
005 Research in Motion Limited.
006 All rights reserved.
007 Permission is hereby granted, without written agreement and without
008 license or royalty fees, to use, copy, modify, and distribute this
009 software and its documentation for any purpose, provided that the above
010 copyright notice and the following two paragraphs appear in all copies
011 of this software.
012
013 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA OR RESEARCH IN MOTION
014 LIMITED BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
015 INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS
016 SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA
017 OR RESEARCH IN MOTION LIMITED HAVE BEEN ADVISED OF THE POSSIBILITY OF
018 SUCH DAMAGE.
019
020 THE UNIVERSITY OF CALIFORNIA AND RESEARCH IN MOTION LIMITED
021 SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
022 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
023 PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
024 BASIS, AND THE UNIVERSITY OF CALIFORNIA AND RESEARCH IN MOTION
025 LIMITED HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
026 ENHANCEMENTS, OR MODIFICATIONS.
027
028
029 Created : May 1998
030
031 */
032package ptolemy.data.expr;
033
034import ptolemy.kernel.util.IllegalActionException;
035
036//////////////////////////////////////////////////////////////////////////
037//// ASTPtMethodCallNode
038
039/**
040 The parse tree created from the expression string consists of a
041 hierarchy of node objects. This class represents method call nodes
042 in the parse tree.
043 <p>
044 To allow extension of the parser capabilities without modifying
045 the kernel code, method calls on Tokens are supported with the following
046 syntax  (token).methodName(comma separated arguments).
047 <p>
048 Method arguments are processed as described in {@link
049 ASTPtFunctionApplicationNode}.  However, to allow element-by-element
050 method calls on ArrayTokens, the following sequence is followed here
051 to find a method to execute:
052 <ul>
053 <li>Look for a method with tokens as supplied by PtParser.</li>
054 <li>If that fails, convert all instances of ArrayToken to Token[] and
055 look again, element-by-element.</li>
056 <li>If that fails, convert all method arguments to their underlying java
057 types and try again.</li>
058 <li>Finally, if the above fails, convert the method object Token to
059 its underlying java type and try again.</li>
060 </ul>
061 <p>
062
063 @author Neil Smyth, University of California;
064 @author Zoltan Kemenczy, Research in Motion Limited
065 @version $Id$
066 @since Ptolemy II 0.2
067 @Pt.ProposedRating Yellow (nsmyth)
068 @Pt.AcceptedRating Red (cxh)
069 @see ptolemy.data.expr.ASTPtRootNode
070 @see ptolemy.data.expr.PtParser
071 @see ptolemy.data.Token
072 */
073public class ASTPtMethodCallNode extends ASTPtRootNode {
074    public ASTPtMethodCallNode(int id) {
075        super(id);
076    }
077
078    public ASTPtMethodCallNode(PtParser p, int id) {
079        super(p, id);
080    }
081
082    /** Return the name of the method invoked by this node.
083     *  @return the name of the method invoked by this node.
084     */
085    public String getMethodName() {
086        return _methodName;
087    }
088
089    @Override
090    public void jjtClose() {
091        super.jjtClose();
092
093        // We cannot assume anything about a method call.
094        _isConstant = false;
095    }
096
097    /** Traverse this node with the given visitor.
098     */
099    @Override
100    public void visit(ParseTreeVisitor visitor) throws IllegalActionException {
101        visitor.visitMethodCallNode(this);
102    }
103
104    /** Need to store the method name of the method call.
105     */
106    protected String _methodName;
107}