Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
   *
   * This Source Code Form is subject to the terms of the Mozilla Public
   * License, v. 2.0. If a copy of the MPL was not distributed with this
   * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  
  package org.mozilla.javascript.ast;
  
AST node representing an expression in a statement context. The node type is org.mozilla.javascript.Token.EXPR_VOID if inside a function, or else org.mozilla.javascript.Token.EXPR_RESULT if inside a script.
 
 public class ExpressionStatement extends AstNode {
 
     private AstNode expr;
 
     {
          = .;
     }

    
Called by the parser to set node type to EXPR_RESULT if this node is not within a Function.
 
     public void setHasResult() {
          = .;
     }
 
     public ExpressionStatement() {
     }

    
Constructs a new ExpressionStatement wrapping the specified expression. Sets this node's position to the position of the wrapped node, and sets the wrapped node's position to zero. Sets this node's length to the length of the wrapped node.

Parameters:
expr the wrapped expression
hasResult true if this expression has side effects. If true, sets node type to EXPR_RESULT, else to EXPR_VOID.
 
     public ExpressionStatement(AstNode exprboolean hasResult) {
         this(expr);
         if (hasResultsetHasResult();
     }

    
Constructs a new ExpressionStatement wrapping the specified expression. Sets this node's position to the position of the wrapped node, and sets the wrapped node's position to zero. Sets this node's length to the length of the wrapped node.

Parameters:
expr the wrapped expression
 
     public ExpressionStatement(AstNode expr) {
         this(expr.getPosition(), expr.getLength(), expr);
     }
 
     public ExpressionStatement(int posint len) {
         super(poslen);
     }

    
Constructs a new ExpressionStatement

Parameters:
expr the wrapped AstNode. The ExpressionStatement's bounds are set to those of expr, and expr's parent is set to this node.
Throws:
java.lang.IllegalArgumentException if expr is null
 
     public ExpressionStatement(int posint lenAstNode expr) {
         super(poslen);
         setExpression(expr);
     }

    
Returns the wrapped expression
 
     public AstNode getExpression() {
         return ;
     }

    
Sets the wrapped expression, and sets its parent to this node.

Throws:
java.lang.IllegalArgumentException} if expression is null
 
     public void setExpression(AstNode expression) {
         assertNotNull(expression);
          = expression;
         expression.setParent(this);
         setLineno(expression.getLineno());
     }

    
Returns true if this node has side effects

Throws:
java.lang.IllegalStateException if expression has not yet been set.
    @Override
    public boolean hasSideEffects() {
        return  == . || .hasSideEffects();
    }
    @Override
    public String toSource(int depth) {
        StringBuilder sb = new StringBuilder();
        sb.append(.toSource(depth));
        sb.append(";\n");
        return sb.toString();
    }

    
Visits this node, then the wrapped statement.
    @Override
    public void visit(NodeVisitor v) {
        if (v.visit(this)) {
            .visit(v);
        }
    }
New to GrepCode? Check out our FAQ X