package com.drawbridge.jsengine.ast; import java.util.LinkedList; import com.drawbridge.jsengine.Scope; import com.drawbridge.jsengine.jsobjects.JSReference; import com.drawbridge.jsengine.jsobjects.JSType; import com.drawbridge.vl.blocks.BlockIdentifier; import com.google.caja.parser.js.Identifier; import com.google.caja.parser.js.Reference; public class ReferenceEvaluator extends Evaluator { /* * An expression that evaluates to the value associated with the property of * the same name in either the current scope chain, or the object to the * left of a dot-operator. */ private Identifier identifier; public ReferenceEvaluator(Evaluator parent, Scope scope, Reference reference) { super(parent, scope, reference.getFilePosition()); identifier = reference.getIdentifier(); } @Override public JSType evaluate() throws EvaluatorException { JSReference result = new JSReference(identifier.getValue()); return result; } @Override public LinkedList<com.drawbridge.vl.blocks.Block> getBlocks() { LinkedList<com.drawbridge.vl.blocks.Block> results = new LinkedList<com.drawbridge.vl.blocks.Block>(); results.add(new BlockIdentifier(getFilePosition(), this, identifier.getName())); return results; } public Identifier getIdentifier() { return identifier; } @Override public boolean compare(Evaluator e) { if (!e.getClass().equals(getClass())) return false; ReferenceEvaluator re = (ReferenceEvaluator) e; if (identifier.getValue().equals(re.identifier.getValue()) && e.getFilePosition().equals(getFilePosition())) return true; else return false; } }