/**
  * Constructor.
  *
  * @param pTree  The tree node representing an array element access.
  * @param pTokenRewriteStream  The token stream the token of the stated
  *                             tree node belongs to.
  */
 public AST2ArrayElementAccess(AST2JSOMTree pTree, TokenRewriteStream pTokenRewriteStream)
     : base(pTree, ExpressionType.ARRAY_ELEMENT_ACCESS, pTokenRewriteStream)
 {
     if (pTree.Type != JavaTreeParser.ARRAY_ELEMENT_ACCESS) {
     throw new ArgumentException(
             CommonErrorMessages.getInvalidArgumentValueMessage(
                     "pTree.Type == " + pTree.Type, "pTree"));
     }
     mArrayAccess = AST2Expression.resolvePrimaryExpression((AST2JSOMTree)
         getTreeNode().GetChild(0), getTokenRewriteStream());
     mOffset = AST2Expression.resolveExpression((AST2JSOMTree)
         getTreeNode().GetChild(1), getTokenRewriteStream());
     // Resolve the identifier of the array if the array is accessed via its
     // identifier at all.
     if (mArrayAccess.isExpressionType(ExpressionType.IDENTIFIER)) {
     mIdentifierNode = (AST2JSOMTree)mArrayAccess.getTreeNode();
     } else if (mArrayAccess.isExpressionType(
         ExpressionType.DOT_EXPRESSION)) {
             AST2PrimaryExpression rightExpression = (AST2PrimaryExpression)
         ((AST2DotExpression) mArrayAccess).getRightExpression();
     if (rightExpression.isExpressionType(ExpressionType.IDENTIFIER)) {
         mIdentifierNode = (AST2JSOMTree)rightExpression.getTreeNode();
     }
     }
 }
Esempio n. 2
0
        /**
         * Returns the expression from the dot's left side.
         * <p>
         * Note that for dot expressions of type <code>PRIMITIVE_TYPE_DOT_CLASS
         * </code> the left side of the dot is a primitive type and this is not an
         * expression. Therefore this method will always return <code>null</code>
         * for that dot expression type.
         *
         * @see  DotExpression#getPrimitiveTypeFromLeft()
         *
         * @return The expression from the dot's left side or <code>null</code> for
         *         dot expressions of type <code>PRIMITIVE_TYPE_DOT_CLASS</code>.
         */
        public PrimaryExpression getLeftExpression()
        {
            if (mDotExprType == DotExprType.PRIMITIVE_TYPE_DOT_CLASS) {
            return null; // Nothing to return for 'DOTEXPR_TYPE_2'
            }
            if (mLeftExpr == null) {
            if (mDotExprType != DotExprType.VOID_DOT_CLASS) {
                mLeftExpr = AST2Expression.resolvePrimaryExpression((AST2JSOMTree)
                        getTreeNode().GetChild(0), getTokenRewriteStream());
            } else {
                mLeftExpr = new AST2PrimaryExpressionKeyword((AST2JSOMTree)
                        getTreeNode().GetChild(0), getTokenRewriteStream());
            }
            }

            return mLeftExpr;
        }
Esempio n. 3
0
        /**
         * Returns the expression from the dot's right side.
         *
         * @return The expression from the dot's right side.
         */
        public PrimaryExpression getRightExpression()
        {
            if (mRightExpr == null) {
            AST2JSOMTree tree = (AST2JSOMTree)getTreeNode().GetChild(1);
            if (   mDotExprType == DotExprType.DOTEXPR_TYPE_1_VARIANTS
                && tree.Type != JavaTreeParser.CLASS) {
                mRightExpr = AST2Expression.resolvePrimaryExpression(
                        tree, getTokenRewriteStream());
            } else {
                mRightExpr = new AST2PrimaryExpressionKeyword(
                        tree, getTokenRewriteStream());
            }
            }

            return mRightExpr;
        }
Esempio n. 4
0
        /**
         * Returns the method invocation.
         * <p>
         * Such an invocation is a more or less complicated primary expression
         * ending with the methods identifier. A formal example could look like:
         * <pre>
         *     anyPrimaryExpression.anyMethodCall(...).anotherMethodCall(...)
         * </pre>.
         * Calling this method for the example above the primary expression
         * representing <code>
         * 'anyPrimaryExpression.anyMethodCall(...).anotherMethodCall'</code> would
         * be returned.
         * <p>
         * The most trivial primary expression would be the method's identifier, of
         * course.
         *
         * @see #getIdentifier()
         *
         * @return  The method invocation.
         */
        public PrimaryExpression getMethodInvocation()
        {
            if (mMethodInvocation == null) {
            mMethodInvocation = AST2Expression.resolvePrimaryExpression((AST2JSOMTree)
                    getTreeNode().GetChild(0), getTokenRewriteStream());
            }

            return mMethodInvocation;
        }