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;
 
New expression. Node type is org.mozilla.javascript.Token.NEW.

NewExpression :
      MemberExpression
      new NewExpression
This node is a subtype of FunctionCall, mostly for internal code sharing. Structurally a NewExpression node is very similar to a FunctionCall, so it made a certain amount of sense.
public class NewExpression extends FunctionCall {
    private ObjectLiteral initializer;
    {
         = .;
    }
    public NewExpression() {
    }
    public NewExpression(int pos) {
        super(pos);
    }
    public NewExpression(int posint len) {
        super(poslen);
    }

    
Returns initializer object, if any.

Returns:
extra initializer object-literal expression, or null if not specified.
    public ObjectLiteral getInitializer() {
      return ;
    }

    
Sets initializer object. Rhino supports an experimental syntax of the form new expr [ ( arglist ) ] [initializer], in which initializer is an object literal that is used to set additional properties on the newly-created expr object.

Parameters:
initializer extra initializer object. Can be null.
    public void setInitializer(ObjectLiteral initializer) {
      this. = initializer;
      if (initializer != null)
          initializer.setParent(this);
    }
    @Override
    public String toSource(int depth) {
        StringBuilder sb = new StringBuilder();
        sb.append(makeIndent(depth));
        sb.append("new ");
        sb.append(.toSource(0));
        sb.append("(");
        if ( != null) {
            printList(sb);
        }
        sb.append(")");
        if ( != null) {
            sb.append(" ");
            sb.append(.toSource(0));
        }
        return sb.toString();
    }

    
Visits this node, the target, and each argument. If there is a trailing initializer node, visits that last.
    @Override
    public void visit(NodeVisitor v) {
        if (v.visit(this)) {
            .visit(v);
            for (AstNode arg : getArguments()) {
                arg.visit(v);
            }
            if ( != null) {
                .visit(v);
            }
        }
    }
New to GrepCode? Check out our FAQ X