package com.drawbridge.jsengine.ast; import java.util.LinkedList; import com.drawbridge.jsengine.Scope; import com.drawbridge.jsengine.SymbolTable.SymbolTableException; import com.drawbridge.jsengine.jsobjects.JSType; import com.drawbridge.utils.Utils; import com.drawbridge.vl.blocks.BlockIdentifier; import com.google.caja.parser.js.Identifier; public class IdentifierEvaluator extends Evaluator { String name; public IdentifierEvaluator(Evaluator parent, Scope scope, Identifier identifier) { super(parent, scope, identifier.getFilePosition()); name = identifier.getName(); Utils.out.println(this.getClass(), "I'm an identifier (named " + identifier.getName() + " evaluator and I don't know what to do!"); } @Override public JSType evaluate() throws EvaluatorException { try { return mScope.getSymbolTable().get(name).getVariable(); } catch (SymbolTableException e) { throw new EvaluatorException("IdentifierEvaluator exception: " + e.getMessage()); } } @Override public LinkedList<com.drawbridge.vl.blocks.Block> getBlocks() { LinkedList<com.drawbridge.vl.blocks.Block> results = new LinkedList<com.drawbridge.vl.blocks.Block>(); BlockIdentifier ib = new BlockIdentifier(getFilePosition(), this, name); results.add(ib); return results; } @Override public boolean compare(Evaluator e) { if (!e.getClass().equals(getClass())) return false; IdentifierEvaluator ie = (IdentifierEvaluator) e; if (name.equals(ie.name) && e.getFilePosition().equals(getFilePosition())) return true; else return false; } }