Java Javascript Mozilla Library getPropertyName(AstNode propKeyNode)

Here you can find the source of getPropertyName(AstNode propKeyNode)

Description

Property keys in object literals can be identifiers or string literals.

License

BSD License

Parameter

Parameter Description
propKeyNode The AST node for the property key.

Return

The property key's value.

Declaration

public static final String getPropertyName(AstNode propKeyNode) 

Method Source Code

//package com.java2s;
/*/*w w  w .  ja va2 s.c o m*/
 * 06/05/2014
 *
 * Copyright (C) 2014 Robert Futrell
 * robert_futrell at users.sourceforge.net
 * http://fifesoft.com/rsyntaxtextarea
 *
 * This library is distributed under a modified BSD license.  See the included
 * RSTALanguageSupport.License.txt file for details.
 */

import org.mozilla.javascript.ast.AstNode;

import org.mozilla.javascript.ast.Name;

import org.mozilla.javascript.ast.StringLiteral;

public class Main {
    /**
     * Property keys in object literals can be identifiers or string literals.
     * This method takes an AST node that was the key of an
     * <code>ObjectProperty</code> and returns its value, no matter what the
     * concrete AST node's type.
     *
     * @param propKeyNode The AST node for the property key.
     * @return The property key's value.
     */
    public static final String getPropertyName(AstNode propKeyNode) {
        // TODO: Does Rhino use any other node type for this?
        return (propKeyNode instanceof Name) ? ((Name) propKeyNode).getIdentifier()
                : ((StringLiteral) propKeyNode).getValue();
    }
}

Related

  1. getJavaObject(Scriptable scope, String name)
  2. getJsArray(Scriptable scope, Vector v)
  3. getMapArgument(Object[] args, int pos)
  4. getObjectArgument(Object[] args, int pos, Object defaultValue)
  5. getProperty(Scriptable obj, final String prop)
  6. getPrototypeClazz(List nodes)
  7. getScriptableArgument(Object[] args, int pos, boolean allowNull)
  8. getStaticProperty(Scriptable mixin, String name)
  9. getStringArgument(Object[] args, int pos, boolean allowNull)