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 keyword literals: currently, this, null, true, false, and debugger. Node type is one of org.mozilla.javascript.Token.THIS, org.mozilla.javascript.Token.NULL, org.mozilla.javascript.Token.TRUE, org.mozilla.javascript.Token.FALSE, or org.mozilla.javascript.Token.DEBUGGER.
 
 public class KeywordLiteral extends AstNode {
 
     public KeywordLiteral() {
     }
 
     public KeywordLiteral(int pos) {
         super(pos);
     }
 
     public KeywordLiteral(int posint len) {
         super(poslen);
     }

    
Constructs a new KeywordLiteral

Parameters:
nodeType the token type
 
     public KeywordLiteral(int posint lenint nodeType) {
         super(poslen);
         setType(nodeType);
     }

    
Sets node token type

Throws:
java.lang.IllegalArgumentException if nodeType is unsupported
 
     @Override
     public KeywordLiteral setType(int nodeType) {
         if (!(nodeType == .
               || nodeType == .
               || nodeType == .
               || nodeType == .
               || nodeType == .))
             throw new IllegalArgumentException("Invalid node type: "
                                                + nodeType);
          = nodeType;
         return this;
     }

    
 
     public boolean isBooleanLiteral() {
         return  == . ||  == .;
     }
 
     @Override
     public String toSource(int depth) {
         StringBuilder sb = new StringBuilder();
         sb.append(makeIndent(depth));
         switch (getType()) {
         case .:
             sb.append("this");
             break;
         case .:
             sb.append("null");
             break;
         case .:
             sb.append("true");
             break;
         case .:
             sb.append("false");
             break;
         case .:
             sb.append("debugger;\n");
             break;
         default:
             throw new IllegalStateException("Invalid keyword literal type: "
                                             + getType());
         }
         return sb.toString();
     }

    
Visits this node. There are no children to visit.
 
     @Override
     public void visit(NodeVisitor v) {
        v.visit(this);
    }
New to GrepCode? Check out our FAQ X