Java Javascript Mozilla Library isSimplePropertyGet(PropertyGet pg, String expectedObj, String expectedField)

Here you can find the source of isSimplePropertyGet(PropertyGet pg, String expectedObj, String expectedField)

Description

Returns whether a PropertyGet is a simple one, referencing an object's value 1 level deep.

License

BSD License

Parameter

Parameter Description
pg The <code>PropertyGet</code>.
expectedObj The expected object value.
expectedField The expected string value.

Return

Whether the object is what was expected.

Declaration

public static final boolean isSimplePropertyGet(PropertyGet pg, String expectedObj, String expectedField) 

Method Source Code

//package com.java2s;
/*/*from w  w w. j ava  2  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.PropertyGet;

public class Main {
    /**
     * Returns whether a <code>PropertyGet</code> is a simple one, referencing
     * an object's value 1 level deep.  For example, <code>Object.create</code>.
     *
     * @param pg The <code>PropertyGet</code>.
     * @param expectedObj The expected object value.
     * @param expectedField The expected string value.
     * @return Whether the object is what was expected.
     */
    public static final boolean isSimplePropertyGet(PropertyGet pg, String expectedObj, String expectedField) {
        return pg != null && isName(pg.getLeft(), expectedObj) && isName(pg.getRight(), expectedField);
    }

    /**
     * Returns whether an AST node is a <code>Name</code> with the specified
     * value.
     *
     * @param node The AST node.
     * @param value The expected value.
     * @return Whether the AST node is a <code>Name</code> with the specified
     *         value.
     */
    private static final boolean isName(AstNode node, String value) {
        return node instanceof Name && value.equals(((Name) node).getIdentifier());
    }
}

Related

  1. isDefined(final Object object)
  2. isName(AstNode node, String value)
  3. isNullNativeObject(Object val)
  4. isPrototypeNameNode(AstNode node)
  5. isPrototypePropertyGet(PropertyGet pg)
  6. isStaticProperty(Scriptable property)
  7. isValid(Object[] args)
  8. isVariable(Name name)
  9. javaToJS(Object o, Scriptable scope)