Here you can find the source of isSimplePropertyGet(PropertyGet pg, String expectedObj, String expectedField)
PropertyGet
is a simple one, referencing an object's value 1 level deep.
Parameter | Description |
---|---|
pg | The <code>PropertyGet</code>. |
expectedObj | The expected object value. |
expectedField | The expected string value. |
public static final boolean isSimplePropertyGet(PropertyGet pg, String expectedObj, String expectedField)
//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()); } }