Exemple #1
0
  /**
   * @return <code>false</code> if sub-expression represented the specified ParseNode definitely
   *     cannot appear on either side of the range (':') operator
   */
  private static boolean isValidRangeOperand(ParseNode a) {
    Ptg tkn = a.getToken();
    // Note - order is important for these instance-of checks
    if (tkn instanceof OperandPtg) {
      // notably cell refs and area refs
      return true;
    }

    // next 2 are special cases of OperationPtg
    if (tkn instanceof AbstractFunctionPtg) {
      AbstractFunctionPtg afp = (AbstractFunctionPtg) tkn;
      byte returnClass = afp.getDefaultOperandClass();
      return Ptg.CLASS_REF == returnClass;
    }
    if (tkn instanceof ValueOperatorPtg) {
      return false;
    }
    if (tkn instanceof OperationPtg) {
      return true;
    }

    // one special case of ControlPtg
    if (tkn instanceof ParenthesisPtg) {
      // parenthesis Ptg should have only one child
      return isValidRangeOperand(a.getChildren()[0]);
    }

    // one special case of ScalarConstantPtg
    if (tkn == ErrPtg.REF_INVALID) {
      return true;
    }

    // All other ControlPtgs and ScalarConstantPtgs cannot be used with ':'
    return false;
  }
Exemple #2
0
  /**
   * From OOO doc: "Whenever one operand of the reference subexpression is a function, a defined
   * name, a 3D reference, or an external reference (and no error occurs), a tMemFunc token is used"
   */
  private static boolean needsMemFunc(ParseNode root) {
    Ptg token = root.getToken();
    if (token instanceof AbstractFunctionPtg) {
      return true;
    }
    if (token instanceof ExternSheetReferenceToken) { // 3D refs
      return true;
    }
    if (token instanceof NamePtg || token instanceof NameXPtg) { // 3D refs
      return true;
    }

    if (token instanceof OperationPtg || token instanceof ParenthesisPtg) {
      // expect RangePtg, but perhaps also UnionPtg, IntersectionPtg etc
      for (ParseNode child : root.getChildren()) {
        if (needsMemFunc(child)) {
          return true;
        }
      }
      return false;
    }
    if (token instanceof OperandPtg) {
      return false;
    }
    if (token instanceof OperationPtg) {
      return true;
    }

    return false;
  }