/******************************************************************************* * * Copyright 2010 Alexandru Craciun, and individual contributors as indicated * by the @authors tag. * * This is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 3 of * the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this software; if not, write to the Free * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA, or see the FSF site: http://www.fsf.org. ******************************************************************************/ /* Generated By:JJTree: Do not edit this line. ASTCellReference.java Version 4.3 */ /* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=false,TRACK_TOKENS=false,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ package org.netxilia.spi.impl.formula.parser; import org.netxilia.api.formula.IFormulaContext; import org.netxilia.api.formula.IFormulaRenderer; import org.netxilia.api.reference.AreaReference; import org.netxilia.api.reference.CellReference; import org.netxilia.api.value.IGenericValue; import org.netxilia.api.value.ReferenceValue; /** * An AST node representing a reference to another cell. */ public class ASTCellReference extends ASTBaseNode implements IReferenceNode { private AreaReference ref; public ASTCellReference(int id) { super(id); } public ASTCellReference(FormulaParser p, int id) { super(p, id); } private String removeQuotes(String name) { if (name.length() < 3) { return name; } if (name.charAt(0) == '\'') { return name.substring(1, name.length() - 1); } return name; } public void setRef(String sheetRef, String cellRef) { // ACR: ref contains trailing ! String cleanSheetRef = sheetRef; if (sheetRef != null && sheetRef.length() > 1) { cleanSheetRef = removeQuotes(sheetRef.substring(0, sheetRef.length() - 1)); } CellReference topLeft = new CellReference(cleanSheetRef, cellRef); ref = new AreaReference(topLeft, topLeft); } @Override public IGenericValue eval(IFormulaContext context) { return new ReferenceValue(getReference(context), context); } @Override public String text(IFormulaRenderer context) { return context.getCellText(ref.getTopLeft()); } @Override public String toString(String prefix, IFormulaContext context, IFormulaRenderer renderer) { return prefix + "CellReference[" + ref.getTopLeft() + "]=" + eval(context); } @Override public AreaReference getReference(IFormulaContext context) { return ref.withRelativeSheetName(context.getSheet().getName()); } } /* * JavaCC - OriginalChecksum=76e9b91dd772efbf82b5c5778dad2355 (do not edit this line) */