Package org.openntf.formula.ast

Source Code of org.openntf.formula.ast.ASTAtFocEval

/* Generated By:JJTree: Do not edit this line. ASTAtFocEval.java Version 4.3 */
/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=true,VISITOR=false,TRACK_TOKENS=false,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
/*
* © Copyright FOCONIS AG, 2014
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
*/
package org.openntf.formula.ast;

import java.util.Set;

import org.openntf.formula.EvaluateException;
import org.openntf.formula.FormulaContext;
import org.openntf.formula.FormulaParseException;
import org.openntf.formula.FormulaReturnException;
import org.openntf.formula.ValueHolder;
import org.openntf.formula.ValueHolder.DataType;
import org.openntf.formula.parse.AtFormulaParserImpl;

public class ASTAtFocEval extends SimpleNode {

  public ASTAtFocEval(final AtFormulaParserImpl p, final int id) {
    super(p, id);
  }

  /**
   * Evaluates every entry and returns the last one
   */
  @Override
  public ValueHolder evaluate(final FormulaContext ctx) throws FormulaReturnException {
    ValueHolder vhEval = children[0].evaluate(ctx);
    if (vhEval.dataType == DataType.ERROR)
      return vhEval;

    ValueHolder ret[] = new ValueHolder[vhEval.size];
    int size = 0;
    try {
      for (int i = 0; i < vhEval.size; i++) {
        String toEval = vhEval.getString(i);

        Node n = (Node) ctx.getParser().parse(toEval, true);
        ValueHolder vh = ret[i] = n.evaluate(ctx);

        if (vh.dataType == DataType.ERROR)
          return ret[i];

        size += vh.size;
      }
      ValueHolder vh = ret[0].newInstance(size);
      for (int i = 0; i < vhEval.size; i++) {
        vh.addAll(ret[i]);
      }
      return vh;

    } catch (FormulaParseException e) {
      return ValueHolder.valueOf(new EvaluateException(codeLine, codeColumn, e));
    }
  }

  /*
   * (non-Javadoc)
   * @see org.openntf.formula.ast.SimpleNode#analyzeThis(java.util.Set, java.util.Set, java.util.Set, java.util.Set)
   */
  @Override
  protected void analyzeThis(final Set<String> readFields, final Set<String> modifiedFields, final Set<String> variables,
      final Set<String> functions) {
    functions.add("@foceval");
  }
}
/* JavaCC - OriginalChecksum=5fefeb9d8f5f65f21bd54ddbf22000c8 (do not edit this line) */ 
TOP

Related Classes of org.openntf.formula.ast.ASTAtFocEval

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.