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 for a single name:value entry in an Object literal. For simple entries, the node type is org.mozilla.javascript.Token.COLON, and the name (left side expression) is either a Name, a StringLiteral or a NumberLiteral.

This node type is also used for getter/setter properties in object literals. In this case the node bounds include the "get" or "set" keyword. The left-hand expression in this case is always a Name, and the overall node type is org.mozilla.javascript.Token.GET or org.mozilla.javascript.Token.SET, as appropriate.

The operatorPosition field is meaningless if the node is a getter or setter.

ObjectProperty :
       PropertyName : AssignmentExpression
 PropertyName :
       Identifier
       StringLiteral
       NumberLiteral
 
 public class ObjectProperty extends InfixExpression {
 
     {
          = .;
     }

    
 
     public void setNodeType(int nodeType) {
         if (nodeType != .
             && nodeType != .
             && nodeType != .)
             throw new IllegalArgumentException("invalid node type: "
                                                + nodeType);
         setType(nodeType);
     }
 
     public ObjectProperty() {
     }
 
     public ObjectProperty(int pos) {
         super(pos);
     }
 
     public ObjectProperty(int posint len) {
         super(poslen);
     }

    
Marks this node as a "getter" property.
 
     public void setIsGetter() {
          = .;
     }

    
Returns true if this is a getter function.
 
     public boolean isGetter() {
         return  == .;
     }

    
Marks this node as a "setter" property.
 
     public void setIsSetter() {
          = .;
     }

    
Returns true if this is a setter function.
 
     public boolean isSetter() {
         return  == .;
     }
 
     @Override
     public String toSource(int depth) {
         StringBuilder sb = new StringBuilder();
         sb.append("\n");
         sb.append(makeIndent(depth+1));
         if (isGetter()) {
             sb.append("get ");
         } else if (isSetter()) {
            sb.append("set ");
        }
        sb.append(.toSource(getType()==. ? 0 : depth));
        if ( == .) {
            sb.append(": ");
        }
        sb.append(.toSource(getType()==. ? 0 : depth+1));
        return sb.toString();
    }
New to GrepCode? Check out our FAQ X